Compare commits

..

3 Commits

Author SHA1 Message Date
1b7aa49227 Add install script and Systemd units 2022-03-12 18:15:04 +01:00
bb6c735355 Add script 2022-03-12 18:14:11 +01:00
1b9a2abcf6 Add variables file and gitignore 2022-03-12 18:13:24 +01:00
7 changed files with 88 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
variables.conf

31
conf-sync.sh Normal file
View File

@ -0,0 +1,31 @@
#!/bin/bash
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
continue
fi
git -C $dir fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git -C $dir rev-parse @)
REMOTE=$(git -C $dir rev-parse "$UPSTREAM")
BASE=$(git -C $dir merge-base @ "$UPSTREAM")
if [ $LOCAL = $REMOTE ]; then
echo "$dir: up-to-date"
elif [ $LOCAL = $BASE ]; then
echo "pulling $dir"
git -C pull
if []; then
echo "Running $dir\'s install script..."
$dir/install.sh
fi
elif [ $REMOTE = $BASE ]; then
echo "WARNING: $dir is ahead of remote!"
else
echo "WARNING: $dir and remote have diverged!"
fi
done
exit 0

23
install.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
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 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
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

View File

@ -0,0 +1,9 @@
[Unit]
Description=Run conf-sync after boot (for desktops)
[Timer]
Unit=conf-sync.service
OnBootSec=5min
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,10 @@
[Unit]
Description=Run conf-sync daily (for servers)
[Timer]
Unit=conf-sync.service
OnCalendar=*-*-* 06:00:00
Persistent=true
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,8 @@
[Unit]
Description=Configuration files synchronisation
After=network.target
[Service]
Type=oneshot
User=PH_USER
ExecStart=PH_DIRECTORY/conf-sync.sh

6
variables.conf.template Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# Copy this file as variables.conf, with the correct values
sync_directory=/home/$(whoami)/.sync
client_type="desktop" # change to server if needed