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 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). * if changes are detected, it runs install script (if present).
### Files ### 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 #### 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" source "$(dirname "$0")/variables.conf"
for dir in $sync_directory; do for dir in $sync_directory/*; do
git -C $dir rev-parse 2>/dev/null git -C $dir rev-parse 2>/dev/null >/dev/null
if [ "$?" -ne 0 ]; then # ie. this is not a git repo if [ "$?" -ne 0 ]; then
echo "$dir: not a Git repo"
continue continue
fi fi
git -C $dir fetch git -C $dir fetch 2>/dev/null >/dev/null
UPSTREAM=${1:-'@{u}'} UPSTREAM=${1:-'@{u}'}
LOCAL=$(git -C $dir rev-parse @) LOCAL=$(git -C $dir rev-parse @)
REMOTE=$(git -C $dir rev-parse "$UPSTREAM") REMOTE=$(git -C $dir rev-parse "$UPSTREAM")
@ -16,9 +17,9 @@ for dir in $sync_directory; do
echo "$dir: up-to-date" echo "$dir: up-to-date"
elif [ $LOCAL = $BASE ]; then elif [ $LOCAL = $BASE ]; then
echo "pulling $dir" echo "pulling $dir"
git -C pull git -C $dir pull 2>/dev/null >/dev/null
if []; then if [ -e $dir/install.sh ]; then
echo "Running $dir\'s install script..." echo "Running $dir's install script..."
$dir/install.sh $dir/install.sh
fi fi
elif [ $REMOTE = $BASE ]; then elif [ $REMOTE = $BASE ]; then

View File

@ -1,11 +1,20 @@
#!/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 [ -f $run_directory/.disabled ]; then
if [[ $user != 'root' ]]; 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
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 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_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service
sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service sudo sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service
@ -14,7 +23,7 @@ if [[ $user != 'root' ]]; then
else else
sudo cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer sudo cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer
fi fi
else else
cp systemd-templates/conf-sync.service /etc/systemd/system/ 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_USER/$(whoami)/g" /etc/systemd/system/conf-sync.service
sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service sed -i -e "s:PH_DIRECTORY:$(pwd):g" /etc/systemd/system/conf-sync.service
@ -23,19 +32,25 @@ else
else else
cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer cp systemd-templates/conf-sync-desktop.timer /etc/systemd/system/conf-sync.timer
fi fi
fi fi
echo "Reloading Systemd..."
echo "Reloading Systemd..." if [[ $user != 'root' ]]; then
if [[ $user != 'root' ]]; then
sudo systemctl daemon-reload sudo systemctl daemon-reload
else else
systemctl daemon-reload systemctl daemon-reload
fi fi
echo "Enabling timer (not starting it, either do it manually or reboot)..." echo "Enabling timer (not starting it, either do it manually or reboot)..."
if [[ $user != 'root' ]]; then if [[ $user != 'root' ]]; then
sudo systemctl enable conf-sync.timer sudo systemctl enable conf-sync.timer
else else
systemctl enable conf-sync.timer systemctl enable conf-sync.timer
fi
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 fi
echo "Finished install. Exiting..." 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 # Copy this file as variables.conf, with the correct values