docker-images/boop-keys/setup-boop.sh

47 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2023-07-21 15:35:02 +00:00
#!/bin/bash
2023-07-21 15:57:36 +00:00
echo "[BOOTSTRAP] Running initial setup for BOOP..."
2023-07-21 15:35:02 +00:00
mysql -u root -e "CREATE DATABASE IF NOT EXISTS oauth_provider;"
password=$(openssl rand -base64 32)
2023-07-21 20:32:43 +00:00
password=$(echo $password | sed 's/[^a-zA-Z0-9]//g')
2023-07-21 15:35:02 +00:00
echo $password > /home/coder/oauth-provider/.dbpass
2023-07-21 20:42:33 +00:00
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"
2023-07-21 15:35:02 +00:00
chown coder:coder /home/coder/oauth-provider/.dbpass
2023-07-21 15:57:36 +00:00
echo "[BOOTSTRAP] DB Configured, setting up .env file..."
2023-07-21 15:35:02 +00:00
# read /home/coder/.coder-env as they contain the workspace name and username
2023-07-21 16:17:36 +00:00
echo "[BOOTSTRAP] Generating Encryption Secret"
2023-07-21 20:32:43 +00:00
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}
2023-07-21 16:17:36 +00:00
2023-07-21 16:13:42 +00:00
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)
2023-07-21 15:35:02 +00:00
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
2023-07-23 17:57:54 +00:00
sed -i "s/BASE_LOCAL_URL=/BASE_LOCAL_URL=https:\/\/boop--main--$WORKSPACE_ENV--$USERNAME_ENV.coder.kakio.us/g" /home/coder/oauth-provider/.env
2023-07-21 16:17:36 +00:00
echo "" >> /home/coder/oauth-provider/.env
echo "ENCRYPTION_SECRET=$encryption_secret" >> /home/coder/oauth-provider/.env
2023-07-21 15:35:02 +00:00
2023-07-21 16:17:36 +00:00
echo "[BOOTSTRAP] Done!"