mirror of
https://github.com/solero/wand.git
synced 2024-11-23 22:17:36 +00:00
Now I'm logging the First Run and the installation process
This commit is contained in:
parent
c8bdf9227e
commit
d5136cde94
101
install.sh
101
install.sh
@ -1,52 +1,89 @@
|
|||||||
#!/bin/bash
|
#!/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
|
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):"
|
# Function to read password silently
|
||||||
dbpass=""
|
read_password() {
|
||||||
while IFS= read -r -s -n1 char; do
|
local password=""
|
||||||
if [[ -z $char ]]; then
|
while IFS= read -r -s -n1 char; do
|
||||||
break
|
if [[ -z $char ]]; then
|
||||||
elif [[ $char == $'\177' ]]; then # handle backspace
|
break
|
||||||
if [ ${#dbpass} -gt 0 ]; then
|
elif [[ $char == $'\177' ]]; then # handle backspace
|
||||||
dbpass="${dbpass%?}" # remove last character
|
if [ ${#password} -gt 0 ]; then
|
||||||
echo -ne '\b \b' # erase last character on the screen
|
password="${password%?}" # remove last character
|
||||||
|
echo -ne '\b \b' # erase last character on the screen
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -n '*'
|
||||||
|
password+="$char"
|
||||||
fi
|
fi
|
||||||
else
|
done
|
||||||
echo -n '*'
|
echo "$password"
|
||||||
dbpass+="$char"
|
}
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
# 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
|
if [ -z "$dbpass" ]; then
|
||||||
dbpass=$(openssl rand -base64 12)
|
dbpass=$(openssl rand -base64 12)
|
||||||
|
log "Generated random database password."
|
||||||
fi
|
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
|
read hostname
|
||||||
if [ -z "$hostname" ]; then
|
if [ -z "$hostname" ]; then
|
||||||
hostname=localhost
|
hostname=localhost
|
||||||
fi
|
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
|
read ipadd
|
||||||
if [ -z "$ipadd" ]; then
|
if [ -z "$ipadd" ]; then
|
||||||
ipadd=127.0.0.1
|
ipadd=127.0.0.1
|
||||||
fi
|
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
|
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."
|
# Setting up environment
|
||||||
sudo apt update
|
log "Setting up the environment."
|
||||||
sudo apt install docker.io git curl -y
|
sudo apt update >> "$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
|
sudo apt install docker.io git curl -y >> "$log_file" 2>&1
|
||||||
sudo chmod +x /usr/local/bin/docker-compose
|
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
|
||||||
echo "Done setting up the environment."
|
sudo chmod +x /usr/local/bin/docker-compose >> "$log_file" 2>&1
|
||||||
echo "Downloading Game Files"
|
log "Environment setup completed."
|
||||||
git clone --recurse-submodules https://github.com/solero/wand && cd wand
|
|
||||||
echo "Done Downloading the game files."
|
|
||||||
sudo rm -r .env
|
|
||||||
|
|
||||||
|
# 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
|
echo "# database
|
||||||
POSTGRES_USER=postgres
|
POSTGRES_USER=postgres
|
||||||
POSTGRES_PASSWORD=$dbpass
|
POSTGRES_PASSWORD=$dbpass
|
||||||
@ -69,11 +106,17 @@ WEB_SENDGRID_KEY=
|
|||||||
GAME_ADDRESS=$ipadd
|
GAME_ADDRESS=$ipadd
|
||||||
GAME_LOGIN_PORT=6112" > .env
|
GAME_LOGIN_PORT=6112" > .env
|
||||||
|
|
||||||
|
log "Environment variables written to .env file."
|
||||||
|
|
||||||
|
# Final message
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
log "Setup completed."
|
||||||
|
|
||||||
|
# Run the game if chosen
|
||||||
if [ "$run_game" == "y" ] || [ "$run_game" == "Y" ]; then
|
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
|
else
|
||||||
echo "You chose not to run the game. To run the game later, execute the command: cd wand && sudo docker-compose up"
|
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
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user