Files
bash/venv_solus.sh
2021-03-09 06:38:04 +01:00

118 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
italic="\033[3m"
underline="\033[4m"
ita_under="\033[3;4m"
bgd="\033[1;4;31m"
red="\033[1;31m"
bold="\033[1m"
box="\033[1;41m"
reset="\033[0m"
echo -e "${bold}🐍 Update apps in Python virtuals environments ${reset}\n"
###########################################################
#
# Configuration
#
###########################################################
mkdocs_ext=("mkdocs-material" "mkdocs-material-extensions" "mkdocs-git-revision-date-localized-plugin" "mkdocs-minify-plugin" "fontawesome_markdown" "mkdocs-pdf-export-plugin")
sound="Glass"
image="$BKP_BASE_DIR/success.png"
# macos: silverbook
if [[ "$OSTYPE" == "darwin"* ]]; then
v=$HOME/Documents/venv
# Listes des apps:
declare -a apps=("soco-cli" "mkdocs")
# solus: linux-gnu
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
v=$HOME/Applications
# Listes des apps:
declare -a apps=("soco-cli" "mkdocs")
# rpi4: linux_gnueabihf
# rpi3:
elif [[ "$OSTYPE" == "linux_gnueabihf" ]]; then
v=$HOME/venv
# Listes des apps:
declare -a apps=("soco-cli" "mkdocs")
fi
###########################################################
#
# Script
#
###########################################################
for app in ${apps[*]}
do
echo -e "${bold}Update $app${reset}";
cd "$v/$app"
source bin/activate
python3 -V
pip3 install -U pip setuptools
echo ""
info=$(pip3 show "$app")
l1=$(echo "$info" | sed -n '1p')
l1="\\\033[4m$l1\\\033[0m"
info=$(echo "$info" | sed "1s/.*/$l1/")
echo -e "$info"
upd=$(pip3 install -U "$app")
a=$(grep "Successfully installed" <<< "$upd")
if [ -n "$a" ]; then
if [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v terminal-notifier)" ]; then
terminal-notifier -title "Update $app package" -message "" -sound "$sound" -contentImage "$image"
elif [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v notify-send)" ]; then
notify-send -i "/usr/share/icons/Adwaita/48x48/legacy/face-laugh.png" "Update $app package" ""
fi
fi
<<COMMENT
echo ""
avail=$(pip3 list --outdated --format columns | sed '1,2d')
if [ -n "$avail" ]; then
while read i
do
pkg=$(echo "$i" | awk '{print $1}')
b=$(echo "$i" | awk 'NF{NF-=1};1')
#echo "pip3 install -U $pkg"
pip3 install -U "$pkg"
c+="$b\n"
d+="$pkg, "
done <<< "$avail"
title="Update outdated packages in $app venv"
if [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v terminal-notifier)" ]; then
terminal-notifier -title "$title" -message "$d" -sound "$sound" -contentImage "$image"
elif [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v notify-send)" ]; then
notify-send -i "/usr/share/icons/Adwaita/48x48/legacy/face-laugh.png" "$title" "$c"
fi
fi
COMMENT
# Update mkdocs plugins & themes:
if [ $app == "mkdocs" ]; then
for i in ${mkdocs_ext[*]}
do
echo -e "\n${bold}Update $i:${reset}" && pip3 install -U $i
done
fi
deactivate
echo ""
done