Fix merge conflict

This commit is contained in:
Alexandre CATTEAU 2022-07-24 15:23:33 +02:00
commit 914b5a88e4
5 changed files with 66 additions and 43 deletions

1
.gitignore vendored
View File

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

View File

@ -11,6 +11,12 @@ 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

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

@ -1,13 +1,14 @@
#!/bin/bash
#!/usr/bin/env 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
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,9 +17,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,41 +1,56 @@
#!/bin/bash
#!/usr/bin/env bash
source "$(dirname "$0")/variables.conf"
run_directory=$(dirname "$0")
# TODO handle non-Systemd systems
source "$run_directory/variables.conf"
echo "Copying Systemd units to system directory..."
if [[ $user != 'root' ]]; then
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
sudo cp systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer
else
sudo cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer
fi
else
cp systemd-templates/conf-sync.service /etc/systemd/system/
sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service
sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service
if $client_type == "server"; then
cp systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer
else
cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer
fi
if [ -f $run_directory/.disabled ]; then
echo "Installation is disabled. Exiting..."
exit 0
fi
echo "Reloading Systemd..."
if [[ $user != 'root' ]]; then
sudo systemctl daemon-reload
# 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..."
if [[ $user != 'root' ]]; then
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
sudo cp systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer
else
sudo cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer
fi
else
cp systemd-templates/conf-sync.service /etc/systemd/system/
sed -i -e "s/PH_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service
sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service
if $client_type == "server"; then
cp systemd-templates/conf-sync-server.timer /etc/systemd/system/conf-sync.timer
else
cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer
fi
fi
echo "Reloading Systemd..."
if [[ $user != 'root' ]]; then
sudo systemctl daemon-reload
else
systemctl daemon-reload
fi
echo "Enabling timer (not starting it, either do it manually or reboot)..."
if [[ $user != 'root' ]]; then
sudo systemctl enable conf-sync.timer
else
systemctl enable conf-sync.timer
fi
elif [ "$(uname)" = "OpenBSD" ]; then
echo "ERROR: OpenBSD is not yet supported, but this is planned."
exit 0
else
systemctl daemon-reload
fi
echo "Enabling timer (not starting it, either do it manually or reboot)..."
if [[ $user != 'root' ]]; then
sudo systemctl enable conf-sync.timer
else
systemctl enable conf-sync.timer
echo "ERROR: could not determine a supported system. Exiting."
exit 1
fi
echo "Finished install. Exiting..."

View File

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