436 lines
15 KiB
Bash
Executable File
436 lines
15 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"
|
|
bold_ita="\033[1;3m"
|
|
box="\033[1;41m"
|
|
redbold="\033[1;31m"
|
|
redbox="\033[1;41m"
|
|
green="\033[0;32m"
|
|
reset="\033[0m"
|
|
|
|
echo "$OSTYPE"
|
|
|
|
# Fine-grained personal access tokens:
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
# Put token in macOS Keychain
|
|
# security add-generic-password -s service_name -a account -w github_pat_blablablablabla
|
|
# Get token from macOS Keychain
|
|
gh_access_tokens=$(security find-generic-password -w -s gh_access_tokens)
|
|
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
|
|
gh_access_tokens=
|
|
fi
|
|
|
|
upd_avail=0
|
|
|
|
vercomp() {
|
|
if [[ $1 == $2 ]]
|
|
then
|
|
return 0
|
|
fi
|
|
local IFS=.
|
|
local i ver1=($1) ver2=($2)
|
|
# fill empty fields in ver1 with zeros
|
|
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
|
|
do
|
|
ver1[i]=0
|
|
done
|
|
for ((i=0; i<${#ver1[@]}; i++))
|
|
do
|
|
if [[ -z ${ver2[i]} ]]
|
|
then
|
|
# fill empty fields in ver2 with zeros
|
|
ver2[i]=0
|
|
fi
|
|
if ((10#${ver1[i]} > 10#${ver2[i]}))
|
|
then
|
|
return 1
|
|
fi
|
|
if ((10#${ver1[i]} < 10#${ver2[i]}))
|
|
then
|
|
return 2
|
|
fi
|
|
done
|
|
return 0
|
|
}
|
|
|
|
testvercomp() {
|
|
vercomp $2 $3
|
|
case $? in
|
|
0) op='=';;
|
|
1) op='>';;
|
|
2) op='<';;
|
|
esac
|
|
if [[ $op != $4 ]]
|
|
then
|
|
#echo "Fail: Expected '$3', Actual '$op', Arg1 '$1', Arg2 '$2'"
|
|
echo -e " - $1: $2 (last: $3)"
|
|
upd_avail=0
|
|
else
|
|
#echo "Pass: '$1 $op $2'"
|
|
echo -e "${red} - $1: $2 (last: $3)${reset}"
|
|
echo -e " - $1: $2 (last: **$3**)" >> update.md
|
|
upd_avail=1
|
|
fi
|
|
}
|
|
|
|
|
|
#############################
|
|
# #
|
|
# find latest versions #
|
|
# #
|
|
#############################
|
|
|
|
declare -A latest
|
|
|
|
echo -e "${green}Let's find latest versions on SourceForge...${reset}\n"
|
|
|
|
# https://sourceforge.net/projects/asuswrt-merlin/files/RT-AC88U/Release/
|
|
# https://www.asuswrt-merlin.net/download
|
|
|
|
# curl -qsL "https://sourceforge.net/projects/asuswrt-merlin/best_release.json" | sed "s/, /,\n/g" | sed -rn "/release/,/\}/{ /filename/{ 0,//s/([^0-9]*)([0-9\.]+)([^0-9]*.*)/\2/ p }}"
|
|
|
|
#curl -H "Accept: application/json" -X PUT -d "default=windows&default=mac&default=linux&default=bsd&default=solaris&default=others" -d "api_key=54fa10c5-1038-4238-8a8f-f24d34659ddb" https://sourceforge.net/projects/asuswrt-merlin/files/RT-AC88U
|
|
|
|
# ok
|
|
# curl -H "Accept: application/json" -X PUT -d "default=windows&default=mac&default=linux&default=bsd&default=solaris&default=others" -d "api_key=54fa10c5-1038-4238-8a8f-f24d34659ddb" "https://sourceforge.net/projects/asuswrt-merlin/files/RT-AC88U/stats/json?start_date=2023-07-01&end_date=2023-08-05" | jq
|
|
|
|
asus=$(curl -s "https://sourceforge.net/projects/asuswrt-merlin/rss?path=/RT-AC88U/Release" | xmllint --nocdata --xpath "//title/text() | //pubDate/text() | //link/text()" - | awk NR\>3 | head -n3)
|
|
|
|
while IFS= read -r line; do
|
|
merlin+=("${line}")
|
|
done <<< "$asus"
|
|
release=$(echo "${merlin[0]}" | awk -F"/" '{print $NF}') # RT-AC88U_386.12_0.zip
|
|
release=${release:0:-4} # RT-AC88U_386.12_0
|
|
router=$(echo "$release" | awk -F"_" '{print $1}') # ok
|
|
last=${release//$router/}
|
|
last=${last:1}
|
|
url=$(echo "${merlin[1]}")
|
|
url=${url///download/}
|
|
url=$(echo "$url" | awk -F"/" 'BEGIN{OFS=FS} {NF--; print}')
|
|
dat=$(date -d "${merlin[2]}" +%Y-%m-%d)
|
|
latest+=(["Asuswrt-Merlin $router"]="$last")
|
|
echo -e "${bold}Asus $router${reset}"
|
|
echo -e "Latest release: $last"
|
|
echo -e "Url: $url"
|
|
echo -e "Published date: $dat"
|
|
|
|
echo -e "\n${green}Let's find latest versions on Github...${reset}\n"
|
|
|
|
last_joplin_server=$(git ls-remote --tags --sort="-v:refname" https://github.com/laurent22/joplin.git | grep "server" | head -n1 | sed 's/.*\///')
|
|
latest_joplin_server="${last_joplin_server/server-v/}"
|
|
latest+=([Joplin server]="$latest_joplin_server")
|
|
echo -e "${bold}Joplin server${reset}"
|
|
echo -e "Latest version: $latest_joplin_server"
|
|
echo -e "Url: https://github.com/laurent22/joplin/releases/tag/$last_joplin_server"
|
|
echo
|
|
|
|
declare -A repositories
|
|
repositories=(['Gitea']="go-gitea/gitea"
|
|
['Nextcloud']="nextcloud/server"
|
|
['nvm']="nvm-sh/nvm"
|
|
['Zenphoto']="zenphoto/zenphoto"
|
|
['Joplin']="laurent22/joplin"
|
|
['MkDocs']="mkdocs/mkdocs"
|
|
['Piwigo']="Piwigo/Piwigo"
|
|
['SoCo-CLI']="avantrec/soco-cli"
|
|
['thumbsup']="thumbsup/thumbsup"
|
|
['Vegas']="jaysalvat/vegas"
|
|
['WordPress']="WordPress/wordpress-develop"
|
|
)
|
|
|
|
|
|
|
|
for app in "${!repositories[@]}";
|
|
do
|
|
last=$(curl -s --header "Authorization: Bearer $gh_access_tokens" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${repositories[${app}]}/releases/latest" | jq -r '.name, .tag_name, .html_url, .published_at')
|
|
|
|
echo -e "${bold}${app}${reset}"
|
|
|
|
release=$(echo "$last" | head -n1)
|
|
[ -z "$release" ] & release=$(echo "$last" | awk 'FNR == 2 {print}') # name="" tag_name=1.5.2 (MkDocs)
|
|
|
|
if [ "$release" == "null" ]; then
|
|
last=$(curl -s --header "Authorization: Bearer $gh_access_tokens" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${repositories[${app}]}/tags" | jq -r '.[].name' | grep -v -E 'rc|dev|beta' | head -n1)
|
|
url="https://github.com/${repositories[${app}]}/releases/tag/$last"
|
|
last="${last/v/}"
|
|
echo -e "Latest tag: $last"
|
|
echo -e "Url: $url\n"
|
|
latest+=([$app]="$last")
|
|
else
|
|
url=$(echo "$last" | grep "http")
|
|
dat=$(echo "$last" | tail -n1 | awk -F "T" '{print $1}')
|
|
release="${release/v/}"
|
|
release="${release/Zenphoto\ /}"
|
|
echo -e "Latest release: $release"
|
|
echo -e "Published date: $dat"
|
|
echo -e "Url: $url\n"
|
|
latest+=([$app]="$release")
|
|
fi
|
|
|
|
done
|
|
|
|
#for app in "${!latest[@]}";
|
|
#do
|
|
#echo "${app} - ${latest[${app}]}"
|
|
#done
|
|
|
|
|
|
#############################
|
|
# #
|
|
# find availables updates #
|
|
# #
|
|
#############################
|
|
|
|
echo -e "${green}Let's find availables updates...${reset}\n"
|
|
|
|
chemin=$(dirname "$0")
|
|
Installed=$(find $chemin -name 'update.md' -maxdepth 1)
|
|
if [ -n "$Installed" ]; then
|
|
echo -e "A file ${italic}update.md\033${reset} already exist! We remove it.\n"
|
|
a=$(echo "$Installed" | xargs rm)
|
|
fi
|
|
|
|
echo -e "# Availables updates:" >> update.md
|
|
|
|
|
|
#############################
|
|
# #
|
|
# router Asus #
|
|
# #
|
|
#############################
|
|
|
|
if nmap "192.168.2.1" -PN -p 56222 | grep open &>/dev/null; then
|
|
motd=$(ssh -p56222 bruno@192.168.2.1 'cat /rom/etc/motd' | awk NF)
|
|
# ASUSWRT-Merlin RT-AC88U 386.12_0 Mon Sep 4 15:47:31 UTC 2023
|
|
firmw=$(echo "$motd" | awk '{print $1}')
|
|
router=$(echo "$motd" | awk '{print $2}')
|
|
version_fw=$(echo "$motd" | awk '{print $3}')
|
|
echo -e "${bold}Asus $router${reset}"
|
|
testvercomp "$firmw" $version_fw ${latest[Asuswrt-Merlin $router]} "<"
|
|
fi
|
|
|
|
echo
|
|
|
|
|
|
#############################
|
|
# #
|
|
# sur-le-sentier.fr #
|
|
# #
|
|
#############################
|
|
|
|
echo -e "${bold}sur-le-sentier.fr${reset}"
|
|
echo -e "## sur-le-sentier.fr" >> update.md
|
|
|
|
if nmap "sur-le-sentier.fr" -PN -p 22 | grep open &>/dev/null; then
|
|
|
|
sls_thumbsup=$(thumbsup --version | sed '/^$/d')
|
|
testvercomp "thumbsup" $sls_thumbsup ${latest[thumbsup]} "<"
|
|
#echo -e " - thumbsup: $sls_thumbsup (last: ${latest[thumbsup]})"
|
|
|
|
echo -e " - Piwigo: aller sur https://sur-le-sentier.fr/piwigo/admin.php?page=maintenance&tab=env"
|
|
|
|
sls_wordpress=$(curl --silent "https://sur-le-sentier.fr/blog/feed/" | grep generator | awk -F'=' '{print $2}' | awk -F'<' '{print $1}')
|
|
testvercomp "WordPress" $sls_wordpress ${latest[WordPress]} "<"
|
|
#echo -e " - WordPress: $sls_wordpress (last: ${latest[WordPress]})"
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update WordPress (y/n) ?" upd_wp_sls
|
|
[ "$upd_wp_sls" == "y" ] || [ "$upd_wp_sls" == "Y" ] && open 'https://212.227.191.167:8443/modules/wp-toolkit/index.php/index/list?context=extNavButton_wp_toolkit_1'
|
|
echo ""
|
|
fi
|
|
|
|
#sls_vegas=$(curl --silent https://sur-le-sentier.fr/vegas/js/vegas.js | sed -n '3p' | awk '{print $2}' | sed 's/v//')
|
|
sls_vegas=$(ssh -q -t sentier@sur-le-sentier.fr "cd httpdocs/vegas/js && git show | grep -m 1 \"Build\"" | awk -F"v" '{print $2}' | sed 's/.$//')
|
|
testvercomp "Vegas" $sls_vegas ${latest[Vegas]} "<"
|
|
#echo -e " - Vegas: $sls_vegas (last: ${latest[Vegas]})"
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update Vegas (y/n) ?" upd_vegas_cc
|
|
# https://github.com/jaysalvat/vegas.git
|
|
if [ "$upd_vegas_cc" == "y" ] || [ "$upd_vegas_cc" == "Y" ]; then
|
|
open 'https://github.com/jaysalvat/vegas'
|
|
ssh -t sentier@sur-le-sentier.fr "cd httpdocs/vegas/js && git pull --depth=1 origin master"
|
|
|
|
open 'https://sur-le-sentier.fr'
|
|
fi
|
|
echo ""
|
|
fi
|
|
|
|
else
|
|
echo -e "sur-le-sentier.fr seems planté !"
|
|
fi
|
|
|
|
echo
|
|
echo "" >> update.md
|
|
|
|
|
|
#############################
|
|
# #
|
|
# maboiteverte.fr #
|
|
# #
|
|
#############################
|
|
|
|
echo -e "${bold}maboiteverte.fr${reset}"
|
|
echo -e "## maboiteverte.fr" >> update.md
|
|
|
|
mbv_gitea=$(ssh bruno@maboiteverte.fr 'gitea --version' | awk '{print $3}')
|
|
testvercomp "Gitea" $mbv_gitea ${latest[Gitea]} "<"
|
|
#echo -e " - Gitea: $mbv_gitea (last: ${latest[Gitea]})"
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update Gitea (y/n) ?" upd_gitea
|
|
[ "$upd_gitea" == "y" ] || [ "$upd_gitea" == "Y" ] && ssh -t bruno@maboiteverte.fr ./mbv-gitea-upd.sh
|
|
echo ""
|
|
fi
|
|
|
|
mbv_joplinserver=$(curl --silent https://joplin.maboiteverte.fr/login | grep -E 'copyright' | xargs | awk '{print $3}' | sed 's/,//')
|
|
testvercomp "Joplin server" ${mbv_joplinserver/v} ${latest[Joplin server]} "<"
|
|
#echo -e " - Joplin server: $mbv_joplinserver (last: ${latest[Joplin server]})"
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update Joplin server (y/n) ?" upd_jop
|
|
[ "$upd_jop" == "y" ] || [ "$upd_jop" == "Y" ] && ssh -t bruno@maboiteverte.fr ./upgrade_joplin.sh
|
|
echo ""
|
|
fi
|
|
|
|
echo -e " - MkDocs"
|
|
|
|
mbv_nextcloud=$(ssh bruno@maboiteverte.fr 'cd httpdocs/nextcloud/ ; /opt/plesk/php/8.2/bin/php -d memory_limit=-1 occ --version' | awk '{print $2}')
|
|
testvercomp "Nextcloud" $mbv_nextcloud ${latest[Nextcloud]} "<"
|
|
#echo -e " - Nextcloud: $mbv_nextcloud (last: ${latest[Nextcloud]})"
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update Nextcloud (y/n) ?" upd_next
|
|
[ "$upd_next" == "y" ] || [ "$upd_next" == "Y" ] && ssh -t bruno@maboiteverte.fr ./upgrade_nextcloud.sh
|
|
echo ""
|
|
fi
|
|
|
|
|
|
#mbv_zenphoto=$(ssh bruno@maboiteverte.fr 'cat httpdocs/zenphoto/zp-core/version.php' | awk -F"," '{print $2}' | awk -F"'" '{print $2}')
|
|
#echo -e " - Zenphoto"
|
|
echo
|
|
echo "" >> update.md
|
|
|
|
|
|
#############################
|
|
# #
|
|
# clicclac.info #
|
|
# #
|
|
#############################
|
|
|
|
echo -e "${bold}clicclac.info${reset}"
|
|
echo -e "## clicclac.info" >> update.md
|
|
|
|
# git show | grep -m 1 "Build"
|
|
# ssh -t funnymac@ftp.cluster011.ovh.net "cd www/photoblog/js/vegas && git show | grep -m 1 \"Build\""
|
|
clicclac_vegas=$(ssh -q -t funnymac@ftp.cluster011.ovh.net "cd www/photoblog/js/vegas && git show | grep -m 1 \"Build\"" | awk -F"v" '{print $2}' | sed 's/.$//')
|
|
#clicclac_vegas=$(curl --silent https://clicclac.info/photoblog/js/vegas/dist/vegas.js | sed -n '3p' | awk '{print $2}' | sed 's/v//')
|
|
|
|
testvercomp "Vegas" $clicclac_vegas ${latest[Vegas]} "<"
|
|
#echo -e " - Vegas: $clicclac_vegas (last: ${latest[Vegas]})"
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update Vegas (y/n) ?" upd_vegas_cc
|
|
# https://github.com/jaysalvat/vegas.git
|
|
if [ "$upd_vegas_cc" == "y" ] || [ "$upd_vegas_cc" == "Y" ]; then
|
|
open 'https://github.com/jaysalvat/vegas'
|
|
# cd www/photoblog/js/vegas
|
|
# git pull --depth=1 origin master
|
|
ssh -t funnymac@ftp.cluster011.ovh.net "cd www/photoblog/js/vegas && git pull --depth=1 origin master"
|
|
# ssh -t funnymac@ftp.cluster011.ovh.net "cd www/photoblog/js/vegas && git pull --depth=1 origin master ; bash --login"
|
|
# ssh -t funnymac@ftp.cluster011.ovh.net "cd www/photoblog/js/vegas && git pull --depth=1 origin master ; exec \$SHELL -l"
|
|
# https://stackoverflow.com/questions/626533/how-can-i-ssh-directly-to-a-particular-directory
|
|
|
|
open 'https://clicclac.info'
|
|
fi
|
|
echo ""
|
|
fi
|
|
|
|
clicclac_wordpress=$(ssh funnymac@ftp.cluster011.ovh.net 'cat www/wordpress/wp-includes/version.php' | grep 'wp_version =' | awk -F"'" '{print $2}')
|
|
testvercomp "WordPress" $clicclac_wordpress ${latest[WordPress]} "<"
|
|
#echo -e " - WordPress: $clicclac_wordpress (last: ${latest[WordPress]})"
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update WordPress (y/n) ?" upd_wp_cc
|
|
[ "$upd_wp_cc" == "y" ] || [ "$upd_wp_cc" == "Y" ] && open 'https://clicclac.info/wordpress/wp-admin/update-core.php'
|
|
echo ""
|
|
fi
|
|
|
|
|
|
clicclac_zenphoto=$(ssh funnymac@ftp.cluster011.ovh.net 'cat www/zenphoto/zp-core/version.php' | awk -F"," '{print $2}' | awk -F"'" '{print $2}')
|
|
testvercomp "Zenphoto" $clicclac_zenphoto ${latest[Zenphoto]} "<"
|
|
#echo -e " - Zenphoto: $clicclac_zenphoto (last: ${latest[Zenphoto]})"
|
|
|
|
echo
|
|
echo "" >> update.md
|
|
|
|
|
|
#############################
|
|
# #
|
|
# clicclac.synology.me #
|
|
# #
|
|
#############################
|
|
|
|
echo -e "${bold}clicclac.synology.me${reset}"
|
|
echo -e "## clicclac.synology.me" >> update.md
|
|
echo
|
|
echo "" >> update.md
|
|
|
|
|
|
#############################
|
|
# #
|
|
# airbook.local #
|
|
# #
|
|
#############################
|
|
|
|
echo -e "${bold}airbook.local${reset}"
|
|
echo -e "## airbook.local" >> update.md
|
|
|
|
airbook_mkdocs=$(mkdocs --version | awk '{print $3}')
|
|
testvercomp "MkDocs" $airbook_mkdocs ${latest[MkDocs]} "<"
|
|
#echo -e " - MkDocs: $airbook_mkdocs (last: ${latest[MkDocs]})"
|
|
|
|
airbook_thumbsup=$(thumbsup --version | sed '/^$/d')
|
|
testvercomp "thumbsup" $airbook_thumbsup ${latest[thumbsup]} "<"
|
|
#echo -e " - thumbsup: $airbook_thumbsup (last: ${latest[thumbsup]})"
|
|
|
|
#airbook_vegas=$(cd $HOME/Sites/sls/js/vegas && git show | grep -m 1 \"Build\" | awk -F"v" '{print $2}' | sed 's/.$//')
|
|
airbook_vegas=$(curl --silent -k airbook.local/sls/js/vegas/dist/vegas.js | sed -n '3p' | awk '{print $2}' | sed 's/v//')
|
|
testvercomp "Vegas" $airbook_vegas ${latest[Vegas]} "<"
|
|
#echo -e " - Vegas: $airbook_vegas (last: ${latest[Vegas]})"
|
|
|
|
if [ $upd_avail -eq 1 ]; then
|
|
echo ""
|
|
read -e -p "Do you want to update Vegas (y/n) ?" upd_vegas_ab
|
|
# https://github.com/jaysalvat/vegas.git
|
|
if [ "$upd_vegas_ab" == "y" ] || [ "$upd_vegas_ab" == "Y" ]; then
|
|
open 'https://github.com/jaysalvat/vegas'
|
|
cd $HOME/Sites/sls/js/vegas
|
|
git pull --depth=1 origin master
|
|
|
|
open 'https://airbook.local/sls'
|
|
fi
|
|
echo ""
|
|
fi
|
|
|
|
echo -e "\n" >> update.md
|
|
echo -e "\n" >> update.md
|
|
d=$(date)
|
|
echo -e "*$d*" >> update.md
|
|
|
|
open -a Typora update.md
|
|
|
|
# cd "$NVM_DIR"
|
|
# git fetch --tags origin
|
|
# git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
|
|
|
|
cd $HOME/Downloads/github
|
|
#pwd
|
|
|
|
|