From 24664b3b88714f4b79335fadc1799a423b47a513 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Mar 2018 10:39:00 +0100 Subject: [SSUS] Add diffcp helper Copies a file from the updater to a destination, but only if the destination file does not exist or is different from the file to copy. The function returns 0 if the file was copied, so you can execute further commands only if the file actually changed, like restarting a service etc. --- satellit_upgrader/updater.template.sh | 94 ++++++++++++++--------------------- 1 file changed, 36 insertions(+), 58 deletions(-) (limited to 'satellit_upgrader/updater.template.sh') diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh index 58d3368..95de6f0 100644 --- a/satellit_upgrader/updater.template.sh +++ b/satellit_upgrader/updater.template.sh @@ -87,6 +87,25 @@ fixperms () { fi } +# diffcp "foo.txt" "/opt/openslx/dest.txt" ["Installing new foo file"] +diffcp () { + local SRC="$FILEDIR/$1" + local DST=$2 + [ -e "$SRC" ] || return 1 + [ -f "$SRC" ] || perror "$1 included in updater, but is not regular file." + if [ -e "$DST" ]; then + [ -f "$DST" ] || perror "$DST exists and is not a regular file, cannot replace." + diff -q "$SRC" "$DST" &>/dev/null && return 1 # diff returns 0 if files are equal + fi + if [ -n "$3" ]; then + echo "$3" + else + echo "Installing $1" + fi + cp "$SRC" "$DST" || cp -f "$SRC" "$DST" || perror "Could not copy '$1' to '$DST'" + return 0 +} + # ** Constants - to be patched by the packaging script declare -rg TARGET_WEBIF_VERSION="%TARGET_WEBIF_VERSION%" declare -rg TGZ_SLXADMIN="%TGZ_SLXADMIN%" @@ -184,9 +203,7 @@ if [ -n "$TGZ_TASKMANAGER" ]; then fi # *****************taskmanager sudo config ***************** -if [ -s "$FILEDIR/tm-sudo-config" ]; then - echo "Installing new sudo config for taskmanager" - cp -f "$FILEDIR/tm-sudo-config" "/etc/sudoers.d/taskmanager" || pwarning "Could not update sudo conf for taskmanager" +if diffcp "tm-sudo-config" "/etc/sudoers.d/taskmanager" "Installing new sudo config for taskmanager"; then chmod 0440 "/etc/sudoers.d/taskmanager" fi @@ -253,15 +270,9 @@ if [ -n "$TGZ_SLXADMIN" ]; then echo "Config updated" fi # New cronscript supplied - if [ -s "$FILEDIR/slxadmin-cronscript" ]; then - echo "Installing slx-admin cron script" - cp "$FILEDIR/slxadmin-cronscript" "/opt/openslx/slxadmin-cronscript" - fi + diffcp "slxadmin-cronscript" "/opt/openslx/slxadmin-cronscript" # New crontab supplied - if [ -s "$FILEDIR/slxadmin-crontab" ]; then - echo "Installing slx-admin cron file" - cp "$FILEDIR/slxadmin-crontab" "/etc/cron.d/slx-admin" - fi + diffcp "slxadmin-crontab" "/etc/cron.d/slx-admin" # Enable modules ( mkdir -p "$PATH_SLXADMIN/modules" @@ -273,6 +284,7 @@ if [ -n "$TGZ_SLXADMIN" ]; then ln -s "../modules-available/$mod" "$name" || pwarning "Could not activate module '$mod' (alias '$name')" done # Update DB + echo "Running database upgrade" cd "$PATH_SLXADMIN" if ! ./install-all > "$TMPDIR/wwwup.log"; then cat "$TMPDIR/wwwup.log" @@ -356,32 +368,15 @@ fi echo "* Configuring lighttpd" RESTART_LIGHTY= -# ********************** lighttpd config ******************* -if [ -e "$FILEDIR/lighttpd.conf" ] && [ -e "/etc/lighttpd/lighttpd.conf" ]; then - echo "Replacing lighttpd.conf" - cp "$FILEDIR/lighttpd.conf" "/etc/lighttpd/lighttpd.conf" || perror "Could not replace /etc/lighttpd/lighttpd.conf" - RESTART_LIGHTY=ja -fi - -# ********************** lighttpd auto ssl ******************* -if [ -e "$FILEDIR/lighttpd-auto-ssl.sh" ] && [ -d "/usr/share/lighttpd" ]; then - echo "Installing lighttpd auto-ssl.sh" - cp "$FILEDIR/lighttpd-auto-ssl.sh" "/usr/share/lighttpd/auto-ssl.sh" || perror "Could not replace /usr/share/lighttpd/auto-ssl.sh" - RESTART_LIGHTY=ja -fi - -# ********************** lighttpd-include-conf-d.sh ******************* -if [ -e "$FILEDIR/lighttpd-include-conf-d.sh" ] && [ -d "/usr/share/lighttpd" ]; then - echo "Installing lighttpd include-conf-d.sh" - cp "$FILEDIR/lighttpd-include-conf-d.sh" "/usr/share/lighttpd/include-conf-d.sh" || perror "Could not replace /usr/share/lighttpd/include-conf-d.sh" - RESTART_LIGHTY=ja -fi +diffcp "lighttpd.conf" "/etc/lighttpd/lighttpd.conf" && RESTART_LIGHTY=ja +diffcp "lighttpd-auto-ssl.sh" "/usr/share/lighttpd/auto-ssl.sh" && RESTART_LIGHTY=ja +diffcp "lighttpd-include-conf-d.sh" "/usr/share/lighttpd/include-conf-d.sh" && RESTART_LIGHTY=ja # ********************** lighttpd php_children ************* -if [ -e "$FILEDIR/patch_lighttpd_phpchildren" ]; then - echo "Installing script to set dynamic php children value" - cp "$FILEDIR/patch_lighttpd_phpchildren" /usr/local/sbin || perror "Could not copy patch_lighttpd_phpchildren script!" - chmod +x /usr/local/sbin/patch_lighttpd_phpchildren # Just to sleep better in dark nights. +mkdir -p /usr/local/sbin + +# TODO Make this a separate service, don't patch system file +if diffcp "patch_lighttpd_phpchildren" "/usr/local/sbin/patch_lighttpd_phpchildren" "Installing script to set dynamic php children value"; then if [ -f "/lib/systemd/system/lighttpd.service" ]; then # service file found, patching dynamic php children value at system start via patchfile if ! grep -q patch_lighttpd_phpchildren "/lib/systemd/system/lighttpd.service"; then @@ -434,22 +429,17 @@ if [ "$MAJOR" = 8 ] && [ -s "$FILEDIR/atftpd32.deb" ] && [ "$(uname -m)" == "i68 fi # ********************** atftpd.service ******************** -if [ -e "$FILEDIR/atftpd.service" ]; then - echo "Replacing atftpd.service" - cp "$FILEDIR/atftpd.service" "/etc/systemd/system/atftpd.service" || perror "Could not replace /etc/systemd/system/atftpd.service" +if diffcp "atftpd.service" "/etc/systemd/system/atftpd.service"; then ln -s -f "../atftpd.service" "/etc/systemd/system/multi-user.target.wants/" systemctl daemon-reload restart_service atftpd fi # ********************** dmsd.service ********************** -if [ -e "$FILEDIR/dmsd.service" ]; then - echo "* Replacing dmsd.service" - cp "$FILEDIR/dmsd.service" "/etc/systemd/system/dmsd.service" || perror "Could not replace /etc/systemd/system/dmsd.service" +if diffcp "dmsd.service" "/etc/systemd/system/dmsd.service"; then ln -s -f "../dmsd.service" "/etc/systemd/system/multi-user.target.wants/" systemctl daemon-reload restart_service dmsd - echo "Service file replaced" fi # ********************** dnbd3 config ******************* @@ -493,18 +483,9 @@ if ! dpkg -l | grep -q "^ii\\s.*$PACKAGE_LIBJANSSON"; then fi # config -if [ -e "$FILEDIR/server.conf" ]; then - echo "Inserting server.conf (dnbd3)" - cp "$FILEDIR/server.conf" "/etc/dnbd3-server/server.conf" || perror "Could not write /etc/dnbd3-server/server.conf" -fi -if [ -e "$FILEDIR/is-enabled" ]; then - echo "Inserting is-enabled to $PATH_DNBD3 (dnbd3)" - cp "$FILEDIR/is-enabled" "$PATH_DNBD3/is-enabled" || perror "Could not write /opt/openslx/dnbd3/is-enabled" -fi -if [ -e "$FILEDIR/rpc.acl" ]; then - echo "Inserting rpc.acl to $PATH_DNBD3 (dnbd3)" - cp "$FILEDIR/rpc.acl" "/etc/dnbd3-server/rpc.acl" || perror "Could not write /etc/dnbd3-server/rpc.acl" -fi +diffcp "server.conf" "/etc/dnbd3-server/server.conf" +diffcp "is-enabled" "$PATH_DNBD3/is-enabled" +diffcp "$FILEDIR/rpc.acl" "/etc/dnbd3-server/rpc.acl" if [ -n "$TGZ_DNBD3" ]; then echo "Extracting new dnbd3-server binary" @@ -512,10 +493,7 @@ if [ -n "$TGZ_DNBD3" ]; then fi # ********************** dnbd3.service ******************* -if [ -e "$FILEDIR/dnbd3-server.service" ]; then - echo "Replacing/writing dnbd3-server.service" - cp "$FILEDIR/dnbd3-server.service" "/etc/systemd/system/dnbd3-server.service" \ - || perror "Could not replace/write /etc/systemd/system/dnbd3-server.service" +if diffcp "dnbd3-server.service" "/etc/systemd/system/dnbd3-server.service"; then ln -s -f "../dnbd3-server.service" "/etc/systemd/system/multi-user.target.wants/" systemctl daemon-reload echo "Service file replaced" -- cgit v1.2.3-55-g7522