Update install.sh to be interactive

This commit is contained in:
2025-12-08 15:54:46 +07:00
parent b3f73fd331
commit 3ed853f97f

View File

@@ -35,20 +35,74 @@ else
exit 1 exit 1
fi fi
# 2. Setup Environment Variables # 2. Setup Environment Variables (Interactive)
echo "Setting up environment configuration..." ENV_FILE="$SERVER_DIR/.env"
if [ ! -f ".env" ]; then CONFIGURE=true
if [ -f ".env.example" ]; then
cp .env.example .env if [ -f "$ENV_FILE" ]; then
echo -e "${GREEN}Created .env from .env.example.${NC}" echo -e "\n${GREEN}.env file already exists.${NC}"
echo "Please edit $SERVER_DIR/.env with your database configuration." read -p "Do you want to reconfigure it? (y/N): " RECONF
else if [[ ! "$RECONF" =~ ^[Yy]$ ]]; then
echo -e "${RED}Warning: .env.example not found.${NC}" CONFIGURE=false
fi fi
else
echo ".env already exists."
fi fi
if [ "$CONFIGURE" = true ]; then
echo -e "\n${GREEN}Configuring Environment Variables...${NC}"
echo "Press Enter to accept defaults [in brackets]"
# Helper function for prompts
prompt_val() {
local var_name=$1
local prompt_text=$2
local default_val=$3
read -p "$prompt_text [$default_val]: " input
input=${input:-$default_val}
# Escape special characters if necessary, simpler for now
eval "$var_name=\"$input\""
}
prompt_val DB_HOST "Database Host" "localhost"
prompt_val DB_USER "Database User" "bacula"
prompt_val DB_PASSWORD "Database Password" "bacula" # Default might be insecure, but user can change
prompt_val DB_NAME "Database Name" "bacula"
prompt_val DB_PORT "Database Port" "5432"
echo ""
prompt_val SSH_HOST "Remote Bacula SSH Host" "10.10.14.82"
prompt_val SSH_USER "Remote SSH User" "root"
prompt_val SSH_PASSWORD "Remote SSH Password" ""
prompt_val SSH_KEY_PATH "Remote SSH Key Path" ""
prompt_val BACULA_CONF_DIR "Bacula Config Dir" "/etc/bacula/conf.d/clients"
echo ""
prompt_val PORT "Application Port" "3000"
# Write to .env
cat > "$ENV_FILE" <<EOF
# Database Configuration
DB_HOST=$DB_HOST
DB_USER=$DB_USER
DB_PASSWORD=$DB_PASSWORD
DB_NAME=$DB_NAME
DB_PORT=$DB_PORT
# Remote Admin (SSH)
SSH_HOST=$SSH_HOST
SSH_USER=$SSH_USER
SSH_PASSWORD=$SSH_PASSWORD
SSH_KEY_PATH=$SSH_KEY_PATH
BACULA_CONF_DIR=$BACULA_CONF_DIR
# Server Config
PORT=$PORT
EOF
echo -e "${GREEN}Configuration saved to $ENV_FILE${NC}"
fi
# 3. Create Systemd Service # 3. Create Systemd Service
echo "Creating systemd service..." echo "Creating systemd service..."
@@ -67,7 +121,7 @@ User=$REAL_USER
WorkingDirectory=$SERVER_DIR WorkingDirectory=$SERVER_DIR
ExecStart=$NODE_PATH index.js ExecStart=$NODE_PATH index.js
Restart=on-failure Restart=on-failure
Environment=PORT=3000 Environment=PORT=$PORT
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
@@ -83,4 +137,4 @@ systemctl restart $SERVICE_NAME
echo -e "${GREEN}Installation Complete!${NC}" echo -e "${GREEN}Installation Complete!${NC}"
echo -e "You can check the status with: ${GREEN}systemctl status $SERVICE_NAME${NC}" echo -e "You can check the status with: ${GREEN}systemctl status $SERVICE_NAME${NC}"
echo -e "Access the UI at: ${GREEN}http://$(hostname -I | awk '{print $1}'):3000${NC}" echo -e "Access the UI at: ${GREEN}http://$(hostname -I | awk '{print $1}'):$PORT${NC}"