Jenkins/resources/com/cadoles/podman/post-install.sh.gotmpl

79 lines
1.9 KiB
Go Template
Raw Permalink Normal View History

#!/bin/sh
# Adapted from https://nfpm.goreleaser.com/tips/
use_systemctl="True"
systemd_version=0
if ! command -V systemctl >/dev/null 2>&1; then
use_systemctl="False"
else
systemd_version=$( systemctl --version | head -1 | sed 's/systemd //g' | cut -d' ' -f1 )
fi
SERVICE_NAME="cadoles-pod-{{ .Env.IMAGE_NAME }}"
cleanup() {
if [ "${use_systemctl}" = "False" ]; then
rm -f /usr/lib/systemd/system/$SERVICE_NAME.service
else
rm -f /etc/chkconfig/$SERVICE_NAME
rm -f /etc/init.d/$SERVICE_NAME
fi
}
cleanInstall() {
if [ "${use_systemctl}" = "False" ]; then
if command -V chkconfig >/dev/null 2>&1; then
chkconfig --add $SERVICE_NAME
fi
service $SERVICE_NAME restart ||:
else
if [ "${systemd_version}" -lt 231 ]; then
printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
sed -i "s/=+/=/g" /usr/lib/systemd/system/$SERVICE_NAME.service
fi
systemctl daemon-reload ||:
systemctl unmask $SERVICE_NAME ||:
systemctl preset $SERVICE_NAME ||:
systemctl enable $SERVICE_NAME ||:
systemctl restart $SERVICE_NAME ||:
fi
}
upgrade() {
if [ "${use_systemctl}" = "False" ]; then
service $SERVICE_NAME restart ||:
else
if [ "${systemd_version}" -lt 231 ]; then
printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
sed -i "s/=+/=/g" /usr/lib/systemd/system/$SERVICE_NAME.service
fi
systemctl daemon-reload ||:
systemctl restart $SERVICE_NAME ||:
fi
echo 'Cleaning up unused images...'
podman image prune -f --filter "reference={{ .Env.IMAGE_NAME }}"
}
action="$1"
if [ "$1" = "configure" ] && [ -z "$2" ]; then
action="install"
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
action="upgrade"
fi
case "$action" in
"1" | "install")
cleanInstall
;;
"2" | "upgrade")
upgrade
;;
*)
cleanInstall
;;
esac
cleanup