#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/edit - ask user for edit # # Copyright (c) 2003-2004 Frank Meyer # # Creation: 19.07.2003 fm # Last Update: $Id$ # # 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" mecho 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 # loop all given packages... for current_package in $package do if [ -f $configdir/$current_package ] then editor="$EDITOR_FALLBACK" param='' dirname=`dirname $EDITOR` if [ "$dirname" = "/var/install/bin" ] then if $EDITOR --check $configdir/$current_package then editor="$EDITOR" else mecho anykey mecho 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." mecho fi else editor="$EDITOR" mecho 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." mecho fi basename=`basename $editor` 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` if [ "$dirname" != "/var/install/bin" ] then if ! /var/install/bin/ask "Continue" "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 cp -p $configdir/$current_package /tmp/edit-$$ 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 ! /usr/local/bin/eischk -c /etc/config.d \ -x /etc/check.d \ -l /tmp/$current_package.log \ -p $current_package then if ! /var/install/bin/ask "Edit configuration again" "yes" then exitval=1 break fi else break fi else break fi done umask $old_umask if ! diff /tmp/edit-$$ $configdir/$current_package >/dev/null then backup_config $current_package /tmp/edit-$$ fi rm -f /tmp/edit-$$ rm -f /tmp/$current_package.log fi done if [ $exitval -eq 0 -a "$apply" != "" ] then mecho if /var/install/bin/ask "Activate configuration now" "yes" then # activate changes for current_package in $package do if [ -f /var/install/config.d/$current_package.sh -a -f /etc/init.d/$current_package ] then # we have both an apply- and an init.d script if [ "$apply" = "restart" ] then if sh /var/install/config.d/$current_package.sh then sh /etc/init.d/$current_package restart fi elif [ "$apply" = "stopstart" ] then sh /etc/init.d/$current_package stop sh /var/install/config.d/$current_package.sh sh /etc/init.d/$current_package start fi elif [ -f /var/install/config.d/$current_package.sh ] then # we only have an apply-script sh /var/install/config.d/$current_package.sh fi done fi anykey fi exit $exitval