Release
[nbd.git] / debian / nbd-server.postinst
blob07e79847bb4fead30249a74efac08e2033d7555f
1 #! /bin/bash
2 # postinst script for nbd
4 # see: dh_installdeb(1)
6 set -e
8 . /usr/share/debconf/confmodule
10 # Quotes each argument for shell expression inclusion, to prevent
11 # interpretation of special characters.
12 function shell_quote () {
13 local first=true
14 while [ "$#" -gt 0 ]; do
15 if [ ! "$first" ]; then
16 echo -n ' '
18 # sed expression transforms instances of ' to '\''
19 echo -n "'$(echo "$1" | sed -e "s/'/'\\\\''/g")'"
20 first=
21 shift
22 done
25 case "$1" in
26 configure)
27 if [ -f /etc/nbd-server -o -f /etc/nbd-server.oldconf ]
28 then
29 db_get nbd-server/convert
30 if [ "$RET" = "true" ]
31 then
32 convert_config;
33 exit 0;
36 db_get nbd-server/number
37 NUMBER=${RET:-0}
38 umask 066
39 if [ "$NUMBER" -gt 0 ]
40 then
41 TMPFILE=`mktemp /tmp/nbd-server.XXXXXX`
42 cat /usr/share/nbd-server/nbd-server.conf.tmpl > $TMPFILE
43 db_get nbd-server/useports
44 DOPORTS="$RET"
45 if [ "$DOPORTS" ]
46 then
47 echo " oldstyle = true" >> $TMPFILE
49 for i in $(seq 0 $(( $NUMBER - 1 )) )
51 # stay downward compatible
52 if [ "$i" -eq 0 ]
53 then
54 unset i
56 db_get nbd-server/port$i
57 PORT=$RET
58 db_get nbd-server/name$i
59 NAME=$RET
60 db_get nbd-server/filename$i
61 FN=$RET
62 ( echo "[$NAME]"
63 echo " exportname = $FN"
64 ) >> $TMPFILE
65 if [ $DOPORTS ]
66 then
67 echo " port = $PORT" >> $TMPFILE
69 done
70 ucf --debconf-ok $TMPFILE /etc/nbd-server/config
71 else
72 ucf --debconf-ok /usr/share/nbd-server/nbd-server.conf.tmpl /etc/nbd-server/config
74 if ! id nbd >/dev/null 2>&1; then
75 adduser --system --group --home /etc/nbd-server --no-create-home nbd
79 abort-upgrade|abort-remove|abort-deconfigure)
84 echo "postinst called with unknown argument \`$1'">&2
85 exit 0
87 esac
89 db_stop
91 # dh_installdeb will replace this with shell code automatically
92 # generated by other debhelper scripts.
94 #DEBHELPER#
96 exit 0