updated launcher + autoupdate

This commit is contained in:
2026-06-20 16:07:15 +04:00
parent 4997798453
commit e03b7bf6c5
3 changed files with 79 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
set -euo pipefail
BASE_URL="${BASE_URL:-https://git.jewguard.xyz/linusware/main/raw/branch/main}"
INSTALL_DIR="${HOME}/linusware"
INSTALL_DIR="${LINUSWARE_DIR:-${HOME}/linusware}"
RED='\033[0;31m'
GREEN='\033[0;32m'
@@ -35,7 +35,7 @@ update_edition() {
local run_path="${INSTALL_DIR}/${edition}/linusware/run.sh"
local ver_file="${INSTALL_DIR}/${edition}/version.txt"
[ -f "$run_path" ] || return
[ -f "$run_path" ] || return 0
local cur_ver=""
[ -f "$ver_file" ] && cur_ver=$(cat "$ver_file")
@@ -107,5 +107,51 @@ for dir in "${INSTALL_DIR}"/*/; do
update_edition "$(basename "$dir")"
done
# --- self-update ---
self_update() {
local script="$1"
local url="${BASE_URL}/${script}"
local cache="${INSTALL_DIR}/.scripts"
local remote_id
case "$url" in
file://*)
local filepath="${url#file://}"
remote_id=$(stat -c %Y "$filepath" 2>/dev/null) || return 0
;;
*)
local headers; headers=$(curl -fsSL -I "$url" 2>/dev/null) || return 0
remote_id=$(echo "$headers" | grep -im1 '^etag:' | tr -d '\r') || true
remote_id="${remote_id#*: }"
if [ -z "$remote_id" ]; then
remote_id=$(echo "$headers" | grep -im1 '^last-modified:' | tr -d '\r') || true
remote_id="${remote_id#*: }"
fi
[ -n "$remote_id" ] || return 0
;;
esac
local local_id
local_id=$(grep -F "$script " "$cache" 2>/dev/null | head -1 | cut -d' ' -f2-) || true
[ "$remote_id" = "$local_id" ] && { info "${script}: up-to-date"; return; }
info "${script}: updating..."
local tmp; tmp="$(mktemp)"
curl -fsSL -o "$tmp" "$url" || { rm -f "$tmp"; warn "${script}: download failed"; return; }
chmod +x "$tmp"
mv "$tmp" "${INSTALL_DIR}/${script}"
local tmp_cache; tmp_cache="$(mktemp)"
grep -vF "$script " "$cache" 2>/dev/null > "$tmp_cache" || true
echo "$script $remote_id" >> "$tmp_cache"
mv "$tmp_cache" "$cache"
info "${script}: updated"
}
self_update "launcher.sh"
self_update "update.sh"
echo ""
info "Done."