mirror of
https://github.com/oupala/apaxy.git
synced 2025-08-20 12:52:49 +02:00
refactor: large rewrite of install script
This commit is contained in:
229
apaxy-configure.sh
Executable file → Normal file
229
apaxy-configure.sh
Executable file → Normal file
@@ -1,69 +1,200 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
echo "Apaxy Configurator - by Jordan Bancino"
|
#
|
||||||
echo "Checking configuration..."
|
# apaxy configurator
|
||||||
|
# v0.2
|
||||||
|
# configure apaxy according to your local paths and configuration
|
||||||
|
# author : Jordan Bancino and Ploc
|
||||||
|
# contact : jordan [@] bancino.net
|
||||||
|
# licence : GPLv3
|
||||||
|
|
||||||
CONFIG="apaxy.config"
|
# enabling strict mode
|
||||||
|
# -e - exit immediatly on error (disable with "+e" when an error can happens, then enable it again with "-e")
|
||||||
|
# -u - undefined variables are forbidden (enable this option after getting parameters from $1 $2...) see below
|
||||||
|
# -o pipefail - find error return code inside piped commands
|
||||||
|
# IFS - set strong internal field separator
|
||||||
|
set -eo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
if [ -f "$CONFIG" ]; then
|
# default config
|
||||||
. "$CONFIG"
|
defaultLogLevel=2
|
||||||
else
|
defaultLogFile="$(basename "${0}" .sh).log"
|
||||||
echo "Apaxy configuration not found! Please restore or create the configuration file: $CONFIG"
|
defaultApacheWebRootPath="/var/www/html"
|
||||||
exit 1
|
defaultInstallWebPath=""
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -v INSTALL_DIRECTORY ] && [ -v WEB_ROOT ]; then
|
# functions
|
||||||
echo "- Configuring Apaxy for use in directory: $INSTALL_DIRECTORY (Web root: $WEB_ROOT)"
|
|
||||||
mkdir -p "$WEB_ROOT$INSTALL_DIRECTORY"
|
###
|
||||||
if [ ! -w "$WEB_ROOT$INSTALL_DIRECTORY" ] || [ ! -d "$WEB_ROOT$INSTALL_DIRECTORY" ]; then
|
# display help
|
||||||
echo "Directory does not exist or is not writable by the current user: $WEB_ROOT$INSTALL_DIRECTORY"
|
##
|
||||||
exit 1
|
displayHelp () {
|
||||||
|
cat <<EOF
|
||||||
|
$(basename "${0}") configure apaxy according to your local paths and configuration.
|
||||||
|
|
||||||
|
It can either configure apaxy according to your local paths and configuration bu it can also install the required files in your http server path.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
displayUsage
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
Available optionnal parameters are :
|
||||||
|
-h - display help
|
||||||
|
-d - set path/to/dir/ directory where apaxy will be installed on the filesystem
|
||||||
|
-w - set path/to/dir/ directory where apaxy will be available on the httpd server
|
||||||
|
-ll - set the log level
|
||||||
|
-lf - set the log file
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# display usage
|
||||||
|
##
|
||||||
|
displayUsage () {
|
||||||
|
cat <<EOF
|
||||||
|
usage - $(basename "${0}") [-h] [-d path/to/dir/] [-w path/to/dir/] [-ll logLevel] [-lf logFile]
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# log a message
|
||||||
|
#
|
||||||
|
# @global $logLevel the log level
|
||||||
|
# @global $logFile the log file
|
||||||
|
# @param $1 the log level of the message
|
||||||
|
# @param $2 the log message
|
||||||
|
##
|
||||||
|
log () {
|
||||||
|
local paramLogLevel="${1}"
|
||||||
|
local paramLogMessage="${2}"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2155
|
||||||
|
local logDate="$(date +%H:%M:%S)"
|
||||||
|
local logMessage="[${logDate}] ${paramLogMessage}"
|
||||||
|
|
||||||
|
if [ "${paramLogLevel}" -le "${logLevel}" ]
|
||||||
|
then
|
||||||
|
echo "${logMessage}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "${logFile}" ]
|
||||||
|
then
|
||||||
|
echo "${logMessage}" >> "${logFile}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# getting parameters value from config file (can be overloaded by cli values)
|
||||||
|
workingDirectory=$(dirname "$0")
|
||||||
|
|
||||||
|
if [ -f "${workingDirectory}/apaxy.config" ]; then
|
||||||
|
# shellcheck source=apaxy.config
|
||||||
|
source "${workingDirectory}/apaxy.config"
|
||||||
else
|
else
|
||||||
echo "No directory specified! Please define the INSTALL_DIRECTORY and WEB_ROOT variables in $CONFIG"
|
log 1 "ERROR - apaxy configuration not found, please restore or create the configuration file apaxy.config"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Copying files to web root..."
|
# getting parameters value from cli (can overload config file values)
|
||||||
cp -r . "$WEB_ROOT$INSTALL_DIRECTORY"
|
while [ "$#" -ge 1 ] ; do
|
||||||
cd "$WEB_ROOT$INSTALL_DIRECTORY"
|
case "${1}" in
|
||||||
|
-h|--help) # display help
|
||||||
|
displayHelp
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-d) # set path/to/dir/ directory where apaxy will be available on the httpd server
|
||||||
|
shiftStep=2
|
||||||
|
apacheWebRootPath="${2}"
|
||||||
|
;;
|
||||||
|
-w) # set path/to/dir/ directory where apaxy will be installed on the filesystem
|
||||||
|
shiftStep=2
|
||||||
|
installWebPath="${2}"
|
||||||
|
;;
|
||||||
|
-ll) # set the log level
|
||||||
|
shiftStep=2
|
||||||
|
logLevel="${2}"
|
||||||
|
;;
|
||||||
|
-lf) # set the log file
|
||||||
|
shiftStep=2
|
||||||
|
logFile="${2}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
displayUsage
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [ -v HTACCESS ]; then
|
if [ "$#" -ge "${shiftStep}" ]
|
||||||
if [ -f "$HTACCESS" ]; then
|
then
|
||||||
echo "- Using template: $HTACCESS to generate configuration"
|
shift "${shiftStep}"
|
||||||
else
|
else
|
||||||
echo "Configuration template does not exist! Please specify an existing configuration template in $CONFIG"
|
log 1 "ERROR - invalid number of arguments"
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# setting parameters value
|
||||||
|
if [ -z "${apacheWebRootPath}" ]
|
||||||
|
then
|
||||||
|
apacheWebRootPath="${defaultApacheWebRootPath}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${installWebPath}" ]
|
||||||
|
then
|
||||||
|
installWebPath="${defaultInstallWebPath}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${apacheWebRootPath}" ] && [ -z "${installWebPath}" ]
|
||||||
|
then
|
||||||
|
installDir="${apacheWebRootPath}"
|
||||||
else
|
else
|
||||||
echo "No configuration template specified. Please define the HTACCESS variable in $CONFIG"
|
installDir="${apacheWebRootPath}${installWebPath}"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -v TEMPLATE_VAR_FOLDERNAME ]; then
|
if [ -z "${logLevel}" ]
|
||||||
echo "No foldername variable defined. Please define the TEMPLATE_VAR_FOLDERNAME variable in $CONFIG"
|
then
|
||||||
exit
|
logLevel="${defaultLogLevel}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Configuring..."
|
if [ -z "${logFile}" ]
|
||||||
echo "- Generating .htaccess..."
|
then
|
||||||
sed "s|$TEMPLATE_VAR_FOLDERNAME|$INSTALL_DIRECTORY/apaxy/|g" <"$HTACCESS" >"$HTACCESS_OUTPUT"
|
logFile="${workingDirectory}/${defaultLogFile}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "- Setting variables in documents..."
|
# enabling strict mode
|
||||||
# find all the HTML files and replace the variable in them.
|
# -u - undefined variables are forbidden (enable this option after getting parameters from $1 $2...)
|
||||||
# This will automatically take care of the error pages, headers and
|
set -u
|
||||||
# footers.
|
|
||||||
FILES=$(find -name "*.html")
|
# checking parameters value
|
||||||
|
if [ ! -d "$(dirname "${logFile}")" ]
|
||||||
|
then
|
||||||
|
log 1 "ERROR - $(dirname "${logFile}") does not exist"
|
||||||
|
exit 4
|
||||||
|
fi
|
||||||
|
|
||||||
|
# script
|
||||||
|
log 1 "- creating install directory ${installDir}"
|
||||||
|
mkdir -p "${installDir}"
|
||||||
|
if [ ! -d "${installDir}" ] || [ ! -w "${installDir}" ]; then
|
||||||
|
log 1 "ERROR - install directory ${installDir} does not exist or is not writable by the current user"
|
||||||
|
exit 5
|
||||||
|
fi
|
||||||
|
|
||||||
|
log 1 "- copying apaxy in install directory"
|
||||||
|
cp -r apaxy/* "${installDir}/"
|
||||||
|
|
||||||
|
log 1 "- configuring apaxy in install directory"
|
||||||
|
|
||||||
|
log 2 "- generating htaccess"
|
||||||
|
sed "s|{FOLDERNAME}|${installWebPath}|g" < "${installDir}/htaccess.txt" > "${installDir}/.htaccess"
|
||||||
|
rm "${installDir}/htaccess.txt"
|
||||||
|
|
||||||
|
# find all the html files and replace the variable in them
|
||||||
|
# this will automatically take care of the error pages, headers and footers
|
||||||
|
log 2 "- setting path in html files"
|
||||||
|
files=$(find ${installDir} -name "*.html")
|
||||||
while read -r file; do
|
while read -r file; do
|
||||||
sed -i "s|$TEMPLATE_VAR_FOLDERNAME|$INSTALL_DIRECTORY/apaxy/|g" "$file"
|
sed -i "s|{FOLDERNAME}|${installWebPath}|g" "${file}"
|
||||||
done <<< "$FILES"
|
done <<< "${files}"
|
||||||
|
|
||||||
if [ -v THEME_HTACCESS_IN ] && [ -v THEME_HTACCESS_OUT ]; then
|
log 2 "- syncing filesystem"
|
||||||
echo "- Activating theme configuration..."
|
sync
|
||||||
mv "$THEME_HTACCESS_IN" "$THEME_HTACCESS_OUT"
|
log 1 "- filesystem has been synced and is now consistent"
|
||||||
fi
|
log 1 "- apaxy has been successfully configured and installed in ${installDir}"
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# - Implement any other options we want here
|
|
||||||
|
|
||||||
echo "Done."
|
|
||||||
exit 0
|
|
||||||
|
77
apaxy.config
77
apaxy.config
@@ -1,45 +1,44 @@
|
|||||||
# Apaxy Configuration - by Jordan Bancino
|
#!/bin/bash
|
||||||
# (C) 2018 Jordan Bancino <jordan@bancin0.com>
|
|
||||||
#
|
#
|
||||||
# Use "apaxy-configure.sh" to configure Apaxy after adjusting the needed values.
|
# apaxy configurator
|
||||||
|
# v0.2
|
||||||
|
# use "apaxy-configure.sh" to configure apaxy after adjusting the needed values in this file
|
||||||
|
# author : Jordan Bancino and Ploc
|
||||||
|
# contact : jordan [@] bancino.net
|
||||||
|
# licence : GPLv3
|
||||||
|
|
||||||
|
# default log level on the console (the lower the number is, the less verbose it is)
|
||||||
|
#defaultLogLevel=2
|
||||||
|
|
||||||
|
# all log messages are written to log file
|
||||||
|
#defaultLogFile="apaxy.log"
|
||||||
|
|
||||||
|
# the apache web root path where the server serves documents
|
||||||
#
|
#
|
||||||
# NOTICE: Directories can be absolute or relative, but make sure they start with either "/", "../", or "./",
|
# default for apache is /var/www/html
|
||||||
# and DO NOT leave a trailing slash.
|
|
||||||
# Good: "/var/www/html" <- Starts with "/", does not have trailing slash
|
|
||||||
# Bad : "var/www/html" <- Does not start with "/", "./", or "../"
|
|
||||||
# Good: "./var/www/html" <- Starts with "./", does not have trailing slash
|
|
||||||
# Bad : "/var/www/html/" <- Has trailing slash
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# GENERAL CONFIGURATION
|
# note that path should be absolute, so make sure it starts with a "/"
|
||||||
|
# and DO NOT leave a trailing slash
|
||||||
#
|
#
|
||||||
|
# good: "/var/www/html" <- starts with "/", does not have trailing "/"
|
||||||
# The directory to configure Apaxy for use in. This is relative to the web server root, and contains the "theme" folder.
|
# bad : "var/www/html/" <- does not start with "/", have a trailing "/"
|
||||||
# For instance: "http://website.com/share" would make this value "/share", where "/share/apaxy/theme" is the theme directory
|
|
||||||
INSTALL_DIRECTORY="/dev/apaxy-deploy"
|
|
||||||
|
|
||||||
# The web root where the server serves documents. Default for Apache is /var/www/html
|
|
||||||
WEB_ROOT="/var/www/html"
|
|
||||||
|
|
||||||
# The output .htaccess file.
|
|
||||||
# Place the file in the root of the directory in which you are applying apaxy.
|
|
||||||
HTACCESS_OUTPUT="$WEB_ROOT$INSTALL_DIRECTORY/.htaccess"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# ADVANCED CONFIGURATION
|
apacheWebRootPath="/var/www/html"
|
||||||
# Normal users: Do not modify below this line.
|
|
||||||
|
# the directory where apaxy will be used (this is relative to the web server root, and contains the "theme" folder)
|
||||||
#
|
#
|
||||||
|
# for instance: "http://example.org/share" would make this value "/share", where "/share/theme" is the theme directory
|
||||||
# The htaccess template to run the configuration on.
|
#
|
||||||
# Do not change this value for a regular installation of Apaxy.
|
# note that path should be absolute, so make sure it starts with a "/"
|
||||||
HTACCESS="apaxy/htaccess.txt"
|
# and DO NOT leave a trailing slash
|
||||||
|
#
|
||||||
# The theme config for Apaxy. IN will be renamed to OUT.
|
# good: "/share" <- starts with "/", does not have trailing "/"
|
||||||
# There should be no reason to change this in most cases.
|
# bad : "share/" <- does not start with "/", has a trailing "/"
|
||||||
THEME_HTACCESS_IN="apaxy/theme/htaccess.txt"
|
#
|
||||||
THEME_HTACCESS_OUT="apaxy/theme/.htaccess"
|
# by default, apaxy is configured to be installed at the root level of your web server
|
||||||
|
#
|
||||||
|
# if you want apaxy to be installed anywhere else, you can set it in the installWebPath variable
|
||||||
# The variable in the htaccess and footer templates.
|
#
|
||||||
# Do not change this value unless you use a different template with a different variable.
|
# installWebPath="/share"
|
||||||
TEMPLATE_VAR_FOLDERNAME="/{FOLDERNAME}/"
|
#
|
||||||
|
installWebPath=""
|
||||||
|
Reference in New Issue
Block a user