From 19c1c025e73d72709ec1ede928184ae9bec66d05 Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Sun, 25 Aug 2024 18:58:16 +0200 Subject: [PATCH] 1st commit --- apps.db | Bin 0 -> 8192 bytes sqlite.sh | 63 +++++++ update.md | 12 ++ updates.sh | 435 +++++++++++++++++++++++++++++++++++++++++++++++ updates_menu.sh | 436 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 946 insertions(+) create mode 100644 apps.db create mode 100755 sqlite.sh create mode 100644 update.md create mode 100755 updates.sh create mode 100755 updates_menu.sh diff --git a/apps.db b/apps.db new file mode 100644 index 0000000000000000000000000000000000000000..018811db0da5fdf05197217450e4ac64256e6d77 GIT binary patch literal 8192 zcmeI%O-sWt7zgllvv^S_co;p18D13Dq%Y#slT(HuL#EDMrCVcL=w58Hp$89s0Y8VI zQp~IyQwHAU|Ij2&^W+KqdMdrWZYE05hhf$a6!pm_F^siSN(mvRZUxkv!o%N>n`Vvfi-I2eVu*MK%!`&qOK$DI`}x#3y-$R>3S=mFElnYdvt8=diS;*0zQ Dph9_2 literal 0 HcmV?d00001 diff --git a/sqlite.sh b/sqlite.sh new file mode 100755 index 0000000..f019866 --- /dev/null +++ b/sqlite.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# The commands to submit - note that each statement must be ";"-terminated. + +if [ ! -f ./apps.db ]; then + cmd0="CREATE TABLE latest (App string, Latest string, Published date, Url string);" + echo "$cmd0" | sqlite3 ./apps.db +fi + +#cmd1=' +#insert into latest (App, Version) values ("Nextcloud", "27.1.4"), ("Gitea", "1.20.6"); +#' + +app="nvm" +latest="0.39.5" +published="2023-08-22" +url="https://github.com/nvm-sh/nvm/releases/tag/v0.39.5" + +#echo "$cmd1" | sqlite3 ./apps.db + + +app="nvm" +latest="0.39.7" +published="2023-10-20" +url="https://github.com/nvm-sh/nvm/releases/tag/v0.39.7" + +app="Gitea" +latest="1.20.6" +published="2023-11-28" +url="https://github.com/go-gitea/gitea/releases/tag/v1.20.6" + +app="Nextcloud" +latest="27.1.4" +published="2023-11-23" +url="https://github.com/nextcloud/server/releases/tag/v27.1.4" + +# Pipe the commands to `sqlite3` while also passing the database file path. +#echo "$cmd2" | sqlite3 ./apps.db + + +#app="gitea" +#query="select * from latest where App = '$app' COLLATE NOCASE;" + +insert() { + + query="SELECT App FROM latest WHERE App LIKE '$1';" + result=$(sqlite3 ./apps.db "$query") + #echo "$result" + + if [ -n "$result" ]; then + cmd1="UPDATE latest SET Latest = '$2', Url = '$4', Published = '$3' WHERE App = '$1';" + else + cmd1="INSERT INTO latest (App, Latest, Published, Url) VALUES ('$1','$2','$3','$4');" + fi + + echo "$cmd1" | sqlite3 ./apps.db +} + +insert $app $latest $published $url + +query="SELECT * FROM latest;" +result=$(sqlite3 ./apps.db "$query") +echo "$result" \ No newline at end of file diff --git a/update.md b/update.md new file mode 100644 index 0000000..31e3071 --- /dev/null +++ b/update.md @@ -0,0 +1,12 @@ +# Availables updates: +## sur-le-sentier.fr + +## maboiteverte.fr + - Nextcloud: not (last: **27.1.3**) +## maboiteverte.fr +## maboiteverte.fr +## maboiteverte.fr +## maboiteverte.fr +## maboiteverte.fr +## maboiteverte.fr +## maboiteverte.fr diff --git a/updates.sh b/updates.sh new file mode 100755 index 0000000..34c95dd --- /dev/null +++ b/updates.sh @@ -0,0 +1,435 @@ +#!/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 + + diff --git a/updates_menu.sh b/updates_menu.sh new file mode 100755 index 0000000..51109b8 --- /dev/null +++ b/updates_menu.sh @@ -0,0 +1,436 @@ +#!/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" + + +# 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 + +if [ ! -f ./applis.db ]; then + cmd0="CREATE TABLE latest (App string, Latest string, Published date, Url string);" + echo "$cmd0" | sqlite3 ./applis.db +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 +} + +insert() { + + #echo "app: $1" + #query='SELECT App FROM latest WHERE App LIKE "$1";' + query="SELECT App FROM latest WHERE App LIKE \"$1\"" + #echo $query + result=$(sqlite3 ./applis.db "$query") + #echo "result: $result" + + if [ -n "$result" ]; then + cmd1="UPDATE latest SET Latest = '$2', Url = '$4', Published = '$3' WHERE App = '$1';" + else + cmd1="INSERT INTO latest (App, Latest, Published, Url) VALUES ('$1','$2','$3','$4');" + fi + + echo "$cmd1" | sqlite3 ./applis.db +} + + +############################# +# # +# 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) +app="Asus $router" + +insert "$app" "$last" "$dat" "$url" + +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 tag: $latest_joplin_server" +echo -e "Url: https://github.com/laurent22/joplin/releases/tag/$last_joplin_server" +echo + +app="Joplin server" +dat="" +url="https://github.com/laurent22/joplin/releases/tag/$last_joplin_server" + +insert "$app" "$latest_joplin_server" "$dat" "$url" + +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 + # tag: Vegas, SoCo-CLI, WordPress, thumbsup, Joplin server + 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") + + dat="" + insert "$app" "$last" "$dat" "$url" + + else + # release: MkDocs, Nextcloud, Piwigo, Joplin, Gitea, Zenphoto, nvm + 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") + + insert "$app" "$release" "$dat" "$url" + fi + +done + + +for app in "${!latest[@]}"; +do + echo "${app} - ${latest[${app}]}" + +done + + +############################# +# # +# sur-le-sentier.fr # +# # +############################# + +surlesentier(){ + # thumbsup, wordpress, vegas + surlesentier=( "thumbsup" "wordpress" "vegas" ) + clear + for app in ${!surlesentier[@]} + do + echo "${surlesentier[$app]}" + done +} + +############################# +# # +# maboiteverte.fr # +# # +############################# + +maboiteverte(){ + # gitea, joplin server, nextcloud + maboiteverte=( "gitea" "joplin server" "nextcloud" ) + query="SELECT * FROM latest;" + clear + + echo -e "${bold}maboiteverte.fr${reset}" + echo -e "## maboiteverte.fr" >> update.md + echo + + #current_gitea= + #current_nextcloud= + #current_joplinserver= + + if nmap "maboiteverte.fr" -PN -p 22 | grep open &>/dev/null; then + + mbv_gitea=$(ssh bruno@maboiteverte.fr 'gitea --version 2>/dev/null' | awk '{print $3}') + + #if [[ $mbv_gitea =~ ^[0-9]{1,2}\.[0-9]{0,2}\.[0-9]{0,2}$ ]]; then + # current_gitea=$mbv_gitea + #fi + + [[ $mbv_gitea =~ ^[0-9]{1,2}\.[0-9]{0,2}\.[0-9]{0,2}$ ]] && current_gitea=$mbv_gitea || current_gitea="" + + mbv_nextcloud=$(ssh bruno@maboiteverte.fr 'cd httpdocs/nextcloud/ 2>/dev/null; /opt/plesk/php/8.2/bin/php -d memory_limit=-1 occ --version' | awk '{print $2}' 2>/dev/null) + + #if [[ $mbv_nextcloud =~ ^[0-9]{1,2}\.[0-9]{0,2}\.[0-9]{0,2}$ ]]; then + # current_nextcloud=$mbv_nextcloud + #fi + + [[ $mbv_nextcloud =~ ^[0-9]{1,2}\.[0-9]{0,2}\.[0-9]{0,2}$ ]] && current_nextcloud=$mbv_nextcloud || current_nextcloud="" + + elif nmap "maboiteverte.fr" -PN -p 443 | grep open &>/dev/null; then + + mbv_joplinserver=$(curl --silent https://joplin.maboiteverte.fr/login 2>/dev/null | grep -E 'copyright' | xargs | awk '{print $3}' | sed 's/,//') + + #if [[ $mbv_joplinserver =~ ^[0-9]{1,2}\.[0-9]{0,2}\.[0-9]{0,2}$ ]]; then + # current_joplinserver=$mbv_joplinserver + #fi + + [[ $mbv_joplinserver =~ ^[0-9]{1,2}\.[0-9]{0,2}\.[0-9]{0,2}$ ]] && current_joplinserver=$mbv_joplinserver || current_joplinserver="" + fi + + echo $current_gitea + echo $current_nextcloud + echo $current_joplinserver + + for appli in ${!maboiteverte[@]} + do + a="${maboiteverte[$appli]}" + query="SELECT * FROM latest WHERE App LIKE \"$a\"" + result=$(sqlite3 ./applis.db "$query") + + app=$(echo "$result" | awk -F "|" '{print $1}') + latest=$(echo "$result" | awk -F "|" '{print $2}') + published=$(echo "$result" | awk -F "|" '{print $3}') + url=$(echo "$result" | awk -F "|" '{print $4}') + + echo -e "${bold}${app}${reset}" + if [ -n "$published" ]; then + echo -e "Latest release: $latest" + echo -e "Published date: $published" + else + echo -e "Latest tag: $latest" + fi + echo -e "Url: $url\n" + + done +} + +############################# +# # +# clicclac.info # +# # +############################# + +clicclac(){ + # vegas, wordpress, zenphoto + clicclac=( "vegas" "wordpress" "zenphoto" ) + clear + + if ssh funnymac@ftp.cluster011.ovh.net "true"; then + + clicclac_vegas=$(ssh -q -t funnymac@ftp.cluster011.ovh.net "cd www/photoblog/js/vegas 2>/dev/null && git show | grep -m 1 \"Build\"" | awk -F"v" '{print $2}' | sed 's/.$//' 2>/dev/null) + [[ $clicclac_vegas =~ ^[0-9]{1,2}\.[0-9]{0,2}\.{0,1}[0-9]{0,2}$ ]] && current_vegas=$clicclac_vegas || current_vegas="" + + clicclac_wordpress=$(ssh funnymac@ftp.cluster011.ovh.net 'cat www/wordpress/wp-includes/version.php 2>/dev/null' | grep 'wp_version =' | awk -F"'" '{print $2}') + [[ $clicclac_wordpress =~ ^[0-9]{1,2}\.[0-9]{0,2}\.{0,1}[0-9]{0,2}$ ]] && current_wordpress=$clicclac_wordpress || current_wordpress="" + + clicclac_zenphoto=$(ssh funnymac@ftp.cluster011.ovh.net 'cat www/zenphoto/zp-core/version.php 2>/dev/null' | awk -F"," '{print $2}' | awk -F"'" '{print $2}') + [[ $clicclac_zenphoto =~ ^[0-9]{1,2}\.[0-9]{0,2}\.{0,1}[0-9]{0,2}$ ]] && current_zenphoto=$clicclac_zenphoto || current_zenphoto="" + fi + + echo $current_vegas + echo $current_wordpress + echo $current_zenphoto + + + for app in ${!clicclac[@]} + do + echo "${clicclac[$app]}" + done +} + +############################# +# # +# clicclac.synology.me # +# # +############################# + +synology(){ + # adminer (editor) #docker + synology=( "wordpress" "mkdocs" "nextcloud" "thumbsup" "vegas" "zenphoto" "piwigo" "plex" "gitea" "adminer" "phpmyadmin") + clear + for app in ${!synology[@]} + do + echo "${synology[$app]}" + done +} + +airbook(){ + # mkdocs, thumbsup, vegas + airbook=( "mkdocs" "thumbsup" "vegas" ) + clear + for app in ${!airbook[@]} + do + echo "${airbook[$app]}" + done +} + +############################# +# # +# router Asus # +# # +############################# + +asus(){ + # asus, diversion + asus=( "Asus RT-AC88U" ) + clear + + 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 + + for app in ${!asus[@]} + do + echo "${asus[$app]}" + done +} + + +# Main menu +menu(){ + + options=( + "sur-le-(s)entier.fr" + "maboite(v)erte.fr" + "(c)licclac.info" + "clicclac.s(y)nology.me" + "(a)irbook.local" + "Asus (r)outer" + "(Q)uit" + ) + + + echo -e "\n\033[1mFind Updates: \033[0m\n" + + select option in "${options[@]}"; do + case "$REPLY" in + 1|s|S) surlesentier ; menu ;; + 2|v|V) maboiteverte ; menu ;; + 3|c|C) clicclac ; menu ;; + 4|y|Y) synology ; menu ;; + 5|a|A) airbook ; menu ;; + 6|r|R) asus ; menu ;; + 7|q|Q) exit 0 ;; + esac + done + +} + +menu +