File: postinst

package info (click to toggle)
node-constants-browserify 1.0.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 96 kB
  • sloc: sh: 57; makefile: 17
file content (47 lines) | stat: -rwxr-xr-x 1,196 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

set -e

# use && in order to avoid some problem with set -e in functions
rebuild_constants_list () {
    CONSTANTS_FILE="$DPKG_ROOT/usr/lib/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