#!/bin/bash -e source "/usr/share/scratchpkg/color" source "/usr/share/scratchpkg/message" faileduppkg=() successuppkg=() case "$1" in -up|--update-ports) msg "Updating ports..." if [ $UID != 0 ]; then if [ $(type -pa sudo) ]; then sudo scratch -up else msgerr "Updating package need root access!" exit 1 fi else scratch -up fi ;; esac if [[ ! $(scratch -cu | grep "up to date") ]]; then outdatepkg=($(scratch -cu | awk '{print $2}')) totalopkgs=$(echo ${#outdatepkg[@]}) count=1 for i in ${outdatepkg[@]}; do if [ $UID != 0 ]; then if [ $(type -pa sudo) ]; then echo -e "[ $count/$totalopkgs ] Updating $i..." sudo scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i) else msgerr "Updating package need root access!" exit 1 fi else echo -e "[ $count/$totalopkgs ] Updating $i..." scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i) fi echo ((count++)) done else msg "All packages is up to date." exit 0 fi if [ "${#successuppkg[@]}" -gt 0 ]; then echo "Successfully update this package(s):" for ok in ${successuppkg[@]}; do echo -e "${color_green}>>>${color_reset} $ok" done fi if [ "${#faileduppkg[@]}" -gt 0 ]; then [ "${#successuppkg[@]}" -gt 0 ] && echo # make space between success and failed echo "Failed update this package(s):" for ko in ${faileduppkg[@]}; do echo -e "${color_red}>>>${color_reset} $ko" done fi exit 0