diff options
author | Simon Rettberg | 2021-03-09 14:42:26 +0100 |
---|---|---|
committer | Simon Rettberg | 2021-03-09 14:42:26 +0100 |
commit | 99f8b79a1c4f897ef2c30c213f39ba4b7b7f9fe1 (patch) | |
tree | b1e12a6ae4bc054f3314faf3df3f681279d151e7 /satellit_upgrader | |
parent | [SSPS] Update dnbd3 config: bgrWindowSize and diskFreeDelay (diff) | |
download | setup-scripts-99f8b79a1c4f897ef2c30c213f39ba4b7b7f9fe1.tar.gz setup-scripts-99f8b79a1c4f897ef2c30c213f39ba4b7b7f9fe1.tar.xz setup-scripts-99f8b79a1c4f897ef2c30c213f39ba4b7b7f9fe1.zip |
[SSUS] Get ready for changed static_files struct, support new dnbd3
Diffstat (limited to 'satellit_upgrader')
-rw-r--r-- | satellit_upgrader/dnbd3-Makefile | 48 | ||||
-rwxr-xr-x | satellit_upgrader/pack-update.sh | 65 | ||||
-rw-r--r-- | satellit_upgrader/updater.template.sh | 133 |
3 files changed, 135 insertions, 111 deletions
diff --git a/satellit_upgrader/dnbd3-Makefile b/satellit_upgrader/dnbd3-Makefile new file mode 100644 index 0000000..75455dc --- /dev/null +++ b/satellit_upgrader/dnbd3-Makefile @@ -0,0 +1,48 @@ +all: dnbd3-server + +CC?=gcc +CFLAGS+=-pipe -DNDEBUG -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE \ + -O3 -W -Wall -Wextra -std=gnu11 -Wno-unused-parameter -Iinc/ +#CC=clang +#CFLAGS=-g -pipe -fsanitize=address -O1 -fno-omit-frame-pointer -W -Wall -Wextra -std=gnu99 -Wno-unused-parameter + +LIBS+=-ljansson -latomic -lpthread + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + + +dnbd3-server: inc/dnbd3/build.h \ + src/server/altservers.o \ + src/server/fileutil.o \ + src/server/fuse.o \ + src/server/globals.o \ + src/server/helper.o \ + src/server/image.o \ + src/server/ini.o \ + src/server/integrity.o \ + src/server/locks.o \ + src/server/net.o \ + src/server/picohttpparser/picohttpparser.o \ + src/server/reference.o \ + src/server/rpc.o \ + src/server/server.o \ + src/server/threadpool.o \ + src/server/uplink.o \ + src/server/urldecode.o \ + src/shared/crc32.o \ + src/shared/fdsignal.o \ + src/shared/log.o \ + src/shared/serialize.o \ + src/shared/sockhelper.o \ + src/shared/timing.o + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) ${LIBS} + +inc/dnbd3/build.h: + @sed "s/@DNBD3_BUILD@/Makefile/;s/@DNBD3_BUILD_DATE@/$$(date +%Y-%m-%d)/" inc/dnbd3/build.h.in > inc/dnbd3/build.h + +.PHONY: clean inc/dnbd3/build.h + +clean: + rm -f -- *.[ao] dnbd3-server inc/dnbd3/build.h src/*/*.o src/*/*/*.o + diff --git a/satellit_upgrader/pack-update.sh b/satellit_upgrader/pack-update.sh index fb25efb..b23aaa7 100755 --- a/satellit_upgrader/pack-update.sh +++ b/satellit_upgrader/pack-update.sh @@ -20,6 +20,9 @@ patchtgz () { declare -rg UPDATER="updater.sh" +# Declare all the archives we need with a couple of expected contents, +# so we can detect goof-ups right when packing the update + declare -rg TGZ_SLXADMIN="files/slx-admin.tar.gz" declare -rg FILES_SLXADMIN=" modules-available/ @@ -105,12 +108,8 @@ cp "updater.template.sh" "$UPDATER" || perror "could not copy template" chmod +x "$UPDATER" VERSION= -LEAN= while true; do case "$1" in - --lean|-l) - LEAN=true - ;; --version) shift VERSION="$1" @@ -166,24 +165,6 @@ addpayload () { fi } -addinstallfile () { - echo -n "Includes $1: " - local file=$1 - local path=$(dirname "$file") - if [ ! -d "../satellit_installer" ]; then - echo "${RED}NO!${RESET} (satellit_installer not found)" - elif [ ! -e "../satellit_installer/static_files/$file" ]; then - echo "${RED}NO!${RESET} (file not found in satellit_installer/static_files)" - else - mkdir -p "files/$path" || echo -n "(mkdir failed) " - if cp "../satellit_installer/static_files/$file" "files/$file"; then - echo "${GREEN}yes${RESET}" - else - echo "...${RED}no!${RESET} (copy failed)" - fi - fi -} - # Replace variables # slxadmin version echo -n "Includes SLX-Admin: " @@ -207,39 +188,13 @@ addpayload "IPXE" "iPXE source code" addpayload "LDADP" "ldap/ad proxy source code" addpayload "DNBD3" "dnbd3-server source code" -addinstallfile "taskmanager/config" -addinstallfile "taskmanager/environment" -addinstallfile "taskmanager/taskmanager.service" - -if [ -z "$LEAN" ]; then - addinstallfile "lighttpd.conf" - addinstallfile "lighttpd-auto-ssl.sh" - addinstallfile "lighttpd-include-conf-d.sh" - addinstallfile "slxadmin-config.php" - addinstallfile "slxadmin-cronscript" - addinstallfile "slxadmin-crontab" - addinstallfile "slxadmin-bootscript" - addinstallfile "slxadmin-boot.service" - addinstallfile "patch_lighttpd_phpchildren" - addinstallfile "slx-cert" - - addinstallfile "dnbd3/dnbd3-server.service" - addinstallfile "dnbd3/server.conf" - addinstallfile "dnbd3/rpc.acl" - addinstallfile "dnbd3/alt-servers" - addinstallfile "dnbd3/dnbd3-master-proxy.service" - - addinstallfile "tftpd/tftpd-hpa.service" - addinstallfile "tftpd/tftpd-hpa" - addinstallfile "tftpd/tftpd-remap" - addinstallfile "slxadmin-init/gpg-key.asc" - addinstallfile "slxadmin-init/slxadmin-init.php" - addinstallfile "slxadmin-init/init.sh" - - # TODO: Unify more - source ../satellit_installer/includes/10-sudo_config.inc - sudo_config files/tm-sudo-config -fi +# Add complete static_files directory structure +find ../satellit_installer/static_files -mindepth 1 -maxdepth 1 -type d \ + -exec cp -a {} files/ \; \ + || perror "Could not copy static_files dir structure" + +# Add simple dnbd3-server Makefile we need for older Debian 9 sats +cp dnbd3-Makefile files/ || perror "Could not include dnbd3 Makefile" # Last patch: Payload offset # Calc payload offset, which is tricky as the size changes as we patch 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 <module> <file> [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." |