Compare commits
26 Commits
ce6b0c0d8c
...
master
Author | SHA1 | Date | |
---|---|---|---|
42c257c046 | |||
11db96cb90 | |||
ef03efe3c5 | |||
105057bff3 | |||
e3e6a73f95 | |||
ec76702b93 | |||
e2dcc5cf7c | |||
dd0f0e115d | |||
d2d323b150 | |||
914b5a88e4 | |||
a10e5b42e5 | |||
8a9dd0768d | |||
f7c40ab06b | |||
779143ff40 | |||
f63e9e0992 | |||
a552c76a36 | |||
64573a9f58 | |||
0523c113b0 | |||
b007eb3488 | |||
d0e825b329 | |||
410d179a07 | |||
213c7f3dc3 | |||
5d5c9033f4 | |||
1b7aa49227 | |||
bb6c735355 | |||
1b9a2abcf6 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
variables.conf
|
||||
.disabled
|
12
README.md
12
README.md
@ -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
|
||||
|
37
conf-sync.sh
Executable file
37
conf-sync.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
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 >/dev/null
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "$dir: not a Git repo"
|
||||
continue
|
||||
fi
|
||||
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")
|
||||
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 $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
|
||||
echo "WARNING: $dir is ahead of remote!"
|
||||
else
|
||||
echo "WARNING: $dir and remote have diverged!"
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
45
install.sh
Executable file
45
install.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
run_directory=$(dirname $(readlink -f "$0"))
|
||||
user=$(whoami)
|
||||
|
||||
source "$run_directory/variables.conf"
|
||||
|
||||
if [ -f $run_directory/.disabled ]; then
|
||||
echo "Installation is disabled. Exiting..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
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
|
9
systemd-templates/conf-sync-desktop.timer
Normal file
9
systemd-templates/conf-sync-desktop.timer
Normal 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
|
10
systemd-templates/conf-sync-server.timer
Normal file
10
systemd-templates/conf-sync-server.timer
Normal 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
|
8
systemd-templates/conf-sync.service
Normal file
8
systemd-templates/conf-sync.service
Normal 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
6
variables.conf.template
Normal file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copy this file as variables.conf, with the correct values
|
||||
|
||||
sync_directory=/home/$(whoami)/.sync
|
||||
client_type="desktop" # change to server if needed
|
Reference in New Issue
Block a user