From 23f3b8ec67f41b08eb4583a64cfc8a666fed0409 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Wed, 5 Dec 2018 00:57:25 +0000 Subject: [PATCH 1/5] feat: add install script with instructions --- README.md | 19 ++++++++++++- apaxy-configure.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++ apaxy.config | 45 ++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100755 apaxy-configure.sh create mode 100755 apaxy.config diff --git a/README.md b/README.md index 50b8052..480e9fb 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,23 @@ _Sadly, visual style is all you can work with. It's not possible to alter the ge Apaxy requires an Apache(2.2.11+) enabled HTTP server. +### Quick Start +If you would like, you can automate the installation of Apaxy with the included `apaxy-configure.sh` script. + +To get started, first open `apaxy.config` in your favorite editor: + + $ vim apaxy.config + +Edit the WEB_ROOT and INSTALL_DIRECTORY variables to correspond to your server's settings, then save and exit. + +Then run the configuration script as a user that can write to the install directory. With Apache, this would be the `www-data` user: + + $ sudo -u www-data ./apaxy-configure.sh + +The files will be copied to the web server directory, and modified automatically based on the settings specified. + +### Manual Install + Let's assume you have a folder named `share` in your server root directory (the path thus being `http://mywebsite.com/share`) that you'd like to use as your listing directory: * [Download](https://github.com/AdamWhitcroft/Apaxy/archive/master.zip) and unzip Apaxy @@ -46,7 +63,7 @@ Should be changed to... AddIcon /share/theme/icons/gif.png .gif ``` -* Edit `footer.html`, `400.html`, `403.html`, `404.html`, `408.html`, `500.html`, `502.html` (now in the `/share/theme` folder) and update all instances of paths marked with *{FOLDERNAME}* to point to your site root. +* Edit `footer.html` (now in the `/share/theme` folder) and update all instances of paths marked with *{FOLDERNAME}* to point to your site root. So... diff --git a/apaxy-configure.sh b/apaxy-configure.sh new file mode 100755 index 0000000..a1712a8 --- /dev/null +++ b/apaxy-configure.sh @@ -0,0 +1,69 @@ +#!/bin/bash +echo "Apaxy Configurator - by Jordan Bancino" +echo "Checking configuration..." + +CONFIG="apaxy.config" + +if [ -f "$CONFIG" ]; then + . "$CONFIG" +else + echo "Apaxy configuration not found! Please restore or create the configuration file: $CONFIG" + exit 1 +fi + +if [ -v INSTALL_DIRECTORY ] && [ -v WEB_ROOT ]; then + 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 + echo "Directory does not exist or is not writable by the current user: $WEB_ROOT$INSTALL_DIRECTORY" + exit 1 + fi +else + echo "No directory specified! Please define the INSTALL_DIRECTORY and WEB_ROOT variables in $CONFIG" + exit 1 +fi + +echo "Copying files to web root..." +cp -r . "$WEB_ROOT$INSTALL_DIRECTORY" +cd "$WEB_ROOT$INSTALL_DIRECTORY" + +if [ -v HTACCESS ]; then + if [ -f "$HTACCESS" ]; then + echo "- Using template: $HTACCESS to generate configuration" + else + echo "Configuration template does not exist! Please specify an existing configuration template in $CONFIG" + exit 1 + fi +else + echo "No configuration template specified. Please define the HTACCESS variable in $CONFIG" + exit 1 +fi + +if [ ! -v TEMPLATE_VAR_FOLDERNAME ]; then + echo "No foldername variable defined. Please define the TEMPLATE_VAR_FOLDERNAME variable in $CONFIG" + exit +fi + +echo "Configuring..." +echo "- Generating .htaccess..." +sed "s|$TEMPLATE_VAR_FOLDERNAME|$INSTALL_DIRECTORY/apaxy/|g" <"$HTACCESS" >"$HTACCESS_OUTPUT" + +echo "- Setting variables in documents..." +# find all the HTML files and replace the variable in them. +# This will automatically take care of the error pages, headers and +# footers. +FILES=$(find -name "*.html") +while read -r file; do + sed -i "s|$TEMPLATE_VAR_FOLDERNAME|$INSTALL_DIRECTORY/apaxy/|g" "$file" +done <<< "$FILES" + +if [ -v THEME_HTACCESS_IN ] && [ -v THEME_HTACCESS_OUT ]; then + echo "- Activating theme configuration..." + mv "$THEME_HTACCESS_IN" "$THEME_HTACCESS_OUT" +fi + +# TODO: +# - Implement any other options we want here + +echo "Done." +exit 0 diff --git a/apaxy.config b/apaxy.config new file mode 100755 index 0000000..0aa6176 --- /dev/null +++ b/apaxy.config @@ -0,0 +1,45 @@ +# Apaxy Configuration - by Jordan Bancino +# (C) 2018 Jordan Bancino +# +# Use "apaxy-configure.sh" to configure Apaxy after adjusting the needed values. +# +# NOTICE: Directories can be absolute or relative, but make sure they start with either "/", "../", or "./", +# 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 +# + +# The directory to configure Apaxy for use in. This is relative to the web server root, and contains the "theme" folder. +# 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 +# Normal users: Do not modify below this line. +# + +# The htaccess template to run the configuration on. +# Do not change this value for a regular installation of Apaxy. +HTACCESS="apaxy/htaccess.txt" + +# The theme config for Apaxy. IN will be renamed to OUT. +# There should be no reason to change this in most cases. +THEME_HTACCESS_IN="apaxy/theme/htaccess.txt" +THEME_HTACCESS_OUT="apaxy/theme/.htaccess" + + +# The variable in the htaccess and footer templates. +# Do not change this value unless you use a different template with a different variable. +TEMPLATE_VAR_FOLDERNAME="/{FOLDERNAME}/" From 4b3d4b80ef1bcff157fec6382a46465a5c520dbf Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Tue, 4 Dec 2018 20:01:10 -0500 Subject: [PATCH 2/5] docs: fix manual install instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 480e9fb..e04e230 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Should be changed to... AddIcon /share/theme/icons/gif.png .gif ``` -* Edit `footer.html` (now in the `/share/theme` folder) and update all instances of paths marked with *{FOLDERNAME}* to point to your site root. +* Edit `footer.html`, along with all the other `html` documents (in the `/share/theme` folder) and update all instances of paths marked with *{FOLDERNAME}* to point to your site root. So... From 17475e12e03e7bf67cea55540d4afcb0de6bd1a9 Mon Sep 17 00:00:00 2001 From: oupala Date: Tue, 7 May 2019 18:06:47 +0200 Subject: [PATCH 3/5] fix: remove the leading slash before {FOLDERNAME} Remove the leading slash before {FOLDERNAME} so that apaxy can be installed at the web root level. --- README.md | 8 +-- apaxy/htaccess.txt | 116 ++++++++++++++++++++-------------------- apaxy/theme/400.html | 2 +- apaxy/theme/403.html | 2 +- apaxy/theme/404.html | 2 +- apaxy/theme/408.html | 2 +- apaxy/theme/500.html | 2 +- apaxy/theme/502.html | 2 +- apaxy/theme/footer.html | 2 +- 9 files changed, 69 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index e04e230..ff7df3c 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Let's assume you have a folder named `share` in your server root directory (the So... ```ApacheConf -AddIcon /{FOLDERNAME}/theme/icons/gif.png .gif +AddIcon {FOLDERNAME}/theme/icons/gif.png .gif ``` Should be changed to... @@ -68,7 +68,7 @@ AddIcon /share/theme/icons/gif.png .gif So... ```html - + ``` Should be changed to... @@ -100,10 +100,10 @@ Edit these as you would any other HTML or CSS file. Adding your own icons is a little more involved. You'll need to edit the main Apaxy `.htaccess` file. Look for the following as an example: ```ApacheConf -AddIcon /{FOLDERNAME}/theme/icons/gif.png .gif +AddIcon {FOLDERNAME}/theme/icons/gif.png .gif ``` -The above rule will assign an icon named `gif.png` from the directory `/{FOLDERNAME}/theme/icons/` to any file with the `.gif` extension. +The above rule will assign an icon named `gif.png` from the directory `{FOLDERNAME}/theme/icons/` to any file with the `.gif` extension. This URL path is relative to your site's root. diff --git a/apaxy/htaccess.txt b/apaxy/htaccess.txt index 57e445c..f82cb04 100644 --- a/apaxy/htaccess.txt +++ b/apaxy/htaccess.txt @@ -29,76 +29,76 @@ IndexIgnore .htaccess /theme # AddIcon /share/theme/icons/blank.png ^^BLANKICON^^ # -AddIcon /{FOLDERNAME}/theme/icons/blank.png ^^BLANKICON^^ -AddIcon /{FOLDERNAME}/theme/icons/folder.png ^^DIRECTORY^^ -AddIcon /{FOLDERNAME}/theme/icons/folder-home.png .. +AddIcon {FOLDERNAME}/theme/icons/blank.png ^^BLANKICON^^ +AddIcon {FOLDERNAME}/theme/icons/folder.png ^^DIRECTORY^^ +AddIcon {FOLDERNAME}/theme/icons/folder-home.png .. -AddIconByType (TXT,/{FOLDERNAME}/theme/icons/text.png) text/* -AddIconByType (IMG,/{FOLDERNAME}/theme/icons/image.png) image/* -AddIconByType (SND,/{FOLDERNAME}/theme/icons/audio.png) audio/* -AddIconByType (VID,/{FOLDERNAME}/theme/icons/video.png) video/* +AddIconByType (TXT,{FOLDERNAME}/theme/icons/text.png) text/* +AddIconByType (IMG,{FOLDERNAME}/theme/icons/image.png) image/* +AddIconByType (SND,{FOLDERNAME}/theme/icons/audio.png) audio/* +AddIconByType (VID,{FOLDERNAME}/theme/icons/video.png) video/* # # EXTENSION SPECIFIC ICONS # -AddIcon /{FOLDERNAME}/theme/icons/archive.png .7z .bz2 .cab .gz .tar -AddIcon /{FOLDERNAME}/theme/icons/audio.png .aac .aif .aifc .aiff .ape .au .flac .iff .m4a .mid .mp3 .mpa .ra .wav .wma .f4a .f4b .oga .ogg .xm .it .s3m .mod -AddIcon /{FOLDERNAME}/theme/icons/bin.png .bin .hex -AddIcon /{FOLDERNAME}/theme/icons/bmp.png .bmp -AddIcon /{FOLDERNAME}/theme/icons/c.png .c -AddIcon /{FOLDERNAME}/theme/icons/calc.png .xlsx .xlsm .xltx .xltm .xlam .xlr .xls .csv -AddIcon /{FOLDERNAME}/theme/icons/cd.png .iso -AddIcon /{FOLDERNAME}/theme/icons/cpp.png .cpp -AddIcon /{FOLDERNAME}/theme/icons/css.png .css .sass .scss -AddIcon /{FOLDERNAME}/theme/icons/deb.png .deb -AddIcon /{FOLDERNAME}/theme/icons/doc.png .doc .docx .docm .dot .dotx .dotm .log .msg .odt .pages .rtf .tex .wpd .wps -AddIcon /{FOLDERNAME}/theme/icons/draw.png .svg .svgz -AddIcon /{FOLDERNAME}/theme/icons/eps.png .ai .eps -AddIcon /{FOLDERNAME}/theme/icons/exe.png .exe -AddIcon /{FOLDERNAME}/theme/icons/gif.png .gif -AddIcon /{FOLDERNAME}/theme/icons/h.png .h -AddIcon /{FOLDERNAME}/theme/icons/html.png .html .xhtml .shtml .htm .URL .url -AddIcon /{FOLDERNAME}/theme/icons/ico.png .ico -AddIcon /{FOLDERNAME}/theme/icons/java.png .jar -AddIcon /{FOLDERNAME}/theme/icons/jpg.png .jpg .jpeg .jpe -AddIcon /{FOLDERNAME}/theme/icons/js.png .js .json -AddIcon /{FOLDERNAME}/theme/icons/markdown.png .md -AddIcon /{FOLDERNAME}/theme/icons/package.png .pkg .dmg -AddIcon /{FOLDERNAME}/theme/icons/pdf.png .pdf -AddIcon /{FOLDERNAME}/theme/icons/php.png .php .phtml -AddIcon /{FOLDERNAME}/theme/icons/playlist.png .m3u .m3u8 .pls .pls8 -AddIcon /{FOLDERNAME}/theme/icons/png.png .png -AddIcon /{FOLDERNAME}/theme/icons/ps.png .ps -AddIcon /{FOLDERNAME}/theme/icons/psd.png .psd -AddIcon /{FOLDERNAME}/theme/icons/py.png .py -AddIcon /{FOLDERNAME}/theme/icons/rar.png .rar -AddIcon /{FOLDERNAME}/theme/icons/rb.png .rb -AddIcon /{FOLDERNAME}/theme/icons/rpm.png .rpm -AddIcon /{FOLDERNAME}/theme/icons/rss.png .rss -AddIcon /{FOLDERNAME}/theme/icons/script.png .bat .cmd .sh -AddIcon /{FOLDERNAME}/theme/icons/sql.png .sql -AddIcon /{FOLDERNAME}/theme/icons/tiff.png .tiff .tif -AddIcon /{FOLDERNAME}/theme/icons/text.png .txt .nfo .epub .mobi .azw -AddIcon /{FOLDERNAME}/theme/icons/video.png .asf .asx .avi .flv .mkv .mov .mp4 .mpg .rm .srt .swf .vob .wmv .m4v .f4v .f4p .ogv -AddIcon /{FOLDERNAME}/theme/icons/xml.png .xml -AddIcon /{FOLDERNAME}/theme/icons/zip.png .zip -DefaultIcon /{FOLDERNAME}/theme/icons/default.png +AddIcon {FOLDERNAME}/theme/icons/archive.png .7z .bz2 .cab .gz .tar +AddIcon {FOLDERNAME}/theme/icons/audio.png .aac .aif .aifc .aiff .ape .au .flac .iff .m4a .mid .mp3 .mpa .ra .wav .wma .f4a .f4b .oga .ogg .xm .it .s3m .mod +AddIcon {FOLDERNAME}/theme/icons/bin.png .bin .hex +AddIcon {FOLDERNAME}/theme/icons/bmp.png .bmp +AddIcon {FOLDERNAME}/theme/icons/c.png .c +AddIcon {FOLDERNAME}/theme/icons/calc.png .xlsx .xlsm .xltx .xltm .xlam .xlr .xls .csv +AddIcon {FOLDERNAME}/theme/icons/cd.png .iso +AddIcon {FOLDERNAME}/theme/icons/cpp.png .cpp +AddIcon {FOLDERNAME}/theme/icons/css.png .css .sass .scss +AddIcon {FOLDERNAME}/theme/icons/deb.png .deb +AddIcon {FOLDERNAME}/theme/icons/doc.png .doc .docx .docm .dot .dotx .dotm .log .msg .odt .pages .rtf .tex .wpd .wps +AddIcon {FOLDERNAME}/theme/icons/draw.png .svg .svgz +AddIcon {FOLDERNAME}/theme/icons/eps.png .ai .eps +AddIcon {FOLDERNAME}/theme/icons/exe.png .exe +AddIcon {FOLDERNAME}/theme/icons/gif.png .gif +AddIcon {FOLDERNAME}/theme/icons/h.png .h +AddIcon {FOLDERNAME}/theme/icons/html.png .html .xhtml .shtml .htm .URL .url +AddIcon {FOLDERNAME}/theme/icons/ico.png .ico +AddIcon {FOLDERNAME}/theme/icons/java.png .jar +AddIcon {FOLDERNAME}/theme/icons/jpg.png .jpg .jpeg .jpe +AddIcon {FOLDERNAME}/theme/icons/js.png .js .json +AddIcon {FOLDERNAME}/theme/icons/markdown.png .md +AddIcon {FOLDERNAME}/theme/icons/package.png .pkg .dmg +AddIcon {FOLDERNAME}/theme/icons/pdf.png .pdf +AddIcon {FOLDERNAME}/theme/icons/php.png .php .phtml +AddIcon {FOLDERNAME}/theme/icons/playlist.png .m3u .m3u8 .pls .pls8 +AddIcon {FOLDERNAME}/theme/icons/png.png .png +AddIcon {FOLDERNAME}/theme/icons/ps.png .ps +AddIcon {FOLDERNAME}/theme/icons/psd.png .psd +AddIcon {FOLDERNAME}/theme/icons/py.png .py +AddIcon {FOLDERNAME}/theme/icons/rar.png .rar +AddIcon {FOLDERNAME}/theme/icons/rb.png .rb +AddIcon {FOLDERNAME}/theme/icons/rpm.png .rpm +AddIcon {FOLDERNAME}/theme/icons/rss.png .rss +AddIcon {FOLDERNAME}/theme/icons/script.png .bat .cmd .sh +AddIcon {FOLDERNAME}/theme/icons/sql.png .sql +AddIcon {FOLDERNAME}/theme/icons/tiff.png .tiff .tif +AddIcon {FOLDERNAME}/theme/icons/text.png .txt .nfo .epub .mobi .azw +AddIcon {FOLDERNAME}/theme/icons/video.png .asf .asx .avi .flv .mkv .mov .mp4 .mpg .rm .srt .swf .vob .wmv .m4v .f4v .f4p .ogv +AddIcon {FOLDERNAME}/theme/icons/xml.png .xml +AddIcon {FOLDERNAME}/theme/icons/zip.png .zip +DefaultIcon {FOLDERNAME}/theme/icons/default.png # # THEME FILES # -HeaderName /{FOLDERNAME}/theme/header.html -ReadmeName /{FOLDERNAME}/theme/footer.html -IndexStyleSheet "/{FOLDERNAME}/theme/style.css" +HeaderName {FOLDERNAME}/theme/header.html +ReadmeName {FOLDERNAME}/theme/footer.html +IndexStyleSheet "{FOLDERNAME}/theme/style.css" # # ERROR PAGES # -ErrorDocument 400 /{FOLDERNAME}/theme/400.html -ErrorDocument 403 /{FOLDERNAME}/theme/403.html -ErrorDocument 404 /{FOLDERNAME}/theme/404.html -ErrorDocument 408 /{FOLDERNAME}/theme/408.html -ErrorDocument 500 /{FOLDERNAME}/theme/500.html -ErrorDocument 502 /{FOLDERNAME}/theme/502.html +ErrorDocument 400 {FOLDERNAME}/theme/400.html +ErrorDocument 403 {FOLDERNAME}/theme/403.html +ErrorDocument 404 {FOLDERNAME}/theme/404.html +ErrorDocument 408 {FOLDERNAME}/theme/408.html +ErrorDocument 500 {FOLDERNAME}/theme/500.html +ErrorDocument 502 {FOLDERNAME}/theme/502.html diff --git a/apaxy/theme/400.html b/apaxy/theme/400.html index a841e66..6204e63 100644 --- a/apaxy/theme/400.html +++ b/apaxy/theme/400.html @@ -6,7 +6,7 @@ Error 400 - + diff --git a/apaxy/theme/403.html b/apaxy/theme/403.html index 519fe4f..645952d 100644 --- a/apaxy/theme/403.html +++ b/apaxy/theme/403.html @@ -6,7 +6,7 @@ Error 403 - + diff --git a/apaxy/theme/404.html b/apaxy/theme/404.html index 9402c0e..f0725d4 100644 --- a/apaxy/theme/404.html +++ b/apaxy/theme/404.html @@ -6,7 +6,7 @@ Error 404 - + diff --git a/apaxy/theme/408.html b/apaxy/theme/408.html index ed0fd62..1cff69f 100644 --- a/apaxy/theme/408.html +++ b/apaxy/theme/408.html @@ -6,7 +6,7 @@ Error 408 - + diff --git a/apaxy/theme/500.html b/apaxy/theme/500.html index b14397d..f07c671 100644 --- a/apaxy/theme/500.html +++ b/apaxy/theme/500.html @@ -6,7 +6,7 @@ Error 500 - + diff --git a/apaxy/theme/502.html b/apaxy/theme/502.html index 155a731..12a7d15 100644 --- a/apaxy/theme/502.html +++ b/apaxy/theme/502.html @@ -6,7 +6,7 @@ Error 502 - + diff --git a/apaxy/theme/footer.html b/apaxy/theme/footer.html index a149eea..6cd77b8 100644 --- a/apaxy/theme/footer.html +++ b/apaxy/theme/footer.html @@ -7,4 +7,4 @@ - + From 05ba73c6a010751d35cf05414fcce76ceb7d5fa7 Mon Sep 17 00:00:00 2001 From: oupala Date: Tue, 7 May 2019 18:19:36 +0200 Subject: [PATCH 4/5] fix: rename htaccess.txt in theme directory Rename htaccess.txt to .htaccess in theme directory as it remove a useless step in installation. --- README.md | 2 +- apaxy/theme/{htaccess.txt => .htaccess} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename apaxy/theme/{htaccess.txt => .htaccess} (100%) diff --git a/README.md b/README.md index ff7df3c..68afcb4 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Should be changed to... ``` -* Once done, rename `htaccess.txt` to `.htaccess` in both the `/share` and `/share/theme` folders. +* Once done, rename `htaccess.txt` to `.htaccess` in the `/share` directory. * [Treat yo'self](http://25.media.tumblr.com/tumblr_lw7q28y0Mz1qanm80o1_500.gif), you're done. ## Docker images diff --git a/apaxy/theme/htaccess.txt b/apaxy/theme/.htaccess similarity index 100% rename from apaxy/theme/htaccess.txt rename to apaxy/theme/.htaccess From 3f98b279fefdecc297a254be6cd0a904d08c2396 Mon Sep 17 00:00:00 2001 From: oupala Date: Thu, 9 May 2019 15:58:29 +0200 Subject: [PATCH 5/5] refactor: large rewrite of install script --- apaxy-configure.sh | 229 +++++++++++++++++++++++++++++++++++---------- apaxy.config | 77 ++++++++------- 2 files changed, 218 insertions(+), 88 deletions(-) mode change 100755 => 100644 apaxy-configure.sh diff --git a/apaxy-configure.sh b/apaxy-configure.sh old mode 100755 new mode 100644 index a1712a8..95cefe2 --- a/apaxy-configure.sh +++ b/apaxy-configure.sh @@ -1,69 +1,200 @@ #!/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 - . "$CONFIG" -else - echo "Apaxy configuration not found! Please restore or create the configuration file: $CONFIG" - exit 1 -fi +# default config +defaultLogLevel=2 +defaultLogFile="$(basename "${0}" .sh).log" +defaultApacheWebRootPath="/var/www/html" +defaultInstallWebPath="" -if [ -v INSTALL_DIRECTORY ] && [ -v WEB_ROOT ]; then - 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 - echo "Directory does not exist or is not writable by the current user: $WEB_ROOT$INSTALL_DIRECTORY" - exit 1 +# functions + +### + # display help + ## +displayHelp () { + cat <> "${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 - 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 fi -echo "Copying files to web root..." -cp -r . "$WEB_ROOT$INSTALL_DIRECTORY" -cd "$WEB_ROOT$INSTALL_DIRECTORY" +# getting parameters value from cli (can overload config file values) +while [ "$#" -ge 1 ] ; do + 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 [ -f "$HTACCESS" ]; then - echo "- Using template: $HTACCESS to generate configuration" + if [ "$#" -ge "${shiftStep}" ] + then + shift "${shiftStep}" else - echo "Configuration template does not exist! Please specify an existing configuration template in $CONFIG" - exit 1 + log 1 "ERROR - invalid number of arguments" + exit 3 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 - echo "No configuration template specified. Please define the HTACCESS variable in $CONFIG" - exit 1 + installDir="${apacheWebRootPath}${installWebPath}" fi -if [ ! -v TEMPLATE_VAR_FOLDERNAME ]; then - echo "No foldername variable defined. Please define the TEMPLATE_VAR_FOLDERNAME variable in $CONFIG" - exit +if [ -z "${logLevel}" ] +then + logLevel="${defaultLogLevel}" fi -echo "Configuring..." -echo "- Generating .htaccess..." -sed "s|$TEMPLATE_VAR_FOLDERNAME|$INSTALL_DIRECTORY/apaxy/|g" <"$HTACCESS" >"$HTACCESS_OUTPUT" +if [ -z "${logFile}" ] +then + logFile="${workingDirectory}/${defaultLogFile}" +fi -echo "- Setting variables in documents..." -# find all the HTML files and replace the variable in them. -# This will automatically take care of the error pages, headers and -# footers. -FILES=$(find -name "*.html") +# enabling strict mode +# -u - undefined variables are forbidden (enable this option after getting parameters from $1 $2...) +set -u + +# 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 - sed -i "s|$TEMPLATE_VAR_FOLDERNAME|$INSTALL_DIRECTORY/apaxy/|g" "$file" -done <<< "$FILES" + sed -i "s|{FOLDERNAME}|${installWebPath}|g" "${file}" +done <<< "${files}" -if [ -v THEME_HTACCESS_IN ] && [ -v THEME_HTACCESS_OUT ]; then - echo "- Activating theme configuration..." - mv "$THEME_HTACCESS_IN" "$THEME_HTACCESS_OUT" -fi - -# TODO: -# - Implement any other options we want here - -echo "Done." -exit 0 +log 2 "- syncing filesystem" +sync +log 1 "- filesystem has been synced and is now consistent" +log 1 "- apaxy has been successfully configured and installed in ${installDir}" diff --git a/apaxy.config b/apaxy.config index 0aa6176..2238029 100755 --- a/apaxy.config +++ b/apaxy.config @@ -1,45 +1,44 @@ -# Apaxy Configuration - by Jordan Bancino -# (C) 2018 Jordan Bancino +#!/bin/bash # -# 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 "./", -# 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 - +# default for apache is /var/www/html # -# GENERAL CONFIGURATION +# note that path should be absolute, so make sure it starts with a "/" +# and DO NOT leave a trailing slash # - -# The directory to configure Apaxy for use in. This is relative to the web server root, and contains the "theme" folder. -# 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" - +# good: "/var/www/html" <- starts with "/", does not have trailing "/" +# bad : "var/www/html/" <- does not start with "/", have a trailing "/" # -# ADVANCED CONFIGURATION -# Normal users: Do not modify below this line. +apacheWebRootPath="/var/www/html" + +# the directory where apaxy will be used (this is relative to the web server root, and contains the "theme" folder) # - -# The htaccess template to run the configuration on. -# Do not change this value for a regular installation of Apaxy. -HTACCESS="apaxy/htaccess.txt" - -# The theme config for Apaxy. IN will be renamed to OUT. -# There should be no reason to change this in most cases. -THEME_HTACCESS_IN="apaxy/theme/htaccess.txt" -THEME_HTACCESS_OUT="apaxy/theme/.htaccess" - - -# The variable in the htaccess and footer templates. -# Do not change this value unless you use a different template with a different variable. -TEMPLATE_VAR_FOLDERNAME="/{FOLDERNAME}/" +# for instance: "http://example.org/share" would make this value "/share", where "/share/theme" is the theme directory +# +# note that path should be absolute, so make sure it starts with a "/" +# and DO NOT leave a trailing slash +# +# good: "/share" <- starts with "/", does not have trailing "/" +# bad : "share/" <- does not start with "/", has a trailing "/" +# +# 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 +# +# installWebPath="/share" +# +installWebPath=""