Files
scratchpkg/extra/sysupdate
2017-12-09 00:56:42 +08:00

58 lines
1.2 KiB
Bash
Executable File

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