#!/usr/bin/env bash print_help() { (>&2 cat < Update the selected packages. If none are given, all packages are updated. EOF ) } # TODO: src-db getver $pkg? read_pkg_version() { local EPKG=$(escape_string "$1") < "$SSPT_SRC_DB_FILE" grep -E "^$EPKG " | grep -E -o "[A-Za-z0-9_\.\-]*$" } update_package() { local PKG="$1" local BEFORE="$(read_pkg_version "$1")" exec_subcommand pkgcmd pull "$PKG" || return 2 local AFTER="$(exec_subcommand pkgcmd version "$PKG")" if [ "$BEFORE" != "$AFTER" ]; then exec_subcommand src-db reg "$PKG" "$AFTER" || return 2 return 1 fi return 0 } upgrade_package() { exec_subcommand pkgcmd config "$1" && \ exec_subcommand pkgcmd build "$1" && \ exec_subcommand strace "$1" return $? } upgrade_pkgs() { local ERRORS="" while read -r PKG; do if ! upgrade_package "$PKG"; then if [ -z "$ERRORS" ]; then ERRORS="$PKG" else ERRORS="$ERRORS, $PKG" fi fi done < "/tmp/upgrade_list" rm /tmp/upgrade_list if ! [ -z "$ERRORS" ]; then (>&2 echo "Failed to compile the following packages: $ERRORS") fi } update_selection() { local ERRORS="" local ALLARGS=("$@") for PKG in "${ALLARGS[@]}"; do echo -n "$PKG: " update_package "$PKG" local RETV="$?" if [ "$RETV" = "2" ]; then if [ -z "$ERRORS" ]; then ERRORS="$PKG" else ERRORS="$ERRORS, $PKG" fi elif [ "$ERTV" = "1" ]; then echo "$PKG" >> /tmp/upgrade_list fi done if ! [ -z "$ERRORS" ]; then (>&2 echo "Failed to update the following packages: $ERRORS\n" \ "Press any key to continue.") local FOOBAR="" read -r FOOBAR unset FOOBAR fi upgrade_pkgs } update_all() { # TODO: speed this up, maybe by parallellising this? while read -r PKG; do echo -n "$PKG: " if ! update_package "$PKG"; then echo "$PKG" >> /tmp/upgrade_list fi done < "$SSPT_BIN_DB_FILE" upgrade_pkgs } if [ -f "/tmp/upgrade_list" ]; then rm /tmp/upgrade_list fi touch /tmp/upgrade_list if [ $# -eq 0 ]; then update_all exit fi update_selection "$@"