Fix two real bugs found in live testing: missing sudo, and curl-pipe mode

pacman -S was run unprivileged, failing with "you cannot perform this
operation unless you are root." Added sudo.

Bigger issue: install.sh assumed it was running from a full local git
checkout (reading packages.txt/hypr/hyprland.conf/local-bin/*.sh as sibling
files via $REPO_DIR). When curl-piped directly -- the whole point of this
installer -- $BASH_SOURCE resolves to a transient /dev/fd path with no
sibling files at all, so every read failed. Added ensure_repo_files(),
which detects that case and fetches the needed files from Gitea's raw URLs
into a temp dir first. Running from a real checkout (packages.txt already
present) is unaffected. Verified end-to-end via actual process substitution
against the real public repo, not just against local files.
This commit is contained in:
edemilov committed 2026-08-29 15:14:08 +03:00
1 parent d3b4dde12f
commit 478450b209
2 files changed
+85 -1

No files matched your search

+27 -1
View File
@@ -4,11 +4,36 @@ set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_HOME="${CONFIG_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}}"
LOCAL_BIN="${LOCAL_BIN:-$HOME/.local/bin}"
HYPREVO_RAW_BASE="${HYPREVO_RAW_BASE:-https://git.edemilov.ru/edemilov/hyprevo/raw/branch/master}"
check_arch() {
command -v pacman >/dev/null 2>&1
}
# When install.sh is curl-piped straight into bash (the normal way to run it),
# $BASH_SOURCE resolves to a transient fd path (e.g. /dev/fd/63) with no
# sibling files at all -- there's no local checkout of the rest of the repo.
# Detect that case and fetch the handful of files apply() needs into a fresh
# temp dir instead, then repoint REPO_DIR there. Running from a real git
# checkout (packages.txt already sits next to this script) is left untouched.
ensure_repo_files() {
if [[ -f "$REPO_DIR/packages.txt" ]]; then
return 0
fi
local tmp_dir
tmp_dir="$(mktemp -d)"
mkdir -p "$tmp_dir/hypr" "$tmp_dir/local-bin"
curl -fsSL "$HYPREVO_RAW_BASE/packages.txt" -o "$tmp_dir/packages.txt"
curl -fsSL "$HYPREVO_RAW_BASE/hypr/hyprland.conf" -o "$tmp_dir/hypr/hyprland.conf"
curl -fsSL "$HYPREVO_RAW_BASE/local-bin/capture-menu.sh" -o "$tmp_dir/local-bin/capture-menu.sh"
curl -fsSL "$HYPREVO_RAW_BASE/local-bin/screenshot.sh" -o "$tmp_dir/local-bin/screenshot.sh"
curl -fsSL "$HYPREVO_RAW_BASE/local-bin/toggle-recording.sh" -o "$tmp_dir/local-bin/toggle-recording.sh"
REPO_DIR="$tmp_dir"
}
slot_package() {
local slot="$1" choice="$2"
case "$slot:$choice" in
@@ -197,7 +222,7 @@ apply() {
local pkg_list
pkg_list="$(build_package_list)"
# shellcheck disable=SC2086
pacman -S --needed $pkg_list
sudo pacman -S --needed $pkg_list
mkdir -p "$CONFIG_HOME/hypr"
render_hyprland_conf "$REPO_DIR/hypr/hyprland.conf" > "$CONFIG_HOME/hypr/hyprland.conf"
@@ -229,6 +254,7 @@ main() {
exit 0
fi
ensure_repo_files
run_picker
if ! confirm_summary; then
+58
View File
@@ -1,5 +1,59 @@
#!/usr/bin/env bats
@test "ensure_repo_files leaves REPO_DIR untouched when running from a real checkout" {
source "${BATS_TEST_DIRNAME}/../install.sh"
local before="$REPO_DIR"
ensure_repo_files
[ "$REPO_DIR" = "$before" ]
[ -f "$REPO_DIR/packages.txt" ]
}
@test "ensure_repo_files fetches repo files via curl when running curl-piped (no local packages.txt)" {
source "${BATS_TEST_DIRNAME}/../install.sh"
local fake_repo_dir
fake_repo_dir="$(mktemp -d)"
local stub_bin
stub_bin="$(mktemp -d)"
cat > "$stub_bin/curl" <<'EOF'
#!/usr/bin/env bash
# Stub: ignore real flags/URL, just write recognizable content based on the
# requested path (the last argument) so the test can assert per-file.
url="${@: -1}"
out=""
for ((i=1; i<=$#; i++)); do
if [[ "${!i}" == "-o" ]]; then
j=$((i+1))
out="${!j}"
fi
done
case "$url" in
*/packages.txt) echo "stub-package" > "$out" ;;
*/hypr/hyprland.conf) echo "stub-hyprland-conf" > "$out" ;;
*/local-bin/capture-menu.sh) echo "stub-capture-menu" > "$out" ;;
*/local-bin/screenshot.sh) echo "stub-screenshot" > "$out" ;;
*/local-bin/toggle-recording.sh) echo "stub-toggle-recording" > "$out" ;;
*) echo "unexpected url: $url" >&2; exit 1 ;;
esac
EOF
chmod +x "$stub_bin/curl"
REPO_DIR="$fake_repo_dir"
PATH="$stub_bin:$PATH"
ensure_repo_files
[ "$REPO_DIR" != "$fake_repo_dir" ]
[ "$(cat "$REPO_DIR/packages.txt")" = "stub-package" ]
[ "$(cat "$REPO_DIR/hypr/hyprland.conf")" = "stub-hyprland-conf" ]
[ "$(cat "$REPO_DIR/local-bin/capture-menu.sh")" = "stub-capture-menu" ]
[ "$(cat "$REPO_DIR/local-bin/screenshot.sh")" = "stub-screenshot" ]
[ "$(cat "$REPO_DIR/local-bin/toggle-recording.sh")" = "stub-toggle-recording" ]
rm -rf "$fake_repo_dir" "$stub_bin"
}
@test "check_arch returns 0 when pacman is on PATH" {
source "${BATS_TEST_DIRNAME}/../install.sh"
run check_arch
@@ -202,6 +256,10 @@ EOF
#!/usr/bin/env bash
echo "hyprctl $*" >> "$HYPREVO_TEST_LOG"
exit 0
EOF
cat > "$stub_bin/sudo" <<'EOF'
#!/usr/bin/env bash
exec "$@"
EOF
chmod +x "$stub_bin"/*