From 7692c4e889434b366def22cddb2b61c8e488acbd Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Fri, 30 Sep 2022 15:25:09 +0200 Subject: [PATCH] Update install scripts and prereqs (sudo) --- lib/prerequisites.sh | 6 ++++++ lib/remove-bridgehead-units.sh | 4 ++++ lib/setup-bridgehead-units.sh | 31 +++++++++++++++++++++------- lib/systemd/bridgehead-update@.timer | 4 ++-- lib/systemd/bridgehead@.service | 3 ++- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/prerequisites.sh b/lib/prerequisites.sh index e04161b..4e03530 100755 --- a/lib/prerequisites.sh +++ b/lib/prerequisites.sh @@ -23,6 +23,12 @@ for prerequisite in $prerequisites; do # TODO: Check for specific version done +log INFO "Checking if sudo is installed ..." +if [ ! -d /etc/sudoers.d ]; then + log ERROR "/etc/sudoers.d does not exist. Please install sudo package." + exit 1 +fi + log INFO "Checking configuration ..." ## Download submodule diff --git a/lib/remove-bridgehead-units.sh b/lib/remove-bridgehead-units.sh index b81b042..36d1dad 100755 --- a/lib/remove-bridgehead-units.sh +++ b/lib/remove-bridgehead-units.sh @@ -16,6 +16,10 @@ export PROJECT=$1 #checkRequirements // not needed when uninstalling +log INFO "Removing bridgehead sudoers permissions." + +rm -vf /etc/sudoers.d/bridgehead-${PROJECT} + log "INFO" "Stopping system units and removing bridgehead for ${PROJECT} ..." systemctl disable --now bridgehead@${PROJECT}.service bridgehead-update@${PROJECT}.timer bridgehead-update@${PROJECT}.service diff --git a/lib/setup-bridgehead-units.sh b/lib/setup-bridgehead-units.sh index dc3f9fb..f2c213c 100755 --- a/lib/setup-bridgehead-units.sh +++ b/lib/setup-bridgehead-units.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e source lib/functions.sh @@ -18,6 +18,18 @@ export PROJECT=$1 checkRequirements +log "INFO" "Allowing the bridgehead user to start/stop the bridgehead." + +cat < /etc/sudoers.d/bridgehead-"${PROJECT}" +# This has been added by the Bridgehead installer. Remove with bridgehead uninstall. +Cmnd_Alias BRIDGEHEAD${PROJECT} = \\ + /bin/systemctl start bridgehead@${PROJECT}.service, \\ + /bin/systemctl stop bridgehead@${PROJECT}.service, \\ + /bin/systemctl restart bridgehead@${PROJECT}.service + +bridgehead ALL= NOPASSWD: BRIDGEHEAD${PROJECT} +EOF + log "INFO" "Register system units for bridgehead and bridgehead-update" cp -v \ lib/systemd/bridgehead\@.service \ @@ -27,11 +39,14 @@ cp -v \ systemctl daemon-reload -if ! systemctl is-active --quiet bridgehead@"${PROJECT}"; then - log "INFO" "Enabling autostart of bridgehead@${PROJECT}.service" - systemctl enable bridgehead@"${PROJECT}" - log "INFO" "Enabling nightly updates for bridgehead@${PROJECT}.service ..." - systemctl enable --now bridgehead-update@"${PROJECT}".timer -fi +log INFO "Trying to update your bridgehead ..." -log "INFO" "\nDone - now start your bridgehead by running\n\tsystemctl start bridgehead@${PROJECT}.service\nor by rebooting your machine." +systemctl start bridgehead-update@"${PROJECT}".service + +log "INFO" "Enabling autostart of bridgehead@${PROJECT}.service" +systemctl enable bridgehead@"${PROJECT}".service + +log "INFO" "Enabling auto-updates for bridgehead@${PROJECT}.service ..." +systemctl enable --now bridgehead-update@"${PROJECT}".timer + +log "INFO" "\nSuccess - now start your bridgehead by running\n systemctl start bridgehead@${PROJECT}.service\n or by rebooting your machine." diff --git a/lib/systemd/bridgehead-update@.timer b/lib/systemd/bridgehead-update@.timer index ce44814..4c8fada 100644 --- a/lib/systemd/bridgehead-update@.timer +++ b/lib/systemd/bridgehead-update@.timer @@ -1,8 +1,8 @@ [Unit] -Description=Nightly Updates of Bridgehead (%i) +Description=Hourly Updates of Bridgehead (%i) [Timer] -OnCalendar=*-*-* 03:00:00 +OnCalendar=*-*-* *:00:00 [Install] WantedBy=basic.target diff --git a/lib/systemd/bridgehead@.service b/lib/systemd/bridgehead@.service index 4458d9a..c387c71 100644 --- a/lib/systemd/bridgehead@.service +++ b/lib/systemd/bridgehead@.service @@ -1,5 +1,6 @@ [Unit] -Description=Bridgehead (%i) Service +Description=Bridgehead (%i) +Requires=docker.service [Service] User=bridgehead