From 9f129bc7b085309c58f67f2dcc2ef5fb0bebc676 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 17 Oct 2018 12:48:54 +0100 Subject: [PATCH] Backup and normalise config if needed --- contrib/macos/create-pkg.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/contrib/macos/create-pkg.sh b/contrib/macos/create-pkg.sh index 59647364..167184e3 100755 --- a/contrib/macos/create-pkg.sh +++ b/contrib/macos/create-pkg.sh @@ -41,8 +41,23 @@ cp contrib/macos/yggdrasil.plist pkgbuild/root/Library/LaunchDaemons # Create the postinstall script cat > pkgbuild/scripts/postinstall << EOF #!/bin/sh -test -f /etc/yggdrasil.conf || /usr/local/bin/yggdrasil -genconf > /etc/yggdrasil.conf -test -f /Library/LaunchDaemons/yggdrasil.plist && launchctl unload /Library/LaunchDaemons/yggdrasil.plist + +# Normalise the config if it exists, generate it if it doesn't +if [ -f /etc/yggdrasil.conf ]; +then + mkdir -p /Library/Preferences/Yggdrasil + echo "Backing up configuration file to /Library/Preferences/Yggdrasil/yggdrasil.conf.`date +%Y%m%d`" + cp /etc/yggdrasil.conf /Library/Preferences/Yggdrasil/yggdrasil.conf.`date +%Y%m%d` + echo "Normalising /etc/yggdrasil.conf" + /usr/local/bin/yggdrasil -useconffile /Library/Preferences/Yggdrasil/yggdrasil.conf.`date +%Y%m%d` -normaliseconf > /etc/yggdrasil.conf +else + /usr/local/bin/yggdrasil -genconf > /etc/yggdrasil.conf +fi + +# Unload existing Yggdrasil launchd service, if possible +test -f /Library/LaunchDaemons/yggdrasil.plist && (launchctl unload /Library/LaunchDaemons/yggdrasil.plist || true) + +# Load Yggdrasil launchd service and start Yggdrasil launchctl load /Library/LaunchDaemons/yggdrasil.plist EOF @@ -78,7 +93,7 @@ EOF cat > pkgbuild/flat/Distribution << EOF - Yggdrasil ${PKGVERSION} + Yggdrasil (${PKGNAME}-${PKGVERSION})