From 99f8b79a1c4f897ef2c30c213f39ba4b7b7f9fe1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 9 Mar 2021 14:42:26 +0100 Subject: [SSUS] Get ready for changed static_files struct, support new dnbd3 --- satellit_upgrader/updater.template.sh | 133 ++++++++++++++++++++-------------- 1 file changed, 77 insertions(+), 56 deletions(-) (limited to 'satellit_upgrader/updater.template.sh') diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh index f42b5d8..b745310 100644 --- a/satellit_upgrader/updater.template.sh +++ b/satellit_upgrader/updater.template.sh @@ -94,12 +94,13 @@ fixperms () { fi } -# diffcp "foo.txt" "/opt/openslx/dest.txt" ["Installing new foo file"] +# diffcp [message] +# diffcp "dnbd3" "/opt/openslx/foo.txt" ["Installing new foo file"] diffcp () { - local SRC="$FILEDIR/$1" - local DST=$2 + local SRC="$FILEDIR/$1/$2" + local DST="/$2" [ -e "$SRC" ] || return 1 - [ -f "$SRC" ] || perror "$1 included in updater, but is not regular file." + [ -f "$SRC" ] || perror "$1/$2 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 @@ -107,9 +108,9 @@ diffcp () { if [ -n "$3" ]; then echo "$3" else - echo "Installing $1" + echo "Installing $2" fi - cp "$SRC" "$DST" || cp -f "$SRC" "$DST" || perror "Could not copy '$1' to '$DST'" + cp -d "$SRC" "$DST" 2> /dev/null || cp -d -f "$SRC" "$DST" || perror "Could not copy '$1/$2' to '$DST'" return 0 } @@ -305,11 +306,13 @@ fi if [ -z "$tm_password" ]; then tm_password="$(generate_password)" fi -[ -n "$tm_password" ] && sed -i "s/%TM_OPENSLX_PASS%/${tm_password}/" "$FILEDIR/taskmanager/config" +if [ -n "$tm_password" ]; then + sed -i "s/%TM_OPENSLX_PASS%/${tm_password}/" "$FILEDIR/taskmanager/$PATH_TASKMANAGER/config/config" +fi mkdir -m 0750 -p "$PATH_TASKMANAGER/config" -diffcp "taskmanager/config" "$PATH_TASKMANAGER/config/config" && tm_restart=1 -diffcp "taskmanager/environment" "$PATH_TASKMANAGER/config/environment" && tm_restart=4 -diffcp "taskmanager/taskmanager.service" "/etc/systemd/system/taskmanager.service" && tm_restart=111 +diffcp "taskmanager" "$PATH_TASKMANAGER/config/config" && tm_restart=1 +diffcp "taskmanager" "$PATH_TASKMANAGER/config/environment" && tm_restart=4 +diffcp "taskmanager" "/etc/systemd/system/taskmanager.service" && tm_restart=111 # java app if [ -n "$TGZ_TASKMANAGER" ]; then [ -e "$TMPDIR/$TGZ_TASKMANAGER" ] || perror "$TGZ_TASKMANAGER missing from payload" @@ -331,7 +334,7 @@ fi chmod 0640 "$PATH_TASKMANAGER/config/config" chown -R root:taskmanager "$PATH_TASKMANAGER/config" # sudo config -if diffcp "tm-sudo-config" "/etc/sudoers.d/taskmanager" "Installing new sudo config for taskmanager"; then +if diffcp "taskmanager" "/etc/sudoers.d/taskmanager" "Installing new sudo config for taskmanager"; then chmod 0440 "/etc/sudoers.d/taskmanager" fi if [ -n "$tm_restart" ]; then @@ -408,7 +411,7 @@ if [ -n "$TGZ_SLXADMIN" ]; then tar -x -C "$PATH_SLXADMIN" -f "$TMPDIR/$TGZ_SLXADMIN" || perror "Could not extract $TGZ_SLXADMIN to $PATH_SLXADMIN" rm -f -- "$PATH_SLXADMIN/config.php.example" # New config.php supplied - if [ -s "$FILEDIR/slxadmin-config.php" ]; then + if [ -s "$FILEDIR/slxadmin/${PATH_SLXADMIN}/config.php" ]; then echo "Updating slx-admin config" # Get data from old config OLDFOOTER="$(grep -m 1 CONFIG_FOOTER "${PATH_SLXADMIN}/config.php" | awk -F "'" '{print $4}' | sed 's/[ \[\]\(\)]*Update.*$//;s/#/+/g')" @@ -417,7 +420,7 @@ if [ -n "$TGZ_SLXADMIN" ]; then if [ -z "$SQLPASS" ]; then pwarning "Could not extract old slx-admin mysql password - cannot update config :(" else - sed "s/%MYSQL_OPENSLX_PASS%/${SQLPASS}/g" "$FILEDIR/slxadmin-config.php" > "${PATH_SLXADMIN}/config.php" + sed "s/%MYSQL_OPENSLX_PASS%/${SQLPASS}/g" "$FILEDIR/slxadmin/${PATH_SLXADMIN}/config.php" > "${PATH_SLXADMIN}/config.php" fi sed -i "s/%TM_OPENSLX_PASS%/${tm_password}/g" "${PATH_SLXADMIN}/config.php" # Update version info in footer @@ -434,12 +437,12 @@ if [ -n "$TGZ_SLXADMIN" ]; then echo "Config updated" fi # New scripts supplied - diffcp "slxadmin-cronscript" "/opt/openslx/slxadmin-cronscript" - diffcp "slxadmin-bootscript" "/opt/openslx/slxadmin-bootscript" + diffcp "slxadmin" "/opt/openslx/slxadmin-cronscript" + diffcp "slxadmin" "/opt/openslx/slxadmin-bootscript" # New crontab supplied - diffcp "slxadmin-crontab" "/etc/cron.d/slx-admin" + diffcp "slxadmin" "/etc/cron.d/slx-admin" # Service - diffcp "slxadmin-boot.service" "/etc/systemd/system/slxadmin-boot.service" + diffcp "slxadmin" "/etc/systemd/system/slxadmin-boot.service" ln -nfs "../slxadmin-boot.service" "/etc/systemd/system/multi-user.target.wants/slxadmin-boot.service" # Ask about ipxe / pxelinux if [ -z "$bootmodule" ] || [ "$bootmodule" = "serversetup-bwlp-pxelinux" ] || ! [ -d "$PATH_SLXADMIN/modules-available/$bootmodule" ]; then @@ -550,17 +553,17 @@ echo "* Configuring lighttpd" if [ "$MAJOR" -lt 10 ]; then # Filename changed on Debian 10, patch back for 9 - sed -i 's/create-mime\.conf\.pl/create-mime.assign.pl/' "$FILEDIR/lighttpd.conf" + sed -i 's/create-mime\.conf\.pl/create-mime.assign.pl/' "$FILEDIR/lighttpd/etc/lighttpd/lighttpd.conf" fi -diffcp "lighttpd.conf" "/etc/lighttpd/lighttpd.conf" && restart["lighttpd.service"]=ja -diffcp "lighttpd-auto-ssl.sh" "/usr/share/lighttpd/auto-ssl.sh" && restart["lighttpd.service"]=ja -diffcp "slx-cert" "/opt/openslx/slx-cert" && restart["lighttpd.service"]=ja -diffcp "lighttpd-include-conf-d.sh" "/usr/share/lighttpd/include-conf-d.sh" && restart["lighttpd.service"]=ja +diffcp "lighttpd" "/etc/lighttpd/lighttpd.conf" && restart["lighttpd.service"]=ja +diffcp "lighttpd" "/usr/share/lighttpd/auto-ssl.sh" && restart["lighttpd.service"]=ja +diffcp "lighttpd" "/opt/openslx/slx-cert" && restart["lighttpd.service"]=ja +diffcp "lighttpd" "/usr/share/lighttpd/include-conf-d.sh" && restart["lighttpd.service"]=ja # ********************** lighttpd php_children ************* mkdir -p /usr/local/sbin -if diffcp "patch_lighttpd_phpchildren" "/usr/local/sbin/patch_lighttpd_phpchildren" "Installing script to set dynamic php children value" \ +if diffcp "lighttpd" "/usr/local/sbin/patch_lighttpd_phpchildren" "Installing script to set dynamic php children value" \ || grep -qF 'patch_lighttpd_phpchildren' "/lib/systemd/system/lighttpd.service"; then if [ -f "/lib/systemd/system/lighttpd.service" ]; then # remove old hacky way @@ -589,7 +592,7 @@ fi # ************************** PHP *************************** inicount=0 -for PHPINIFILE in /etc/php/7.*/cgi/php.ini; do +for PHPINIFILE in /etc/php/*/cgi/php.ini; do [ -f "$PHPINIFILE" ] || continue inicount=$(( inicount + 1 )) if ! grep -q -E '^\s*upload_max_filesize = 100M' "$PHPINIFILE"; then @@ -632,13 +635,11 @@ fi chg=false if which "atftpd" &>/dev/null || dpkg-query -W -f='${db:Status-Abbrev}' "atftpd" 2> /dev/null | grep -q '^ii' \ || ! which "in.tftpd" &>/dev/null; then - if diffcp "tftpd/tftpd-hpa" "/etc/default/tftpd-hpa"; then - echo "Replacing atftpd with tftpd-hpa" - systemctl stop atftpd.service - failprint apt-get purge -y atftpd || pwarning "Could not uninstall atftpd" - aptinst tftpd-hpa || perror "Could not install tftpd-hpa. Netboot is now broken." - chg=true - fi + echo "Replacing atftpd with tftpd-hpa" + systemctl stop atftpd.service + failprint apt-get purge -y atftpd || pwarning "Could not uninstall atftpd" + aptinst tftpd-hpa || perror "Could not install tftpd-hpa. Netboot is now broken." + chg=true fi if [ -e "/etc/systemd/system/atftpd.service" ]; then @@ -647,9 +648,9 @@ if [ -e "/etc/systemd/system/atftpd.service" ]; then chg=true fi -diffcp "tftpd/tftpd-hpa" "/etc/default/tftpd-hpa" && chg=true -diffcp "tftpd/tftpd-hpa.service" "/etc/systemd/system/tftpd-hpa.service" && chg=true -diffcp "tftpd/tftpd-remap" "/opt/openslx/tftpd-remap" && chg=true +diffcp "tftpd" "/etc/default/tftpd-hpa" && chg=true +diffcp "tftpd" "/etc/systemd/system/tftpd-hpa.service" && chg=true +diffcp "tftpd" "/opt/openslx/tftpd-remap" && chg=true if "$chg"; then ln -s -f "../tftpd-hpa.service" "/etc/systemd/system/multi-user.target.wants/" daemon_reload=true @@ -657,7 +658,7 @@ if "$chg"; then fi # ********************** dmsd.service ********************** -if diffcp "dmsd.service" "/etc/systemd/system/dmsd.service"; then +if diffcp "dmsd" "/etc/systemd/system/dmsd.service"; then ln -s -f "../dmsd.service" "/etc/systemd/system/multi-user.target.wants/" daemon_reload=1 restart["dmsd.service"]=2 @@ -686,51 +687,65 @@ if ! id -u dnbd3 &> /dev/null; then fi # config -diffcp "dnbd3/server.conf" "/etc/dnbd3-server/server.conf" -diffcp "dnbd3/rpc.acl" "/etc/dnbd3-server/rpc.acl" -diffcp "dnbd3/alt-servers" "/etc/dnbd3-server/alt-servers" +diffcp "dnbd3" "/etc/dnbd3-server/server.conf" +diffcp "dnbd3" "/etc/dnbd3-server/rpc.acl" +diffcp "dnbd3" "/etc/dnbd3-server/alt-servers" rm -f -- "$PATH_DNBD3/is-enabled" if [ -n "$TGZ_DNBD3" ]; then tmpdir="$TMPDIR/dnbd3.tmp" mkdir -p "$tmpdir" tar --transform='s,^[./]*dnbd3[^/]*/,,' -x -C "$tmpdir" -f "$TMPDIR/$TGZ_DNBD3" || perror "Could not extract $TGZ_DNBD3 to $tmpdir" - cver=$( "$PATH_DNBD3/dnbd3-server" --version 2> /dev/null | grep -Po '(?<=^Version: ).*(?=, branch)' ) + cver=$( "$PATH_DNBD3/dnbd3-server" --version 2> /dev/null | grep -Poi '(?<=Version: ).*(?=, branch)' ) nver=$( < "$tmpdir/inc/dnbd3/version.h" grep -Po '(?<=^#define DNBD3_VERSION ").*(?=")' ) [ -z "$cver" ] && pwarning "BUG BUG! Cannot query dnbd3 version information from currently installed binary!" [ -z "$nver" ] && pwarning "BUG BUG! Updater package contains no dnbd3 version information!" mkdir -p "$PATH_DNBD3" if [ "${cver#v}" != "${nver#v}" ]; then - aptinst libjansson-dev - aptinst libfuse-dev - aptinst cmake echo "Compiling new dnbd3-server binary..." cd "$tmpdir" - mkdir build - cd build - if ! failprint cmake -DDNBD3_CLIENT_FUSE=OFF -DDNBD3_KERNEL_MODULE=OFF \ - -DDNBD3_SERVER=ON -DDNBD3_SERVER_FUSE=OFF -DCMAKE_BUILD_TYPE=Release ..; then - pwarning "Could not cmake new version $nver of dnbd3-server" - elif ! failprint make -j2 dnbd3-server; then - pwarning "Could not compile new version $nver of dnbd3-server" - elif ! cp -f dnbd3-server "$PATH_DNBD3/dnbd3-server"; then - pwarning "Successfully built new dnbd3-server, but could not copy binary to $PATH_DNBD3/dnbd3-server" - else # Clear this so we know not to print the "trying to keep going.." message - cver= + aptinst libjansson-dev + if [ "$MAJOR" -le 9 ]; then + # cmake too old; try with makefile + if ! cp "$FILEDIR/dnbd3-Makefile" Makefile; then + pwarning "Could not get legacy dnbd3 make file" + elif ! failprint make -j2 dnbd3-server; then + pwarning "Could not compile new dnbd3-server version $nver" + elif ! cp -f dnbd3-server "$PATH_DNBD3/dnbd3-server"; then + pwarning "Successfully built new dnbd3-server, but could not copy binary to $PATH_DNBD3/dnbd3-server" + else + cver= + fi + else + # New proper cmake way + aptinst libfuse-dev + aptinst cmake + mkdir build + cd build + if ! failprint cmake -DDNBD3_CLIENT_FUSE=OFF -DDNBD3_KERNEL_MODULE=OFF \ + -DDNBD3_SERVER=ON -DDNBD3_SERVER_FUSE=OFF -DCMAKE_BUILD_TYPE=Release ..; then + pwarning "Could not cmake new version $nver of dnbd3-server" + elif ! failprint make -j2 dnbd3-server; then + pwarning "Could not compile new version $nver of dnbd3-server" + elif ! cp -f dnbd3-server "$PATH_DNBD3/dnbd3-server"; then + pwarning "Successfully built new dnbd3-server, but could not copy binary to $PATH_DNBD3/dnbd3-server" + else # Clear this so we know not to print the "trying to keep going.." message + cver= + fi fi [ -n "$cver" ] && pwarning "Trying to keep going with current version $cver" fi fi # ******************* dnbd3-server.service *************** -if diffcp "dnbd3/dnbd3-server.service" "/etc/systemd/system/dnbd3-server.service"; then +if diffcp "dnbd3" "/etc/systemd/system/dnbd3-server.service"; then ln -n -s -f "../dnbd3-server.service" "/etc/systemd/system/multi-user.target.wants/dnbd3-server.service" daemon_reload=1 restart["dnbd3-server.service"]=1 fi # *************** dnbd3-master-proxy.service ************* -if diffcp "dnbd3/dnbd3-master-proxy.service" "/etc/systemd/system/dnbd3-master-proxy.service"; then +if diffcp "dnbd3" "/etc/systemd/system/dnbd3-master-proxy.service"; then aptinst socat ln -n -s -f "../dnbd3-master-proxy.service" "/etc/systemd/system/multi-user.target.wants/dnbd3-master-proxy.service" daemon_reload=2 @@ -792,6 +807,12 @@ if ! [ -s /root/.ssh/id_rsa ]; then ssh-keygen -f /root/.ssh/id_rsa -N '' -C autogenerated &>/dev/null || pwarning "Could not create new ssh keypair in /root/.ssh/id_rsa" fi +# Timesync +diffcp "timesync" "/etc/systemd/system/redneck-timesync.service" +diffcp "timesync" "/usr/local/sbin/redneck-timesync.sh" +mkdir -p "/etc/systemd/system/network-online.target.wants" +ln -nfs "../redneck-timesync.service" "/etc/systemd/system/network-online.target.wants/redneck-timesync.service" + # Wait for webif callbacks and IPXE compile echo -n "Finishing." sudo -u www-data -n php /srv/openslx/www/slx-admin/api.php rebootcontrol --action rebuild >/dev/null 2>&1 @@ -861,7 +882,7 @@ for i in /opt/openslx/restore.d/*/init.sh; do done # Patch the update version in /etc/motd -sed -r -i 's/(bwLehrpool Satelliten-Server, Version[^[(*]*)\s*([[(]Update.*[])]\s*)?/\1\[Update: '"${SLXADMIN_FOOTER}"'] /g' /etc/motd +sed -r -i 's/(bwLehrpool Satelliten-Server, Version[^[(*]*)\s*([[(]Update.*[])])?\s*/\1 [Update: '"${SLXADMIN_FOOTER}"'] /g' /etc/motd echo "" echo "Update complete. This update needs a reboot to be working as intended. Please do so now." -- cgit v1.2.3-55-g7522