mirror of
				https://github.com/solero/wand.git
				synced 2025-11-04 06:32:04 +00:00 
			
		
		
		
	Now I'm logging the First Run and the installation process
This commit is contained in:
		
							
								
								
									
										101
									
								
								install.sh
									
									
									
									
									
								
							
							
						
						
									
										101
									
								
								install.sh
									
									
									
									
									
								
							@@ -1,52 +1,89 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
clear
 | 
			
		||||
echo "Please answer these questions to set up the game:"
 | 
			
		||||
log "Please answer these questions to set up the game:"
 | 
			
		||||
 | 
			
		||||
echo "Enter password for the database (leave empty for a random password):"
 | 
			
		||||
dbpass=""
 | 
			
		||||
while IFS= read -r -s -n1 char; do
 | 
			
		||||
    if [[ -z $char ]]; then
 | 
			
		||||
        break
 | 
			
		||||
    elif [[ $char == $'\177' ]]; then # handle backspace
 | 
			
		||||
        if [ ${#dbpass} -gt 0 ]; then
 | 
			
		||||
            dbpass="${dbpass%?}" # remove last character
 | 
			
		||||
            echo -ne '\b \b' # erase last character on the screen
 | 
			
		||||
# 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"
 | 
			
		||||
        fi
 | 
			
		||||
    else
 | 
			
		||||
        echo -n '*'
 | 
			
		||||
        dbpass+="$char"
 | 
			
		||||
    fi
 | 
			
		||||
done
 | 
			
		||||
    done
 | 
			
		||||
    echo "$password"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# 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
 | 
			
		||||
if [ -z "$dbpass" ]; then
 | 
			
		||||
    dbpass=$(openssl rand -base64 12)
 | 
			
		||||
    log "Generated random database password."
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo "Enter the hostname for the game (example: example.com) (leave empty for localhost):"
 | 
			
		||||
# Read hostname and log
 | 
			
		||||
log "Enter the hostname for the game (example: example.com) (leave empty for localhost):"
 | 
			
		||||
read hostname
 | 
			
		||||
if [ -z "$hostname" ]; then
 | 
			
		||||
    hostname=localhost
 | 
			
		||||
fi
 | 
			
		||||
log "Hostname entered: $hostname"
 | 
			
		||||
 | 
			
		||||
echo "Enter your external IP address (leave empty for localhost):"
 | 
			
		||||
# Read IP address and log
 | 
			
		||||
log "Enter your external IP address (leave empty for localhost):"
 | 
			
		||||
read ipadd
 | 
			
		||||
if [ -z "$ipadd" ]; then
 | 
			
		||||
    ipadd=127.0.0.1
 | 
			
		||||
fi
 | 
			
		||||
log "IP address entered: $ipadd"
 | 
			
		||||
 | 
			
		||||
# Read whether to run the game and log
 | 
			
		||||
read -p "Do you want to run the game when the installation ends? (y/N): " run_game
 | 
			
		||||
log "Choice to run the game: $run_game"
 | 
			
		||||
 | 
			
		||||
echo "Setting up the environment."
 | 
			
		||||
sudo apt update
 | 
			
		||||
sudo apt install docker.io git curl -y
 | 
			
		||||
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
 | 
			
		||||
sudo chmod +x /usr/local/bin/docker-compose
 | 
			
		||||
echo "Done setting up the environment."
 | 
			
		||||
echo "Downloading Game Files"
 | 
			
		||||
git clone --recurse-submodules https://github.com/solero/wand && cd wand
 | 
			
		||||
echo "Done Downloading the game files."
 | 
			
		||||
sudo rm -r .env
 | 
			
		||||
# 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."
 | 
			
		||||
 | 
			
		||||
# Remove existing .env file if exists
 | 
			
		||||
sudo rm -r .env >> "$log_file" 2>&1
 | 
			
		||||
 | 
			
		||||
# Write environment variables to .env file
 | 
			
		||||
echo "# database
 | 
			
		||||
POSTGRES_USER=postgres
 | 
			
		||||
POSTGRES_PASSWORD=$dbpass
 | 
			
		||||
@@ -69,11 +106,17 @@ WEB_SENDGRID_KEY=
 | 
			
		||||
GAME_ADDRESS=$ipadd
 | 
			
		||||
GAME_LOGIN_PORT=6112" > .env
 | 
			
		||||
 | 
			
		||||
log "Environment variables written to .env file."
 | 
			
		||||
 | 
			
		||||
# Final message
 | 
			
		||||
echo "Done!"
 | 
			
		||||
log "Setup completed."
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Run the game if chosen
 | 
			
		||||
if [ "$run_game" == "y" ] || [ "$run_game" == "Y" ]; then
 | 
			
		||||
    sudo docker-compose up
 | 
			
		||||
    log_firstrun "Running the game..."
 | 
			
		||||
    sudo docker-compose up >> "$firstrun_log" 2>&1
 | 
			
		||||
else
 | 
			
		||||
    echo "You chose not to run the game. To run the game later, execute the command: cd wand && sudo docker-compose up"
 | 
			
		||||
    log "Game not started."
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user