Skip to content

Commit e5ea3ba

Browse files
committed
Make deb scripts more compliant with Debian policy
1 parent cd62b3a commit e5ea3ba

16 files changed

+505
-262
lines changed

pkg/debian/salt-api.postinst

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
#!/bin/sh
2+
# postinst script for salt-api
3+
#
4+
# See: dh_installdeb(1).
25

3-
. /usr/share/debconf/confmodule
6+
set -e
7+
8+
# Summary of how this script can be called:
9+
# * <postinst> 'configure' <most-recently-configured-version>
10+
# * <old-postinst> 'abort-upgrade' <new version>
11+
# * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
12+
# <new-version>
13+
# * <postinst> 'abort-remove'
14+
# * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
15+
# <failed-install-package> <version> 'removing'
16+
# <conflicting-package> <version>
17+
# for details, see https://www.debian.org/doc/debian-policy/ or
18+
# the debian-policy package.
419

520
case "$1" in
621
configure)
7-
db_get salt-api/user
8-
if [ "$RET" != "root" ]; then
9-
if [ ! -e "/var/log/salt/api" ]; then
10-
touch /var/log/salt/api
11-
chmod 640 /var/log/salt/api
12-
fi
13-
chown $RET:$RET /var/log/salt/api
14-
fi
15-
if command -v systemctl; then
16-
db_get salt-api/active
17-
RESLT=$(echo "$RET" | cut -d ' ' -f 1)
18-
if [ "$RESLT" != 10 ]; then
19-
systemctl daemon-reload
20-
if [ "$RESLT" = "active" ]; then
21-
systemctl restart salt-api
22-
fi
23-
db_get salt-api/enabled
24-
RESLT=$(echo "$RET" | cut -d ' ' -f 1)
25-
if [ "$RESLT" = "disabled" ]; then
26-
systemctl disable salt-api
27-
else
28-
systemctl enable salt-api
29-
fi
30-
else
31-
systemctl daemon-reload
32-
systemctl restart salt-api
33-
systemctl enable salt-api
22+
. /usr/share/debconf/confmodule
23+
if db_get salt-api/user; then
24+
if [ "$RET" != "root" ]; then
25+
if [ ! -e "/var/log/salt/api" ]; then
26+
touch /var/log/salt/api
27+
chmod 640 /var/log/salt/api
3428
fi
29+
chown $RET:$RET /var/log/salt/api
30+
fi
3531
fi
3632
;;
33+
abort-upgrade|abort-remove|abort-deconfigure)
34+
;;
35+
36+
*)
37+
echo "postinst called with unknown argument '$1'" >&2
38+
exit 1
39+
;;
3740
esac
41+
42+
# dh_installdeb will replace this with shell code automatically
43+
# generated by other debhelper scripts.
44+
45+
#DEBHELPER#
46+
47+
exit 0

pkg/debian/salt-api.preinst

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
11
#!/bin/sh
2+
# preinst script for salt-api.
3+
#
4+
# See: dh_installdeb(1).
25

3-
. /usr/share/debconf/confmodule
6+
set -e
7+
8+
# Summary of how this script can be called:
9+
# * <new-preinst> 'install'
10+
# * <new-preinst> 'install' <old-version>
11+
# * <new-preinst> 'upgrade' <old-version>
12+
# * <old-preinst> 'abort-upgrade' <new-version>
13+
# for details, see https://www.debian.org/doc/debian-policy/ or
14+
# the debian-policy package.
15+
16+
[ -n "$SALT_HOME" ] || SALT_HOME=/opt/saltstack/salt
17+
[ -n "$SALT_USER" ] || SALT_USER=salt
18+
[ -n "$SALT_NAME" ] || SALT_NAME="Salt"
19+
[ -n "$SALT_GROUP" ] || SALT_GROUP=salt
420

521
case "$1" in
22+
install)
23+
;;
24+
625
upgrade)
7-
[ -z "$SALT_HOME" ] && SALT_HOME=/opt/saltstack/salt
8-
[ -z "$SALT_USER" ] && SALT_USER=salt
9-
[ -z "$SALT_NAME" ] && SALT_NAME="Salt"
10-
[ -z "$SALT_GROUP" ] && SALT_GROUP=salt
26+
. /usr/share/debconf/confmodule
1127

