#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/edit - ask user for edit # # Creation : 2003-07-19 fm # Last Update: $Id$ # # Copyright (c) 2001-2009 the eisfair team, team@eisfair(dot)org # # usage: edit [-apply|-apply-stopstart] file # edit [-apply|-apply-stopstart] package message # # return values: # 0 editor started # 1 editor not started # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib # include function library . /var/install/bin/config_shlib # include configuration . /etc/config.d/setup apply='' if [ "$1" = "-apply" ] then apply='restart' shift elif [ "$1" = "-apply-stopstart" ] then apply='stopstart' shift fi if [ $# -eq 1 ] then package=`basename $1` configdir=`dirname $1` else package="$1" configdir='/etc/config.d' clrhome mecho -info "$2" echo fi # if EDITOR is set, try to add path [ "$EDITOR" = "" ] && EDITOR='joe' [ "$EDITOR_FALLBACK" = "" ] && EDITOR_FALLBACK='joe' editor="`echo "$EDITOR_FALLBACK" | cut -d' ' -f1`" editor_param="`echo "$EDITOR_FALLBACK" | cut -d' ' -f2-`" [ "$editor" = "$editor_param" ] && editor_param='' if [ "$editor" != "" ] && [ ! -x "$editor" ] then if [ -x "/var/install/bin/$editor" ] then EDITOR_FALLBACK="/var/install/bin/$editor $editor_param" elif which $editor >/dev/null 2>/dev/null then EDITOR_FALLBACK="`which $editor` $editor_param" else EDITOR_FALLBACK="`which joe`" fi fi editor="`echo "$EDITOR" | cut -d' ' -f1`" editor_param="`echo "$EDITOR" | cut -d' ' -f2-`" [ "$editor" = "$editor_param" ] && editor_param='' if [ "$editor" != "" ] && [ ! -x "$editor" ] then if [ -x "/var/install/bin/$editor" ] then EDITOR="/var/install/bin/$editor $editor_param" elif which $editor >/dev/null 2>/dev/null then EDITOR="`which $editor` $editor_param" else EDITOR="$EDITOR_FALLBACK" fi fi exitval=0 # edit first package... current_package=`echo $package | sed -e 's/ .*$//g'` if [ -f $configdir/$current_package ] then editor="$EDITOR_FALLBACK" param='' editor_pgm=`echo $EDITOR | cut -d' ' -f1` dirname=`dirname $editor_pgm` if [ "$dirname" = "/var/install/bin" ] then if $EDITOR --check $configdir/$current_package then editor="$EDITOR" else echo anykey echo mecho "The configuration of this package can't be opened by the config" mecho "editor currently setup on your system. This may be due to some" mecho "inconsistent config files or options." mecho "You can now edit the configuration manually using editor $editor." echo fi else editor="$EDITOR" echo mecho "There is no configuration editor for the EIS/FAIR console configured" mecho "on your system. Alternatively you can edit the configuration manually" mecho "using editor $editor." echo fi editor_pgm=`echo $editor | cut -d' ' -f1` basename=`basename $editor_pgm` if [ "$basename" = "joe" ] then mecho "You can get help by joe if you press 'Ctrl-K H'." mecho param="-nobackups" elif [ "$basename" = "vi" -o "$basename" = "vim" ] then mecho "You can get help by vi/vim if you enter ':help'." mecho fi dirname=`dirname $editor_pgm` if [ "$dirname" != "/var/install/bin" ] then /var/install/bin/ask "Continue" "yes" > /tmp/ask.$$ rc=${?} a=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ # if ask break, ask returned 255 if [ ${rc} = 255 ] then a=no fi if [ "${a}" != "yes" ] then exit 1 fi fi old_umask=`umask` umask 077 # do not allow anybody to read anything # config or logfile may contain secret passwords # delete old tmpfile first, if exists ;-) rm -f /tmp/edit-${current_package}-* # create tmpfile name, # do not change this name, # many programs get the old config settings from it, # to compare the value tmp_edit_file=/tmp/edit-${current_package}-$$ # copy to tmpfile cp -p $configdir/$current_package ${tmp_edit_file} while [ 1 ] do $editor $param $configdir/$current_package if [ -f /usr/local/bin/eischk -a -f /etc/check.d/$current_package ] then mecho -info "Checking configuration file ..." mecho if [ "$current_package" = "environment" ] then eischk_weak='--weak' else eischk_weak='' fi if ! /usr/local/bin/eischk $eischk_weak \ --config /etc/config.d \ --check /etc/check.d \ --log /tmp/$current_package.log \ --package $current_package then /var/install/bin/ask "Edit configuration again" "yes" > /tmp/ask.$$ rc=${?} a=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ # if ask break, ask returned 255 if [ ${rc} = 255 ] then a=no fi if [ "${a}" != "yes" ] then exitval=1 break fi else break fi else break fi done # config_shlib has owne handling umask $old_umask if [ "$exitval" -eq 0 ] then if ! diff ${tmp_edit_file} $configdir/$current_package >/dev/null then backup_config $current_package ${tmp_edit_file} fi fi rm -f /tmp/$current_package.log fi # call apply-script if exists apply_script () { if [ -f /var/install/config.d/$1.sh ] then sh /var/install/config.d/$1.sh else return 0 fi rm -f ${tmp_edit_file} } # call init-script if exists init_script () { if [ -f /etc/init.d/$1 ] then sh /etc/init.d/$1 $2 fi } # can start package can_start () { # read configuration file . /etc/config.d/${1} # change also '-' to '_', many packages use a '-' in the name, # like package-dev and START_PACKAGE-DEV does not work :-( startvar=`echo START_${1} | tr 'a-z' 'A-Z' | tr '-' '_'` eval start='$'${startvar} test "${start}" = "yes" } if [ $exitval -eq 0 -a "$apply" != "" ] then echo if [ "$package" = "base" -o "$package" = "environment" ] then if apply_script $package then init_script $package restart fi else /var/install/bin/ask "Activate configuration now" "yes" > /tmp/ask.$$ rc=${?} a=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ # if ask break, ask returned 255 if [ ${rc} = 255 ] then a=no rm -f ${tmp_edit_file} fi if [ "${a}" = "yes" ] then # activate changes for current_package in $package do if [ "$apply" = "restart" ] then if apply_script $current_package && can_start $current_package then # restart package init_script $current_package restart else # stop package init_script $current_package stop fi elif [ "$apply" = "stopstart" ] then init_script $current_package stop if apply_script $current_package && can_start $current_package then init_script $current_package start fi fi done fi fi anykey fi # do it twice ;-) rm -f ${tmp_edit_file} exit $exitval