This file is indexed.

postinst is in redmine 2.4.2-1.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/sh
# postinst script for redmine
#
# see: dh_installdeb(1)

set -e
#set -x

RAKE_VERBOSE=false

. /usr/share/debconf/confmodule

# remove and purge old instances each time postinst is called
db_get redmine/old-instances || true
gOldInstances="${RET}"
for lInstance in $gOldInstances; do
	db_get redmine/instances/$lInstance/dbconfig-install || true
	if [ "$RET" = "true" ]; then
		( . /usr/share/dbconfig-common/dpkg/prerm ; dbc_go redmine/instances/$lInstance remove )
	fi
done

for lInstance in $gOldInstances; do
	db_get redmine/instances/$lInstance/dbconfig-install || true
	if [ "$RET" = "true" ]; then
		( . /usr/share/dbconfig-common/dpkg/postrm ; dbc_go redmine/instances/$lInstance purge )
	fi
	if which ucf >/dev/null 2>&1; then
		ucf --purge /etc/redmine/$lInstance/database.yml
		ucf --purge /etc/redmine/$lInstance/session.yml
		ucf --purge /etc/redmine/$lInstance/configuration.yml
		# email.yml was renamed to configuration.yml since 1.2.0
		ucf --purge /etc/redmine/$lInstance/email.yml
	fi
	rm -rf /etc/redmine/$lInstance
done
db_set redmine/old-instances ""

fRailsEnv=production
fRailsLog=/var/log/redmine
fRailsVar=/var/lib/redmine
fRailsCache=/var/cache/redmine
fRailsDir=/usr/lib/ruby/vendor_ruby/rails
if [ ! -e "$fRailsDir" ]; then
	# keep rails package compatibility
	fRailsDir="/usr/share/rails-ruby1.8"
fi

case "$1" in
	configure|reconfigure)
		# passenger runs as the owner of that file, thanks Micah Anderson.
		chown www-data:root /usr/share/redmine/config/environment.rb
		chown -f www-data:www-data $fRailsLog
		chown -f www-data:www-data $fRailsVar
		chown -f www-data:www-data $fRailsCache
		savedir="`pwd`"
		cd /usr/share/redmine
		if [ -L vendor/railties ]; then
			# rails 2.2 to 2.3 migration
			rm -f vendor/actionmailer
			rm -f vendor/actionpack
			rm -f vendor/activemodel
			rm -f vendor/activerecord
			rm -f vendor/activeresource
			rm -f vendor/activesupport
			rm -f vendor/railties
			rm -f vendor/rails
		fi
		if [ -L vendor/rails ]; then
			# rails 2.3 to ruby-rails-2.3 migration
			fMigrateLink=$(readlink vendor/rails)
			if [ "$fMigrateLink" != "$fRailsDir" ]; then
				rm -f vendor/rails
			else
			        echo "Inconsistent link in vendor/rails, please remove manually"
			fi
		fi
		if [ ! -e app/views/members ]; then
			mkdir app/views/members
		fi
		if [ ! -e app/sweepers ]; then
			mkdir app/sweepers
		fi
		# this directory should never be used: /usr not writable policy
		if [ -e tmp ]; then
			rm -rf tmp
		fi
		cd $savedir
	;;

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

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

