server-config/update.sh
Harsh Shandilya 19a3eccdec
Fix update script
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
2019-05-05 02:41:35 +05:30

34 lines
989 B
Bash
Executable file

#!/bin/bash
CL_RST="\033[0m"
CL_YLW="\033[01;33m"
function reportWarning {
echo -e ""
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')
# 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
# Reload systemctl so that it processes our changes
reportWarning "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}"
sudo service "${service}" restart
[ -f "/etc/systemd/system/multi-user.target.wants/${service}.service" ] && sudo systemctl enable "${service}"
done