Update branch detection
This commit is contained in:
40
install.sh
40
install.sh
@@ -5,15 +5,16 @@
|
|||||||
#
|
#
|
||||||
# Configurable via env:
|
# Configurable via env:
|
||||||
# REPO_URL git url (default: this public repo)
|
# REPO_URL git url (default: this public repo)
|
||||||
# REF branch/tag/commit to check out (default: main)
|
# REF branch/tag/commit (default: remote's HEAD branch, e.g. main/master)
|
||||||
# DEST clone destination (default: /opt/linux-bootstrap)
|
# DEST clone destination (default: /opt/linux-bootstrap)
|
||||||
# Any extra args are forwarded to bootstrap.sh, e.g.:
|
# Any extra args are forwarded to bootstrap.sh, e.g.:
|
||||||
# curl -fsSL .../install.sh | bash -s -- --skip hardening
|
# curl -fsSL .../install.sh | bash -s -- --skip hardening
|
||||||
#
|
#
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
REPO_URL="${REPO_URL:-https://gitea.big-chungus.me/moritz/linux-bootstrap.git}"
|
REPO_URL="${REPO_URL:-https://gitea.big-chungus.me/moritz/linux-bootstrap.git}"
|
||||||
REF="${REF:-main}"
|
REF="${REF:-}" # empty -> auto-detect remote default branch
|
||||||
DEST="${DEST:-/opt/linux-bootstrap}"
|
DEST="${DEST:-/opt/linux-bootstrap}"
|
||||||
|
|
||||||
say() { printf '\e[34m[install]\e[0m %s\n' "$*"; }
|
say() { printf '\e[34m[install]\e[0m %s\n' "$*"; }
|
||||||
@@ -40,19 +41,32 @@ if ! command -v git >/dev/null 2>&1; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. clone or update
|
# 2. resolve ref: explicit env wins; otherwise ask the remote what its default
|
||||||
if [[ -d "$DEST/.git" ]]; then
|
# branch is (handles main vs master without guessing).
|
||||||
say "updating existing clone at $DEST"
|
if [[ -z "$REF" ]]; then
|
||||||
$SUDO git -C "$DEST" fetch --depth=1 origin "$REF"
|
REF="$(git ls-remote --symref "$REPO_URL" HEAD 2>/dev/null \
|
||||||
$SUDO git -C "$DEST" checkout -f "$REF"
|
| awk '/^ref:/ {sub("refs/heads/","",$2); print $2; exit}')"
|
||||||
$SUDO git -C "$DEST" reset --hard "origin/$REF" 2>/dev/null || true
|
if [[ -z "$REF" ]]; then
|
||||||
else
|
say "could not detect default branch, falling back to 'main'"
|
||||||
say "cloning $REPO_URL -> $DEST"
|
REF="main"
|
||||||
$SUDO git clone --depth=1 --branch "$REF" "$REPO_URL" "$DEST" 2>/dev/null \
|
else
|
||||||
|| $SUDO git clone --depth=1 "$REPO_URL" "$DEST"
|
say "remote default branch: $REF"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. run bootstrap, forwarding any extra args
|
# 3. clone or update
|
||||||
|
if [[ -d "$DEST/.git" ]]; then
|
||||||
|
say "updating existing clone at $DEST ($REF)"
|
||||||
|
$SUDO git -C "$DEST" remote set-url origin "$REPO_URL"
|
||||||
|
$SUDO git -C "$DEST" fetch --depth=1 origin "$REF"
|
||||||
|
$SUDO git -C "$DEST" checkout -B "$REF" "origin/$REF"
|
||||||
|
$SUDO git -C "$DEST" reset --hard "origin/$REF"
|
||||||
|
else
|
||||||
|
say "cloning $REPO_URL ($REF) -> $DEST"
|
||||||
|
$SUDO git clone --depth=1 --branch "$REF" "$REPO_URL" "$DEST"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4. run bootstrap, forwarding any extra args
|
||||||
say "running bootstrap.sh $*"
|
say "running bootstrap.sh $*"
|
||||||
$SUDO chmod +x "$DEST/bootstrap.sh" "$DEST/config/motd/01-banner.sh"
|
$SUDO chmod +x "$DEST/bootstrap.sh" "$DEST/config/motd/01-banner.sh"
|
||||||
exec "$DEST/bootstrap.sh" "$@"
|
exec "$DEST/bootstrap.sh" "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user