diff options
author | Christian Rößler | 2016-09-09 18:05:35 +0200 |
---|---|---|
committer | Christian Rößler | 2016-09-09 18:05:35 +0200 |
commit | 9b24cfdde569e7333abcdc1255a438329e432906 (patch) | |
tree | 50a05d791d4c5734c16041c41667a4c267c09ceb /satellit_upgrader | |
parent | [SSPS/SSUS] Added repos, tmate: litte refinements (diff) | |
parent | [SSUS] Minor improvements (patch version, wait for ipxe compile, ...) (diff) | |
download | setup-scripts-9b24cfdde569e7333abcdc1255a438329e432906.tar.gz setup-scripts-9b24cfdde569e7333abcdc1255a438329e432906.tar.xz setup-scripts-9b24cfdde569e7333abcdc1255a438329e432906.zip |
Merge branch 'master' of git.openslx.org:bwlp/setup-scripts
Diffstat (limited to 'satellit_upgrader')
-rwxr-xr-x | satellit_upgrader/pack-update.sh | 1 | ||||
-rw-r--r-- | satellit_upgrader/updater.template.sh | 79 |
2 files changed, 51 insertions, 29 deletions
diff --git a/satellit_upgrader/pack-update.sh b/satellit_upgrader/pack-update.sh index 526956e..9e6d3b6 100755 --- a/satellit_upgrader/pack-update.sh +++ b/satellit_upgrader/pack-update.sh @@ -87,6 +87,7 @@ if [ -e "$TGZ_SLXADMIN" ]; then [ -n "$VERS" ] || perror "Could not extract slx-admin version!" echo "Version: $VERS" sed -i "s/%TARGET_WEBIF_VERSION%/${VERS}/" "$UPDATER" || perror "could not patch slxadmin version in updater" + sed -i "s/%SLXADMIN_FOOTER%/$(date '+%y-%m-%d %H:%M')/" "$UPDATER" || perror "could not patch slxadmin footer in updater" patchtgz "TGZ_SLXADMIN" "$TGZ_SLXADMIN" else echo "no" diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh index 8f11d45..669821d 100644 --- a/satellit_upgrader/updater.template.sh +++ b/satellit_upgrader/updater.template.sh @@ -68,10 +68,8 @@ restart_service () { } # ** Recursively set permissions of given directory to 0755/0644 optionally setting owner/group -# ** If directory is not there it will be mkdir'ed. fixperms () { [ -e "$1" ] || perror "normalize_perms: $1 does not exist" - [ -d "$1" ] || mkdir -p "$1" chmod -R a-rw,u+rwX,go+rX "$1" if [ -n "$2" ]; then chown -R "$2" "$1" || pwarning "Could not change owner of $1 to $2" @@ -87,6 +85,7 @@ declare -rg TGZ_TFTP="%TGZ_TFTP%" declare -rg TGZ_IPXE="%TGZ_IPXE%" declare -rg TGZ_LDADP="%TGZ_LDADP%" declare -rg PAYLOAD_OFFSET="%PAYLOAD_OFFSET%" +declare -rg SLXADMIN_FOOTER="%SLXADMIN_FOOTER%" # ** Constants - hardcoded or determined at runtime declare -rg PATH_SLXADMIN="/srv/openslx/www/slx-admin" @@ -152,6 +151,7 @@ if [ -n "$TGZ_TASKMANAGER" ]; then fi # ************************** IPXE ************************** +IPXE_PID= if [ -n "$TGZ_IPXE" ]; then [ -e "$TMPDIR/$TGZ_IPXE" ] || perror "$TGZ_IPXE missing from payload" echo "* iPXE source code" @@ -167,18 +167,44 @@ if [ -n "$TGZ_IPXE" ]; then { cd "$PATH_IPXE/src" && sudo -n -u taskmanager nice -n 10 make -j2 bin/undionly.kkkpxe > /dev/null 2>&1 } & + IPXE_PID=$! fi # ************************** SLX-Admin ********************* if [ -n "$TGZ_SLXADMIN" ]; then [ -e "$TMPDIR/$TGZ_SLXADMIN" ] || perror "$TGZ_SLXADMIN missing from payload." echo "* SLX-Admin: $CURRENT_WEBIF_VERSION -> $TARGET_WEBIF_VERSION" - # Cheap hack: extract, then delete, extract again to get rid of old unused files. If the extraction fails, we don't leave - # the user with a broken webif, because we didn't remove the directories yet - tar tf "$TMPDIR/$TGZ_SLXADMIN" >/dev/null 2>&1 || perror "Could not extract $TGZ_SLXADMIN to $PATH_SLXADMIN" + # Test archive + tar tf "$TMPDIR/$TGZ_SLXADMIN" >/dev/null 2>&1 || perror "Could not read $TGZ_SLXADMIN" rm -rf -- "$PATH_SLXADMIN/"{inc,apis,modules,templates,Mustache,script,style} - tar -x -C "$PATH_SLXADMIN" -f "$TMPDIR/$TGZ_SLXADMIN" + 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 + # Get data from old config + OLDFOOTER="$(grep -m 1 CONFIG_FOOTER "${PATH_SLXADMIN}/config.php" | awk -F "'" '{print $4}' | sed 's/[ \[\]\(\)]*Update.*$//;s/#/+/g')" + SQLPASS=$(grep -m1 '^define.*CONFIG_SQL_PASS.*;' "${PATH_SLXADMIN}/config.php" | awk -F "'" '{print $4}') + # Patch config with new features using old mysql password + 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" + fi + # Update version info in footer + [ -z "$OLDFOOTER" ] && OLDFOOTER="Unknown base version" + FOOTER="$SLXADMIN_FOOTER" + [[ "$FOOTER" == %*% ]] && FOOTER= + if [ -z "$FOOTER" ]; then + D=$(stat -c %Y "$0") + [ -z "$D" ] && D=$(date +%s) + D=$(date -d "@$D" "+%y-%m-%d %H:%M") + FOOTER="Unknown $D" + fi + FOOTER="$OLDFOOTER [Update: ${FOOTER}]" + sed -i "s#^.*define.*CONFIG_FOOTER.*\$#define('CONFIG_FOOTER', '${FOOTER}');#" "${PATH_SLXADMIN}/config.php" + grep -q 'CONFIG_FOOTER' "${PATH_SLXADMIN}/config.php" || echo "define('CONFIG_FOOTER', '${FOOTER}');" >> "${PATH_SLXADMIN}/config.php" + echo "$TARGET_WEBIF_VERSION" > "${PATH_SLXADMIN}/version" + fi # Enable modules ( mkdir -p "$PATH_SLXADMIN/modules" @@ -203,23 +229,10 @@ if [ -n "$TGZ_SLXADMIN" ]; then pwarning "slxadmin updater didn't finish with 'Done.'" fi ) - # New config.php supplied - if [ -s "$FILEDIR/slxadmin-config.php" ]; then - # Patch config with new features using old mysql password - SQLPASS=$(grep -m1 '^define.*CONFIG_SQL_PASS.*;' "${PATH_SLXADMIN}/config.php" | awk -F "'" '{print $4}') - 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" - fi - fi fixperms "$PATH_SLXADMIN" root:root chmod 0640 "$PATH_SLXADMIN/config.php" chown root:www-data "$PATH_SLXADMIN/config.php" - # Update version number in DB - doesn't make too much sense like this, restore would overwrite - mysql -e "INSERT INTO openslx.property (name, value) VALUES ('webif-version', '${TARGET_WEBIF_VERSION}') - ON DUPLICATE KEY UPDATE value = VALUES(value)" || pwarning "Could not update version number in DB" # config.tgz symlink -> db entry if [ -L /srv/openslx/www/boot/default/config.tgz ]; then CONFTGZ=$(readlink /srv/openslx/www/boot/default/config.tgz | sed "s/'/\\\'/g") @@ -230,20 +243,18 @@ if [ -n "$TGZ_SLXADMIN" ]; then fi ln -s -f "$PATH_TFTP" "/srv/openslx/www/tftp" || perror "Could not symlink $PATH_TFTP to /srv/openslx/www/tftp" echo "Web interface upgrade complete" + mkdir -p "${PATH_SLXADMINCACHE}" fixperms "${PATH_SLXADMINCACHE}" www-data:www-data - - if [ -h "${PATH_SLXADMINCACHE}/baseconfig-bwidm_settings.json" ]; then - pwarning "There is already a link or file /srv/openslx/www/slx-admin/modules-available/baseconfig_bwidm/baseconfig/settings.json. Please check manually, it should lead to /srv/openslx/www/slx-admin/modules-available/baseconfig_bwidm/baseconfig/settings.json" - else - ln -s "${PATH_SLXADMINCACHE}/baseconfig-bwidm_settings.json" /srv/openslx/www/slx-admin/modules-available/baseconfig_bwidm/baseconfig/settings.json || \ - pwarning "Could not set link ${PATH_SLXADMINCACHE}/baseconfig-bwidm_settings.json to /srv/openslx/www/slx-admin/modules-available/baseconfig_bwidm/baseconfig/settings.json - do so manually" - fi + + rm -f -- "/srv/openslx/www/slx-admin/modules-available/baseconfig_bwidm/baseconfig/settings.json" + ln -s "${PATH_SLXADMINCACHE}/baseconfig-bwidm_settings.json" /srv/openslx/www/slx-admin/modules-available/baseconfig_bwidm/baseconfig/settings.json || \ + pwarning "Could not set link ${PATH_SLXADMINCACHE}/baseconfig-bwidm_settings.json to /srv/openslx/www/slx-admin/modules-available/baseconfig_bwidm/baseconfig/settings.json - do so manually if you need bwIDM login on client computers" fi -#************************* Dozmod ************************* +# ************************* Dozmod ************************* if [ -n "$TGZ_DOZMOD" ]; then [ -e "$TMPDIR/$TGZ_DOZMOD" ] || perror "$TGZ_DOZMOD missing from payload." - echo "* Dozentenmodul" + echo "* bwLehrpool-Suite Server (dmsd)" echo "Adjusting mysql permissions of user sat" mysql -e 'GRANT CREATE, ALTER ON sat.* TO sat@localhost' || perror "Could not GRANT permissions ON sat.* to sat@localhost" mysql -e 'GRANT SELECT ON openslx.location TO sat@localhost' || perror "Could not GRANT permissions ON openslx.location to sat@localhost" @@ -259,7 +270,7 @@ if [ -n "$TGZ_DOZMOD" ]; then fixperms "$PATH_DOZMOD" root:images echo "Restarting service" restart_service dmsd - echo "Dozentenmodul Server Daemon upgrade complete" + echo "dmsd upgrade complete" fi # ************************** TFTP ************************** @@ -339,12 +350,22 @@ if [ -n "$FILEDIR/tm-sudo-config" ]; then chmod 0440 "/etc/sudoers.d/taskmanager" fi +echo -n "Finishing." for i in 1 1 1 1 2 2 3 4 END; do CB=$(sudo -u www-data -n php /srv/openslx/www/slx-admin/api.php cb) [ "x$CB" != "xTrue" ] && break [ "$i" = "END" ] && break + echo -n "." sleep $i done +count=0 +[ -n "$IPXE_PID" ] && while kill -0 "$IPXE_PID" 2>/dev/null; do + echo -n "." + sleep 2 + count=$(( count + 1 )) + [ "$count" -gt 5 ] && break +done +echo ". done!" echo "" echo "Update complete. It is recommended to reboot the server." |