summaryrefslogtreecommitdiffstats
path: root/build/apt/DEBIAN/postinst
blob: 589f73dbc30c28afbde1d46a02fd7805d2bfd869 (plain)
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash

################################################################################
#
# Copyright (c) 2010 penSec.IT UG (haftungsbeschränkt)
#        http://www.pensec.it
#        mail@pensec.it
# 
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
# 
#        http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License. 
#
################################################################################



set -e
. /usr/share/debconf/confmodule

if [ -n "$ETHERPAD_DEBUG" ]; then
  echo "now debugging $0 $@"
  set -x
fi

db_version 2.0





#####
#
# Fragt einen Konfigurationswert ab und schreibt ihn in die Eigenschaftsdatei
#
# @param $1 Name des debconfig Templates
# @param $2 Name der Datei in welche der Konfigurationswert geschrieben werden
#     soll
# @param $3 Wird aktuell nicht verwendet, Platzhalter in etherpad.properties
#     welcher mit dem Wert dieser Varialbe ersetzt werden soll
#
function configuration_property() {
	TEMPLATE="${1}"
	PROPERTY_FILE="/etc/etherpad/properties/${2}"
	PLACEHOLDER="${3}"

	PROPERTY=`cat "${PROPERTY_FILE}"`
	db_input high "etherpad-%BRANCH%/${TEMPLATE}" || true
	db_go

	db_get "etherpad-%BRANCH%/${TEMPLATE}"
	if [ "" != "$RET" ]; then
		PROPERTY="$RET"
	fi

	echo "${PROPERTY}" > "${PROPERTY_FILE}"
}
#
#####



case "$1" in

	configure)

		# Create system user
		if ! getent passwd etherpad > /dev/null ; then
			echo 'Adding system-user for etherpad' 1>&2
			adduser --system --group --quiet \
				--home /usr/share/etherpad --no-create-home \
				--disabled-login --force-badname etherpad
		fi


		# Give user the rights to write into the log & data directory
		if [ -d "/var/log/etherpad" ]; then
			EMPTY_STATEMENT="true"
		else
			mkdir -p "/var/log/etherpad"
		fi
		chown -R etherpad:etherpad "/var/log/etherpad"

		if [ -d "/usr/share/etherpad/etherpad/data" ]; then
			EMPTY_STATEMENT="true"
		else
			mkdir -p "/usr/share/etherpad/etherpad/data"
		fi
		chown -R etherpad:etherpad "/usr/share/etherpad/etherpad/data"


		# Give user the rights do write everywhere, did not yet figure
		# out which rights are necessary, exactly
		chown -R etherpad:etherpad "/usr/share/etherpad"
	;;

esac



#####
#
# Get configuration properties
#
configuration_property "is_production"		"is-production"		"IS_PRODUCTION"
configuration_property "admin_password"		"admin-password"	"ADMIN_PASSWORD"
configuration_property "port"			"port"			"PORT"
configuration_property "database_host"		"database-host"		"DATABASE_HOST"
configuration_property "database_port"		"database-port"		"DATABASE_PORT"
configuration_property "database_name"		"database-name"		"DATABASE_NAME"
configuration_property "database_username"	"database-username"	"DATABASE_USERNAME"
configuration_property "database_password"	"database-password"	"DATABASE_PASSWORD"
#
#####





#		#####
#		#
#		# Install in production mode
#		#
#		IS_PRODUCTION="false"
#		db_input high "etherpad-%BRANCH%/is_production" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/is_production"
#		if [ "" != "$RET" ]; then
#			IS_PRODUCTION="$RET"
#		fi
#
#		apply_config "IS_PRODUCTION" "${IS_PRODUCTION}"
#		#
#		#####

#		#####
#		#
#		# Admin password
#		#
#		ADMIN_PASSWORD="password"
#		db_input high "etherpad-%BRANCH%/admin_password" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/admin_password"
#		if [ "" != "$RET" ]; then
#			ADMIN_PASSWORD="$RET"
#		fi
#
#		apply_config "ADMIN_PASSWORD" "${ADMIN_PASSWORD}"
#		#
#		#####

#		#####
#		#
#		# Application listen port
#		#
#		PORT="9000"
#		db_input high "etherpad-%BRANCH%/port" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/port"
#		if [ "" != "$RET" ]; then
#			PORT="$RET"
#		fi
#
#		apply_config "PORT" "${PORT}"
#		#
#		#####

#		#####
#		#
#		# MySQL Host
#		#
#		DATABASE_HOST="localhost"
#		db_input high "etherpad-%BRANCH%/database_host" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/database_host"
#		if [ "" != "$RET" ]; then
#			DATABASE_HOST="$RET"
#		fi
#
#		apply_config "DATABASE_HOST" "${DATABASE_HOST}"
#		#
#		#####

#		#####
#		#
#		# MySQL Port
#		#
#		DATABASE_PORT="3306"
#		db_input high "etherpad-%BRANCH%/database_port" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/database_port"
#		if [ "" != "$RET" ]; then
#			DATABASE_PORT="$RET"
#		fi
#
#		apply_config "DATABASE_PORT" "${DATABASE_PORT}"
#		#
#		#####

#		#####
#		#
#		# MySQL database name
#		#
#		DATABASE_NAME="etherpad"
#		db_input high "etherpad-%BRANCH%/database_name" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/database_name"
#		if [ "" != "$RET" ]; then
#			DATABASE_NAME="$RET"
#		fi
#
#		apply_config "DATABASE_NAME" "${DATABASE_NAME}"
#		#
#		#####

#		#####
#		#
#		# MySQL database username
#		#
#		DATABASE_USERNAME="etherpad"
#		db_input high "etherpad-%BRANCH%/database_username" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/database_username"
#		if [ "" != "$RET" ]; then
#			DATABASE_USERNAME="$RET"
#		fi
#
#		apply_config "DATABASE_USERNAME" "${DATABASE_USERNAME}"
#		#
#		#####

#		#####
#		#
#		# MySQL database password
#		#
#		DATABASE_PASSWORD="password"
#		db_input high "etherpad-%BRANCH%/database_password" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/database_password"
#		if [ "" != "$RET" ]; then
#			DATABASE_PASSWORD="$RET"
#		fi
#
#		apply_config "DATABASE_PASSWORD" "${DATABASE_PASSWORD}"
#		#
#		#####


#####
#
# MySQL-Autosetup should be discussed. Simply calling setup-myql-db.sh is
# insufficient
#
#		# Auto-setup database
#		db_input medium "etherpad-%BRANCH%/setup_database" || true
#		db_go
#
#		db_get "etherpad-%BRANCH%/setup_database"
#		if [ "$RET" = "true" ]; then
#			# TODO
#		fi
#
#####