Skip to content

Instantly share code, notes, and snippets.

@djhaskin987
Created August 27, 2014 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djhaskin987/873a7b720eddd44c5475 to your computer and use it in GitHub Desktop.
Save djhaskin987/873a7b720eddd44c5475 to your computer and use it in GitHub Desktop.
debian install scripts explained

Possible first-hack at the debian scripts for install-upgrade-configure: preinst

if [ "${1}" = "install" -a -z "${1}" ]
then
    # "before install" goes here
elif [ "${1}" = "upgrade" -a -n "${2}" ]
then
    upgradeVersion="${2}"
    # "before upgrade" goes here
elif [ "${1}" = "install" -a -n "${2}" ]
then
    upgradeFromVersion="${2}"
    # executed when a package is removed but its config files aren't,
    # and a new version is installed.
    # looks a _lot_ like an upgrade case, I say we just execute the
    # same "before upgrade" script as in the previous case
elif echo "${1}" | grep -E -q '(fail|abort)'
then
    # fail with error message
    # maybe some debug output
fi

postinst

if [ "${1}" = "configure " -a -z "${2}" ]
then
    # "on install" here
elif [ "${1}" = "configure" -a -n "${2}" ]
then
    upgradeFromVersion="${2}"
    # "on upgrade" here
    # NOTE: This slot is also used when deb packages are removed,
    # but their config files aren't, but a newer version of the
    # package is installed later, called "Config-Files" state.
    # basically, that still looks a _lot_ like an upgrade to me.
elif echo "${1}" | grep -E -q "(abort|fail)"
then
    # fail with error message
fi

prerm

if [ "${1}" = "remove" -a -z "${2}" ]
then
    # "before remove" goes here
elif [ "${1}" = "upgrade" ]
then
    upgradeVersionTo="${2}"
    # Executed before the old version is removed
    # upon upgrade.
    # Maybe we just do nothing here.
elif echo "${1}" | grep -E -q "(fail|abort)"
then
    # Something went wrong, fail with error message
fi

postrm

if [ "${1}" = "remove" ]
then
    # "on remove" goes here
elif [ "${1}" = "purge" -a -z "${2}" ]
then
    # like "on remove", but executes after dpkg deletes config files
    # 'apt-get purge' runs 'on remove' section, then this section.
    # Maybe we ignore this; it seems really fine-grained.
    # There is no equivalent in RPM. A debian-specific argument
    # might perhaps be used here, but most people
    # probably don't need it.
elif [ "${1}" = "upgrade" ]
then
    # This represents the case where the old package's postrm is called after
    # the 'preinst' script is called.
    # Maybe we ignore this and just use 'preinst upgrade' and
    # 'postinst' configure'
elif echo "${1}" | grep -E -q '(fail|abort)'
then
    # something went wrong, print error message
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment