dragonfly/tools/packaging/debian/dragonfly.preinst
Boaz Sade 57e3ec9a81
feat(build): debian package building (#689)
Signed-off-by: Boaz Sade <boaz@dragonflydb.io>
2023-01-16 17:44:53 +02:00

50 lines
965 B
Bash
Executable file

#!/bin/sh
set -eu
# Script to run before the installation starts.
# We are creating a user "dragonfly", and the directories that
# would be used by the application
USER="dfly"
DIR_NAME="dragonfly"
setup_dir () {
DIR="${1}"
MODE="${2}"
GROUP="${3}"
mkdir -p ${DIR} || {
echo "failed to create dir ${DIR}"
return 1
}
if ! dpkg-statoverride --list ${DIR} >/dev/null 2>&1
then
echo "changing owner for ${DIR} to user ${USER}"
chown ${USER}:${GROUP} ${DIR}
chmod ${MODE} ${DIR}
fi
}
if [ "$1" = "install" ]; then
if ! id ${USER} >/dev/null 2>&1 ; then
echo "trying to create user ${USER}"
adduser \
--system \
--home /var/lib/${DIR_NAME} \
--quiet \
--group \
${USER} || {
echo "failed to add user ${USER}"
exit 1
}
setup_dir /var/log/${DIR_NAME} 2755 adm
setup_dir /var/lib/${DIR_NAME} 755 ${USER}
setup_dir /var/run/${DIR_NAME} 755 ${USER}
setup_dir /etc/${DIR_NAME} 2775 ${USER}
fi
fi
#DEBHELPER#
exit 0