47 lines
No EOL
2.3 KiB
Bash
47 lines
No EOL
2.3 KiB
Bash
#!/bin/bash
|
|
|
|
echo "[BOOTSTRAP] Running initial setup for BOOP..."
|
|
|
|
mysql -u root -e "CREATE DATABASE IF NOT EXISTS oauth_provider;"
|
|
password=$(openssl rand -base64 32)
|
|
password=$(echo $password | sed 's/[^a-zA-Z0-9]//g')
|
|
echo $password > /home/coder/oauth-provider/.dbpass
|
|
mysqladmin -u root password $password 2>&1 | grep -V "Warning"
|
|
mysql -u root -p$password -e "CREATE USER 'oauth_provider'@'%' IDENTIFIED BY '$password';" 2>&1 | grep -V "Warning"
|
|
mysql -u root -p$password -e "GRANT ALL PRIVILEGES ON oauth_provider.* TO 'oauth_provider'@'%';" 2>&1 | grep -V "Warning"
|
|
mysql -u root -p$password -e "FLUSH PRIVILEGES;" 2>&1 | grep -V "Warning"
|
|
chown coder:coder /home/coder/oauth-provider/.dbpass
|
|
|
|
echo "[BOOTSTRAP] DB Configured, setting up .env file..."
|
|
|
|
# read /home/coder/.coder-env as they contain the workspace name and username
|
|
|
|
echo "[BOOTSTRAP] Generating Encryption Secret"
|
|
|
|
encryption_secret=$(openssl rand -base64 64)
|
|
encryption_secret=$(echo $encryption_secret | sed 's/[^a-zA-Z0-9]//g')
|
|
|
|
while [ ${#encryption_secret} -lt 64 ]
|
|
do
|
|
encryption_secret_2=$(openssl rand -base64 64)
|
|
encryption_secret_2=$(echo $encryption_secret_2 | sed 's/[^a-zA-Z0-9]//g')
|
|
encryption_secret=$encryption_secret$encryption_secret_2
|
|
done
|
|
encryption_secret=${encryption_secret:0:64}
|
|
|
|
|
|
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/oauth-provider/.env
|
|
sed -i "s/DATABASE_PORT=/DATABASE_PORT=3306/g" /home/coder/oauth-provider/.env
|
|
sed -i "s/DATABASE_USER=/DATABASE_USER=oauth_provider/g" /home/coder/oauth-provider/.env
|
|
sed -i "s/DATABASE_PASSWORD=/DATABASE_PASSWORD=$password/g" /home/coder/oauth-provider/.env
|
|
sed -i "s/DATABASE_NAME=/DATABASE_NAME=oauth_provider/g" /home/coder/oauth-provider/.env
|
|
sed -i "s/REDIS_HOST=/REDIS_HOST=localhost/g" /home/coder/oauth-provider/.env
|
|
sed -i "s/REDIS_PORT=/REDIS_PORT=6379/g" /home/coder/oauth-provider/.env
|
|
sed -i "s/BASE_LOCAL_URL=/BASE_LOCAL_URL=https:\/\/3123--$WORKSPACE_ENV--$USERNAME_ENV.coder.kakio.us/g" /home/coder/oauth-provider/.env
|
|
echo "" >> /home/coder/oauth-provider/.env
|
|
echo "ENCRYPTION_SECRET=$encryption_secret" >> /home/coder/oauth-provider/.env
|
|
|
|
echo "[BOOTSTRAP] Done!" |