Files
scratchpkg/extra/sysupdate
2017-12-08 21:13:21 +08:00

46 lines
1021 B
Bash
Executable File

#!/bin/bash -e
source "/usr/share/scratchpkg/color"
source "/usr/share/scratchpkg/message"
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 $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 $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):"
echo ${successuppkg[@]} | tr ' ' '\n'
echo
fi
if [ "${#faileduppkg[@]}" -gt 0 ]; then
echo "Failed update this package(s):"
echo ${faileduppkg[@]} | tr ' ' '\n'
fi
exit 0