Add self-update command to refresh miaur from Git
Introduce `miaur self-update` / `--self-update` that clones RepoUrl@Branch, detects user vs system install prefix, and reinstalls in place. Configurable via conf/env; supports --noconfirm, --repo-url, and --branch. Co-authored-by: Frank Vitrano <WHC2006@users.noreply.github.com>
This commit is contained in:
co-authored by
Frank Vitrano
parent
bba71040d6
commit
a4f4767c47
@@ -121,4 +121,67 @@ INNER
|
||||
pass "resolve_src survives process substitution"
|
||||
}
|
||||
|
||||
# --- self-update CLI ---
|
||||
# shellcheck source=lib/self_update.sh
|
||||
source "$ROOT/lib/self_update.sh"
|
||||
|
||||
{
|
||||
OP=
|
||||
MIAUR_NOCONFIRM=0
|
||||
MIAUR_REPO=https://example.invalid/miaur.git
|
||||
MIAUR_BRANCH=main
|
||||
TARGETS=()
|
||||
PACMAN_EXTRA=()
|
||||
parse_args self-update --noconfirm --repo-url https://example.com/fork.git --branch dev
|
||||
[[ $OP == selfupdate ]] || fail "OP selfupdate"
|
||||
[[ $MIAUR_NOCONFIRM -eq 1 ]] || fail "noconfirm for self-update"
|
||||
[[ $MIAUR_REPO == https://example.com/fork.git ]] || fail "repo url: $MIAUR_REPO"
|
||||
[[ $MIAUR_BRANCH == dev ]] || fail "branch: $MIAUR_BRANCH"
|
||||
pass "parse_args self-update options"
|
||||
}
|
||||
|
||||
{
|
||||
OP=
|
||||
parse_args --self-update
|
||||
[[ $OP == selfupdate ]] || fail "OP from --self-update"
|
||||
pass "parse_args --self-update"
|
||||
}
|
||||
|
||||
{
|
||||
HOME=/tmp/miaur-home-test
|
||||
MIAUR_HOME=/tmp/miaur-home-test/.local/share/miaur
|
||||
info=$(miaur_detect_prefix)
|
||||
[[ $info == "user|/tmp/miaur-home-test/.local" ]] || fail "user prefix detect: $info"
|
||||
MIAUR_HOME=/usr/local/share/miaur
|
||||
info=$(miaur_detect_prefix)
|
||||
[[ $info == "system|/usr/local" ]] || fail "system prefix detect: $info"
|
||||
pass "miaur_detect_prefix"
|
||||
}
|
||||
|
||||
{
|
||||
ver=$(_miaur_read_version_file "$ROOT/lib/common.sh")
|
||||
[[ $ver == "$MIAUR_VERSION" ]] || fail "version read: $ver vs $MIAUR_VERSION"
|
||||
pass "_miaur_read_version_file"
|
||||
}
|
||||
|
||||
# Mocked self-update install into a temp HOME
|
||||
{
|
||||
fake_home=$(mktemp -d)
|
||||
fake_src=$(mktemp -d)
|
||||
mkdir -p "$fake_src/lib" "$fake_src/completions" "$fake_src/config"
|
||||
printf '%s\n' '#!/usr/bin/env bash' 'echo miaur-fake' >"$fake_src/miaur"
|
||||
chmod +x "$fake_src/miaur"
|
||||
printf '%s\n' 'MIAUR_VERSION="9.9.9"' >"$fake_src/lib/common.sh"
|
||||
printf '%s\n' '# fake' >"$fake_src/completions/miaur.bash"
|
||||
printf '%s\n' '# fake' >"$fake_src/config/miaur.conf.example"
|
||||
|
||||
HOME=$fake_home
|
||||
bin=$(_miaur_install_tree user "$fake_home/.local" "$fake_src")
|
||||
[[ -x $bin ]] || fail "bin missing: $bin"
|
||||
[[ -f $fake_home/.local/share/miaur/lib/common.sh ]] || fail "lib not installed"
|
||||
grep -q '9.9.9' "$fake_home/.local/share/miaur/lib/common.sh" || fail "version file not copied"
|
||||
pass "_miaur_install_tree user mode"
|
||||
rm -rf "$fake_home" "$fake_src"
|
||||
}
|
||||
|
||||
echo "All tests passed."
|
||||
|
||||
Reference in New Issue
Block a user