mirror of
https://github.com/solero/wand.git
synced 2024-11-09 23:18:21 +00:00
Now I'm logging the First Run and the installation process
This commit is contained in:
parent
c8bdf9227e
commit
d5136cde94
89
install.sh
89
install.sh
@ -1,52 +1,89 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
clear
|
|
||||||
echo "Please answer these questions to set up the game:"
|
|
||||||
|
|
||||||
echo "Enter password for the database (leave empty for a random password):"
|
log_file="wand/logs/installLog.txt"
|
||||||
dbpass=""
|
firstrun_log="wand/logs/firstrun.txt"
|
||||||
while IFS= read -r -s -n1 char; do
|
|
||||||
|
# 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
|
||||||
|
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
|
if [[ -z $char ]]; then
|
||||||
break
|
break
|
||||||
elif [[ $char == $'\177' ]]; then # handle backspace
|
elif [[ $char == $'\177' ]]; then # handle backspace
|
||||||
if [ ${#dbpass} -gt 0 ]; then
|
if [ ${#password} -gt 0 ]; then
|
||||||
dbpass="${dbpass%?}" # remove last character
|
password="${password%?}" # remove last character
|
||||||
echo -ne '\b \b' # erase last character on the screen
|
echo -ne '\b \b' # erase last character on the screen
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -n '*'
|
echo -n '*'
|
||||||
dbpass+="$char"
|
password+="$char"
|
||||||
fi
|
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
|
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