tellconf/sync-config.sh

49 lines
988 B
Bash
Executable File

#!/bin/sh
set -e
REMOTE_HOST="schema-gw.dsv.su.se"
REMOTE_FILE="/etc/dnsmasq.d/dhcp-leases.conf"
TEMPL="tellstick.templ"
SKEL="tellstick.skel"
CONFFILE="tellstick.conf"
TMPCONF="$CONFFILE.new"
TMPFILE=$(mktemp)
trap 'rm -f $TMPFILE' EXIT
cd /opt/tellconf
if ! git diff --quiet; then
git commit -qam "Pre-update autocommit on boot at $(date '+%F %R')"
fi
git pull -q
scp -q "$REMOTE_HOST:$REMOTE_FILE" "$TMPFILE"
cp "$SKEL" "$TMPCONF"
while read line; do
hostname=$(echo "$line" | cut -d',' -f2 | sed "s/.local//")
hostnum=$(echo "$line" | cut -d',' -f3 | cut -d'.' -f4)
sed -e "s/HOSTNAME/$hostname/g" \
-e "s/HOSTNUM/$hostnum/g" \
"$TEMPL" >> "$TMPCONF"
done < "$TMPFILE"
if ! diff -N "$TMPCONF" "$CONFFILE" >/dev/null 2>&1; then
mv "$TMPCONF" "$CONFFILE"
service telldusd restart
service slim restart
else
rm "$TMPCONF"
fi
if ! git diff --quiet; then
git commit -qam "Post-update autocommit on boot at $(date '+%F %R')"
fi
git push -q