From 8185fd7023cb318f52a5fb3b9abd632b98960aa1 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 6 Jun 2019 18:51:03 +0530 Subject: [PATCH] Update and streamline update script Signed-off-by: Harsh Shandilya --- update.sh | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/update.sh b/update.sh index c89ff50..3308c05 100755 --- a/update.sh +++ b/update.sh @@ -3,32 +3,27 @@ CL_RST="\033[0m" CL_YLW="\033[01;33m" -function reportWarning { - echo -e "" +function prettyPrint { echo -e "${CL_YLW}${1}${CL_RST}" - if [[ -z "${2}" ]]; then - echo -e "" - fi } # Grab all service names -declare -a services -while IFS= read -r -d $'\0'; do - services+=("$REPLY") -done < <(find . -name '*.service' -print0 | sed 's/\.\///g') +declare -a services=('caddy' 'horbiswalls-bot' 'mirror-bot' 'uno-bot') # Place the systemd unit files where they belong -reportWarning "Copying systemd files to /etc/systemd/system" -for service in "${services[@]}"; do sudo cp "${service}" /etc/systemd/system/; done +prettyPrint "Copying systemd files to /etc/systemd/system" +for service in "${services[@]}"; do sudo cp -v "${service}.service" /etc/systemd/system/; done # Reload systemctl so that it processes our changes -reportWarning "Reloading systemctl daemon" +prettyPrint "Reloading systemctl daemon" sudo systemctl daemon-reload # Now loop through each service and restart it for service in "${services[@]}"; do - service="${service/.service/}" - reportWarning "Restarting ${service}" + prettyPrint "Restarting ${service}" sudo service "${service}" restart - [ -f "/etc/systemd/system/multi-user.target.wants/${service}.service" ] && sudo systemctl enable "${service}" + if [ ! -f "/etc/systemd/system/multi-user.target.wants/${service}.service" ]; then + prettyPrint "Enabling ${service}" + sudo systemctl enable "${service}" + fi done