1228
# Reset permissions to fix previous installs
13-
CUR_USER=$(ls -dl /run/salt-api.pid | cut -d ' ' -f 3)
14-
CUR_GROUP=$(ls -dl /run/salt-api.pid | cut -d ' ' -f 4)
15-
db_set salt-api/user $CUR_USER
16-
chown -R $CUR_USER:$CUR_GROUP /var/log/salt/api
17-
if command -v systemctl; then
18-
SM_ENABLED=$(systemctl show -p UnitFileState salt-api | cut -d '=' -f 2)
19-
db_set salt-api/enabled $SM_ENABLED
20-
SM_ACTIVE=$(systemctl is-active salt-api)
21-
db_set salt-api/active $SM_ACTIVE
29+
if [ -f /run/salt-api.pid ]
30+
then
31+
CUR_USER=$(ls -dl /run/salt-api.pid | cut -d ' ' -f 3)
32+
CUR_GROUP=$(ls -dl /run/salt-api.pid | cut -d ' ' -f 4)
2233
else
23-
db_set salt-api/enabled enabled
24-
db_set salt-api/active active
34+
CUR_USER=$SALT_USER
35+
CUR_GROUP=$SALT_GROUP
2536
fi
26-
;;
37+
db_set salt-api/user $CUR_USER
38+
chown -R $CUR_USER:$CUR_GROUP /var/log/salt/api || true
39+
;;
40+
41+
abort-upgrade)
42+
;;
43+
44+
*)
45+
echo "preinst called with unknown argument '$1'" >&2
46+
exit 1
47+
;;
2748
esac
49+
50+
# dh_installdeb will replace this with shell code automatically
51+
# generated by other debhelper scripts.
52+
53+
#DEBHELPER#
54+
55+
exit 0

pkg/debian/salt-api.templates

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,3 @@ Type: string
33
Default: salt
44
Description: User for salt-api
55
User to run the salt-api process as
6-
7-
Template: salt-api/enabled
8-
Type: string
9-
Default: enabled
10-
Description: Systemd enable state for salt-api
11-
default enable state for salt-api systemd state
12-
13-
Template: salt-api/active
14-
Type: string
15-
Default: active
16-
Description: Systemd active state for salt-api
17-
default active state for salt-api systemd state

pkg/debian/salt-cloud.postinst

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
#!/bin/sh
2+
# postinst script for salt-cloud.
3+
#
4+
# See: dh_installdeb(1).
25

3-
. /usr/share/debconf/confmodule
6+
set -e
7+
8+
# Summary of how this script can be called:
9+
# * <postinst> 'configure' <most-recently-configured-version>
10+
# * <old-postinst> 'abort-upgrade' <new version>
11+
# * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
12+
# <new-version>
13+
# * <postinst> 'abort-remove'
14+
# * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
15+
# <failed-install-package> <version> 'removing'
16+
# <conflicting-package> <version>
17+
# for details, see https://www.debian.org/doc/debian-policy/ or
18+
# the debian-policy package.
419

520
case "$1" in
621
configure)
7-
db_get salt-master/user
8-
if [ "$RET" != "root" ]; then
9-
PY_VER=$(/opt/saltstack/salt/bin/python3 -c "import sys; sys.stdout.write('{}.{}'.format(*sys.version_info)); sys.stdout.flush;")
10-
chown -R $RET:$RET /etc/salt/cloud.deploy.d /opt/saltstack/salt/lib/python${PY_VER}/site-packages/salt/cloud/deploy
22+
. /usr/share/debconf/confmodule
23+
if db_get salt-master/user
24+
then
25+
if [ "$RET" != "root" ]; then
26+
PY_VER=$(/opt/saltstack/salt/bin/python3 -c "import sys; sys.stdout.write('{}.{}'.format(*sys.version_info)); sys.stdout.flush;")
27+
chown -R $RET:$RET /etc/salt/cloud.deploy.d /opt/saltstack/salt/lib/python${PY_VER}/site-packages/salt/cloud/deploy
28+
fi
1129
fi
1230
;;
31+
abort-upgrade|abort-remove|abort-deconfigure)
32+
;;
33+
34+
*)
35+
echo "postinst called with unknown argument '$1'" >&2
36+
exit 1
37+
;;
1338
esac
39+
40+
# dh_installdeb will replace this with shell code automatically
41+
# generated by other debhelper scripts.
42+
43+
#DEBHELPER#
44+
45+
exit 0

pkg/debian/salt-common.postinst

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
11
#!/bin/sh
2+
# postinst script for salt-common.
3+
#
4+
# See: dh_installdeb(1).
5+
26
set -e
37

