33 lines
No EOL
1.4 KiB
Bash
33 lines
No EOL
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
echo "[BOOTSTRAP] Running initial setup for F.O.X. API (Node)..."
|
|
|
|
|
|
mysql -u root -e "CREATE DATABASE IF NOT EXISTS fox_api";
|
|
password=$(openssl rand -base64 32)
|
|
password=$(echo $password | sed 's/[^a-zA-Z0-9]//g')
|
|
|
|
echo $password > /home/coder/.dbpass
|
|
|
|
mysqladmin -u root password $password 2>&1 | grep -v "Warning"
|
|
mysql -u root -p$password -e "CREATE USER 'fox_api'@'%' IDENTIFIED BY '$password';" 2>&1 | grep -v "Warning"
|
|
mysql -u root -p$password -e "GRANT ALL PRIVILEGES ON fox_api.* TO 'fox_api'@'%';" 2>&1 | grep -v "Warning"
|
|
mysql -u root -p$password -e "FLUSH PRIVILEGES;" 2>&1 | grep -v "Warning"
|
|
|
|
chown coder:coder /home/coder/.dbpass
|
|
|
|
echo "[BOOTSTRAP] DB Configured, setting up .env file..."
|
|
|
|
# read /home/coder/.coder-env as they contain the workspace name and username
|
|
|
|
WORKSPACE_ENV=$(cat /home/coder/.coder-env | grep WORKSPACE_ENV | cut -d '=' -f2)
|
|
USERNAME_ENV=$(cat /home/coder/.coder-env | grep USERNAME_ENV | cut -d '=' -f2)
|
|
|
|
sed -i "s/DATABASE_HOST=10.10.30.11/DATABASE_HOST=localhost/g" /home/coder/fox-api/.env
|
|
sed -i "s/DATABASE_PORT=3306/DATABASE_PORT=3306/g" /home/coder/fox-api/.env
|
|
sed -i "s/DATABASE_USER=/DATABASE_USER=fox_api/g" /home/coder/fox-api/.env
|
|
sed -i "s/DATABASE_PASSWORD=/DATABASE_PASSWORD=$password/g" /home/coder/fox-api/.env
|
|
sed -i "s/DATABASE_NAME=/DATABASE_NAME=fox_api/g" /home/coder/fox-api/.env
|
|
|
|
sed -i "s/REDIS_HOST=127.0.0.1/REDIS_HOST=localhost/g" /home/coder/fox-api/.env
|
|
sed -i |