Compare commits

...

23 Commits

Author SHA1 Message Date
42c257c046 Update README 2023-06-24 19:59:25 +02:00
11db96cb90 Set main script to new run_directory norm 2022-09-22 18:45:35 +02:00
ef03efe3c5 Really, finally, make install script working unattended 2022-09-22 18:43:48 +02:00
105057bff3 Add TODO on timer choice 2022-09-22 18:19:19 +02:00
e3e6a73f95 Fix error preventing the install script to be run unattended 2022-09-22 18:17:43 +02:00
ec76702b93 Update install script with new good practices (sudo and run_directory) 2022-08-28 12:49:38 +02:00
e2dcc5cf7c When .disabled is present, do not pull repo 2022-08-19 21:00:45 +02:00
dd0f0e115d Fix error in previous merge conflict resolution 2022-07-24 15:27:54 +02:00
d2d323b150 Fix issue in install.sh 2022-07-24 15:26:04 +02:00
914b5a88e4 Fix merge conflict 2022-07-24 15:23:33 +02:00
a10e5b42e5 Allow install for root user 2022-07-24 15:19:59 +02:00
8a9dd0768d Add run_directory to install.sh 2022-03-17 15:10:44 +01:00
f7c40ab06b Add the ability to disable install 2022-03-17 14:55:37 +01:00
779143ff40 Add shebang to variables file 2022-03-16 15:02:12 +01:00
f63e9e0992 Correct typo in README 2022-03-16 14:27:14 +01:00
a552c76a36 Add initial structure for supporting multiple service managers 2022-03-13 15:47:15 +01:00
64573a9f58 Correct stupid errors 2022-03-13 12:49:27 +01:00
0523c113b0 install.sh: correct if statement 2022-03-13 12:46:15 +01:00
b007eb3488 Update shebangs 2022-03-13 12:18:06 +01:00
d0e825b329 Complete README 2022-03-13 11:55:33 +01:00
410d179a07 Add dirname to systemd-templates paths 2022-03-13 11:55:24 +01:00
213c7f3dc3 Finish install.sh 2022-03-13 11:47:57 +01:00
5d5c9033f4 Finish conf-sync.sh 2022-03-13 11:40:33 +01:00
5 changed files with 64 additions and 27 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
variables.conf
.disabled

View File

@ -11,6 +11,14 @@ 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.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
* `install.sh`
* `install.sh` script copies Systemd templates to their destination, and enables conf-sync timer.
### TODO
* Add install support for OpenBSD
* Replace desktop/server timer choice in one line in install script
* Add `$sudo` in install script

24
conf-sync.sh Normal file → Executable file
View File

@ -1,13 +1,19 @@
#!/bin/bash
#!/usr/bin/env bash
source "$(dirname "$0")/variables.conf"
run_directory=$(dirname $(readlink -f "$0"))
source "$run_directory/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
if [ -f $dir/.disabled ]; then
echo "$dir update is disabled."
continue
fi
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,9 +22,9 @@ for dir in $sync_directory; do
echo "$dir: up-to-date"
elif [ $LOCAL = $BASE ]; then
echo "pulling $dir"
git -C pull
if []; then
echo "Running $dir\'s install script..."
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
elif [ $REMOTE = $BASE ]; then

View File

@ -1,23 +1,45 @@
#!/bin/bash
#!/usr/bin/env bash
source "$(dirname "$0")/variables.conf"
run_directory=$(dirname $(readlink -f "$0"))
user=$(whoami)
# TODO handle non-Systemd systems
source "$run_directory/variables.conf"
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
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
if [ -f $run_directory/.disabled ]; then
echo "Installation is disabled. Exiting..."
exit 0
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
if [[ $user != 'root' ]]; then
sudo="sudo"
else
sudo=""
fi
# NOTE: the handling of init/service manager comes from this discussion:
# https://unix.stackexchange.com/questions/18209/detect-init-system-using-the-shell
if [ -e /run/systemd/system ]; then # service manager is Systemd
echo "Copying Systemd units to system directory..."
$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:$run_directory:g" /etc/systemd/system/conf-sync.service
if [ "$client_type" = "server" ]; then # TODO could be replaced in one line: cp conf-sync-$client_type
$sudo cp $run_directory/systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer
else
$sudo cp $run_directory/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
echo "ERROR: could not determine a supported system. Exiting."
exit 1
fi
echo "Finished install. Exiting..."
exit 0

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copy this file as variables.conf, with the correct values