openwebrx-clone/debian/openwebrx.postinst

60 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

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