„deb/pre-post-build.sh“ ändern

This commit is contained in:
BlubbFish 2022-01-19 21:11:09 +01:00
parent 63e10d9476
commit fee852d358

View File

@ -6,79 +6,94 @@ usage() {
"NAME=app " \
"CONFIGREPLACEASK=setting.conf params.conf " \
"[MOREGROUPS=dialout " \
"USERNAMEGROUP=appuser " \
"LOGFILE=/var/log/app.log " \
"DATADIR=/var/lib/data]"
"sh pre-post-build.sh"
exit 1
}
echo "DEB Builder pre-post-file: https://github.com/linksmart/ci-scripts/blob/master/deb/pre-post-build.sh"
echo "DEB Builder pre-post-file: https://git.blubbfish.net/vs_utils/CI-Scripts/src/branch/master/deb/pre-post-build.sh"
if [[ -z "$NAME" ]]; then
if [ -z "${NAME}" ]; then
usage
fi
if [[ -z "$CONFIGREPLACEASK" ]]; then
if [ -z "${CONFIGREPLACEASK}" ]; then
usage
fi
echo "#!/bin/bash" > postinst
echo "" >> postinst
if [ -z "${USERNAMEGROUP}" ]; then
USERNAMEGROUP="${NAME}bot"
fi
echo "if [ \"\$1\" = \"configure\" ]; then" >> postinst
echo " if [ -z \"\`id -u ${NAME}bot 2> /dev/null\`\" ]; then" >> postinst
echo " adduser --system --group --home /nonexistent --gecos \"${NAME} User\" --no-create-home --disabled-password --quiet ${NAME}bot || true" >> postinst
if [[ -z "$MOREGROUPS" ]]; then
echo " usermod -G ${NAME}bot,adm ${NAME}bot" >> postinst
###################################### POSTINST #################################
echo "#!/bin/bash" > postinst
echo "" >> postinst
echo "if [ \"\$1\" = \"configure\" ]; then" >> postinst
# Create User and Group(s) if not exist
echo " if [ -z \"\`id -u ${USERNAMEGROUP} 2> /dev/null\`\" ]; then" >> postinst
echo " adduser --system --group --home /nonexistent --gecos \"${NAME} User\" --no-create-home --disabled-password --quiet ${USERNAMEGROUP} || true" >> postinst
if [ -n "${MOREGROUPS}" ]; then
echo " usermod -G ${USERNAMEGROUP},adm,${MOREGROUPS} ${USERNAMEGROUP}" >> postinst
else
echo " usermod -G ${NAME}bot,adm,${MOREGROUPS} ${NAME}bot" >> postinst
echo " usermod -G ${USERNAMEGROUP},adm ${USERNAMEGROUP}" >> postinst
fi
echo " fi" >> postinst
echo "" >> postinst
for conffile in $CONFIGREPLACEASK ; do
echo " ucf --three-way /usr/share/${NAME}/etc/${conffile} /etc/${NAME}/${conffile}" >> postinst
echo " fi" >> postinst
# Config replacement via ucf
echo "" >> postinst
for conffile in ${CONFIGREPLACEASK} ; do
echo " ucf --three-way /usr/share/${NAME}/etc/${conffile} /etc/${NAME}/${conffile}" >> postinst
done
echo "" >> postinst
echo "" >> postinst
echo " chown -R ${NAME}bot:${NAME}bot /usr/local/bin/${NAME}" >> postinst
echo "" >> postinst
# Set userright to binary folder
echo " chown -R ${USERNAMEGROUP}:${USERNAMEGROUP} /usr/local/bin/${NAME}" >> postinst
echo "" >> postinst
echo " chown -R ${NAME}bot:${NAME}bot /etc/${NAME}/" >> postinst
echo "" >> postinst
# Set usserrights to config folder
echo " if [ -d "/etc/${NAME}/" ]; then" >> postinst
echo " chown -R ${USERNAMEGROUP}:${USERNAMEGROUP} /etc/${NAME}/" >> postinst
echo " fi" >> postinst
echo "" >> postinst
if [ -f "logrotate-$NAME" ]; then
echo " touch /var/log/${NAME}.log" >> postinst
echo " chown ${NAME}bot:${NAME}bot /var/log/${NAME}.log" >> postinst
echo " chmod 644 /var/log/${NAME}.log" >> postinst
echo "" >> postinst
# Create Logfile
if [ -n "${LOGFILE}" ]; then
echo " mkdir -p \$(dirname \"${LOGFILE}\")" >> postinst
echo " touch ${LOGFILE}" >> postinst
echo " chown ${USERNAMEGROUP}:${USERNAMEGROUP} ${LOGFILE}" >> postinst
echo " chmod 644 ${LOGFILE}" >> postinst
echo "" >> postinst
fi
if [[ -n "$DATADIR" ]]; then
echo " mkdir -p ${DATADIR}" >> postinst
echo " chown -R ${NAME}bot:${NAME}bot ${DATADIR}" >> postinst
echo "" >> postinst
# Create datadir
if [ -n "${DATADIR}" ]; then
echo " mkdir -p ${DATADIR}" >> postinst
echo " chown -R ${USERNAMEGROUP}:${USERNAMEGROUP} ${DATADIR}" >> postinst
echo "" >> postinst
fi
echo "fi" >> postinst
echo "fi" >> postinst
echo "" >> postinst
echo "systemctl enable ${NAME}" >> postinst
echo "systemctl daemon-reload" >> postinst
echo "" >> postinst
# Enable service
echo "systemctl enable ${NAME}" >> postinst
echo "systemctl daemon-reload" >> postinst
echo "" >> postinst
# Start Service if it was running
echo "if [ -f /tmp/${NAME}_service_runner ]; then" >> postinst
echo " service ${NAME} start" >> postinst
echo " rm /tmp/${NAME}_service_runner" >> postinst
echo "fi" >> postinst
echo "if [ -f /tmp/${NAME}_service_runner ]; then" >> postinst
echo " service ${NAME} start" >> postinst
echo " rm /tmp/${NAME}_service_runner" >> postinst
echo "fi" >> postinst
echo "#!/bin/bash" > prerm
echo "" >> prerm
echo "if [[ \$(systemctl is-active ${NAME} || true) == \"active\" ]]" >> prerm
echo "then" >> prerm
echo " touch /tmp/${NAME}_service_runner" >> prerm
echo " service ${NAME} stop" >> prerm
echo "fi" >> prerm
################### PRERM ###################
echo "#!/bin/bash" > prerm
echo "" >> prerm
echo "if [[ \$(systemctl is-active ${NAME} || true) == \"active\" ]]" >> prerm
echo "then" >> prerm
echo " touch /tmp/${NAME}_service_runner" >> prerm
echo " service ${NAME} stop" >> prerm
echo "fi" >> prerm