From 5d5c9033f4f885a8fa692e560fb6130f9ff8d438 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 11:40:33 +0100 Subject: [PATCH 01/12] Finish conf-sync.sh --- conf-sync.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) mode change 100644 => 100755 conf-sync.sh diff --git a/conf-sync.sh b/conf-sync.sh old mode 100644 new mode 100755 index 3296fcd..53f7481 --- a/conf-sync.sh +++ b/conf-sync.sh @@ -2,12 +2,13 @@ source "$(dirname "$0")/variables.conf" -for dir in $sync_directory; do - git -C $dir rev-parse 2>/dev/null - if [ "$?" -ne 0 ]; then # ie. this is not a git repo +for dir in $sync_directory/*; do + git -C $dir rev-parse 2>/dev/null >/dev/null + if [ "$?" -ne 0 ]; then + echo "$dir: not a Git repo" continue fi - git -C $dir fetch + git -C $dir fetch 2>/dev/null >/dev/null UPSTREAM=${1:-'@{u}'} LOCAL=$(git -C $dir rev-parse @) REMOTE=$(git -C $dir rev-parse "$UPSTREAM") @@ -16,8 +17,8 @@ for dir in $sync_directory; do echo "$dir: up-to-date" elif [ $LOCAL = $BASE ]; then echo "pulling $dir" - git -C pull - if []; then + git -C $dir pull 2>/dev/null >/dev/null + if [ -e $dir/install.sh ]; then echo "Running $dir\'s install script..." $dir/install.sh fi From 213c7f3dc345adc4e2605a57cbb7c6191090bdff Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 11:47:57 +0100 Subject: [PATCH 02/12] Finish install.sh --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index aa03eb2..11f4e76 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ echo "Copying Systemd units to system directory..." sudo cp systemd-templates/conf-sync.service /etc/systemd/system/ sudo sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service -if $client_type == "server"; then # TODO not finished +if [ $client_type = "server" ]; then sudo cp systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer else sudo cp systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer From 410d179a07c782bb0795f002d7b08d0a2e29b976 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 11:55:24 +0100 Subject: [PATCH 03/12] Add dirname to systemd-templates paths --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 11f4e76..3a4fd8e 100755 --- a/install.sh +++ b/install.sh @@ -5,13 +5,13 @@ source "$(dirname "$0")/variables.conf" # TODO handle non-Systemd systems echo "Copying Systemd units to system directory..." -sudo cp systemd-templates/conf-sync.service /etc/systemd/system/ +sudo cp $(dirname "$0")/systemd-templates/conf-sync.service /etc/systemd/system/ sudo sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service if [ $client_type = "server" ]; then - sudo cp systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer + sudo cp $(dirname "$0")/systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer else - sudo cp systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer + sudo cp $(dirname "$0")/systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer fi echo "Reloading Systemd..." From d0e825b329d7950b0b30ff99106e8ae42a99f2a8 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 11:55:33 +0100 Subject: [PATCH 04/12] Complete README --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d51341b..dbd6fc7 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ Version 2 implementation works roughly as follows: * if changes are detected, it runs install script (if present). ### Files -* `conf-sync.sh` +* `conf-sync.sh` is the main script, which updates the files. +* `variables.conf.templates` contains examples variables definitions, and should be copied locally to `variables.conf` + (with any required modifications). +* `systemd-templates/` contains Systemd units templates for running the script unattended. #### Installation -* `install.sh` +* `install.sh` script copies Systemd templates to their destination, and enables conf-sync timer. From b007eb3488c2a6acc534cde41c96e900859ad9d5 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 12:18:06 +0100 Subject: [PATCH 05/12] Update shebangs --- conf-sync.sh | 2 +- install.sh | 2 +- variables.conf.template | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/conf-sync.sh b/conf-sync.sh index 53f7481..4a6d3df 100755 --- a/conf-sync.sh +++ b/conf-sync.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash source "$(dirname "$0")/variables.conf" diff --git a/install.sh b/install.sh index 3a4fd8e..5ba3e02 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash source "$(dirname "$0")/variables.conf" diff --git a/variables.conf.template b/variables.conf.template index b60c486..4d53baa 100644 --- a/variables.conf.template +++ b/variables.conf.template @@ -1,5 +1,3 @@ -#!/bin/bash - # Copy this file as variables.conf, with the correct values sync_directory=/home/$(whoami)/.sync From 0523c113b09d65d8daf49e6a4b26150a3481aeaf Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 12:46:15 +0100 Subject: [PATCH 06/12] install.sh: correct if statement --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 5ba3e02..355e1b4 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ echo "Copying Systemd units to system directory..." sudo cp $(dirname "$0")/systemd-templates/conf-sync.service /etc/systemd/system/ sudo sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service -if [ $client_type = "server" ]; then +if [ "$client_type" = "server" ]; then sudo cp $(dirname "$0")/systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer else sudo cp $(dirname "$0")/systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer From 64573a9f588537a0aaeee2a5770af42bfa90f4f8 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 12:49:18 +0100 Subject: [PATCH 07/12] Correct stupid errors --- conf-sync.sh | 2 +- install.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conf-sync.sh b/conf-sync.sh index 4a6d3df..1ae243f 100755 --- a/conf-sync.sh +++ b/conf-sync.sh @@ -19,7 +19,7 @@ for dir in $sync_directory/*; do echo "pulling $dir" git -C $dir pull 2>/dev/null >/dev/null if [ -e $dir/install.sh ]; then - echo "Running $dir\'s install script..." + echo "Running $dir's install script..." $dir/install.sh fi elif [ $REMOTE = $BASE ]; then diff --git a/install.sh b/install.sh index 355e1b4..531e747 100755 --- a/install.sh +++ b/install.sh @@ -9,9 +9,9 @@ sudo cp $(dirname "$0")/systemd-templates/conf-sync.service /etc/systemd/system/ sudo sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service if [ "$client_type" = "server" ]; then - sudo cp $(dirname "$0")/systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer + sudo cp $(dirname "$0")/systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer else - sudo cp $(dirname "$0")/systemd-templates/dns-update.timer /etc/systemd/system/conf-sync.timer + sudo cp $(dirname "$0")/systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer fi echo "Reloading Systemd..." From a552c76a36da20756aa445c38501177a259aeaa5 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 13 Mar 2022 15:47:15 +0100 Subject: [PATCH 08/12] Add initial structure for supporting multiple service managers --- README.md | 3 +++ install.sh | 35 ++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index dbd6fc7..733b321 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,6 @@ Version 2 implementation works roughly as follows: * `systemd-templates/` contains Systemd units templates for running the script unattended. #### Installation * `install.sh` script copies Systemd templates to their destination, and enables conf-sync timer. + +### TODO +* Add install support for OpenBSD diff --git a/install.sh b/install.sh index 531e747..fc17a97 100755 --- a/install.sh +++ b/install.sh @@ -2,22 +2,31 @@ source "$(dirname "$0")/variables.conf" -# TODO handle non-Systemd systems +# NOTE: the handling of init/service manager comes from this discussion: +# https://unix.stackexchange.com/questions/18209/detect-init-system-using-the-shell -echo "Copying Systemd units to system directory..." -sudo cp $(dirname "$0")/systemd-templates/conf-sync.service /etc/systemd/system/ -sudo sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service -sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service -if [ "$client_type" = "server" ]; then - sudo cp $(dirname "$0")/systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer +if [ -e /run/systemd/system ]; then # service manager is Systemd + echo "Copying Systemd units to system directory..." + sudo cp $(dirname "$0")/systemd-templates/conf-sync.service /etc/systemd/system/ + sudo sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service + sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service + if [ "$client_type" = "server" ]; then + sudo cp $(dirname "$0")/systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer + else + sudo cp $(dirname "$0")/systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer + fi + + echo "Reloading Systemd..." + sudo systemctl daemon-reload + echo "Enabling timer (not starting it, either do it manually or reboot)..." + sudo systemctl enable conf-sync.timer +elif [ "$(uname)" = "OpenBSD" ]; then + echo "ERROR: OpenBSD is not yet supported, but this is planned." + exit 0 else - sudo cp $(dirname "$0")/systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer + echo "ERROR: could not determine a supported system. Exiting." + exit 1 fi -echo "Reloading Systemd..." -sudo systemctl daemon-reload -echo "Enabling timer (not starting it, either do it manually or reboot)..." -sudo systemctl enable conf-sync.timer - echo "Finished install. Exiting..." exit 0 From f63e9e099291c7e0fde32bbefd0db7f12d44999d Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Wed, 16 Mar 2022 14:27:14 +0100 Subject: [PATCH 09/12] Correct typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 733b321..f3661ce 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Version 2 implementation works roughly as follows: ### Files * `conf-sync.sh` is the main script, which updates the files. -* `variables.conf.templates` contains examples variables definitions, and should be copied locally to `variables.conf` +* `variables.conf.template` contains examples variables definitions, and should be copied locally to `variables.conf` (with any required modifications). * `systemd-templates/` contains Systemd units templates for running the script unattended. #### Installation From 779143ff40d29f1b70955bd6d0fe3797227ab8ad Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Wed, 16 Mar 2022 15:02:12 +0100 Subject: [PATCH 10/12] Add shebang to variables file --- variables.conf.template | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variables.conf.template b/variables.conf.template index 4d53baa..4400e79 100644 --- a/variables.conf.template +++ b/variables.conf.template @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Copy this file as variables.conf, with the correct values sync_directory=/home/$(whoami)/.sync From f7c40ab06bbe11f9845d2017a180fae85ef11c40 Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Thu, 17 Mar 2022 14:55:37 +0100 Subject: [PATCH 11/12] Add the ability to disable install --- .gitignore | 1 + install.sh | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index bfdbd30..99a3140 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ variables.conf +.disabled diff --git a/install.sh b/install.sh index fc17a97..91b2f18 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,11 @@ source "$(dirname "$0")/variables.conf" +if [ -f $run_directory/.disabled ]; then + echo "Installation is disabled. Exiting..." + exit 0 +fi + # NOTE: the handling of init/service manager comes from this discussion: # https://unix.stackexchange.com/questions/18209/detect-init-system-using-the-shell From 8a9dd0768da246c8647e0cf9cdfd66e824fdf9a0 Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Thu, 17 Mar 2022 15:10:44 +0100 Subject: [PATCH 12/12] Add run_directory to install.sh --- install.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 91b2f18..bc2bcc7 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -source "$(dirname "$0")/variables.conf" +run_directory=$(dirname "$0") + +source "$run_directory/variables.conf" if [ -f $run_directory/.disabled ]; then echo "Installation is disabled. Exiting..." @@ -12,13 +14,13 @@ fi if [ -e /run/systemd/system ]; then # service manager is Systemd echo "Copying Systemd units to system directory..." - sudo cp $(dirname "$0")/systemd-templates/conf-sync.service /etc/systemd/system/ + sudo cp $run_directory/systemd-templates/conf-sync.service /etc/systemd/system/ sudo sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service if [ "$client_type" = "server" ]; then - sudo cp $(dirname "$0")/systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer + sudo cp $run_directory/systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer else - sudo cp $(dirname "$0")/systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer + sudo cp $run_directory/systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer fi echo "Reloading Systemd..."