4-
/opt/saltstack/salt/bin/python3 -m compileall -qq /opt/saltstack/salt/lib
8+
# Summary of how this script can be called:
9+
# * <postinst> 'configure' <most-recently-configured-version>
10+
# * <old-postinst> 'abort-upgrade' <new version>
11+
# * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
12+
# <new-version>
13+
# * <postinst> 'abort-remove'
14+
# * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
15+
# <failed-install-package> <version> 'removing'
16+
# <conflicting-package> <version>
17+
# for details, see https://www.debian.org/doc/debian-policy/ or
18+
# the debian-policy package.
19+
20+
21+
case "$1" in
22+
configure)
23+
/opt/saltstack/salt/bin/python3 -m compileall -qq /opt/saltstack/salt/lib
24+
;;
25+
26+
abort-upgrade|abort-remove|abort-deconfigure)
27+
;;
28+
29+
*)
30+
echo "postinst called with unknown argument '$1'" >&2
31+
exit 1
32+
;;
33+
esac
34+
35+
# dh_installdeb will replace this with shell code automatically
36+
# generated by other debhelper scripts.
37+
38+
#DEBHELPER#
39+
40+
exit 0

pkg/debian/salt-common.preinst

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
#!/bin/sh
2+
# preinst script for salt-common.
3+
#
4+
# See: dh_installdeb(1).
5+
6+
set -e
7+
8+
# Summary of how this script can be called:
9+
# * <new-preinst> 'install'
10+
# * <new-preinst> 'install' <old-version>
11+
# * <new-preinst> 'upgrade' <old-version>
12+
# * <old-preinst> 'abort-upgrade' <new-version>
13+
# for details, see https://www.debian.org/doc/debian-policy/ or
14+
# the debian-policy package.
15+
16+
[ -n "$SALT_HOME" ] || SALT_HOME=/opt/saltstack/salt
17+
[ -n "$SALT_USER" ] || SALT_USER=salt
18+
[ -n "$SALT_NAME" ] || SALT_NAME="Salt"
19+
[ -n "$SALT_GROUP" ] || SALT_GROUP=salt
20+
[ -n "$SALT_SHELL" ] || SALT_SHELL=/usr/sbin/nologin
21+
122
case "$1" in
223
install|upgrade)
3-
[ -z "$SALT_HOME" ] && SALT_HOME=/opt/saltstack/salt
4-
[ -z "$SALT_USER" ] && SALT_USER=salt
5-
[ -z "$SALT_NAME" ] && SALT_NAME="Salt"
6-
[ -z "$SALT_GROUP" ] && SALT_GROUP=salt
7-
[ -z "$SALT_SHELL" ] && SALT_SHELL=/usr/sbin/nologin
8-
924
# create user to avoid running server as root
1025
# 1. create group if not existing
1126
if ! getent group | grep -q "^$SALT_GROUP:" ; then
@@ -36,4 +51,19 @@ case "$1" in
3651
test -d /etc/logrotate.d/salt && rm -r /etc/logrotate.d/salt || /bin/true
3752

3853
;;
54+
55+
abort-upgrade)
56+
;;
57+
58+
*)
59+
echo "preinst called with unknown argument '$1'" >&2
60+
exit 1
61+
;;
3962
esac
63+
64+
# dh_installdeb will replace this with shell code automatically
65+
# generated by other debhelper scripts.
66+
67+
#DEBHELPER#
68+
69+
exit 0

pkg/debian/salt-common.prerm

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
#!/bin/sh
2+
# prerm script for salt-common.
3+
#
4+
# See: dh_installdeb(1).
5+
26
set -e
37

4-
dpkg -L salt-common | perl -ne 's,/([^/]*)\.py$,/__pycache__/\1.*, or next; unlink $_ or die $! foreach glob($_)'
5-
find /opt/saltstack/salt -type d -name __pycache__ -empty -print0 | xargs --null --no-run-if-empty rmdir
8+
# Summary of how this script can be called:
9+
# * <prerm> 'remove'
10+
# * <old-prerm> 'upgrade' <new-version>
11+
# * <new-prerm> 'failed-upgrade' <old-version>
12+
# * <conflictor's-prerm> 'remove' 'in-favour' <package> <new-version>
13+
# * <deconfigured's-prerm> 'deconfigure' 'in-favour'
14+
# <package-being-installed> <version> 'removing'
15+
# <conflicting-package> <version>
16+
# for details, see https://www.debian.org/doc/debian-policy/ or
17+
# the debian-policy package.
18+
19+
20+
case "$1" in
21+
remove|upgrade|deconfigure)
22+
dpkg -L salt-common | perl -ne 's,/([^/]*)\.py$,/__pycache__/\1.*, or next; unlink $_ or die $! foreach glob($_)'
23+
find /opt/saltstack/salt -type d -name __pycache__ -empty -print0 | xargs --null --no-run-if-empty rmdir
24+
;;
25+
26+
failed-upgrade)
27+
;;
28+
29+
*)
30+
echo "prerm called with unknown argument '$1'" >&2
31+
exit 1
32+
;;
33+
esac
34+
35+
# dh_installdeb will replace this with shell code automatically
36+
# generated by other debhelper scripts.
37+
38+
#DEBHELPER#
39+
40+
exit 0

0 commit comments

Comments
 (0)