1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#!/bin/sh
set -e
# use && in order to avoid some problem with set -e in functions
rebuild_constants_list () {
OLD_CONSTANTS_FILE="${DPKG_ROOT:-}/usr/lib/nodejs/constants-browserify/constants.json"
if test -e $OLD_CONSTANTS_FILE; then
rm -f "${DPKG_ROOT:-}/usr/lib/nodejs/constants-browserify/constants.json"
rmdir "${DPKG_ROOT:-}/usr/lib/nodejs/constants-browserify" || true
fi
CONSTANTS_FILE="${DPKG_ROOT:-}/usr/share/nodejs/constants-browserify/constants.json"
# set -e is unspecified in function, moreover we want clean up
while true; do
# create file if not exist with some sensible right rw-r--r--
(umask 022 && touch "$CONSTANTS_FILE.triggered") || break;
# force right if it exist
chmod 0644 "$CONSTANTS_FILE.triggered" || break;
#reconstruct node constant list
# move is atomic not redirection
"${DPKG_ROOT:-}/usr/bin/node" -pe 'JSON.stringify(require("constants"), null, " ")' > "$CONSTANTS_FILE.triggered" || break;
mv "$CONSTANTS_FILE.triggered" "$CONSTANTS_FILE" || break;
return 0;
done
echo "postinst failled to create $CONSTANTS_FILE" >&2
# recover
rm -f "$CONSTANTS_FILE.triggered"
rm -f "$CONSTANTS_FILE"
return 1
}
case "$1" in
configure)
rebuild_constants_list
;;
triggered)
rebuild_constants_list
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0
|