summaryrefslogtreecommitdiffstats
path: root/satellit_upgrader/updater.template.sh
diff options
context:
space:
mode:
authorSimon Rettberg2016-09-09 13:58:04 +0200
committerSimon Rettberg2016-09-09 13:58:04 +0200
commitd9eabe8d94c31c045ddb6e50536ff1325581b43b (patch)
tree8ea71b2570b667acfe14aa58df81cfdcddf9ed9e /satellit_upgrader/updater.template.sh
parent[SSPS] Update slxadmin config.php (diff)
downloadsetup-scripts-d9eabe8d94c31c045ddb6e50536ff1325581b43b.tar.gz
setup-scripts-d9eabe8d94c31c045ddb6e50536ff1325581b43b.tar.xz
setup-scripts-d9eabe8d94c31c045ddb6e50536ff1325581b43b.zip
[SSUS] Minor improvements (patch version, wait for ipxe compile, ...)
Diffstat (limited to 'satellit_upgrader/updater.template.sh')
-rw-r--r--satellit_upgrader/updater.template.sh75
1 files changed, 49 insertions, 26 deletions
diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh
index 93cafc3..7b3ef0a 100644
--- a/satellit_upgrader/updater.template.sh
+++ b/satellit_upgrader/updater.template.sh
@@ -85,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"
@@ -150,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"
@@ -165,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"
@@ -201,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")
@@ -228,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"
@@ -257,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 **************************
@@ -329,12 +342,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."