Skip to content

Commit 30983d5

Browse files
committed
fix(install): never block on interactive sudo; fall back to ~/.local/bin
When the install dir isn't writable, install.sh ran a bare `sudo mv` that hangs forever in non-interactive `curl | sh` (agents/CI have no TTY to answer the password prompt). Try passwordless `sudo -n` first; otherwise install to $HOME/.local/bin instead of blocking. Also mkdir -p the target so a caller-provided FLASHDUTY_INSTALL_DIR that doesn't exist yet works.
1 parent 056b20b commit 30983d5

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

install.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,27 @@ main() {
170170
fail "binary '${BINARY}' not found in archive"
171171
fi
172172

173-
# Install (rename flashduty-cli -> flashduty for convenience)
173+
# Install (rename flashduty-cli -> flashduty for convenience).
174+
# Create the target dir first so a caller-provided FLASHDUTY_INSTALL_DIR that
175+
# doesn't exist yet is usable without sudo.
176+
mkdir -p "${INSTALL_DIR}" 2>/dev/null || true
174177
if [ -w "${INSTALL_DIR}" ]; then
175178
mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${INSTALLED_NAME}"
176-
else
177-
info "Need elevated permissions to install to ${INSTALL_DIR}"
179+
chmod +x "${INSTALL_DIR}/${INSTALLED_NAME}"
180+
elif sudo -n true 2>/dev/null; then
181+
# Passwordless sudo is available — install to the privileged dir without
182+
# prompting (a prompt would hang `curl | sh` in agents/CI: no TTY to answer).
178183
sudo mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${INSTALLED_NAME}"
184+
sudo chmod +x "${INSTALL_DIR}/${INSTALLED_NAME}"
185+
else
186+
# Not writable and sudo would need an interactive password. Never block on
187+
# an unanswerable prompt — fall back to a user-writable directory.
188+
INSTALL_DIR="${HOME}/.local/bin"
189+
info "Install dir not writable and no passwordless sudo; installing to ${INSTALL_DIR}"
190+
mkdir -p "${INSTALL_DIR}"
191+
mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${INSTALLED_NAME}"
192+
chmod +x "${INSTALL_DIR}/${INSTALLED_NAME}"
179193
fi
180-
chmod +x "${INSTALL_DIR}/${INSTALLED_NAME}"
181194

182195
info "Installed to ${INSTALL_DIR}/${INSTALLED_NAME}"
183196

0 commit comments

Comments
 (0)