first commit
This commit is contained in:
parent
c67892cfbd
commit
2b479d89da
72
edocker
Executable file
72
edocker
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/bin/bash
|
||||
|
||||
#exit table
|
||||
#exit 1 - legato a file
|
||||
#exit 3 - legato a editor
|
||||
#exit 4 - legato a sudo
|
||||
|
||||
usage() {
|
||||
echo "edocker - docker (compose) edit"
|
||||
echo "Usage: edocker directory_of_compose_file [-y] [-c]"
|
||||
echo "Options:"
|
||||
echo "-h -> Show this help"
|
||||
#echo "-y -> skip confirm on reload"
|
||||
echo "-c -> manually choose the text editor (default = vim)"
|
||||
echo "Note: edocker chooses sudo by default, to change this behaviour update the file ~/.local/share/ne/program_privileges"
|
||||
echo "Default behaviour: without arguments just chamge the working directory to /mnt/docker-data"
|
||||
exit 0
|
||||
}
|
||||
|
||||
cd /mnt/docker-data/
|
||||
|
||||
#load default settings
|
||||
text_editor=${EDITOR:=vim}
|
||||
file="docker-compose.yml"
|
||||
|
||||
#parse settings for this run
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
usage
|
||||
;;
|
||||
#-y|--skip-confirm)
|
||||
# skip_confirm=1
|
||||
# shift # past argument
|
||||
# ;;
|
||||
-f|--filename-compose)
|
||||
shift # past argument
|
||||
[[ $1 = "" ]] && echo "No filename specified, looking for docker-compose.yml" || file=$1
|
||||
shift
|
||||
;;
|
||||
-c|--choose-editor)
|
||||
shift # past argument
|
||||
[[ $1 = "" ]] && echo "No specified editor, exiting, run -h for help" && exit 3
|
||||
text_editor=$1
|
||||
shift # past value
|
||||
;;
|
||||
-*|--*)
|
||||
echo "Unknown option $1"
|
||||
# exit 1
|
||||
;;
|
||||
*)
|
||||
POSITIONAL_ARGS+=("$1") # save positional arg
|
||||
shift # past argument
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
[[ ! $POSITIONAL_ARGS = "" ]] && dir=$POSITIONAL_ARGS || exit 0
|
||||
cd $dir || exit 1 #se non fallisce siamo in /mnt/docker-data/$1
|
||||
|
||||
$(which cp) $file /tmp/copia_check_docker_${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 "File $file not found, exiting\n" && exit 1
|
||||
|
||||
#qua command -v e non which per silent quando fallisce
|
||||
[[ ! -e $(command -v $text_editor) ]] && echo "$text_editor is not installed" && exit 3
|
||||
$text_editor $file
|
||||
diff --color=always $file /tmp/copia_check_docker_${USER}
|
||||
|
||||
edited=$?
|
||||
[[ $edited = 1 ]] && confirm "compose file edited, recreate container(s)?" && docker-compose up -d || echo "No edits found, exiting"
|
Loading…
Reference in New Issue
Block a user