From e93fd14e88d93ef98047df618ea323d2acc3b4ad Mon Sep 17 00:00:00 2001 From: Marco Raber Date: Sat, 9 Apr 2022 15:32:19 +0200 Subject: [PATCH] aggiustato i default --- ne | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ne b/ne index 62d6e81..1d29b51 100755 --- a/ne +++ b/ne @@ -1,6 +1,9 @@ #!/bin/bash -RED='\033[0;31m' -NC='\033[0m' # No Color + +#exit table +#exit 1 - legato a file +#exit 3 - legato a editor +#exit 4 - legato a sudo usage() { echo "ne - nginx edit" @@ -13,14 +16,12 @@ usage() { echo "Default behaviour: without arguments edits nginx.conf with confirmation" exit 0 } -text_editor=$EDITOR -skip_confirm=0 -#sites-enabled="/etc/nginx/sites-enabled" pushd /etc/nginx/sites-enabled #load default settings -[[ -e ~/.local/share/ne/settings/auto_confirm ]] && skip_confirm=1 #se esiste ~/.local/share/ne/settings/auto_confirm +text_editor=${EDITOR:=vim} +[[ -e ~/.local/share/ne/settings/auto_confirm ]] && skip_confirm=1 || skip_confirm=0 #se esiste ~/.local/share/ne/settings/auto_confirm [[ -e ~/.local/share/ne/settings/program_privileges ]] && program_privileges=$(cat ~/.local/share/ne/settings/program_privileges) || program_privileges=sudo #parse settings for this run @@ -35,9 +36,16 @@ while [[ $# -gt 0 ]]; do ;; -c|--choose-editor) shift # past argument + [[ $1 = "" ]] && echo "No specified editor, exiting, run -h for help" && exit 3 text_editor=$1 shift # past value ;; + -p|--choose-privileges-escalator) + shift # past argument + [[ $1 = "" ]] && echo "No program specified, exiting, run -h for help" && exit 4 + program_privileges=$1 + shift # past value + ;; -*|--*) echo "Unknown option $1" # exit 1 @@ -54,9 +62,11 @@ done $(which cp) $file /tmp/copia_check_nginx_${USER} #$(which cat) $file > /tmp/copia_check_nginx_${USER} #non so se usare cat > o cp #se cat > o cp danno errore vuol dire che il file non esiste ed esco male: -[[ $? -eq 1 ]] && printf "${RED}File${NC} $file ${RED}not found, aborting${NC}\n" && exit 1 +[[ $? -eq 1 ]] && printf "File $file not found, exiting\n" && exit 1 -[[ -e $(which $text_editor) ]] || exit 3 +#qua command -v e non which per silent quando fallisce +[[ ! -e $(command -v $text_editor) ]] && echo "$program_privileges is not installed" && exit 3 +[[ ! -e $(command -v $program_privileges) ]] && echo "$program_privileges is not installed" && exit 4 $program_privileges $text_editor $file diff --color=always $file /tmp/copia_check_nginx_${USER}