Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions download-and-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,39 @@ else
fi

# 4. Docker Check & Install
check_docker_status() {
if systemctl is-active --quiet docker; then
return 0
else
echo -e "${BLUE}Starting Docker service...${NC}"
systemctl start docker
if systemctl is-active --quiet docker; then
return 0
fi
fi
return 1
}

if ! command -v docker &> /dev/null; then
echo -e "${BLUE}Docker not found. Installing via official script...${NC}"
curl -fsSL https://get.docker.com | bash
systemctl enable docker
systemctl start docker
echo -e "${GREEN}Docker installed.${NC}"

if check_docker_status; then
echo -e "${GREEN}Docker installed and started successfully.${NC}"
else
echo -e "${RED}Error: Docker installed but failed to start.${NC}"
echo -e "${YELLOW}Please check logs: journalctl -xeu docker.service${NC}"
echo -e "${YELLOW}You may need to install Docker manually.${NC}"
exit 1
fi
else
echo -e "${GREEN}Docker detected.${NC}"
if ! check_docker_status; then
echo -e "${RED}Error: Docker is installed but not running and failed to start.${NC}"
echo -e "${YELLOW}Please check logs: journalctl -xeu docker.service${NC}"
exit 1
fi
fi

# 5. Handover to setup-services.sh
Expand All @@ -116,8 +141,22 @@ if [ -f "$DEPLOY_SCRIPT" ]; then
echo ""
# Switch to directory before execution to ensure relative paths work
cd "$INSTALL_DIR"

# If PROJECT env var is set, append it to arguments
if [ -n "$PROJECT" ]; then
echo -e "${BLUE}Project selection detected via env: PROJECT=$PROJECT${NC}"
set -- "$@" "--project" "$PROJECT"
fi

# If AUTO_YES env var is set, append it to arguments
if [ -n "$AUTO_YES" ]; then
echo -e "${BLUE}Auto-confirm detected via env: AUTO_YES=$AUTO_YES${NC}"
set -- "$@" "--yes"
fi

echo -e "${BLUE}Executing: ./setup-services.sh $@${NC}"
# Ensure stdin is attached to terminal for interactive input
exec ./setup-services.sh < /dev/tty
exec ./setup-services.sh "$@" < /dev/tty
else
echo -e "${RED}Critical Error: setup-services.sh not found in downloaded repository!${NC}"
exit 1
Expand Down
6 changes: 6 additions & 0 deletions examples/track-http/.env
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Server information, You must fill in the information accurately.
SERVER_IP_PUBLIC='58.82.168.197'
SERVER_HOSTNAME='th-track.transcodegroup.cn'

# Custom Port Info, recommended use default. 9000~9100, 443, 80
WEB_PORT_HTTP=80

# Initial password. Recommended use random password; do not change it after started the service.
MYSQL_PASSWORD='12345678'
REDIS_PASSWORD='12345678'
MONGODB_PASSWORD='12345678'
RABBITMQ_PASSWORD='12345678'
MINIO_PASSWORD='12345678'
MAIL_PASSWORD='12345678'

8 changes: 8 additions & 0 deletions examples/track-https/.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Server information, You must fill in the information accurately.
SERVER_HOSTNAME='vpn.transbustransportes.com.br'
SERVER_IP_PUBLIC='200.155.137.26'

# The certificate can be set to placeholder first to ensure compose starts, and then change it to the actual certificate path after applying for the certificate
SSL_CERTIFICATE=/home/docker/nginx/ssl/placeholder
# SSL_CERTIFICATE=/home/docker-compose/ssl/certificate

# Custom Port Info, recommended use default. 9000~9100, 443, 80
WEB_PORT_HTTP=80
WEB_PORT_HTTPS=443

# Initial password. Recommended use random password; do not change it after started the service.
MYSQL_PASSWORD='12345678'
REDIS_PASSWORD='12345678'
MONGODB_PASSWORD='12345678'
RABBITMQ_PASSWORD='12345678'
MINIO_PASSWORD='12345678'
MAIL_PASSWORD='12345678'

