fix(install): prevent stdin stream truncation when running via pipe
Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
+56
-49
@@ -47,21 +47,25 @@ log_step() {
|
||||
printf "\n${CLR_BOLD}${CLR_CYAN}==>${CLR_RESET} ${CLR_BOLD}%s${CLR_RESET}\n" "$*"
|
||||
}
|
||||
|
||||
# If stdin is a pipe (e.g. curl ... | bash), reconnect to /dev/tty if available for interactive prompts & TUI
|
||||
if [[ ! -t 0 ]]; then
|
||||
if (exec < /dev/tty) 2>/dev/null; then
|
||||
exec < /dev/tty
|
||||
TMP_DIR=""
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "${TMP_DIR:-}" && -d "$TMP_DIR" ]]; then
|
||||
log_info "Cleaning up temporary installation files..."
|
||||
rm -rf "$TMP_DIR"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
REPO_URL="${REPO_URL:-https://gitea.creative-dragonslayer.de/Scripts/Setup.git}"
|
||||
REPO_BRANCH="${REPO_BRANCH:-}"
|
||||
main() {
|
||||
local repo_url="${REPO_URL:-https://gitea.creative-dragonslayer.de/Scripts/Setup.git}"
|
||||
local repo_branch="${REPO_BRANCH:-}"
|
||||
|
||||
log_step "Debian Unstable & Hyprland Setup Framework Installer"
|
||||
log_info "Repository: $REPO_URL ${REPO_BRANCH:+(Branch: $REPO_BRANCH)}"
|
||||
log_step "Debian Unstable & Hyprland Setup Framework Installer"
|
||||
log_info "Repository: $repo_url ${repo_branch:+(Branch: $repo_branch)}"
|
||||
|
||||
# Ensure git is available
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
# Ensure git is available
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
log_info "Installing git..."
|
||||
if [[ "$(id -u)" -eq 0 ]]; then
|
||||
DEBIAN_FRONTEND=noninteractive apt-get update -y
|
||||
@@ -74,61 +78,64 @@ if ! command -v git >/dev/null 2>&1; then
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git ca-certificates
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create temporary directory
|
||||
TMP_DIR="$(mktemp -d /tmp/debian-setup-XXXXXX)"
|
||||
cleanup() {
|
||||
if [[ -d "$TMP_DIR" ]]; then
|
||||
log_info "Cleaning up temporary installation files..."
|
||||
rm -rf "$TMP_DIR"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
log_info "Cloning repository into temporary directory: $TMP_DIR..."
|
||||
CLONE_SUCCESS=0
|
||||
if [[ -n "$REPO_BRANCH" ]]; then
|
||||
if git clone --depth 1 -b "$REPO_BRANCH" "$REPO_URL" "$TMP_DIR" 2>/dev/null; then
|
||||
CLONE_SUCCESS=1
|
||||
# Create temporary directory
|
||||
TMP_DIR="$(mktemp -d /tmp/debian-setup-XXXXXX)"
|
||||
|
||||
log_info "Cloning repository into temporary directory: $TMP_DIR..."
|
||||
local clone_success=0
|
||||
if [[ -n "$repo_branch" ]]; then
|
||||
if git clone --depth 1 -b "$repo_branch" "$repo_url" "$TMP_DIR" 2>/dev/null; then
|
||||
clone_success=1
|
||||
else
|
||||
log_warn "Failed to clone branch '$REPO_BRANCH', falling back to default branch..."
|
||||
log_warn "Failed to clone branch '$repo_branch', falling back to default branch..."
|
||||
rm -rf "${TMP_DIR:?}"/* "${TMP_DIR:?}"/.* 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$CLONE_SUCCESS" -eq 0 ]]; then
|
||||
if git clone --depth 1 "$REPO_URL" "$TMP_DIR"; then
|
||||
CLONE_SUCCESS=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$CLONE_SUCCESS" -eq 0 ]]; then
|
||||
log_error "Failed to clone repository from $REPO_URL"
|
||||
if [[ "$clone_success" -eq 0 ]]; then
|
||||
if git clone --depth 1 "$repo_url" "$TMP_DIR"; then
|
||||
clone_success=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$clone_success" -eq 0 ]]; then
|
||||
log_error "Failed to clone repository from $repo_url"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cd "$TMP_DIR"
|
||||
chmod +x setup.sh
|
||||
cd "$TMP_DIR"
|
||||
chmod +x setup.sh
|
||||
|
||||
log_success "Repository cloned successfully. Starting setup orchestrator..."
|
||||
log_success "Repository cloned successfully. Starting setup orchestrator..."
|
||||
|
||||
# Check if dry-run flag is requested
|
||||
is_dry_run=0
|
||||
for arg in "$@"; do
|
||||
# Check if dry-run flag is requested
|
||||
local is_dry_run=0
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "-d" || "$arg" == "--dry-run" ]]; then
|
||||
is_dry_run=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# Execute setup.sh with root privileges (or directly if dry-run) while preserving arguments
|
||||
if [[ "$(id -u)" -eq 0 ]] || [[ "$is_dry_run" -eq 1 ]]; then
|
||||
./setup.sh "$@"
|
||||
else
|
||||
# Prepare command to execute setup.sh
|
||||
local -a setup_cmd=()
|
||||
if [[ "$(id -u)" -ne 0 ]] && [[ "$is_dry_run" -eq 0 ]]; then
|
||||
if ! command -v sudo >/dev/null 2>&1; then
|
||||
log_error "sudo is required to run setup.sh. Please install sudo or run as root."
|
||||
exit 1
|
||||
fi
|
||||
sudo ./setup.sh "$@"
|
||||
fi
|
||||
setup_cmd+=(sudo)
|
||||
fi
|
||||
setup_cmd+=(./setup.sh "$@")
|
||||
|
||||
# Reconnect stdin to /dev/tty if stdin is currently piped and /dev/tty is accessible (for interactive prompts/TUI)
|
||||
if [[ ! -t 0 ]] && [[ -e /dev/tty ]] && ( : < /dev/tty ) 2>/dev/null; then
|
||||
"${setup_cmd[@]}" < /dev/tty
|
||||
else
|
||||
"${setup_cmd[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user