updated launcher + autoupdate
This commit is contained in:
12
install.sh
12
install.sh
@@ -2,7 +2,15 @@
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${BASE_URL:-https://git.jewguard.xyz/linusware/main/raw/branch/main}"
|
||||
INSTALL_DIR="${HOME}/linusware"
|
||||
|
||||
if [ -n "${LINUSWARE_DIR-}" ]; then
|
||||
INSTALL_DIR="$LINUSWARE_DIR"
|
||||
else
|
||||
default_dir="${HOME}/linusware"
|
||||
read -rp "Installation directory [~/linusware]: " input
|
||||
INSTALL_DIR="${input:-$default_dir}"
|
||||
INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}"
|
||||
fi
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
@@ -23,7 +31,7 @@ command -v curl >/dev/null 2>&1 || error "curl is required"
|
||||
command -v md5sum >/dev/null 2>&1 || error "md5sum is required"
|
||||
command -v tar >/dev/null 2>&1 || error "tar is required"
|
||||
|
||||
rm -rf $HOME/linusware
|
||||
rm -rf "$INSTALL_DIR"
|
||||
mkdir -p "${INSTALL_DIR}/external" "${INSTALL_DIR}/internal"
|
||||
|
||||
download() {
|
||||
|
||||
22
launcher.sh
22
launcher.sh
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
INSTALL_DIR="${HOME}/linusware"
|
||||
INSTALL_DIR="${LINUSWARE_DIR:-${HOME}/linusware}"
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
@@ -40,6 +40,26 @@ run_updater() {
|
||||
read -rp "Press Enter to return to menu..." _
|
||||
}
|
||||
|
||||
auto_update() {
|
||||
[ -x "${INSTALL_DIR}/update.sh" ] && "${INSTALL_DIR}/update.sh"
|
||||
}
|
||||
|
||||
# --- startup ---
|
||||
auto_update
|
||||
|
||||
if [ $# -ge 1 ]; then
|
||||
arg="$1"
|
||||
for i in "${!edition_names[@]}"; do
|
||||
name_lc=$(echo "${edition_names[$i]}" | tr '[:upper:]' '[:lower:]')
|
||||
arg_lc=$(echo "$arg" | tr '[:upper:]' '[:lower:]')
|
||||
if [ "$arg_lc" = "$name_lc" ]; then
|
||||
exec "${editions[$i]}"
|
||||
fi
|
||||
done
|
||||
echo -e "${RED}Unknown edition: $arg${NC}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# whiptail TUI
|
||||
if command -v whiptail >/dev/null 2>&1; then
|
||||
while true; do
|
||||
|
||||
50
update.sh
50
update.sh
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user