#!/usr/bin/env bash # Provision a blank DokuWiki install and configure it for general use. # The root location may exist or not, depending on your needs, and you # should aim not to change this file, instead providing a specific # configuration script that sources this file. # To use this in Vagrant, call your provisioning script, and set the # shell environment variables, DW_DOWNLOAD, DW_PACKAGE, DW_PATH, # DW_TITLE, DW_ADMIN_EMAIL, and DW_ADMIN_PASS. # Configuration ======================================================== # Script constants ----------------------------------------------------- PROVISION_TIME=$(date '+%Y-%m-%dT%H:%M:%S%:z') SUCCESS=0 FAILURE=1 # Script variables ----------------------------------------------------- dw_download="${DW_DOWNLOAD}" dw_package="${DW_PACKAGE}" dw_path="${DW_PATH}" dw_title="${DW_TITLE}" dw_admin_email="${DW_ADMIN_EMAIL}" dw_admin_pass="${DW_ADMIN_PASS}" # Installation steps =================================================== function prepare_dokuwiki_path { if [[ -d "${dw_path}" ]] ; then echo "DokuWiki path ${dw_path} already exists" return ${SUCCESS} fi echo "Making DokuWiki path ${dw_path}" mkdir -p "${dw_path}" status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then echo "Error ${status} from mkdir while making DokuWiki path ${dw_path}" return ${FAILURE} fi if [[ ! -d "${dw_path}" ]] ; then echo "No error from mkdir, but DokuWiki path ${dw_path} doesn't exist" return ${FAILURE} fi } function download_dokuwiki { if [[ -e "${dw_package}" ]] ; then echo "DokuWiki package ${dw_package} is already downloaded" echo "If you want to replace it, delete this file" return ${SUCCESS} fi echo "Downloading DokuWiki from ${dw_download}" curl --output "${dw_package}" --silent --show-error "${dw_download}" status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then echo "Error ${status} from curl while dowloading DokuWiki from ${dw_download}" return ${FAILURE} fi if [[ -e "${dw_package}" ]] ; then echo "Downloaded DokuWiki package ${dw_package}" return ${SUCCESS} else echo "No error from curl, but ${dw_package} doesn't exist" return ${FAILURE} fi } function unpack_dokuwiki { if [[ ! -e "${dw_package}" ]] ; then echo "No package ${dw_package} to unpack" return ${FAILURE} fi # Check for a container directory in the archive in the format dokuwiki-nnnn-nn-nnx/ contained_files=$(tar -tf "${dw_package}" | grep '^dokuwiki-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][a-z]\?/' | wc -l) # echo "There are ${contained_files} contained files in the package" if [[ ${contained_files} -gt 0 ]] ; then # DokuWiki's files are in a container strip_components=1 echo "Stripping container directory from the compressed files" else strip_components=0 fi echo "Unpacking DokuWiki into ${dw_path}" tar --strip ${strip_components} --directory="${dw_path}" -zxf "${dw_package}" status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then echo "Error ${status} from tar while unpacking DokuWiki from ${dw_package}" return ${FAILURE} fi if [[ ! -e "${dw_path}/doku.php" ]] ; then echo "No error from tar, but DokuWiki isn't unpacked in ${dw_path}" return ${FAILURE} fi echo "DokuWiki unpacked in ${dw_path}" return ${SUCCESS} } function configure_dokuwiki { if [[ -e "${dw_path}/conf/local.php" ]] ; then echo "DokuWiki is already configured in ${dw_path}/conf/local.php" echo "If you want to replace the configuration, delete this file" return ${SUCCESS} fi if [[ ! -d "${dw_path}/conf" ]] ; then echo "Install didn't prepare a conf directory for DokuWiki" return ${FAILURE} fi # Local configuration -------------------------------------------------- config_file="${dw_path}/conf/local.php" cat > "${config_file}" <> "${config_file}" <<'EOF' $conf['lang'] = 'en'; $conf['license'] = '0'; $conf['useacl'] = 1; $conf['superuser'] = '@admin'; $conf['disableactions'] = 'register'; $conf['allowdebug'] = 1; EOF if [[ ! -e "${config_file}" ]] ; then echo "No error from cat command, but DokuWiki isn't configured in ${config_file}" return ${FAILURE} fi # ACL configuration ---------------------------------------------------- config_file="${dw_path}/conf/acl.auth.php" cat > "${config_file}" < # Don't modify the lines above # # Access Control Lists # # Auto-generated by Vagrant provisioning # Date: ${PROVISION_TIME} * @ALL 1 * @user 8 EOF if [[ ! -e "${config_file}" ]] ; then echo "No error from cat command, but DokuWiki isn't configured in ${config_file}" return ${FAILURE} fi # User configuration --------------------------------------------------- DW_ADMIN_HASH=$(cd "${dw_path}" ; php /vagrant/dokuwiki_password.php "${DW_ADMIN_PASS}") config_file="${dw_path}/conf/users.auth.php" cat > "${config_file}" < # Don't modify the lines above # # Userfile # # Format: # # login:passwordhash:Real Name:email:groups,comma,seperated # # Auto-generated by Vagrant provisioning # Date: ${PROVISION_TIME} EOF cat >> "${config_file}" < "${config_file}" <> "${config_file}" <<'EOF' $plugins['authad'] = 0; $plugins['authldap'] = 0; $plugins['authmysql'] = 0; $plugins['authpgsql'] = 0; EOF if [[ ! -e "${config_file}" ]] ; then echo "No error from cat command, but DokuWiki isn't configured in ${config_file}" return ${FAILURE} fi echo "DokuWiki configured in ${dw_path}/conf" return ${SUCCESS} } # Full installation function =========================================== function install_dokuwiki { if [[ -e "${dw_path}/doku.php" ]] ; then echo "DokuWiki is already installed" return ${SUCCESS} fi prepare_dokuwiki_path status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then return ${status} fi download_dokuwiki status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then return ${status} fi unpack_dokuwiki status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then return ${status} fi configure_dokuwiki status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then return ${status} fi return ${SUCCESS} } # Script =============================================================== install_dokuwiki status=$? if [[ ${status} -gt ${SUCCESS} ]] ; then exit ${status} fi