diff --git a/xCAT/debian/postinst b/xCAT/debian/postinst index bbb179eded..bba19ba253 100644 --- a/xCAT/debian/postinst +++ b/xCAT/debian/postinst @@ -20,11 +20,28 @@ set -e case "$1" in configure) + state_dir=/var/lib/xcat/configure-state + if [ -L "$state_dir" ] || [ -L "$state_dir/context" ] || + { [ -e "$state_dir" ] && [ ! -d "$state_dir" ]; }; then + echo "Invalid xCAT configuration state: $state_dir" >&2 + exit 1 + fi + if [ -f "$state_dir/context" ]; then + context=$(cat "$state_dir/context") + case "$context" in + fresh|upgrade) ;; + *) echo "Invalid xCAT configuration context in $state_dir/context: $context" >&2; exit 1 ;; + esac + elif [ -f /tmp/xCAT_upgrade.tmp ]; then + context=upgrade + else + context=fresh + fi # Make dir for the current pid mkdir -p /var/run/xcat cp -f /opt/xcat/share/xcat/scripts/xHRM /install/postscripts/ . /etc/profile.d/xcat.sh - if [ -f /tmp/xCAT_upgrade.tmp ] + if [ "$context" = upgrade ] then if [ -r "/tmp/xcat/installservice.pid" ]; then mv /tmp/xcat/installservice.pid /var/run/xcat/installservice.pid @@ -36,7 +53,6 @@ case "$1" in mv /tmp/xcat/mainservice.pid /var/run/xcat/mainservice.pid fi xcat_run_upgrade xcatconfig -u -V - rm /tmp/xCAT_upgrade.tmp else xcatconfig -i fi @@ -75,4 +91,9 @@ esac #DEBHELPER# +if [ "$1" = configure ]; then + rm -f "$state_dir/context" /tmp/xCAT_upgrade.tmp + rmdir "$state_dir" 2>/dev/null || : +fi + exit 0 diff --git a/xCAT/debian/postrm b/xCAT/debian/postrm new file mode 100755 index 0000000000..65ea2b2b66 --- /dev/null +++ b/xCAT/debian/postrm @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +case "$1" in + remove|purge|abort-install|disappear) + state_dir=/var/lib/xcat/configure-state + if [ -L "$state_dir" ]; then + echo "Invalid xCAT configuration state directory: $state_dir" >&2 + exit 1 + fi + rm -f "$state_dir/context" "$state_dir"/context.* /tmp/xCAT_upgrade.tmp + rmdir "$state_dir" 2>/dev/null || : + ;; + upgrade|failed-upgrade|abort-upgrade) ;; + *) echo "postrm called with unknown argument: $1" >&2; exit 1 ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/xCAT/debian/preinst b/xCAT/debian/preinst new file mode 100755 index 0000000000..5231f71e49 --- /dev/null +++ b/xCAT/debian/preinst @@ -0,0 +1,42 @@ +#!/bin/sh +set -e + +state_dir=/var/lib/xcat/configure-state + +case "$1" in + install) context=fresh ;; + upgrade) context=upgrade ;; + abort-upgrade) context= ;; + *) echo "preinst called with unknown argument: $1" >&2; exit 1 ;; +esac + +if [ -n "$context" ]; then + if [ -L "$state_dir" ] || [ -L "$state_dir/context" ] || + { [ -e "$state_dir" ] && [ ! -d "$state_dir" ]; }; then + echo "Invalid xCAT configuration state directory: $state_dir" >&2 + exit 1 + fi + # dpkg skips prerm when the previous package was only unpacked. + if [ "$context" = upgrade ] && [ ! -f /tmp/xCAT_upgrade.tmp ]; then + if [ -f "$state_dir/context" ]; then + context=$(cat "$state_dir/context") + case "$context" in + fresh|upgrade) ;; + *) echo "Invalid xCAT configuration context in $state_dir/context: $context" >&2; exit 1 ;; + esac + else + context=fresh + fi + fi + mkdir -p -m 700 "$state_dir" + chmod 700 "$state_dir" + temporary=$(mktemp "$state_dir/context.XXXXXX") + trap 'rm -f "$temporary"' EXIT + trap 'exit 1' HUP INT TERM + printf '%s\n' "$context" > "$temporary" + mv -f "$temporary" "$state_dir/context" +fi + +#DEBHELPER# + +exit 0