File: gnunet.postinst

package info (click to toggle)
gnunet 0.6.6b-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,964 kB
  • ctags: 6,940
  • sloc: ansic: 82,380; sh: 13,056; makefile: 1,121; cpp: 189; php: 74; sed: 16
file content (230 lines) | stat: -rw-r--r-- 8,159 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#! /bin/sh
# postinst script for gnunet
#
# Author: Arnaud Kyheng <Arnaud.Kyheng@free.fr>

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#


case "$1" in
    configure)
    	# Source debconf library.
	. /usr/share/debconf/confmodule
	
	if dpkg --compare-versions "$2" lt "0.6.4a-7" && \
	[ -e /etc/gnunet.conf ]; then

		TMP_FILE=`/bin/tempfile`
		echo -n "Backuping configuration file (/etc/gnunet.conf to /etc/gnunet.conf.old)"
		cp -f /etc/gnunet.conf /etc/gnunet.conf.old || true
		echo " [done]"
	
		if [ -e /etc/default/gnunet ]; then
			echo -n "Backuping configuration file (/etc/default/gnunet to /etc/default/gnunet.old)"
			# Moving, we definitly need a fresh one
			mv -f /etc/default/gnunet /etc/default/gnunet.old || true
			echo " [done]"
		fi
	
		# Try to read configuration values (now use new gnunet-update -g)		
		GNUNETD_HOME=`gnunet-update --get=:GNUNETD_HOME`
		PIDFILE=`gnunet-update --get=GNUNETD:PIDFILE`
		LOGFILE=`gnunet-update --get=GNUNETD:LOGFILE`
	
		# Check values (PS: we will need to be able to extract $GNUNETD_HOME later in postinst
		if [ ! $PIDFILE ] || [ ! $LOGFILE ] || \
		[ ! $GNUNETD_HOME ] || [ ! -d "$GNUNETD_HOME" ]; then
			# Something was wrong
			echo -n "Installing default configuration file (/etc/gnunet.conf)"
			rm -f /etc/gnunet.conf > /dev/null 2>&1 || true
			gnunet-update -c /etc/gnunet.conf > /dev/null 2>&1 || true
			echo " [done]"
			# Create new log and pid directory
			echo -n "Creating new GNUnet logging file directory (/var/log/gnunetd)"
			mkdir -p /var/log/gnunetd
			# Using default values anyway
			mv -f /var/log/gnunetd.log* /var/log/gnunetd/ > /dev/null 2>&1 || true
			echo " [done]"
			echo -n "Creating new GNUnet pid file directory (/var/run/gnunetd)"
			mkdir -p /var/run/gnunetd
			echo " [done]"
		else
			# Update only if needed (if user has never changed his /etc/gnunet.conf, installer will install new default one which is already ok)
			if [ "$PIDFILE" != "/var/run/gnunetd/gnunetd.pid" ] || [ "$LOGFILE" != "/var/log/gnunetd/gnunetd.log" ]; then
				echo -n "Updating LOGFILE and PIDFILE values in /etc/gnunet.conf"
				# Update values in /etc/gnunet.conf
				OLD_PIDFILE=`/bin/grep "^PIDFILE" /etc/gnunet.conf`
				NEW_PIDFILE="\n# Do not change this unless you know exactly what you're doing.\n# Changing this value alone, will break the package.\nPIDFILE         = /var/run/gnunetd/gnunetd.pid"
				sed "s+^$OLD_PIDFILE+$NEW_PIDFILE+g" /etc/gnunet.conf > $TMP_FILE
				OLD_LOGFILE=`/bin/grep "^LOGFILE" /etc/gnunet.conf`
				NEW_LOGFILE="\n# Do not change this unless you know exactly what you're doing.\n# Changing this value alone, will break the package.\nLOGFILE         = /var/log/gnunetd/gnunetd.log"
				sed "s+^$OLD_LOGFILE+$NEW_LOGFILE+g" $TMP_FILE > /etc/gnunet.conf
				echo " [done]"
			fi
			# Create new log and pid directory
			echo -n "Creating new GNUnet logging file directory (/var/log/gnunetd)"
			mkdir -p /var/log/gnunetd
			# Using computed value and default (in case gnunet.conf has been replaced already)
			mv -f $LOGFILE* /var/log/gnunetd/ > /dev/null 2>&1 || true
			mv -f /var/log/gnunetd.log* /var/log/gnunetd/ > /dev/null 2>&1 || true
			echo " [done]"
			echo -n "Creating new GNUnet pid file directory (/var/run/gnunetd)"
			mkdir -p /var/run/gnunetd
			echo " [done]"
		fi
	
		# Cleaning
		rm -f $TMP_FILE
	fi
	
	
	if dpkg --compare-versions "$2" lt "0.6.6b-1" && \
	[ -e /etc/gnunet.conf ]; then

		TMP_FILE=`/bin/tempfile`
		
		# Try to read configuration values (use gnunet-update -g)
		DATABASETYPE=`gnunet-update --get=AFS:DATABASETYPE`

		# Check values
		if [ ! $DATABASETYPE ]; then
			# Something was wrong, but do nothing, since this is not mandatory
			echo "Warning: Can't find default DATABASETYPE value in /etc/gnunet.conf. Aborting database migration."
		else
			if [ "$DATABASETYPE" != "gdbm" ]; then
				# if database type is not "gdbm" (default configuration) then do nothing.
				# We want to keep user specific configuration if there is any.
				echo "We found a user specified value of DATABASETYPE in /etc/gnunet.conf. Keeping user settings."
			else
				echo "Updating DATABASETYPE value in /etc/gnunet.conf (new default recommended db is sqlite3)"
				echo -n "Backuping configuration file (/etc/gnunet.conf to /etc/gnunet.conf.olddb)"
				cp -f /etc/gnunet.conf /etc/gnunet.conf.olddb || true
				echo " [done]"
				# Update values in /etc/gnunet.conf
				OLD_DATABASETYPE=`/bin/grep "^DATABASETYPE" /etc/gnunet.conf`
				NEW_DATABASETYPE="\n# Default database for the Debian package is now sqlite since 0.6.6b-1.\nDATABASETYPE    = \"sqlite\""
				sed "s+^$OLD_DATABASETYPE+$NEW_DATABASETYPE+g" /etc/gnunet.conf > $TMP_FILE
				# Use cat to keep old defaults access rights of gnunet.conf 
				cat $TMP_FILE > /etc/gnunet.conf
				# Convert data
				gnunet-convert || true
				echo "Updating [done]"
			fi
		fi
		# Cleaning
		rm -f $TMP_FILE
	fi

	
	# Read default values
	CONFIG_FILE=/etc/default/gnunet
	# This is need to migrate data from 0.6.1b or later
	echo "Migrating previous GNUnet data (gnunet-update)"
	gnunet-update
	# Needed to migrate AFS-Quota which changed from 0.6.4
	echo "Migrating to new AFS-Quota (gnunet-check -u)"
	gnunet-check -u || true
	# Read debconf values
	db_get gnunet/gnunet_user
	gnunet_user="$RET"
	db_get gnunet/gnunet_group
	gnunet_group="$RET"
	db_get gnunet/launch_at_startup
	launch_at_startup="$RET"
	# Creating gnunet group if needed
	if ! getent group $gnunet_group > /dev/null ; then
		echo -n "Creating new GNUnet group $gnunet_group"
		addgroup --quiet --system $gnunet_group
		echo " [done]"
	fi
	# Creating gnunet user if needed
	if ! getent passwd $gnunet_user > /dev/null ; then
		echo -n "Creating new GNUnet user $gnunet_user"
		adduser --quiet --system --ingroup $gnunet_group --no-create-home $gnunet_user
		echo " [done]"
	fi
	# Update files and directories permissions
	# Assuming default values, this *should* not be changed
	echo -n "Updating files and directories permissions"
	/bin/chown -R $gnunet_user:$gnunet_group /var/run/gnunetd
	/bin/chown -R $gnunet_user:$gnunet_group /var/log/gnunetd
	# Use the new "gnunet-update -g"
	GNUNETD_HOME=`gnunet-update --get=:GNUNETD_HOME`
	/bin/chown -R $gnunet_user:$gnunet_group $GNUNETD_HOME
	echo  " [done]"
	# Writing new values to configuration file
	echo -n "Writing new configuration file"
	CONFIG_NEW=`/bin/tempfile`
	cat > $CONFIG_NEW <<EOF
