debianize-mobilizon/debian/postinst

77 lines
2.1 KiB
Bash

#!/bin/sh
# postinst script for mobilizon.
#
# See: dh_installdeb(1).
set -e
# Load debconf
. /usr/share/debconf/confmodule
case "$1" in
configure)
# Create a dedicated system user
if ! getent passwd mobilizon >/dev/null; then
adduser \
--disabled-password \
--quiet \
--system \
--home /usr/share/mobilizon \
--no-create-home \
--gecos "Mobilizon server" \
--group \
mobilizon
fi
if [ ! -f /etc/mobilizon/config.exs ]; then
# Use debconf values to initialize config.exs
cp /etc/mobilizon/config.exs.tpl /etc/mobilizon/config.exs.tmp
db_get mobilizon/domain_name
sed -i "s/__DOMAIN_NAME__/${RET}/" /etc/mobilizon/config.exs.tmp
db_get mobilizon/listen_port
sed -i "s/__LISTEN_PORT__/${RET}/" /etc/mobilizon/config.exs.tmp
db_get mobilizon/db_host
sed -i "s/__DB_HOST__/${RET}/" /etc/mobilizon/config.exs.tmp
db_get mobilizon/db_name
sed -i "s/__DB_NAME__/${RET}/" /etc/mobilizon/config.exs.tmp
db_get mobilizon/db_username
sed -i "s/__DB_USERNAME__/${RET}/" /etc/mobilizon/config.exs.tmp
db_get mobilizon/db_userpass
sed -i "s/__DB_USERPASS__/${RET}/" /etc/mobilizon/config.exs.tmp
mv /etc/mobilizon/config.exs.tmp /etc/mobilizon/config.exs
fi
# Set permissions
chown -R mobilizon: /var/lib/mobilizon/geo_db
chown -R mobilizon: /var/lib/mobilizon/sitemap
chown -R mobilizon: /var/lib/mobilizon/timezones
chown -R mobilizon: /var/lib/mobilizon/tzdata
chown -R mobilizon: /var/lib/mobilizon/uploads
# Initialize/update database schema
/usr/bin/mobilizon_ctl migrate
;;
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