Saturday, May 4, 2024
16
rated 0 times [  16] [ 0]  / answers: 1 / hits: 27527  / 1 Year ago, thu, may 11, 2023, 8:10:52

I recently started packaging up some of my software and publishing it on Launchpad. The installation and removal works fine, but upgrading the package from one version to the next version is problematic.


The problem is that there are some scripts that only need to run during the first installation of the package. These scripts populate the DB, create a user, etc. They are currently called in the package.postinst configure) section. However this results in them being called during an upgrade as well as shown in the diagram.


Is there a way to include a maintainer script in a .deb package that only executes during the first installation of the package and not during an upgrade? Or what would be an elegant way to include some initial setup scripts in a .deb package?


More From » package-management

 Answers
7

With a debian/preinst file you can perform actions on install but not upgrade.



#!/bin/sh
set -e

case "$1" in
install)
# do some magic
;;

upgrade|abort-upgrade)
;;

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

#DEBHELPER#

exit 0


Though as the name implies, this is run before your package is installed. So you might not be able to do what you need here. Most packages simply test in the configure stage of the postinst if the user has been created already. Here's colord



$ cat  /var/lib/dpkg/info/colord.postinst
#!/bin/sh

set -e

case "$1" in
configure)

# create colord group if it isn't already there
if ! getent group colord >/dev/null; then
addgroup --quiet --system colord
fi

# create the scanner group if it isn't already there
if ! getent group scanner >/dev/null; then
addgroup --quiet --system scanner
fi

# create colord user if it isn't already there
if ! getent passwd colord >/dev/null; then
adduser --system --ingroup colord --home /var/lib/colord colord
--gecos "colord colour management daemon"
# Add colord user to scanner group
adduser --quiet colord scanner
fi

# ensure /var/lib/colord has appropriate permissions
chown -R colord:colord /var/lib/colord

;;
esac



exit 0

[#40529] Friday, May 12, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taigysel

Total Points: 33
Total Questions: 136
Total Answers: 114

Location: Singapore
Member since Wed, Jan 13, 2021
3 Years ago
taigysel questions
;