# This file controls the behaviour of the GNUnet init script. 
# It will be parsed as a shell script.
# please do not edit by hand but
# use dpkg-reconfigure gnunet

GNUNET_USER=$gnunet_user
GNUNET_GROUP=$gnunet_group
LAUNCH_AT_STARTUP=true
EOF

	cp -f $CONFIG_NEW $CONFIG_FILE
	echo " [done]"
	
	# Secure access to the data directory
	/bin/chmod 0700 $GNUNETD_HOME || true
	
	# Cleaning
	rm -f $CONFIG_NEW
	echo "All done."
	if [ "$launch_at_startup" = 'true' ]; then
		if [ -x "/etc/init.d/gnunet" ]; then
		    update-rc.d gnunet defaults > /dev/null 2>&1 || true
		    if [ -x /usr/sbin/invoke-rc.d ]; then
		      invoke-rc.d gnunet start || true
		    else
		      /etc/init.d/gnunet start || true
		    fi
		fi
	else
		if [ -x "/etc/init.d/gnunet" ]; then
		    if [ -x /usr/sbin/invoke-rc.d ] ; then
		        invoke-rc.d gnunet stop || true
		    else
		        /etc/init.d/gnunet stop || true
		    fi
		fi
		update-rc.d -f gnunet remove > /dev/null 2>&1 || true
	fi


    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0