From 3c5e9aba3afff8fb82223820cb252a10cdc92f61 Mon Sep 17 00:00:00 2001 From: Basil Hendroff <63370329+basilhendroff@users.noreply.github.com> Date: Sat, 2 Jan 2021 15:16:13 +0800 Subject: [PATCH] Sanity check WP_ROOT In a worst case, WP_ROOT="path/to/site/" in the config file. This gets normalised to WP_ROOT="/path to/site" --- wordpress-jail.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/wordpress-jail.sh b/wordpress-jail.sh index 5ba0964..73f0c61 100755 --- a/wordpress-jail.sh +++ b/wordpress-jail.sh @@ -89,9 +89,15 @@ if [ -n "${FILES_PATH}" ] || [ -n "${DB_PATH}" ]; then print_err "Configuration error: WP_ROOT replaces FILES_PATH and DB_PATH in newer script versions. Update ${CONFIG_NAME} and run the script again." exit 1 fi - -DB_PATH=${POOL_PATH}${WP_ROOT%/}/db -FILES_PATH=${POOL_PATH}${WP_ROOT%/}/files +if [ ${WP_ROOT:0:1} != "/" ]; then + WP_ROOT="/${WP_ROOT%/}" +fi +# Check that this is a new installation +if [ -e "${POOL_PATH}${WP_ROOT}" ] +then + print_err "This script only works for new installations. The script cannot proceed if WP_ROOT exists." + exit 1 +fi # Extract IP and netmask, sanity check netmask IP=$(echo ${JAIL_IP} | cut -f1 -d/) @@ -105,13 +111,6 @@ then NETMASK="24" fi -# Check that this is a new installation -if [ -e "${POOL_PATH}${WP_ROOT}" ] -then - print_err "This script only works for new installations. The script cannot proceed if WP_ROOT exists." - exit 1 -fi - # Reuse the password file if it exists and is valid if ! [ -e "/root/${JAIL_NAME}_db_password.txt" ]; then DB_PASSWORD=$(rand 24) @@ -160,6 +159,9 @@ rm /tmp/pkg.json ##################################################################### print_msg "Directory Creation and Mounting..." +DB_PATH=${POOL_PATH}${WP_ROOT}/db +FILES_PATH=${POOL_PATH}${WP_ROOT}/files + mkdir -p "${DB_PATH}" chown -R 88:88 "${DB_PATH}" iocage fstab -a "${JAIL_NAME}" "${DB_PATH}" /var/db/mysql nullfs rw 0 0