Last active
February 9, 2018 07:15
-
-
Save ageis/8b231bdb76ca8c7a7e0aede551cc53c5 to your computer and use it in GitHub Desktop.
Update gems, nodejs, Perl, PyPi modules and apt packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateall() { | |
#set -o pipefail noclobber erexit | |
set -v | |
#set -e | |
#set -x | |
function exit_error() { | |
echo "You can only run updateall() once at a time." >&2 | |
} | |
function status() { | |
echo "Exit code is $1" | |
echo "Process ID is $2" | |
#kill $2 | |
jobs -n | |
if [[ $? -gt 0 ]]; then | |
cat <&"${updates[0]}" | |
#read output <&"${updates[0]}" | |
#echo "$output" | |
fi | |
} | |
function lock() { | |
if [ -e /proc/"${UPDATES_COPROC_PID}" ] && [ -a /proc/"${UPDATES_COPROC_PID}"/exe ]; then | |
exit_error; return 1 | |
fi | |
exec 200>/tmp/updates.lock | |
flock --exclusive --nonblock 200 && return 0 || return 1 | |
} | |
#lock || exit_error; return 1 | |
#trap "rm -f /tmp/updates.lock" EXIT SIGABRT SIGTERM | |
trap 'status $? $$' ERR SIGHUP SIGINT SIGTERM | |
coproc updates { | |
sudo --preserve-env --login /bin/bash; | |
} | |
export UPDATES_COPROC_PID="${updates_PID}" | |
dependencies=( | |
"export PERL_MM_USE_DEFAULT=1; perl -MCPAN -e 'install Bundle::CPAN'" | |
"curl -L http://cpanmin.us | perl - App::cpanminus" | |
"cpanm App::cpanoutdated" | |
"wget -qO- https://bootstrap.pypa.io/get-pip.py | python2" | |
"pip2 install -U pip_review" | |
"wget -qO- https://bootstrap.pypa.io/get-pip.py | python3" | |
"pip3 install -U pip_review" | |
) | |
declare -i deps=$(expr "${#dependencies[@]}" - 1) | |
#for i in $(seq 0 "$deps"); do | |
# sudo --preserve-env --login /bin/bash -c "${dependencies[$i]}" & | |
#done | |
commands=( | |
"gem list | cut -d ' ' -f 1 | gem update" | |
"npm update -g" | |
"cpan-outdated -p | cpanm" | |
"python2 -m pip_review --auto" | |
"python3 -m pip_review --auto" | |
#"pip2 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip2 install -U" | |
#"pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U" | |
"apt-get -qy update" | |
"export DEBIAN_FRONTEND=noninteractive; export DEBIAN_PRIORITY=critical; apt-get -qy -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\" upgrade" | |
) | |
declare -i cmds=$(expr "${#commands[@]}" - 1) | |
for i in $(seq 0 "$cmds"); do | |
echo "(${commands[$i]})&" >&"${updates[1]}" | |
done | |
wait; | |
#flock --unlock 200 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ENV gets all screwed up in the coproc subshell.