#!/bin/bash -e faileduppkg=() successuppkg=() 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 package $i..." sudo scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i) else echo "Updating package need root access!" exit 1 fi else echo -e "[ $count/$totalopkgs ] Updating package $i..." scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i) fi echo ((count++)) done else echo "All packages is up to date." exit 0 fi if [ "${#successuppkg[@]}" -gt 0 ]; then echo "Success update this package(s):" echo ${successuppkg[@]} | tr ' ' '\n' fi if [ "${#faileduppkg[@]}" -gt 0 ]; then echo "Failed update this package(s):" echo ${faileduppkg[@]} | tr ' ' '\n' fi exit 0