2022-08-08 17:34:11 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Name: Statique Littérateur
|
|
|
|
# Type: update manager
|
|
|
|
# file: manage__update
|
|
|
|
# Folder: /var/lib/stl/scripts/
|
|
|
|
# By echolib (XMPP: im@echolib.re)
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
2022-08-23 16:48:33 +02:00
|
|
|
#------------
|
|
|
|
# funny stats
|
|
|
|
#------------
|
2022-08-24 12:38:38 +02:00
|
|
|
# lines: 227
|
2022-08-23 16:48:33 +02:00
|
|
|
# functions: 6
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#**********************************************************************
|
2022-08-08 17:34:11 +02:00
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# --------------------
|
|
|
|
# Update app & scripts
|
|
|
|
# --------------------
|
|
|
|
#======================================================================
|
|
|
|
update__OPTIONS() {
|
|
|
|
# Get installed version number
|
|
|
|
cur_stl_version=`awk 'NR==2 {print $3}' "$stl_bin"`
|
|
|
|
|
|
|
|
case "$1" in
|
2022-08-23 16:48:33 +02:00
|
|
|
version) version__installed ;;
|
|
|
|
-u) update__check ;;
|
|
|
|
-U) stl_upg=true;update__check ;;
|
|
|
|
update) update__conf ;;
|
2022-08-08 17:34:11 +02:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Show current version
|
|
|
|
#======================================================================
|
|
|
|
version__installed() {
|
|
|
|
echo "# STL installed: $cur_stl_version"
|
|
|
|
[[ -f "$stl_dir_help/last-version.md" ]] \
|
|
|
|
&& cat "$stl_dir_help/last-version.md"
|
|
|
|
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# check if available update
|
|
|
|
# Also use for -U but then call upgrade__stl
|
|
|
|
#======================================================================
|
|
|
|
update__check() {
|
|
|
|
www_stl_version=`curl -s "$stl_repo" | awk 'NR==2 {print $3}'`
|
|
|
|
|
|
|
|
# Unknown fom repo
|
|
|
|
if ! [[ $www_stl_version ]];then
|
|
|
|
echo "! Unknown available version from repo"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Same version fom repo
|
|
|
|
if [[ $cur_stl_version == $www_stl_version ]];then
|
|
|
|
echo "# STL is up to date: $www_stl_version"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Versions Comparison functions
|
|
|
|
verlte() {
|
|
|
|
[ "$1" = "`printf '%s\n%s' "$1" "$2" | sort -V | head -n1`" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
verlt() {
|
|
|
|
[ "$1" = "$2" ] && return 1 || verlte $1 $2
|
|
|
|
}
|
|
|
|
|
|
|
|
# Should be only for me (Local version is upper)
|
|
|
|
verlt $cur_stl_version $www_stl_version \
|
|
|
|
&& stl_new_version=true \
|
|
|
|
|| stl_old_version=true
|
|
|
|
|
|
|
|
# New version Found
|
|
|
|
[[ $stl_new_version ]] \
|
|
|
|
&& printf '%s %s\n' \
|
|
|
|
"# STL is available from repo:" \
|
|
|
|
"$cur_stl_version > $www_stl_version"
|
|
|
|
|
|
|
|
# Installed version is newer than fom repo
|
|
|
|
[[ $stl_old_version ]] \
|
|
|
|
&& printf '%s %s\n' \
|
|
|
|
"! STL Installed is newer than repo:" \
|
|
|
|
"$cur_stl_version > $www_stl_version"
|
|
|
|
|
|
|
|
[[ $stl_new_version ]] || exit
|
|
|
|
|
|
|
|
if ! (( `curl -o /dev/null -s -w "%{http_code}\n" "$stl_repo_lv"` \
|
|
|
|
>= 400 ));then
|
|
|
|
|
|
|
|
mkdir -p /tmp/STL
|
|
|
|
curl -L -o "/tmp/STL/last-version.md" "$stl_repo_lv" 2>/dev/null
|
|
|
|
[[ -f "/tmp/STL/last-version.md" ]] \
|
|
|
|
&& cat "/tmp/STL/last-version.md" #\
|
|
|
|
#&& rm -rf "/tmp/STL/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Upgrade from -U (except for debian base)
|
|
|
|
[[ $stl_upg ]] || exit
|
|
|
|
|
|
|
|
# Debian based: exit and inform to use .deb
|
|
|
|
[[ `command -v apt` ]] \
|
|
|
|
&& echo "! System is Debian based. Use .deb instead" \
|
|
|
|
&& exit
|
|
|
|
|
|
|
|
echo
|
|
|
|
read -rp "- Do you want to update STL ? " stl_ask
|
|
|
|
|
|
|
|
case "$stl_ask" in
|
|
|
|
Y|y) upgrade__stl ;;
|
|
|
|
*) echo "# Maybe later...";exit ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Download archive to /tmp
|
|
|
|
# check it and extract with rsync
|
|
|
|
#======================================================================
|
|
|
|
upgrade__stl() {
|
|
|
|
mkdir -p /tmp/STL
|
|
|
|
stl_dir_tgz="/tmp/STl/stl_main" # directory from extracted archive
|
|
|
|
|
|
|
|
# Download archive
|
|
|
|
curl -L -o /tmp/STL/stl-main.tar.gz "$stl_repo_tgz" 2>/dev/null
|
|
|
|
! [[ -f "/tmp/STL/stl-main.tar.gz" ]] \
|
|
|
|
&& echo "! Download error from url: $repo_tar" \
|
|
|
|
&& exit
|
|
|
|
|
|
|
|
# Extract archive
|
|
|
|
tar -xzf "/tmp/STL/stl-main.tar.gz" --directory "/tmp/STL/"
|
|
|
|
! [[ -d $stl_dir_tgz ]] \
|
|
|
|
&& echo "! Extract error from archive: /tmp/STL/stl-main.tar.gz" \
|
|
|
|
&& return
|
|
|
|
|
|
|
|
# Rsync from archive to System
|
|
|
|
rsync -a --exclude ".*" \
|
|
|
|
"/tmp/STL/stl_main/usr/" \
|
|
|
|
"/usr/" && \
|
|
|
|
printf '%s\n%s\n' \
|
|
|
|
"- Copy bin: /usr/local/bin/stl" \
|
|
|
|
"- Copy completion: /usr/share/bash-completion/completions/stl"
|
|
|
|
|
|
|
|
rsync -a --exclude ".*" \
|
|
|
|
"/tmp/STL/stl_main/etc/stl/" \
|
|
|
|
"/etc/stl/" && \
|
|
|
|
echo "- Copy configuration: /etc/stl/"
|
|
|
|
|
|
|
|
rsync -a --delete --exclude ".*" \
|
|
|
|
"/tmp/STL/stl_main/var/lib/stl/help/" \
|
|
|
|
"/var/lib/stl/help/" && \
|
|
|
|
echo "- Copy helps: /var/lib/stl/help/"
|
|
|
|
|
|
|
|
rsync -a --delete --exclude ".*" \
|
|
|
|
"/tmp/STL/stl_main/var/lib/stl/scripts/" \
|
|
|
|
"/var/lib/stl/scripts/" && \
|
|
|
|
echo "- Copy scripts: /var/lib/stl/scripts/"
|
|
|
|
|
|
|
|
# Cleaning
|
|
|
|
rm -rf "/tmp/STL/"
|
|
|
|
}
|
2022-08-23 16:48:33 +02:00
|
|
|
|
2022-08-23 19:14:41 +02:00
|
|
|
|
2022-08-23 16:48:33 +02:00
|
|
|
#======================================================================
|
|
|
|
# Checking and updating conf after STL update
|
|
|
|
#======================================================================
|
|
|
|
update__conf() {
|
|
|
|
domain__get
|
|
|
|
echo "# Configuration:"
|
|
|
|
|
|
|
|
# Sidebar
|
|
|
|
if [[ "$domain_dir_sidebar" && "$domain_file_sidebar_load" ]];then
|
|
|
|
echo " - Sidebar Ok"
|
|
|
|
|
|
|
|
else
|
|
|
|
cat << EOCONF >> "$stl_file_pwd_conf"
|
|
|
|
|
|
|
|
# Sidebar
|
|
|
|
domain_dir_sidebar="$PWD/articles/sidebar"
|
|
|
|
domain_file_sidebar_load="$PWD/articles/sidebar/stl.sidebar"
|
|
|
|
EOCONF
|
|
|
|
echo " - Sidebar configured"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Logs
|
|
|
|
echo
|
|
|
|
stl log clean all
|
|
|
|
|
2022-08-24 12:38:38 +02:00
|
|
|
# Create a backup of the config in db
|
|
|
|
rsync -a "$PWD/$stl_file_pwd_conf" \
|
|
|
|
"$stl_dir_db/$domain_name/$stl_file_pwd_conf.bkp"
|
|
|
|
|
2022-08-23 16:48:33 +02:00
|
|
|
# Re check all checked article to wirte DB
|
|
|
|
echo -e "\n# Database:"
|
2022-08-24 12:38:38 +02:00
|
|
|
update__database # Last process with exit
|
2022-08-23 16:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Force check all checked articles
|
|
|
|
#======================================================================
|
|
|
|
update__database() {
|
|
|
|
for db_check in $domain_db_articles/*.db
|
|
|
|
do
|
|
|
|
source "$db_check"
|
|
|
|
uri_dba="$article_uri_srv"
|
|
|
|
uri_dba=${uri_dba:1}
|
|
|
|
uri_dba=${uri_dba/.html/.stl}
|
|
|
|
|
|
|
|
if [[ $check_all ]];then
|
|
|
|
stl check -F "$uri_dba"
|
|
|
|
echo
|
|
|
|
|
|
|
|
else
|
|
|
|
stl check -F "$uri_dba" &>/dev/null
|
|
|
|
echo " - $uri_dba updated"
|
|
|
|
fi
|
|
|
|
done
|
2022-08-23 19:14:41 +02:00
|
|
|
exit
|
2022-08-23 16:48:33 +02:00
|
|
|
}
|