#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/nginx_fileedit - ask user to edit a file # # Creation : 2003-07-19 fm # 2015-04-30 ap # Last Update: $Id$ # # Copyright (c) 2001-2022 the eisfair team, team@eisfair(dot)org # # usage: nginx_fileedit file # # 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. #---------------------------------------------------------------------------- # --------------------------------------------------------------------------- # verify file # --------------------------------------------------------------------------- verify_file () { # return # 0 file exists and is a regular (empty) file # 1 file does not exist # 2 file exists but is NOT a regular (empty) file # 127 /usr/bin/stat missing # ? other error check_file="$1" stat='/usr/bin/stat' # stat check_file file_type=$(LANG=C $stat --format='%F' $check_file 2>/dev/null) rc=$? # only if file exists if [ "$rc" = 0 ] then # check file_type, default wrong file_type rc=2 [ "$file_type" = 'regular file' ] && rc=0 [ "$file_type" = 'regular empty file' ] && rc=0 fi return $rc } UNUSABLE_EDITOR='/var/install/bin/edit-conf.cui' WHICH='/usr/bin/which' # include eislib . /var/install/include/eislib # include configuration . /etc/config.d/setup #Test . ./setup if [ $# -eq 1 ] then act_file="$1" else clrhome mecho --error "No filename given" echo exit 1 fi # check for unusable Editor [ "$EDITOR" = "$UNUSABLE_EDITOR" ] && EDITOR='' [ "$EDITOR_FALLBACK" = "$UNUSABLE_EDITOR" ] && EDITOR_FALLBACK='' if [ "$EDITOR" = '' ] && [ "$EDITOR_FALLBACK" = '' ] then mecho --info "No usable editor found" mecho --info "EDITOR was set to 'joe'" EDITOR='joe' EDITOR_FALLBACK='joe' anykey fi # if EDITOR is set, try to add path editor="`echo "$EDITOR" | cut -d' ' -f1`" editor_param="`echo "$EDITOR" | cut -d' ' -f2-`" [ "$editor" = "$editor_param" ] && editor_param='' if ${WHICH} $editor >/dev/null 2>/dev/null then editor="`${WHICH} $editor`" fi if [ "$editor" = "" ] || [ ! -x "$editor" ] then # EDITOR is empty or not executable EDITOR="$EDITOR_FALLBACK" editor="`echo "$EDITOR" | cut -d' ' -f1`" editor_param="`echo "$EDITOR" | cut -d' ' -f2-`" [ "$editor" = "$editor_param" ] && editor_param='' if ${WHICH} $editor >/dev/null 2>/dev/null then editor="`${WHICH} $editor`" fi if [ "$editor" = "" ] || [ ! -x "$editor" ] then mecho --error "No usable editor found" anykey exit 1 fi fi editor="$editor $editor_param" #echo "Using $editor" #anykey # check act_file verify_file "$act_file" rc=$? if [ "$rc" = 1 ] then mecho "File $act_file does not exist" #anykey rc=0 fi if [ "$rc" = 2 ] then mecho --error "File $act_file is not a regular file" mecho --error "Can't edit $act_file" anykey exit 1 fi if [ ! "$rc" = 0 ] then mecho --error "Internal error in verify_file (rc=$rc)" mecho --error "Can't edit $act_file" anykey exit 1 fi exitval=0 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 $editor $param "$act_file" exit $exitval