Add support for post-upgrade scripts with network

This commit is contained in:
Calin Crisan 2020-01-14 23:43:16 +02:00
parent 6d374f64b7
commit 8ea36fe63d
2 changed files with 45 additions and 2 deletions

View File

@ -3,6 +3,7 @@
SYS_VERSION_FILE="/etc/version" SYS_VERSION_FILE="/etc/version"
VERSION_FILE="/data/etc/version" VERSION_FILE="/data/etc/version"
POST_UPGRADE_DIR="/usr/share/post-upgrade" POST_UPGRADE_DIR="/usr/share/post-upgrade"
POST_UPGRADE_NET_SCHEDULED="/data/.post-upgrade-net-scheduled"
LOG="/var/log/post-upgrade.log" LOG="/var/log/post-upgrade.log"
@ -30,11 +31,18 @@ function run_post_upgrade() {
echo "---- post-upgrade from ${version} to ${sys_version} ----" >> ${LOG} echo "---- post-upgrade from ${version} to ${sys_version} ----" >> ${LOG}
versions=$(ls -1 ${POST_UPGRADE_DIR} | cut -d '.' -f 1) echo -n > ${POST_UPGRADE_NET_SCHEDULED}
versions=$(ls -1 ${POST_UPGRADE_DIR} | rev | cut -d '.' -f 2-100 | rev)
for v in ${versions}; do for v in ${versions}; do
if [[ ${v} == "post-upgrade" ]]; then if [[ ${v} == "post-upgrade" ]]; then
continue continue
fi fi
if [[ ${v} == *-net ]]; then # scripts that require network
echo "${POST_UPGRADE_DIR}/${v}.sh" >> ${POST_UPGRADE_NET_SCHEDULED}
continue
fi
if [[ -z "${version}" ]] || version_gt ${v} ${version}; then if [[ -z "${version}" ]] || version_gt ${v} ${version}; then
msg_begin "Post-upgrading to version ${v}" msg_begin "Post-upgrading to version ${v}"
@ -66,4 +74,3 @@ case "$1" in
esac esac
exit $? exit $?

View File

@ -0,0 +1,36 @@
#!/bin/bash
POST_UPGRADE_NET_SCHEDULED="/data/.post-upgrade-net-scheduled"
LOG="/var/log/post-upgrade.log"
test -n "${OS_VERSION}" || source /etc/init.d/base
test -s ${POST_UPGRADE_NET_SCHEDULED} || exit 0
function run_post_upgrade() {
for script in $(cat ${POST_UPGRADE_NET_SCHEDULED}); do
msg_begin "Running post-upgrade script ${script}"
${script} >> ${LOG} 2>&1
test $? == 0 && msg_done || msg_fail
done
}
case "$1" in
start)
run_post_upgrade
rm ${POST_UPGRADE_NET_SCHEDULED}
;;
stop)
true
;;
*)
echo "Usage: $0 {start}"
exit 1
esac
exit $?