From dc97cffad6bf902bb72beff284ad3a20700dd79d Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Wed, 2 Jun 2021 17:31:56 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9Edeb/pre-post-build.sh=E2=80=9C=20hinzu?= =?UTF-8?q?f=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deb/pre-post-build.sh | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 deb/pre-post-build.sh diff --git a/deb/pre-post-build.sh b/deb/pre-post-build.sh new file mode 100644 index 0000000..6589c65 --- /dev/null +++ b/deb/pre-post-build.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# EXAMPLES +usage() { + echo "usage: " \ + "NAME=app " \ + "CONFIGREPLACEASK=setting.conf params.conf" + "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" + +if [[ -z "$NAME" ]]; then + usage +fi + +if [[ -z "$CONFIGREPLACEASK" ]]; then + usage +fi + +echo "#!/bin/bash" > postinst +echo "" >> postinst + +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 +echo " usermod -G ${NAME}bot,adm ${NAME}bot" >> postinst +echo " fi" >> postinst +echo "" >> postinst +for conffile in $CONFIGREPLACEASK ; do +echo " ucf --three-way /usr/share/${NAME}/etc/${conffile}.dpkg-new /etc/${NAME}/${conffile}" >> postinst +done +echo "" >> postinst + +echo " chown -R ${NAME}bot:${NAME}bot /usr/local/bin/${NAME}" >> postinst +echo "" >> postinst + +echo " chown -R ${NAME}bot:${NAME}bot /etc/${NAME}/" >> 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 +fi + +if [[ -n "$DATADIR" ]]; then + echo " mkdir -p ${DATADIR}" >> postinst + echo " chown -R ${NAME}bot:${NAME}bot ${DATADIR}" >> postinst + echo "" >> postinst +fi + +echo "fi" >> postinst + +echo "systemctl enable ${NAME}" >> postinst +echo "systemctl daemon-reload" >> postinst +echo "" >> 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 \ No newline at end of file