magic
This commit is contained in:
@@ -19,8 +19,9 @@ error() {
|
||||
echo -e "${RED}[x]${NC} $1"
|
||||
}
|
||||
|
||||
command -v curl >/dev/null 2>&1 || { error "curl is required"; exit 1; }
|
||||
command -v curl >/dev/null 2>&1 || { error "curl is required"; exit 1; }
|
||||
command -v md5sum >/dev/null 2>&1 || { error "md5sum is required"; exit 1; }
|
||||
command -v tar >/dev/null 2>&1 || { error "tar is required"; exit 1; }
|
||||
|
||||
download() {
|
||||
local url="$1" dest="$2"
|
||||
@@ -31,10 +32,10 @@ download() {
|
||||
|
||||
update_edition() {
|
||||
local edition="$1"
|
||||
local bin_path="${INSTALL_DIR}/${edition}/linusware/linusware"
|
||||
local run_path="${INSTALL_DIR}/${edition}/linusware/run.sh"
|
||||
local ver_file="${INSTALL_DIR}/${edition}/version.txt"
|
||||
|
||||
[ -f "$bin_path" ] || return
|
||||
[ -f "$run_path" ] || return
|
||||
|
||||
local cur_ver=""
|
||||
[ -f "$ver_file" ] && cur_ver=$(cat "$ver_file")
|
||||
@@ -69,25 +70,30 @@ update_edition() {
|
||||
warn "${edition}: could not fetch MD5SUM"
|
||||
return
|
||||
fi
|
||||
local expected_hash; expected_hash=$(tr -cd '[:xdigit:]' < "$md5_file"); rm -f "$md5_file"
|
||||
local expected_hash
|
||||
expected_hash=$(tr -cd '[:xdigit:]' < "$md5_file"); rm -f "$md5_file"
|
||||
|
||||
local tmp_bin; tmp_bin="$(mktemp)"
|
||||
if ! download "${BASE_URL}/${edition}/bin/linusware" "$tmp_bin"; then
|
||||
rm -f "$tmp_bin"
|
||||
local tmp_archive; tmp_archive="$(mktemp)"
|
||||
if ! download "${BASE_URL}/${edition}/bin/linusware.tar.gz" "$tmp_archive"; then
|
||||
rm -f "$tmp_archive"
|
||||
warn "${edition}: download failed"
|
||||
return
|
||||
fi
|
||||
|
||||
local actual_hash
|
||||
actual_hash=$(md5sum "$tmp_bin" | cut -d' ' -f1)
|
||||
actual_hash=$(md5sum "$tmp_archive" | cut -d' ' -f1)
|
||||
if [ "$actual_hash" != "$expected_hash" ]; then
|
||||
rm -f "$tmp_bin"
|
||||
rm -f "$tmp_archive"
|
||||
error "${edition}: MD5 mismatch"
|
||||
return
|
||||
fi
|
||||
|
||||
mv "$tmp_bin" "$bin_path"
|
||||
chmod +x "$bin_path"
|
||||
rm -rf "${INSTALL_DIR}/${edition}/linusware"
|
||||
tar -xzf "$tmp_archive" -C "${INSTALL_DIR}/${edition}"
|
||||
rm -f "$tmp_archive"
|
||||
|
||||
local new_run="${INSTALL_DIR}/${edition}/linusware/run.sh"
|
||||
chmod +x "$new_run"
|
||||
echo "$remote_ver" > "$ver_file"
|
||||
info "${edition}: updated to v${remote_ver}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user