From 292d71b6c267a1ac631c9d173acc00adbd618034 Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Fri, 28 Oct 2022 15:14:34 +0200 Subject: [PATCH] Support docker installation via snap, e.g. Ubuntu 22.04 --- lib/functions.sh | 16 ++++++++++++++++ lib/setup-bridgehead-units.sh | 6 ++++++ lib/systemd/bridgehead@.service | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/functions.sh b/lib/functions.sh index b5a03a0..7367c66 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -11,6 +11,22 @@ detectCompose() { fi } +# https://unix.stackexchange.com/questions/539147 +systemctl-exists() { + [ $(systemctl list-unit-files "${1}*" | wc -l) -gt 3 ] +} + +dockerUnitName() { + if systemctl-exists docker.service; then + echo "docker.service" + elif systemctl-exists snap.docker.dockerd.service; then + echo "snap.docker.dockerd.service" + else + log ERROR "Unable to detect docker systemd unit." + fail_and_report 1 "Unable to detect docker systemd unit." + fi +} + exitIfNotRoot() { if [ "$EUID" -ne 0 ]; then log "ERROR" "Please run as root" diff --git a/lib/setup-bridgehead-units.sh b/lib/setup-bridgehead-units.sh index 57f7df5..fa50fd5 100755 --- a/lib/setup-bridgehead-units.sh +++ b/lib/setup-bridgehead-units.sh @@ -40,6 +40,12 @@ cp -v \ lib/systemd/bridgehead-update\@.timer \ /etc/systemd/system/ +log INFO "Setting Docker unit ..." + +for file in $(find /etc/systemd/system -mindepth 1 -maxdepth 1 -type f -name "bridgehead*"); do + sed -i "s/DOCKER_UNIT_NAME/$(dockerUnitName)/g" $file +done + systemctl daemon-reload log INFO "Trying to update your bridgehead ..." diff --git a/lib/systemd/bridgehead@.service b/lib/systemd/bridgehead@.service index 7645793..253eb8a 100644 --- a/lib/systemd/bridgehead@.service +++ b/lib/systemd/bridgehead@.service @@ -1,6 +1,6 @@ [Unit] Description=Bridgehead (%i) -Requires=docker.service +Requires=DOCKER_UNIT_NAME [Service] User=bridgehead