From 123ce65c825a62b276fd0d58e00d69a543b326b3 Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Mon, 10 Jan 2022 15:31:07 +0100 Subject: [PATCH] Don't do sudo --- install-bridgehead.sh | 25 +++++++++++++++---------- lib/functions.sh | 12 ++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100755 lib/functions.sh diff --git a/install-bridgehead.sh b/install-bridgehead.sh index df070c7..54f4568 100755 --- a/install-bridgehead.sh +++ b/install-bridgehead.sh @@ -1,6 +1,10 @@ #!/bin/bash ### Note: Currently not complete, needs some features before useable for production +source lib/functions.sh + +exitIfNotRoot + if ! ./lib/prerequisites.sh; then echo "Prerequisites failed, exiting" exit 1 @@ -12,14 +16,15 @@ echo "Installing bridgehead" _systemd_path=/etc/systemd/system/ -echo "Installing bridgehead\@.service in systemd ..." -sudo cp convenience/bridgehead\@.service $_systemd_path -echo "Installing bridgehead\@.update.service in systemd ..." -sudo cp convenience/bridgehead-update\@.service $_systemd_path -sudo cp convenience/bridgehead-update\@.timer $_systemd_path +echo "Installing systemd units ..." +cp -v \ + convenience/bridgehead\@.service \ + convenience/bridgehead-update\@.service \ + convenience/bridgehead-update\@.timer \ + $_systemd_path echo "Loading the bridgehead definitions in systemd" -sudo systemctl daemon-reload +systemctl daemon-reload echo "Starting Project ${project} " @@ -28,14 +33,14 @@ echo "Starting Project ${project} " exit fi - sudo systemctl is-active --quiet bridgehead@"${project}" + systemctl is-active --quiet bridgehead@"${project}" if [ ! $? -eq 0 ]; then echo "Starting bridgehead@${project} service ..." - sudo systemctl start bridgehead@"${project}" + systemctl start bridgehead@"${project}" echo "Enabling autostart of bridgehead@${project}.service" - sudo systemctl enable bridgehead@"${project}" + systemctl enable bridgehead@"${project}" echo "Enabling nightly updates for bridgehead@${project}.service ..." - sudo systemctl enable --now bridgehead-update@"${project}".timer + systemctl enable --now bridgehead-update@"${project}".timer fi # Switch back to execution directory; diff --git a/lib/functions.sh b/lib/functions.sh new file mode 100755 index 0000000..4dc30f5 --- /dev/null +++ b/lib/functions.sh @@ -0,0 +1,12 @@ +#!/bin/bash -e + +exitIfNotRoot() { + if [ "$EUID" -ne 0 ]; then + echo "Please run as root" + exit 1 + fi +} + +log() { + echo "$(date +'%Y-%m-%d %T')" "$1:" "$2" +}