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