2021-02-06 15:50:50 +01:00
|
|
|
#!/bin/bash
|
2021-02-18 00:13:58 +01:00
|
|
|
. /usr/share/debconf/confmodule
|
|
|
|
|
2021-04-24 20:17:55 +02:00
|
|
|
set -euo pipefail
|
2021-02-18 00:22:37 +01:00
|
|
|
|
2021-02-06 15:50:50 +01:00
|
|
|
OWRX_USER="openwebrx"
|
|
|
|
OWRX_DATADIR="/var/lib/openwebrx"
|
2021-02-18 18:28:12 +01:00
|
|
|
OWRX_USERS_FILE="${OWRX_DATADIR}/users.json"
|
2021-04-26 20:10:44 +02:00
|
|
|
OWRX_SETTINGS_FILE="${OWRX_DATADIR}/settings.json"
|
2021-04-26 21:05:33 +02:00
|
|
|
OWRX_BOOKMARKS_FILE="${OWRX_DATADIR}/bookmarks.json"
|
2021-02-06 15:50:50 +01:00
|
|
|
|
|
|
|
case "$1" in
|
2021-02-18 01:36:04 +01:00
|
|
|
configure|reconfigure)
|
2021-02-06 15:50:50 +01:00
|
|
|
adduser --system --group --no-create-home --home /nonexistent --quiet "${OWRX_USER}"
|
2021-05-31 00:44:28 +02:00
|
|
|
usermod -aG plugdev "${OWRX_USER}"
|
2021-02-06 15:50:50 +01:00
|
|
|
|
|
|
|
# create OpenWebRX data directory and set the correct permissions
|
|
|
|
if [ ! -d "${OWRX_DATADIR}" ] && [ ! -L "${OWRX_DATADIR}" ]; then mkdir "${OWRX_DATADIR}"; fi
|
2021-02-11 00:24:02 +01:00
|
|
|
chown "${OWRX_USER}". ${OWRX_DATADIR}
|
2021-02-06 18:59:01 +01:00
|
|
|
|
2021-04-26 21:05:33 +02:00
|
|
|
# create empty config files now to avoid permission problems later
|
2021-02-18 18:28:12 +01:00
|
|
|
if [ ! -e "${OWRX_USERS_FILE}" ]; then
|
|
|
|
echo "[]" > "${OWRX_USERS_FILE}"
|
2021-02-18 20:57:41 +01:00
|
|
|
chown "${OWRX_USER}". "${OWRX_USERS_FILE}"
|
|
|
|
chmod 0600 "${OWRX_USERS_FILE}"
|
2021-02-18 18:28:12 +01:00
|
|
|
fi
|
|
|
|
|
2021-04-26 20:10:44 +02:00
|
|
|
if [ ! -e "${OWRX_SETTINGS_FILE}" ]; then
|
|
|
|
echo "{}" > "${OWRX_SETTINGS_FILE}"
|
|
|
|
chown "${OWRX_USER}". "${OWRX_SETTINGS_FILE}"
|
|
|
|
fi
|
|
|
|
|
2021-04-26 21:05:33 +02:00
|
|
|
if [ ! -e "${OWRX_BOOKMARKS_FILE}" ]; then
|
|
|
|
touch "${OWRX_BOOKMARKS_FILE}"
|
|
|
|
chown "${OWRX_USER}". "${OWRX_BOOKMARKS_FILE}"
|
|
|
|
fi
|
|
|
|
|
2021-02-18 00:13:58 +01:00
|
|
|
db_get openwebrx/admin_user_password
|
2021-02-18 16:14:15 +01:00
|
|
|
if [ ! -z "${RET}" ]; then
|
2021-04-24 20:14:25 +02:00
|
|
|
if ! openwebrx admin --silent hasuser admin; then
|
2021-04-24 20:12:39 +02:00
|
|
|
# create initial openwebrx user
|
|
|
|
OWRX_PASSWORD="${RET}" openwebrx admin --noninteractive adduser admin
|
|
|
|
else
|
|
|
|
# change existing user's password
|
|
|
|
OWRX_PASSWORD="${RET}" openwebrx admin --noninteractive resetpassword admin
|
|
|
|
fi
|
2021-02-18 00:13:58 +01:00
|
|
|
fi
|
2021-02-18 16:14:45 +01:00
|
|
|
# remove password from debconf database
|
|
|
|
db_unregister openwebrx/admin_user_password
|
2021-04-24 19:39:48 +02:00
|
|
|
# set a marker that admin is configured to avoid future questions
|
|
|
|
db_set openwebrx/admin_user_configured true
|
2021-02-06 15:50:50 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "postinst called with unknown argument '$1'" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
#DEBHELPER#
|