From c766678fc7ac911edbbf05a5c479d7e233e2240c Mon Sep 17 00:00:00 2001 From: gust Date: Wed, 20 Mar 2019 00:22:34 +0100 Subject: [PATCH] Small fixes for delete command --- utils/libre | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/utils/libre b/utils/libre index e9e7e78..a0ec0da 100755 --- a/utils/libre +++ b/utils/libre @@ -29,6 +29,19 @@ function systemctl_param { fi } +function show_usage { + echo "Usage:" + echo " - start|status|enable|disable|restart|stop: command sent to systemctl." + echo " - ps|exec|logs: command sent to docker compose." + echo " - update: to update the current folder." + echo " - stats: show docker stats with names." + echo " - delete : remove a libre.sh service." + exit 1 +} + +if [ $# -eq 0 ]; then + show_usage +fi case "$1" in start|status|enable|disable|restart|stop) @@ -62,7 +75,12 @@ case "$1" in stats) docker stats $(docker ps|grep -v "NAMES"|awk '{ print $NF }'|tr "\n" " ");; delete) - read -p "Are you sure you want to delete ${2}? (yY)" -n 1 -r + if [ $# -ne 2 ]; then + echo "delete requires a domainname argument." + exit 1 + fi + + read -p "Are you sure you want to delete ${2}? (yN)" -n 1 -r echo # (optional) move to a new line if [[ $REPLY =~ ^[Yy]$ ]] then @@ -72,6 +90,9 @@ case "$1" in cd /data/domains tar cvzf ${2}.tgz ./${2} if [ -f ./${2}.tgz ]; then + if [ ! -d /data/domains/to_keep/ ]; then + mkdir /data/domains/to_keep/ + fi mv ${2}.tgz /data/domains/to_keep/ rm -rf /data/domains/${2} rm -rf /system/haproxy/certs/${2} @@ -79,9 +100,5 @@ case "$1" in fi fi;; *) - echo "Usage:" - echo " - start|status|enable|disable|restart|stop: command sent to systemctl." - echo " - ps|exec|logs: command sent to docker compose." - echo " - update: to update the current folder." - echo " - stats: show docker stats with names." + show_usage esac