161 lines
4.2 KiB
Plaintext
161 lines
4.2 KiB
Plaintext
|
#!/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
|
||
|
|
||
|
|
||
|
#======================================================================
|
||
|
# --------------------
|
||
|
# Update app & scripts
|
||
|
# --------------------
|
||
|
#======================================================================
|
||
|
update__OPTIONS() {
|
||
|
# Get installed version number
|
||
|
cur_stl_version=`awk 'NR==2 {print $3}' "$stl_bin"`
|
||
|
|
||
|
case "$1" in
|
||
|
-v) version__installed ;;
|
||
|
-u) update__check ;;
|
||
|
-U) stl_upg=true;update__check ;;
|
||
|
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/"
|
||
|
}
|