[go: up one dir, main page]

File: sbnc.postinst

package info (click to toggle)
sbnc 1.3.9-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,156 kB
  • ctags: 4,719
  • sloc: ansic: 20,379; cpp: 14,175; sh: 12,783; tcl: 6,025; php: 448; makefile: 430; perl: 46; awk: 25
file content (117 lines) | stat: -rw-r--r-- 2,182 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
#!/bin/sh

set -e

. /usr/share/debconf/confmodule

do_createconfig() {
	FIRST_START=0
	VALID_CONFIG=1

	db_get sbnc/start_daemon

	DAEMON_START=0

	if [ "$RET" = "true" ] ; then
		DAEMON_START=1
	fi

	db_get sbnc/host
	HOST=$RET
	if [ "X$HOST" = "X" ] ; then
		HOST="0.0.0.0"
	fi

	db_get sbnc/port
	PORT=$RET
	if [ "X$PORT" = "X" ] ; then
		PORT="9000"
	fi

	if [ ! -f /etc/sbnc/sbnc.conf ] ; then
		FIRST_START=1

		db_get sbnc/username
		USERNAME=$RET
		if [ "X$USERNAME" = "X" ] ; then
			VALID_CONFIG=0
		fi

		db_get sbnc/password
		PASSWORD=$RET
		if [ "X$PASSWORD" = "X" ] ; then
			VALID_CONFIG=0
		fi

		if [ "$VALID_CONFIG" = "1" ] ; then
			SALT=`pwgen -s 50 1`

			MD5_HEX=`echo -n "${PASSWORD}${SALT}" | md5sum - | awk '{print $1}'`
			PASSWORD="${SALT}\$${MD5_HEX}"

			umask 077
			mkdir -p /etc/sbnc/users
			umask 177
			echo "user.password=${PASSWORD}" > /etc/sbnc/users/${USERNAME}.conf
			echo "user.admin=1"		>> /etc/sbnc/users/${USERNAME}.conf

			db_set sbnc/password ""
		fi
	fi

	if [ "$VALID_CONFIG" = "1" ] ; then
		sed "s/=[0-9]/=$DAEMON_START/" -i /etc/default/sbnc

		umask 177

		if [ $FIRST_START = "1" ] ; then
			echo "system.users=${USERNAME}"	 > /etc/sbnc/sbnc.conf
			echo "system.port=${PORT}"	>> /etc/sbnc/sbnc.conf
			echo "system.ip=${HOST}"	>> /etc/sbnc/sbnc.conf
			echo "system.md5=1"		>> /etc/sbnc/sbnc.conf
		else
			sed "s/system.port=.*/system.port=${PORT}/" -i /etc/sbnc/sbnc.conf
			sed "s/system.ip=.*/system.ip=${HOST}/" -i /etc/sbnc/sbnc.conf
		fi

		chown sbnc:sbnc -R /etc/sbnc/users
		chown sbnc:sbnc /etc/sbnc/sbnc.conf
	fi

}

do_systeminstall() {
	adduser --system --group --home /var/lib/sbnc --quiet sbnc || true

	chown sbnc:adm /var/log/sbnc
	chmod 0740 /var/log/sbnc
	chown sbnc:sbnc /var/lib/sbnc
	chmod 0775 /var/lib/sbnc
	chown sbnc:sbnc /etc/sbnc
}

do_migrateuserconf () {
	if [ -f /var/lib/sbnc/users/*.conf ] ; then
        mv /var/lib/sbnc/users/ /etc/sbnc/
	fi
}

case "$1" in
	configure)
		do_migrateuserconf;
		do_systeminstall;
		do_createconfig;
	;;

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

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

#DEBHELPER#

exit 0