2024-04-22 05:02:38 +00:00
|
|
|
#!/bin/bash
|
2024-04-26 15:54:40 +00:00
|
|
|
|
|
|
|
log_file="wand/logs/installLog.txt"
|
|
|
|
firstrun_log="wand/logs/firstrun.txt"
|
|
|
|
|
|
|
|
# Function to log output to file
|
|
|
|
log() {
|
|
|
|
echo "$(date +"%Y-%m-%d %T") $1" >> "$log_file"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to log first run output to file
|
|
|
|
log_firstrun() {
|
|
|
|
echo "$(date +"%Y-%m-%d %T") $1" >> "$firstrun_log"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clear screen and log
|
2024-04-22 05:02:38 +00:00
|
|
|
clear
|
2024-04-26 15:54:40 +00:00
|
|
|
log "Please answer these questions to set up the game:"
|
|
|
|
|
|
|
|
# Function to read password silently
|
|
|
|
read_password() {
|
|
|
|
local password=""
|
|
|
|
while IFS= read -r -s -n1 char; do
|
|
|
|
if [[ -z $char ]]; then
|
|
|
|
break
|
|
|
|
elif [[ $char == $'\177' ]]; then # handle backspace
|
|
|
|
if [ ${#password} -gt 0 ]; then
|
|
|
|
password="${password%?}" # remove last character
|
|
|
|
echo -ne '\b \b' # erase last character on the screen
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -n '*'
|
|
|
|
password+="$char"
|
2024-04-22 05:02:38 +00:00
|
|
|
fi
|
2024-04-26 15:54:40 +00:00
|
|
|
done
|
|
|
|
echo "$password"
|
|
|
|
}
|
2024-04-22 05:02:38 +00:00
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Read password and log
|
|
|
|
log "Enter password for the database (leave empty for a random password):"
|
|
|
|
dbpass=$(read_password)
|
|
|
|
log "Database password entered."
|
|
|
|
|
|
|
|
# Generate random password if needed
|
2024-04-22 05:02:38 +00:00
|
|
|
if [ -z "$dbpass" ]; then
|
|
|
|
dbpass=$(openssl rand -base64 12)
|
2024-04-26 15:54:40 +00:00
|
|
|
log "Generated random database password."
|
2024-04-22 05:02:38 +00:00
|
|
|
fi
|
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Read hostname and log
|
|
|
|
log "Enter the hostname for the game (example: example.com) (leave empty for localhost):"
|
2024-04-22 05:02:38 +00:00
|
|
|
read hostname
|
|
|
|
if [ -z "$hostname" ]; then
|
2024-04-24 19:28:08 +00:00
|
|
|
hostname=localhost
|
2024-04-22 05:02:38 +00:00
|
|
|
fi
|
2024-04-26 15:54:40 +00:00
|
|
|
log "Hostname entered: $hostname"
|
2024-04-24 19:28:08 +00:00
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Read IP address and log
|
|
|
|
log "Enter your external IP address (leave empty for localhost):"
|
2024-04-22 05:02:38 +00:00
|
|
|
read ipadd
|
|
|
|
if [ -z "$ipadd" ]; then
|
2024-04-24 19:28:08 +00:00
|
|
|
ipadd=127.0.0.1
|
2024-04-22 05:02:38 +00:00
|
|
|
fi
|
2024-04-26 15:54:40 +00:00
|
|
|
log "IP address entered: $ipadd"
|
2024-04-22 05:02:38 +00:00
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Read whether to run the game and log
|
2024-04-24 19:28:08 +00:00
|
|
|
read -p "Do you want to run the game when the installation ends? (y/N): " run_game
|
2024-04-26 15:54:40 +00:00
|
|
|
log "Choice to run the game: $run_game"
|
|
|
|
|
|
|
|
# Setting up environment
|
|
|
|
log "Setting up the environment."
|
|
|
|
sudo apt update >> "$log_file" 2>&1
|
|
|
|
sudo apt install docker.io git curl -y >> "$log_file" 2>&1
|
|
|
|
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose >> "$log_file" 2>&1
|
|
|
|
sudo chmod +x /usr/local/bin/docker-compose >> "$log_file" 2>&1
|
|
|
|
log "Environment setup completed."
|
|
|
|
|
|
|
|
# Downloading game files
|
|
|
|
log "Downloading Game Files"
|
|
|
|
git clone --recurse-submodules https://github.com/solero/wand && cd wand >> "$log_file" 2>&1
|
|
|
|
log "Game files downloaded."
|
2024-04-24 19:28:08 +00:00
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Remove existing .env file if exists
|
|
|
|
sudo rm -r .env >> "$log_file" 2>&1
|
2024-04-24 19:18:26 +00:00
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Write environment variables to .env file
|
2024-04-22 05:02:38 +00:00
|
|
|
echo "# database
|
|
|
|
POSTGRES_USER=postgres
|
|
|
|
POSTGRES_PASSWORD=$dbpass
|
|
|
|
# Web
|
|
|
|
WEB_PORT=80
|
|
|
|
WEB_HOSTNAME=$hostname
|
|
|
|
|
|
|
|
WEB_LEGACY_PLAY=http://old.$hostname
|
|
|
|
WEB_LEGACY_MEDIA=http://legacy.$hostname
|
|
|
|
|
|
|
|
WEB_VANILLA_PLAY=http://play.$hostname
|
|
|
|
WEB_VANILLA_MEDIA=http://media.$hostname
|
|
|
|
|
|
|
|
WEB_RECAPTCHA_SITE=
|
|
|
|
WEB_RECAPTCHA_SECRET=
|
|
|
|
|
|
|
|
WEB_SENDGRID_KEY=
|
|
|
|
|
|
|
|
# Game
|
|
|
|
GAME_ADDRESS=$ipadd
|
|
|
|
GAME_LOGIN_PORT=6112" > .env
|
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
log "Environment variables written to .env file."
|
2024-04-24 19:28:08 +00:00
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Final message
|
|
|
|
echo "Done!"
|
|
|
|
log "Setup completed."
|
2024-04-24 19:28:08 +00:00
|
|
|
|
2024-04-26 15:54:40 +00:00
|
|
|
# Run the game if chosen
|
2024-04-24 19:28:08 +00:00
|
|
|
if [ "$run_game" == "y" ] || [ "$run_game" == "Y" ]; then
|
2024-04-26 15:54:40 +00:00
|
|
|
log_firstrun "Running the game..."
|
|
|
|
sudo docker-compose up >> "$firstrun_log" 2>&1
|
2024-04-24 19:28:08 +00:00
|
|
|
else
|
|
|
|
echo "You chose not to run the game. To run the game later, execute the command: cd wand && sudo docker-compose up"
|
2024-04-26 15:54:40 +00:00
|
|
|
log "Game not started."
|
2024-04-24 19:28:08 +00:00
|
|
|
fi
|