diff --git a/scripts/systemd/install-systemd.sh b/scripts/systemd/install-systemd.sh index e9cc2e9..cf96aa8 100755 --- a/scripts/systemd/install-systemd.sh +++ b/scripts/systemd/install-systemd.sh @@ -2,9 +2,23 @@ # Sendspin systemd service installation set -e +# Ensure output is visible even when piped +exec 2>&1 + # Colors C='\033[0;36m'; G='\033[0;32m'; Y='\033[1;33m'; R='\033[0;31m'; B='\033[1m'; D='\033[2m'; N='\033[0m' +# Detect if running interactively +INTERACTIVE=true +if [ ! -t 0 ]; then + # stdin is not a terminal (piped) + if [ ! -c /dev/tty ]; then + # No TTY available - fully non-interactive + INTERACTIVE=false + echo "Running in non-interactive mode - using defaults" >&2 + fi +fi + # Check for root via sudo, detect original user to install properly. [[ $EUID -ne 0 ]] && { echo -e "${R}Error:${N} Please run with sudo"; exit 1; } USER=${SUDO_USER:-$(whoami)} @@ -27,15 +41,20 @@ if ! ldconfig -p 2>/dev/null | grep -q libportaudio.so; then echo -e "${Y}Missing:${N} libportaudio2" if [[ -n "$PKG_MGR" ]]; then if [[ "$PKG_MGR" == "pacman" ]]; then - CMD="pacman -S portaudio" + CMD="pacman -S --noconfirm portaudio" + else + CMD="$PKG_MGR install -y libportaudio2" + fi + if [ "$INTERACTIVE" = true ]; then + read -p "Install now? ($CMD) [Y/n] " -n1 -r /dev/null && \ ! sudo -u "$USER" test -f "/home/$USER/.cargo/bin/uv" && \ ! sudo -u "$USER" test -f "/home/$USER/.local/bin/uv"; then echo -e "${Y}Missing:${N} uv" - read -p "Install now? (curl -LsSf https://astral.sh/uv/install.sh | sh) [Y/n] " -n1 -r; echo + if [ "$INTERACTIVE" = true ]; then + read -p "Install now? (curl -LsSf https://astral.sh/uv/install.sh | sh) [Y/n] " -n1 -r &1 | head -n -2 -read -p "Audio device [default]: " DEVICE +if [ "$INTERACTIVE" = true ]; then + read -p "Audio device [default]: " DEVICE /etc/default/sendspin << EOF @@ -121,10 +155,20 @@ systemctl daemon-reload # Enable and start echo "" -read -p "Enable on boot? [Y/n] " -n1 -r; echo +if [ "$INTERACTIVE" = true ]; then + read -p "Enable on boot? [Y/n] " -n1 -r /dev/null -read -p "Start now? [Y/n] " -n1 -r; echo +if [ "$INTERACTIVE" = true ]; then + read -p "Start now? [Y/n] " -n1 -r