Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3006.x] Make deb scripts more compliant with Debian policy #66688

Open
wants to merge 2 commits into
base: 3006.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Package: salt-cloud
Architecture: amd64 arm64
Breaks: salt-common (<= 3006.4)
Depends: salt-common (= ${source:Version}),
salt-master (= ${source:Version}),
${misc:Depends}
Description: public cloud VM management system
provision virtual machines on various public clouds via a cleanly
Expand Down
66 changes: 38 additions & 28 deletions pkg/debian/salt-api.postinst
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
#!/bin/sh
# postinst script for salt-api
#
# See: dh_installdeb(1).

. /usr/share/debconf/confmodule
set -e

# Summary of how this script can be called:
# * <postinst> 'configure' <most-recently-configured-version>
# * <old-postinst> 'abort-upgrade' <new version>
# * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
# <new-version>
# * <postinst> 'abort-remove'
# * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
# <failed-install-package> <version> 'removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.

case "$1" in
configure)
db_get salt-api/user
if [ "$RET" != "root" ]; then
if [ ! -e "/var/log/salt/api" ]; then
touch /var/log/salt/api
chmod 640 /var/log/salt/api
fi
chown $RET:$RET /var/log/salt/api
fi
if command -v systemctl; then
db_get salt-api/active
RESLT=$(echo "$RET" | cut -d ' ' -f 1)
if [ "$RESLT" != 10 ]; then
systemctl daemon-reload
if [ "$RESLT" = "active" ]; then
systemctl restart salt-api
fi
db_get salt-api/enabled
RESLT=$(echo "$RET" | cut -d ' ' -f 1)
if [ "$RESLT" = "disabled" ]; then
systemctl disable salt-api
else
systemctl enable salt-api
fi
else
systemctl daemon-reload
systemctl restart salt-api
systemctl enable salt-api
. /usr/share/debconf/confmodule
if db_get salt-api/user; then
if [ "$RET" != "root" ]; then
if [ ! -e "/var/log/salt/api" ]; then
touch /var/log/salt/api
chmod 640 /var/log/salt/api
fi
chown $RET:$RET /var/log/salt/api
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument '$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
43 changes: 32 additions & 11 deletions pkg/debian/salt-api.preinst
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#!/bin/sh
# preinst script for salt-api.
#
# See: dh_installdeb(1).

. /usr/share/debconf/confmodule
set -e

# Summary of how this script can be called:
# * <new-preinst> 'install'
# * <new-preinst> 'install' <old-version>
# * <new-preinst> 'upgrade' <old-version>
# * <old-preinst> 'abort-upgrade' <new-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.

case "$1" in
install)
;;

upgrade)
. /usr/share/debconf/confmodule
[ -z "$SALT_HOME" ] && SALT_HOME=/opt/saltstack/salt
[ -z "$SALT_USER" ] && SALT_USER=salt
[ -z "$SALT_NAME" ] && SALT_NAME="Salt"
Expand All @@ -14,14 +29,20 @@ case "$1" in
CUR_GROUP=$(ls -dl /run/salt-api.pid | cut -d ' ' -f 4)
db_set salt-api/user $CUR_USER
chown -R $CUR_USER:$CUR_GROUP /var/log/salt/api
if command -v systemctl; then
SM_ENABLED=$(systemctl show -p UnitFileState salt-api | cut -d '=' -f 2)
db_set salt-api/enabled $SM_ENABLED
SM_ACTIVE=$(systemctl is-active salt-api)
db_set salt-api/active $SM_ACTIVE
else
db_set salt-api/enabled enabled
db_set salt-api/active active
fi
;;
;;

abort-upgrade)
;;

*)
echo "preinst called with unknown argument '$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
12 changes: 0 additions & 12 deletions pkg/debian/salt-api.templates
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,3 @@ Type: string
Default: salt
Description: User for salt-api
User to run the salt-api process as

Template: salt-api/enabled
Type: string
Default: enabled
Description: Systemd enable state for salt-api
default enable state for salt-api systemd state

Template: salt-api/active
Type: string
Default: active
Description: Systemd active state for salt-api
default active state for salt-api systemd state
42 changes: 37 additions & 5 deletions pkg/debian/salt-cloud.postinst
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
#!/bin/sh
# postinst script for salt-cloud.
#
# See: dh_installdeb(1).

