#!/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" echo "[BOOTSTRAP] Downloading database dump..." mkdir -p /home/coder/temp wget -q -O /home/coder/temp/schema.sql https://git.kakio.us/Furality/coder-templates/raw/branch/main/configs/fox-api/mysql/schema.sql wget -q -O /home/coder/temp/migrations.sql https://git.kakio.us/Furality/coder-templates/raw/branch/main/configs/fox-api/mysql/migration_table.sql echo "[BOOTSTRAP] Database dump downloaded." echo "[BOOTSTRAP] Importing database dump..." mysql -u root -p$password fox_api < /home/coder/temp/schema.sql mysql -u root -p$password fox_api < /home/coder/temp/migrations.sql rm -rf /home/coder/temp echo "[BOOTSTRAP] Database dump imported." chown coder:coder /home/coder/.dbpass echo "[BOOTSTRAP] DB Configured, setting up .env file..." echo "[BOOTSTRAP] Downloading .env file..." wget -q -O /home/coder/fox-api/.env https://git.kakio.us/Furality/coder-templates/raw/branch/main/configs/fox-api/example.env echo "[BOOTSTRAP] .env file downloaded." 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=/DATABASE_HOST=localhost/g" /home/coder/fox-api/.env sed -i "s/DATABASE_PORT=/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=/REDIS_HOST=localhost/g" /home/coder/fox-api/.env sed -i "s/REDIS_PORT=/REDIS_PORT=6379/g" /home/coder/fox-api/.env sed -i "s/REDIS_PASSWORD=/#REDIS_PASSWORD=/g" /home/coder/fox-api/.env sed -i "s/BASE_URL=/BASE_URL=http:\/\/$WORKSPACE_ENV-$USERNAME_ENV.coder.kakio.us/g" /home/coder/fox-api/.env