fix: Fixed installation issues with the install.sh script.

This commit is contained in:
shaw
2025-12-18 16:00:57 +08:00
parent 6cf60176c3
commit 20aee89dcc
3 changed files with 43 additions and 10 deletions

View File

@@ -260,8 +260,19 @@ print_error() {
echo -e "${RED}[$(msg 'error')]${NC} $1"
}
# Check if running interactively (stdin is a terminal)
is_interactive() {
[ -t 0 ]
}
# Select language
select_language() {
# If not interactive (piped), use default language
if ! is_interactive; then
LANG_CHOICE="zh"
return
fi
echo ""
echo -e "${CYAN}=============================================="
echo " $(msg 'select_lang')"
@@ -271,8 +282,7 @@ select_language() {
echo " 2) $(msg 'lang_en')"
echo ""
# Read with timeout for piped input
read -t 10 -p "$(msg 'enter_choice'): " lang_input 2>/dev/null || lang_input=""
read -p "$(msg 'enter_choice'): " lang_input
case "$lang_input" in
2|en|EN|english|English)
@@ -297,6 +307,12 @@ validate_port() {
# Configure server settings
configure_server() {
# If not interactive (piped), use default settings
if ! is_interactive; then
print_info "$(msg 'server_config_summary'): ${SERVER_HOST}:${SERVER_PORT} (default)"
return
fi
echo ""
echo -e "${CYAN}=============================================="
echo " $(msg 'server_config_title')"
@@ -663,11 +679,20 @@ upgrade() {
# Uninstall function
uninstall() {
print_warning "$(msg 'uninstall_confirm')"
read -p "$(msg 'are_you_sure') " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "$(msg 'uninstall_cancelled')"
exit 0
# If not interactive (piped), require -y flag or skip confirmation
if ! is_interactive; then
if [ "${FORCE_YES:-}" != "true" ]; then
print_error "Non-interactive mode detected. Use 'bash -s -- uninstall -y' to confirm."
exit 1
fi
else
read -p "$(msg 'are_you_sure') " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "$(msg 'uninstall_cancelled')"
exit 0
fi
fi
print_info "$(msg 'stopping_service')"
@@ -693,6 +718,13 @@ uninstall() {
# Main
main() {
# Parse -y flag first
for arg in "$@"; do
if [ "$arg" = "-y" ] || [ "$arg" = "--yes" ]; then
FORCE_YES="true"
fi
done
# Select language first
select_language
@@ -716,13 +748,16 @@ main() {
exit 0
;;
--help|-h)
echo "$(msg 'usage'): $0 [command]"
echo "$(msg 'usage'): $0 [command] [options]"
echo ""
echo "Commands:"
echo " $(msg 'cmd_none') $(msg 'cmd_install')"
echo " upgrade $(msg 'cmd_upgrade')"
echo " uninstall $(msg 'cmd_uninstall')"
echo ""
echo "Options:"
echo " -y, --yes Skip confirmation prompts (for uninstall)"
echo ""
exit 0
;;
esac