111 changes: 91 additions & 20 deletions setup-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ echo -e "${BLUE} Docker Compose One-Click Deployment ${NC}"
echo -e "${BLUE}=================================================${NC}"

# 1. Select Deployment Example
echo -e "${GREEN}Select a deployment scenario:${NC}"
# List directories in examples/ excluding 'docker'
if [ -d "examples" ]; then
OPTIONS=($(ls -d examples/*/ | grep -v "examples/docker/" | xargs -n 1 basename))
Expand All @@ -40,29 +39,72 @@ if [ ${#OPTIONS[@]} -eq 0 ]; then
exit 1
fi

PS3="Enter choice number: "
select OPT in "${OPTIONS[@]}"; do
if [ -n "$OPT" ]; then
SELECTED_EXAMPLE="$OPT"
break
else
echo "Invalid selection."
fi
# Parse arguments manually since we are inside the script flow
ARG_PROJECT=""

while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-p|--project)
ARG_PROJECT="$2"
shift # past argument
shift # past value
;;
-y|--yes)
AUTO_YES="true"
echo -e "${YELLOW}Non-interactive mode enabled (Auto-Yes).${NC}"
shift # past argument
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
echo -e "Usage: ./setup-services.sh [-p|--project <name>]"
exit 1
;;
esac
done

# Logic to select example
if [ -n "$ARG_PROJECT" ]; then
for opt in "${OPTIONS[@]}"; do
if [ "$opt" == "$ARG_PROJECT" ]; then
SELECTED_EXAMPLE="$opt"
echo -e "${GREEN}Project selected via argument: $SELECTED_EXAMPLE${NC}"
break
fi
done
if [ -z "$SELECTED_EXAMPLE" ]; then
echo -e "${RED}Invalid project: $ARG_PROJECT${NC}"
echo -e "Available options: ${OPTIONS[*]}"
exit 1
fi
else
echo -e "${GREEN}Select a deployment project:${NC}"
PS3="Enter choice number: "
select OPT in "${OPTIONS[@]}"; do
if [ -n "$OPT" ]; then
SELECTED_EXAMPLE="$OPT"
break
else
echo "Invalid selection."
fi
done
fi

echo -e "${GREEN}Selected: $SELECTED_EXAMPLE${NC}"

# 2. Prepare Target Directory
echo -e "${GREEN}Hint: Press Enter to accept the [default] value.${NC}"
read -p "Enter installation directory [${DEFAULT_TARGET_BASE}]: " TARGET_BASE
TARGET_BASE=${TARGET_BASE:-$DEFAULT_TARGET_BASE}
TARGET_DIR="$TARGET_BASE"
TARGET_DIR="$DEFAULT_TARGET_BASE"

echo -e "${BLUE}Installing to $TARGET_DIR...${NC}"

if [ -d "$TARGET_DIR" ]; then
echo -e "${YELLOW}Directory $TARGET_DIR already exists.${NC}"
read -p "Backup and overwrite? (y/N) " confirm
if [ "$AUTO_YES" == "true" ]; then
confirm="y"
echo -e "${BLUE}Auto-confirming backup and overwrite.${NC}"
else
read -p "Backup and overwrite? (y/N) " confirm
fi
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
echo "Aborting."
exit 0
Expand Down Expand Up @@ -152,7 +194,11 @@ else
# Always suggest the detected IP (or empty if detection failed)
IP_DEFAULT="$DETECTED_IP"

read -p "Enter Server Public IP [${IP_DEFAULT}]: " INPUT_IP
if [ "$AUTO_YES" == "true" ]; then
INPUT_IP=$IP_DEFAULT
else
read -p "Enter Server Public IP [${IP_DEFAULT}]: " INPUT_IP
fi
INPUT_IP=${INPUT_IP:-$IP_DEFAULT}

COMMENT_IP="User-defined"
Expand All @@ -166,7 +212,11 @@ else
# Logic: Default to the IP address entered above
HOST_DEFAULT=${CURRENT_HOST:-$INPUT_IP}

read -p "Enter Server Hostname (e.g., google.com) [${HOST_DEFAULT}]: " INPUT_HOST
if [ "$AUTO_YES" == "true" ]; then
INPUT_HOST=$HOST_DEFAULT
else
read -p "Enter Server Hostname (e.g., google.com) [${HOST_DEFAULT}]: " INPUT_HOST
fi
INPUT_HOST=${INPUT_HOST:-$HOST_DEFAULT}

COMMENT_HOST="User-defined"
Expand Down Expand Up @@ -197,7 +247,12 @@ else
echo -e " 1) Keep existing passwords (Recommended if preserving data)"
echo -e " 2) Rename old data dir & Generate new passwords (WARNING: Hides old data)"
echo -e " 3) Abort deployment"
read -p "Select option [1]: " DATA_OPT
if [ "$AUTO_YES" == "true" ]; then
DATA_OPT=1
echo -e "${BLUE}Auto-selecting Option 1 (Keep existing passwords).${NC}"
else
read -p "Select option [1]: " DATA_OPT
fi
DATA_OPT=${DATA_OPT:-1}

case $DATA_OPT in
Expand Down Expand Up @@ -225,7 +280,12 @@ else
esac
else
# Data dir empty or doesn't exist, safe to prompt for generation
read -p "Generate new random passwords for key services? (Y/n) " GEN_PASS
if [ "$AUTO_YES" == "true" ]; then
GEN_PASS="y"
echo -e "${BLUE}Auto-confirming password generation.${NC}"
else
read -p "Generate new random passwords for key services? (Y/n) " GEN_PASS
fi
if [[ "$GEN_PASS" != "n" && "$GEN_PASS" != "N" ]]; then
SHOULD_GENERATE_PASS="y"
fi
Expand All @@ -236,7 +296,7 @@ else
# Check if variable exists in the file
if grep -q "^$var=" "$TARGET_ENV"; then
NEW_PASS=$(generate_password)
set_env_val "$var" "$NEW_PASS" "Auto-generated random password"
set_env_val "$var" "$NEW_PASS" "Auto-generated. DO NOT CHANGE after startup or services will break."
echo "Updated $var with new random password."
fi
done
Expand All @@ -249,7 +309,12 @@ else
# Heuristic: if ssl folder exists, and current config is placeholder or empty, prompt to update
if [[ "$SSL_VAL" == *"placeholder"* ]] || [ -z "$SSL_VAL" ]; then
echo -e "${YELLOW}Local SSL certificates detected in ./ssl directory.${NC}"
read -p "Update SSL_CERTIFICATE path to local file? (Y/n) " UPD_SSL
if [ "$AUTO_YES" == "true" ]; then
UPD_SSL="y"
echo -e "${BLUE}Auto-confirming SSL path update.${NC}"
else
read -p "Update SSL_CERTIFICATE path to local file? (Y/n) " UPD_SSL
fi
if [[ "$UPD_SSL" != "n" && "$UPD_SSL" != "N" ]]; then
# Find the crt file
CRT_FILE=$(find "$TARGET_DIR/ssl" -name "*.crt" | head -n 1)
Expand All @@ -269,6 +334,12 @@ fi
echo -e "${GREEN}Deployment setup complete!${NC}"
echo -e "Configuration file: ${YELLOW}$TARGET_ENV${NC}"

echo -e "\n${RED}!!! IMPORTANT CONFIGURATION WARNING !!!${NC}"
echo -e "${YELLOW}Passwords have been auto-generated and synchronized.${NC}"
echo -e "${YELLOW}DO NOT change them manually in the .env file after this point.${NC}"
echo -e "${YELLOW}Changing them will break connections between services and databases.${NC}"
echo -e "${RED}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${NC}"

# --- SSL Certificate Checklist ---
SSL_CERT_VAL=$(get_env_val "SSL_CERTIFICATE")
# Only show checklist if SSL var is set AND the selected example implies HTTPS usage
Expand Down