db_get redmine/current-instances || true
gInstances="${RET}"
for lInstance in $gInstances; do
	fRailsEtc=/etc/redmine/$lInstance
	fRailsLog=/var/log/redmine/$lInstance
	fRailsVar=/var/lib/redmine/$lInstance
	fRailsCache=/var/cache/redmine/$lInstance
	# dbconfig needs this folder to ouput database.yml
	mkdir -p $fRailsEtc
	chown -f www-data:www-data $fRailsEtc
	withdb=0
	lInstall=0
	db_get redmine/instances/$lInstance/dbconfig-install || true
	if [ "$RET" = "true" ]; then
		lInstall=1
		fCode=0
		db_get redmine/instances/$lInstance/dbconfig-reinstall || fCode=$?
		if [ $fCode -eq 0 ]; then
			if [ "$RET" = "false" ]; then
				db_fget redmine/instances/$lInstance/dbconfig-reinstall seen || true
				if [ "$RET" = "true" ]; then
					lInstall=0
				fi
			fi
		fi
	fi
	
	if [ $lInstall -eq 1 ]; then
		fYml=$fRailsEtc/database.yml.new
		lTemplate="database.yml.template"
		# if dbtype=sqlite3, use dbbasepath, else dbname
		fCode=0
		db_get redmine/instances/$lInstance/database-type || fCode=$?
		lDbType="$RET"
		if [ $fCode -eq 0 -a "$lDbType" = "sqlite3" ]; then
			lTemplate="database-sqlite.yml.template"
			lDbType="sqlite"
		fi
		# check if redmine-$lDbType is installed, if not, don't configure and explain what to do
		hasPack=$(dpkg-query -W -f='${Status}\n' "redmine-$lDbType" |cut -d" " -f3)
		if [ "$hasPack" != "installed" ]; then
			# not installed, this cannot be detected in debian/config
			# since redmine-* packages are not yet installed
			db_subst redmine/missing-redmine-package dbtype "$lDbType"
			db_subst redmine/missing-redmine-package instance "$lInstance"
			db_fset redmine/missing-redmine-package seen "false"
			db_input high redmine/missing-redmine-package || true
			db_go || true
			db_stop || true
			echo "Skipping $lInstance because of missing dependency."
			continue
		fi
		
		dbc_generate_include=template:$fYml
		dbc_generate_include_args="-o template_infile=/usr/share/redmine/templates/${lTemplate}"
		dbc_generate_include_owner="root:www-data"
		dbc_generate_include_perms="640"
		dbc_dbfile_owner="root:www-data"
		# this is for sqlite3 to be r/w for www-data
		dbc_dbfile_perms="0660"
		# per-instance dbuser to avoid #695774 - and behave like dbname
		fCode=0
		db_get redmine/instances/$lInstance/db/app-user || fCode=$?
		if [ $fCode -eq 0 -a -n "$RET" ]; then
			dbc_dbuser="$RET"
		else
			dbc_dbuser=redmine_$lInstance
		fi
		# make sure mysql or pgsql database charset is UTF8
		dbc_mysql_createdb_encoding="UTF8"
		dbc_pgsql_createdb_encoding="UTF8"
		# use same dbname if one has been registered in debconf before
		# this is also needed for migration from version <= 0.9.0~svn2819
		fCode=0
		db_get redmine/instances/$lInstance/db/dbname || fCode=$?
		if [ $fCode -eq 0 -a -n "$RET" ]; then
			dbc_dbname="$RET"
		else
			dbc_dbname=redmine_$lInstance
		fi
		fCode=0
		db_get redmine/instances/$lInstance/db/basepath || fCode=$?
		if [ $fCode -eq 0 -a -n "$RET" ]; then
			dbc_basepath="$RET"
		fi
		
		ucf --purge $fYml
		( . /usr/share/dbconfig-common/dpkg/postinst ; dbc_go redmine/instances/$lInstance $@ )
		ucf --purge $fYml
		
		if [ -e $fYml ]; then
			hasdb=$(grep -m 1 -o -E 'adapter: (mysql|pgsql|sqlite3|postgresql)' $fYml) || true
			if [ -n "$hasdb" ]; then
				hasdb=$(echo -n ${hasdb#*:})
				withdb=1
				case "$hasdb" in
					mysql|postgresql|pgsql)
						sed -i -r -e 's/pgsql/postgresql/g' $fYml
					;;
					sqlite3)
						sed -i -r -e 's/^[^#]+((host|port|username|password): [^:]*)$/# \1/g' $fYml
					;;
				esac
			fi
			ucf --debconf-ok $fYml /etc/redmine/$lInstance/database.yml
			rm -f $fYml
		fi
	elif [ -e "$fRailsEtc/database.yml" ]; then
		# don't reinstall, but upgrade
		withdb=1
		lInstall=0
	fi
	case "$1" in
		configure|reconfigure)
			if dpkg --compare-versions "$2" lt "2.3.0+dfsg1-3~"; then
			    rm -rf $fRailsCache
			fi
			# create directories
			mkdir -p $fRailsLog
			mkdir -p $fRailsVar
			mkdir -p $fRailsVar/files
			mkdir -p $fRailsCache
			mkdir -p $fRailsCache/cache
			mkdir -p $fRailsCache/plugin_assets
			chmod 750 $fRailsLog
			chmod 750 $fRailsVar
			chmod 755 $fRailsCache
			chmod 755 $fRailsCache/cache
			chmod 755 $fRailsCache/plugin_assets
			chown -f www-data:www-data $fRailsLog
			chown -f www-data:www-data $fRailsVar
			chown -f www-data:www-data $fRailsVar/files
			chown -f www-data:www-data $fRailsCache
			chown -f www-data:www-data $fRailsCache/cache
			chown -f www-data:www-data $fRailsCache/plugin_assets
			savedir="`pwd`"
			cd /usr/share/redmine
			# copy schema.db to its instance directory
			if [ -f db/schema.db ]; then
				cp db/schema.db $fRailsCache/schema.db
			fi
			# if dpkg --compare-versions "$2" lt "1.2.0-1~"; then
			if [ -e "$fRailsEtc/email.yml" -a ! -e "$fRailsEtc/configuration.yml" ]; then
				# email.yml was renamed to configuration.yml since 1.2.0
				mv "$fRailsEtc/email.yml" "$fRailsEtc/configuration.yml"
			fi
			#fi
			# add secret key, set permissions, manage file with ucf
			# trigger when session file doesn't exist or we are upgrading from previous version
			if [ ! -f "${fRailsEtc}/session.yml" ] || dpkg --compare-versions "$2" lt "2.1.4+dfsg2-2~"; then
				rake -s generate_secret_token YML_SESSION_FILENAME="session.yml.new" RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" || true
				chown -f root:www-data ${fRailsEtc}/session.yml.new
				chmod 640 ${fRailsEtc}/session.yml.new
				ucf --debconf-ok ${fRailsEtc}/session.yml.new ${fRailsEtc}/session.yml
				rm ${fRailsEtc}/session.yml.new
				# move old session_store.rb
				echo "A new secret session key has been generated in ${fRailsEtc}/session.yml"
			else
				fHasOldSessionName=$(fgrep -c session_key "${fRailsEtc}/session.yml" || true)
				if [ $fHasOldSessionName -gt 0 ]; then
					# in-place, because ucf might be configured to keep the old version without asking
					sed -i -r -e 's/session_key/key/g' ${fRailsEtc}/session.yml		
				fi
			fi
			if [ -f config/initializers/session_store.rb ]; then
				mv config/initializers/session_store.rb config/initializers/session_store.rb.dpkg-old
				echo "The old secret session key can be found in
