mirror of
https://github.com/cydrobolt/polr.git
synced 2024-11-09 11:42:28 +01:00
Various updates for .env
* If the user has manually created a .env file, we use that wherever possible, otherwise we generate our environment variables file from copying and editing the .env.setup file. This will be used by docker-compose to set environment variables inside the container. * The startup script no longer creates a .env file if it doesnt exist, we simply create the symlink for it so that if it ever exists in future, it will persist in our volume. * If the .env file does exist inside the container on startup, we make sure tha the website can write to the file for the setup page's needs.
This commit is contained in:
parent
0d38ae6573
commit
59e7428d78
@ -32,41 +32,48 @@ cp docker-compose.yml.tmpl docker-compose.yml
|
||||
ROOT_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
||||
POLR_USER_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
||||
|
||||
# If there is no .env file, then we assume we have not copied
|
||||
# .env.setup to .env yet.
|
||||
echo "creating the polr .env file"
|
||||
cp $DIR/../.env.setup $DIR/.env
|
||||
|
||||
FILEPATH="$DIR/.env"
|
||||
SEARCH="# DB_CONNECTION=mysql"
|
||||
REPLACE="DB_CONNECTION=mysql"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# update the db hostname
|
||||
SEARCH="# DB_HOST=localhost"
|
||||
REPLACE="DB_HOST=db"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# uncomment the db port
|
||||
SEARCH="# DB_PORT=3306"
|
||||
REPLACE="DB_PORT=3306"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# set the database name
|
||||
SEARCH="# DB_DATABASE=homestead"
|
||||
REPLACE="DB_DATABASE=polr"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# set the database user
|
||||
SEARCH="# DB_USERNAME=homestead"
|
||||
REPLACE="DB_USERNAME=polr"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# set the database password
|
||||
SEARCH="# DB_PASSWORD=secret"
|
||||
REPLACE="DB_PASSWORD=$POLR_USER_PASSWORD"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
# If there is no .env file, create one for the user.
|
||||
if [ ! -f $DIR/.env ]; then
|
||||
echo "creating environment variables file to pass to polr container."
|
||||
|
||||
# If the user has manually created a .env file use that
|
||||
# otherwise generate one from .env.setup
|
||||
if [ -f $DIR/../.env ]; then
|
||||
cp $DIR/../.env $DIR/.env
|
||||
else
|
||||
cp $DIR/../.env.setup $DIR/.env
|
||||
|
||||
FILEPATH="$DIR/.env"
|
||||
SEARCH="# DB_CONNECTION=mysql"
|
||||
REPLACE="DB_CONNECTION=mysql"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# update the db hostname
|
||||
SEARCH="# DB_HOST=localhost"
|
||||
REPLACE="DB_HOST=db"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# uncomment the db port
|
||||
SEARCH="# DB_PORT=3306"
|
||||
REPLACE="DB_PORT=3306"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# set the database name
|
||||
SEARCH="# DB_DATABASE=homestead"
|
||||
REPLACE="DB_DATABASE=polr"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# set the database user
|
||||
SEARCH="# DB_USERNAME=homestead"
|
||||
REPLACE="DB_USERNAME=polr"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
|
||||
# set the database password
|
||||
SEARCH="# DB_PASSWORD=secret"
|
||||
REPLACE="DB_PASSWORD=$POLR_USER_PASSWORD"
|
||||
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Creating the .env.mysql file"
|
||||
|
||||
|
@ -1,14 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd /var/www/polr/
|
||||
|
||||
if ! [ -f /data/env ]; then
|
||||
cat /var/www/polr/.env.setup > /data/env
|
||||
fi
|
||||
|
||||
# set up symlink even if .env doesnt exist yet
|
||||
# but don't create it if it doesn't exist
|
||||
ln -s /data/env .env
|
||||
ln -s /data/storage /var/www/polr/.
|
||||
|
||||
ln -s /data/storage /var/www/polr/.
|
||||
mkdir -p /data/storage/app
|
||||
mkdir -p /data/storage/logs
|
||||
mkdir -p /data/storage/framework/cache
|
||||
@ -20,7 +16,10 @@ chown root:www-data -R /var/www/polr
|
||||
chmod 750 -R /var/www/polr
|
||||
|
||||
# The website needs to be able to update the .env file.
|
||||
chmod 770 /var/www/polr/.env
|
||||
# if it does exist
|
||||
if [ -f /data/env ]; then
|
||||
chmod 770 /var/www/polr/.env
|
||||
fi
|
||||
|
||||
chown root:www-data -R /data
|
||||
chmod 770 -R /data
|
||||
|
Loading…
Reference in New Issue
Block a user