Files
scratchpkg/extra/sysupdate
2018-05-26 00:24:19 +08:00

65 lines
1.4 KiB
Bash
Executable File

#!/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 -p sudo) ]; then
sudo scratch portup
else
msgerr "Updating package need root access!"
exit 1
fi
else
scratch portup
fi ;;
esac
if [[ ! $(scratch -cu | grep "up to date") ]]; then
outdatepkg=($(scratch query --outdate | awk '{print $2}'))
totalopkgs=$(echo ${#outdatepkg[@]})
count=1
for i in ${outdatepkg[@]}; do
if [ $UID != 0 ]; then
if [ $(type -p 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 upgrade $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 "${GREEN}>>>${CRESET} $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 "${RED}>>>${CRESET} $ko"
done
fi
exit 0