From a4d6e7a0b2edc397d8e120c33e13bb20a0002ded Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 18 Apr 2016 18:52:56 +1200 Subject: [PATCH] rebuild.sh now a standalone file --- rebuild.sh | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/rebuild.sh b/rebuild.sh index d0074e1..d0847a3 100644 --- a/rebuild.sh +++ b/rebuild.sh @@ -1,33 +1,32 @@ #!/bin/bash set -eu -THREADS=$(cat /proc/cpuinfo | grep '^processor' | wc -l) + +APP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +numcpus() { + cat /proc/cpuinfo | grep '^processor' | wc -l +} buildsite() { - local basedir="$(realpath .)" - local rebuild="${basedir}/rebuild.php" - - if [[ "$(uname -o)" == "Cygwin" ]] ; then - rebuild="$(cygpath -w "$rebuild")" - fi - echo "Site: ${1}" pushd "$1" >/dev/null - echo "Cleaning target directory..." + echo "Cleaning wwwroot directory..." if [[ -d wwwroot ]] ; then rm -r wwwroot - fi - + fi mkdir -p wwwroot/srv + echo "Copying static resources..." + if [[ ! -d static ]] ; then mkdir static fi - cp "${basedir}/static_global/"* wwwroot || true + cp "${APP_DIR}/static/"* wwwroot || true cp static/* wwwroot || true for htm in footer header homepage_blurb ; do @@ -38,8 +37,9 @@ buildsite() { echo "Building pages..." - for i in $(seq 0 "$THREADS") ; do - php "$rebuild" "$THREADS" "$i" & + local threadcount=$(numcpus) + for i in $(seq 0 "$threadcount") ; do + php "${APP_DIR}/rebuild.php" "$threadcount" "$i" & done wait @@ -49,10 +49,17 @@ buildsite() { popd >/dev/null } +usage() { + echo "USAGE: ./rebuild.sh path-to-siteroot" + exit 1 +} + main() { - for site in sites/* ; do - buildsite "$site" - done + if [[ $# -ne 1 ]] ; then + usage + fi + + buildsite "$1" } main "$@"