Skip to content

Instantly share code, notes, and snippets.

@mattyjones
Last active April 4, 2020 17:11
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 mattyjones/a98cf78473789710809cfc49f1d2cb0a to your computer and use it in GitHub Desktop.
Save mattyjones/a98cf78473789710809cfc49f1d2cb0a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# parrot-upgrade
#
# DESCRIPTION:
# Upgrade a parrotOS system to the latest rolling release using sane defaults
#
# OUTPUT:
# plain text
#
# PLATFORMS:
# ParrotOS
#
# DEPENDENCIES:
# apt
# sudo
#
# USAGE:
#
# EXAMPLES:
# sudo parrot-upgrade
#
# NOTES:
#
# LICENSE:
# Copyright 2020 ParrotOS
# Released under the the MIT license; see LICENSE
# for details.
#
set -eo pipefail
_OK() {
declare desc="OK exit status"
# TODO print a status summary
echo Status: Update Successful
exit 0
}
_CRITICAL() {
declare desc="Critical exit status"
# TODO drop the error message here
echo Status: Update Failed
exit 2
}
_UNKNOWN() {
decalre desc="Unknow exit status"
# TODO drop the error message here
echo Status: Update Failed
exit 3
}
show_help() {
declare desc="Help command"
cat <<EOF
sudo parrot-upgrade
EOF
}
die() {
declare desc="standard error handling"
printf '%s\n' "$1" >&2
_UNKNOWN
}
function update {
apt_cmd="/usr/local/bin/apt"
dpkg_cmd="/usr/bin/dpkg"
echo_cmd="/usr/bin/echo"
"$apt_cmd" update || "$echo_cmd" failed to update index lists
"$dpkg_cmd" --configure -a || "$echo_cmd" failed to fix interrupted upgrades
"$apt_cmd" --fix-broken --fix-missing install || "$echo_cmd" failed to fix conflicts
"$apt_cmd" -y --allow-downgrades --fix-broken --fix-missing dist-upgrade
}
function main {
declare desc="Main entry point to the script"
local DEBIAN_FRONTEND="noninteractive"
local DEBIAN_PRIORITY="critical"
local DEBCONF_NOWARNINGS="yes"
export "$DEBIAN_FRONTEND" "$DEBIAN_PRIORITY" "$DEBCONF_NOWARNINGS"
# Update the system
update
_OK
}
while :; do
case $1 in
-h| -\?|--help)
show_help
exit
;;
--)
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*)
break
esac
shift
done
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment