mirror of
https://github.com/N0rthernL1ghts/wordpress.git
synced 2024-11-23 12:01:51 +01:00
Add wp init script
This commit is contained in:
parent
90645d32bd
commit
cfa873fd4b
1
bin/init-wp
Symbolic link
1
bin/init-wp
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../src/init-utils/init-wp
|
51
src/init-utils/init-wp
Executable file
51
src/init-utils/init-wp
Executable file
|
@ -0,0 +1,51 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
get-repository-root() {
|
||||||
|
git rev-parse --show-toplevel
|
||||||
|
}
|
||||||
|
|
||||||
|
generate-secrets-password() {
|
||||||
|
set -e
|
||||||
|
local length="${1:?}"
|
||||||
|
local secret="${2:?}"
|
||||||
|
|
||||||
|
# Set path to the secret file
|
||||||
|
local secretPath="${SCRIPT_ROOT}/.secrets/${secret}.txt"
|
||||||
|
|
||||||
|
if [ -f "${secretPath}" ] && [ -s "${secretPath}" ]; then
|
||||||
|
echo "> Not overwritting already existing secret ${secret}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
export LC_ALL=C
|
||||||
|
|
||||||
|
local randomString
|
||||||
|
randomString="$(tr -dc 'a-zA-Z0-9!@#$%^&*()-=_+[]{};:,.<>?`~' </dev/urandom | head -c "${length}")"
|
||||||
|
|
||||||
|
echo "> Writting ${#randomString} bytes to ${secretPath}"
|
||||||
|
echo -n "${randomString}" >"${secretPath}"
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
SCRIPT_ROOT="$(get-repository-root)"
|
||||||
|
export SCRIPT_ROOT
|
||||||
|
|
||||||
|
mkdir -p "${SCRIPT_ROOT}/.secrets" &
|
||||||
|
mkdir -p "${SCRIPT_ROOT}/data" &
|
||||||
|
wait
|
||||||
|
|
||||||
|
generate-secrets-password 32 wordpress_database_password &
|
||||||
|
generate-secrets-password 32 database_root_password &
|
||||||
|
wait
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "WORDPRESS_DB_USER='wordpress'"
|
||||||
|
echo "WORDPRESS_DB_NAME='wordpress'"
|
||||||
|
echo "WORDPRESS_DB_PASSWORD='$(cat "${SCRIPT_ROOT}/.secrets/wordpress_database_password.txt")'"
|
||||||
|
echo "WORDPRESS_DB_HOST='database'"
|
||||||
|
} >"${SCRIPT_ROOT}/.secrets/wp-database.env"
|
||||||
|
|
||||||
|
echo "Rewrote ${SCRIPT_ROOT}/.secrets/wp-database.env file"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
Loading…
Reference in New Issue
Block a user