/usr/share/redmine/config/initializers/session_store.rb.dpkg-old"
			fi
			if [ $withdb -eq 1 ]; then
				db_get redmine/instances/${lInstance}/default-language && DEFAULT_LANGUAGE="$RET"
				
				# handle rake install
				echo "Populating database for redmine instance \"${lInstance}\".
This may take a while."
				fCode=0
				rake -s db:migrate RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" VERBOSE=$RAKE_VERBOSE || fCode=$?
				if [ $fCode -eq 0 ]; then
					echo "Done."
					if [ $lInstall -eq 1 ]; then
						rake -s redmine:load_default_data RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" REDMINE_LANG=$DEFAULT_LANGUAGE || true
						# because rake task is executed as root here, and this file is used later by web server, make sure owner is www-data
						touch ${fRailsLog}/production.log
						chown -f www-data:www-data ${fRailsLog}/production.log
					fi
					# handle plugins migration
					rake -s redmine:plugins:migrate RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" VERBOSE=$RAKE_VERBOSE || true
				else
					echo "Error when running rake db:migrate, check database configuration."
					exit 1
				fi
			else
				echo "Redmine instance \"${lInstance}\" database must be configured manually."
			fi
			echo "Clearing the cache directory for redmine instance \"${lInstance}\".
This may take a while."
			rake -s tmp:cache:clear RAILS_ENV=$fRailsEnv X_DEBIAN_SITEID="${lInstance}" VERBOSE=$RAKE_VERBOSE || fCode=$?
			if [ $fCode -ne 0 ]; then
				echo "Error when clearing cache. You might need to clear the cache directory /var/cache/redmine/${lInstance}/ manually."
			fi			
			cd $savedir || true
		;;
	
		abort-upgrade|abort-remove|abort-deconfigure)
		;;
	
		*)
			echo "postinst called with unknown argument \`$1'" >&2
			exit 1
		;;
	esac
done


exit 0