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