diff --git a/codepot/docker/Dockerfile.ubnt2004 b/codepot/docker/Dockerfile.ubnt2004 index 69a17724..7203f923 100644 --- a/codepot/docker/Dockerfile.ubnt2004 +++ b/codepot/docker/Dockerfile.ubnt2004 @@ -10,8 +10,9 @@ RUN apt update && \ sqlite3 php-dev libsvn-dev make vim COPY build-ubnt2004.sh /tmp +COPY codepot-0.4.0.tar.gz /tmp RUN /tmp/build-ubnt2004.sh && rm -rf /tmp/* COPY apache2-fg.sh /usr/sbin/ -CMD ["/usr/sbin/apache2-fg.sh"] +ENTRYPOINT ["/usr/sbin/apache2-fg.sh"] diff --git a/codepot/docker/apache2-fg.sh b/codepot/docker/apache2-fg.sh index bbaf48dd..19a03c7d 100755 --- a/codepot/docker/apache2-fg.sh +++ b/codepot/docker/apache2-fg.sh @@ -1,7 +1,12 @@ #!/bin/bash set -e +CODEPOT_CONFIG_FILE="/var/lib/codepot/codepot.ini" +HTTPD_CONFIG_FILE="/etc/apache2/apache2.conf" + SERVICE_PORT="" +HIDE_INDEX_PAGE="" +HTTPS_REDIRECTED="" while getopts ":hp:-:" oc do case "${oc}" in @@ -17,6 +22,28 @@ do opt=${OPTARG%=$val} ;; + hide-index-page) + opt=${OPTARG} + HIDE_INDEX_PAGE="${!OPTIND}" + OPTIND=$(($OPTIND + 1)) + ;; + + hide-index-page=*) + HIDE_INDEX_PAGE=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + + https-redirected) + opt=${OPTARG} + HTTPS_REDIRECTED="${!OPTIND}" + OPTIND=$(($OPTIND + 1)) + ;; + + https-redirected=*) + HTTPS_REDIRECTED=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + *) echo "Warning: unknown option - $OPTARG" ;; @@ -24,15 +51,17 @@ do ;; h) - echo "-----------------------------------------------------------" + echo "-------------------------------------------------------------------------" echo "This container runs a http service on port 80." echo "Use an external reverse proxy to enable https as it doesn't" echo "enable the HTTP service." echo "Extra options allowed when running the container: " - echo " -h print this help message" - echo " -p number specify the port number" - echo " -port number specify the port number" - echo "-----------------------------------------------------------" + echo " -h print this help message" + echo " -p number specify the port number" + echo " -port number specify the port number" + echo " -hide-index-page yes/no hide/show the index page script from the URL" + echo " -https-redirected yes/no indicate if the requets are HTTPS redirected" + echo "-------------------------------------------------------------------------" ;; p) SERVICE_PORT=${OPTARG#*=} @@ -44,7 +73,11 @@ do ;; esac done + +## fall back to default values if the given values are not proper echo "${SERVICE_PORT}" | grep -q -E '^[[:digit:]]+$' || SERVICE_PORT="80" +[[ "${HIDE_INDEX_PAGE}" == "" ]] && HIDE_INDEX_PAGE="no" +[[ "${HTTPS_REDIRECTED}" == "" ]] && HTTPS_REDIRECTED="no" # Note: we don't just use "apache2ctl" here because it itself is just a shell-script wrapper around apache2 which provides extra functionality like "apache2ctl start" for launching apache2 in the background. @@ -93,18 +126,50 @@ done mkdir -p /var/cache/codepot /var/log/codepot chown -R www-data:www-data /var/lib/codepot /var/cache/codepot /var/log/codepot -[ ! -f /var/lib/codepot/codepot.ini ] && cp -pf /etc/codepot/codepot.ini /var/lib/codepot/codepot.ini +[ ! -f "${CODEPOT_CONFIG_FILE}" ] && cp -pf /etc/codepot/codepot.ini "${CODEPOT_CONFIG_FILE}" -### TODO: this needs changes.. -grep -F -q '' /etc/apache2/conf-enabled/codepot.conf || { +grep -F -q '' /etc/apache2/conf-enabled/codepot.conf || { cat <> /etc/apache2/conf-enabled/codepot.conf - - SetEnv CODEPOT_CONFIG_FILE /var/lib/codepot/codepot.ini + + SetEnv CODEPOT_CONFIG_FILE ${CODEPOT_CONFIG_FILE} EOF } -## TODO: change the port number according to SERVICE_PORT +## change the port number as specified on the command line +echo "Configuring to listen on the port[$SERVICE_PORT] hide-index-page[$HIDE_INDEX_PAGE] https-redirected[$HTTPS_REDIRECTED]" + +sed -r -i "s|^Listen[[:space:]]+.*|Listen ${SERVICE_PORT}|g" "${HTTPD_CONFIG_FILE}" + +if [[ "${HTTPS_REDIRECTED}" =~ [Yy][Ee][Ss] ]] +then + ## The DAV COPY request contains the header 'Destination: https://' if the origin request + ## is HTTPS. This container is configured to server on HTTP only. If HTTPS is redirected + ## to HTTP, we must translate https:// to http:// in the Destination header. + ## Otherwise, the response is 502 Bad Gateway. + echo "RequestHeader edit Destination ^https: http: early" > /etc/apache2/conf-enabled/codepot-dav-https-redirected.conf +else + rm -f /etc/apache2/conf-enabled/codepot-dav-https-redirected.conf +fi + +if [[ "${HIDE_INDEX_PAGE}" =~ [Yy][Ee][Ss] ]] +then + sed -r -i 's|^index_page[[:space:]]*=.*$|index_page=""|g' "${CODEPOT_CONFIG_FILE}" + cat < /var/www/html/.htaccess +RewriteEngine On +RewriteBase / +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ index.php/$1 [L] +EOF + sed -r -i '//,/<\/Directory>/s|^[[:space:]]*AllowOverride[[:space:]]+.*$| AllowOverride All|g' "${HTTPD_CONFIG_FILE}" + +else + sed -r -i 's|^index_page[[:space:]]*=.*$|index_page="index.php"|g' "${CODEPOT_CONFIG_FILE}" + rm -rf /var/www/html/.htaccess + + sed -r -i '//,/<\/Directory>/s|^[[:space:]]*AllowOverride[[:space:]]+.*$| AllowOverride None|g' "${HTTPD_CONFIG_FILE}" +fi #httpd server in the foreground exec apache2 -DFOREGROUND diff --git a/codepot/docker/build-ubnt2004.sh b/codepot/docker/build-ubnt2004.sh index 586e1b9b..62a01d6b 100755 --- a/codepot/docker/build-ubnt2004.sh +++ b/codepot/docker/build-ubnt2004.sh @@ -1,6 +1,6 @@ cd /tmp -svn co http://code.miflux.com/svn/codepot/trunk/codepot && \ +tar -zxvf codepot-0.4.0.tar.gz && mv -f codepot-0.4.0 codepot && \ cd codepot && \ ./configure \ --prefix=/usr \