. /usr/share/debconf/confmodule
set -e

# Summary of how this script can be called:
# * <postinst> 'configure' <most-recently-configured-version>
# * <old-postinst> 'abort-upgrade' <new version>
# * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
# <new-version>
# * <postinst> 'abort-remove'
# * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
# <failed-install-package> <version> 'removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.

case "$1" in
configure)
db_get salt-master/user
if [ "$RET" != "root" ]; then
PY_VER=$(/opt/saltstack/salt/bin/python3 -c "import sys; sys.stdout.write('{}.{}'.format(*sys.version_info)); sys.stdout.flush;")
chown -R $RET:$RET /etc/salt/cloud.deploy.d /opt/saltstack/salt/lib/python${PY_VER}/site-packages/salt/cloud/deploy
. /usr/share/debconf/confmodule
if db_get salt-master/user
then
if [ "$RET" != "root" ]; then
PY_VER=$(/opt/saltstack/salt/bin/python3 -c "import sys; sys.stdout.write('{}.{}'.format(*sys.version_info)); sys.stdout.flush;")
chown -R $RET:$RET /etc/salt/cloud.deploy.d /opt/saltstack/salt/lib/python${PY_VER}/site-packages/salt/cloud/deploy
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument '$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
38 changes: 37 additions & 1 deletion pkg/debian/salt-common.postinst
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
#!/bin/sh
# postinst script for salt-common.
#
# See: dh_installdeb(1).

set -e

/opt/saltstack/salt/bin/python3 -m compileall -qq /opt/saltstack/salt/lib
# Summary of how this script can be called:
# * <postinst> 'configure' <most-recently-configured-version>
# * <old-postinst> 'abort-upgrade' <new version>
# * <conflictor's-postinst> 'abort-remove' 'in-favour' <package>
# <new-version>
# * <postinst> 'abort-remove'
# * <deconfigured's-postinst> 'abort-deconfigure' 'in-favour'
# <failed-install-package> <version> 'removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.


case "$1" in
configure)
/opt/saltstack/salt/bin/python3 -m compileall -qq /opt/saltstack/salt/lib
;;

abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument '$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
31 changes: 31 additions & 0 deletions pkg/debian/salt-common.preinst
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#!/bin/sh
# preinst script for salt-common.
#
# See: dh_installdeb(1).

set -e

# Summary of how this script can be called:
# * <new-preinst> 'install'
# * <new-preinst> 'install' <old-version>
# * <new-preinst> 'upgrade' <old-version>
# * <old-preinst> 'abort-upgrade' <new-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.


case "$1" in
install|upgrade)
[ -z "$SALT_HOME" ] && SALT_HOME=/opt/saltstack/salt
Expand Down Expand Up @@ -36,4 +52,19 @@ case "$1" in
test -d /etc/logrotate.d/salt && rm -r /etc/logrotate.d/salt || /bin/true

;;

abort-upgrade)
;;

*)
echo "preinst called with unknown argument '$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
39 changes: 37 additions & 2 deletions pkg/debian/salt-common.prerm
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
#!/bin/sh
# prerm script for salt-common.
#
# See: dh_installdeb(1).

set -e

dpkg -L salt-common | perl -ne 's,/([^/]*)\.py$,/__pycache__/\1.*, or next; unlink $_ or die $! foreach glob($_)'
find /opt/saltstack/salt -type d -name __pycache__ -empty -print0 | xargs --null --no-run-if-empty rmdir
# Summary of how this script can be called:
# * <prerm> 'remove'
# * <old-prerm> 'upgrade' <new-version>
# * <new-prerm> 'failed-upgrade' <old-version>
# * <conflictor's-prerm> 'remove' 'in-favour' <package> <new-version>
# * <deconfigured's-prerm> 'deconfigure' 'in-favour'
# <package-being-installed> <version> 'removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.


case "$1" in
remove|upgrade|deconfigure)
dpkg -L salt-common | perl -ne 's,/([^/]*)\.py$,/__pycache__/\1.*, or next; unlink $_ or die $! foreach glob($_)'
find /opt/saltstack/salt -type d -name __pycache__ -empty -print0 | xargs --null --no-run-if-empty rmdir
;;

failed-upgrade)
;;

*)
echo "prerm called with unknown argument '$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
Loading
Loading