diff --git a/.circleci/config.yml b/.circleci/config.yml index e4b2c3c..79ce09a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,9 +8,9 @@ workflows: requires: - test filters: - branches: - only: - - master + branches: + only: + - master - build_children: context: circle-api requires: @@ -58,8 +58,7 @@ jobs: destination: docker-lancachenet-monolithic.tar - persist_to_workspace: root: workspace - paths: - lancachenet-monolithic.tar + paths: lancachenet-monolithic.tar publish_latest: executor: testbuild-executor steps: @@ -78,7 +77,7 @@ jobs: - run: name: "Request API to build children" command: | - for child in {"generic"}; do - echo "Asking API to trigger build for $child" - curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/lancachenet/$child/build?circle-token=${CIRCLE_API_USER_TOKEN} - done + for child in {"generic"}; do + echo "Asking API to trigger build for $child" + curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/lancachenet/$child/build?circle-token=${CIRCLE_API_USER_TOKEN} + done diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bcaa1e3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true + +[*.md] +indent_size = 0 + +[*.sh] +indent_style = tab diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 0000000..ebecca6 --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,55 @@ +# MegaLinter GitHub Action configuration file +# More info at https://megalinter.io +--- +name: MegaLinter + +on: + pull_request: + branches: + - master + +env: + GITHUB_STATUS_REPORTER: true + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + + permissions: + contents: write + issues: write + pull-requests: write + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: MegaLinter + uses: oxsecurity/megalinter@v8 + id: ml + env: + VALIDATE_ALL_CODEBASE: >- + ${{ + github.event_name == 'push' && + github.ref == 'refs/heads/master' + }} + + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: MegaLinter reports + include-hidden-files: "true" + path: | + megalinter-reports + mega-linter.log diff --git a/.gitignore b/.gitignore index 27a3afb..4dbb08b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ reports +megalinter-reports diff --git a/.lefthook.yml b/.lefthook.yml new file mode 100644 index 0000000..128cbac --- /dev/null +++ b/.lefthook.yml @@ -0,0 +1,6 @@ +pre-commit: + parallel: true + jobs: + - name: megalinter + run: docker run --rm -e USER=$(id -u) -e GROUP=$(id -g) -v "$PWD:/tmp/lint" oxsecurity/megalinter:beta + stage_fixed: true diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 0000000..0687c88 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,28 @@ +# Configuration file for MegaLinter +# +# See all available variables at https://megalinter.io/latest/config-file/ and in +# linters documentation + +APPLY_FIXES: all +FLAVOR_SUGGESTIONS: false +PRINT_ALPACA: false +SHOW_ELAPSED_TIME: true + +ENABLE: + - ACTION + - BASH + - DOCKERFILE + - EDITORCONFIG + - MARKDOWN + - YAML + +DISABLE_LINTERS: + - MARKDOWN_MARKDOWNLINT + - YAML_V8R + +BASH_SHELLCHECK_ARGUMENTS: "-f gcc" +EDITORCONFIG_EDITORCONFIG_CHECKER_ARGUMENTS: "-f gcc" + +POST_COMMANDS: + - command: find . -user root -group root -exec chown ${USER}:${GROUP} {} \; + cwd: workspace diff --git a/Dockerfile b/Dockerfile index 3ed4c76..efe63e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,55 @@ +# hadolint ignore=DL3007 FROM lancachenet/ubuntu-nginx:latest -LABEL version=3 -LABEL description="Single caching container for caching game content at LAN parties." -LABEL maintainer="LanCache.Net Team " - -RUN apt-get update ;\ - apt-get install -y jq git ; - -ENV GENERICCACHE_VERSION=2 \ - CACHE_MODE=monolithic \ - WEBUSER=www-data \ - CACHE_INDEX_SIZE=500m \ - CACHE_DISK_SIZE=1000g \ - MIN_FREE_DISK=10g \ - CACHE_MAX_AGE=3560d \ - CACHE_SLICE_SIZE=1m \ - UPSTREAM_DNS="8.8.8.8 8.8.4.4" \ - BEAT_TIME=1h \ - LOGFILE_RETENTION=3560 \ - CACHE_DOMAINS_REPO="https://github.com/uklans/cache-domains.git" \ - CACHE_DOMAINS_BRANCH=master \ - NGINX_WORKER_PROCESSES=auto \ - NGINX_LOG_FORMAT=cachelog - -COPY overlay/ / - -RUN rm /etc/nginx/sites-enabled/* /etc/nginx/stream-enabled/* ;\ - rm /etc/nginx/conf.d/gzip.conf ;\ - chmod 754 /var/log/tallylog ; \ - id -u ${WEBUSER} &> /dev/null || adduser --system --home /var/www/ --no-create-home --shell /bin/false --group --disabled-login ${WEBUSER} ;\ - chmod 755 /scripts/* ;\ - mkdir -m 755 -p /data/cache ;\ - mkdir -m 755 -p /data/info ;\ - mkdir -m 755 -p /data/logs ;\ - mkdir -m 755 -p /tmp/nginx/ ;\ - chown -R ${WEBUSER}:${WEBUSER} /data/ ;\ - mkdir -p /etc/nginx/sites-enabled ;\ - ln -s /etc/nginx/sites-available/10_cache.conf /etc/nginx/sites-enabled/10_generic.conf; \ - ln -s /etc/nginx/sites-available/20_upstream.conf /etc/nginx/sites-enabled/20_upstream.conf; \ - ln -s /etc/nginx/sites-available/30_metrics.conf /etc/nginx/sites-enabled/30_metrics.conf; \ - ln -s /etc/nginx/stream-available/10_sni.conf /etc/nginx/stream-enabled/10_sni.conf; \ - mkdir -m 755 -p /data/cachedomains ;\ - mkdir -m 755 -p /tmp/nginx - -RUN git clone --depth=1 --no-single-branch https://github.com/uklans/cache-domains/ /data/cachedomains -VOLUME ["/data/logs", "/data/cache", "/data/cachedomains", "/var/www"] +LABEL org.opencontainers.image.version=3 +LABEL org.opencontainers.image.description="Single container for caching game content at LAN parties." +LABEL org.opencontainers.image.authors="LanCache.Net Team " + +SHELL ["/bin/bash", "-c"] + +# hadolint ignore=DL3008 +RUN < /dev/null || adduser --system --home /var/www/ --no-create-home --shell /bin/false --group --disabled-login ${WEBUSER} + mkdir -p /etc/nginx/sites-enabled /data/{cache,cachedomains,info,logs} /tmp/nginx + rm /etc/nginx/sites-enabled/* /etc/nginx/stream-enabled/* /etc/nginx/conf.d/gzip.conf + chown -R ${WEBUSER}: /data/ + chmod 754 /var/log/tallylog + for file in sites-available/10_cache.conf sites-available/20_upstream.conf sites-available/30_metrics.conf stream-available/10_sni.conf; do + ln -s "/etc/nginx/${file}" "/etc/nginx/${file/available/enabled}" + done +EOF + +RUN </CONFIGHASH\`" - echo "" - echo "See: https://lancache.net/docs/advanced/config-hash/ for more details" + ABORTING STARTUP TO AVOID POTENTIALLY INVALIDATING THE CACHE + If you are happy that this cache is valid with the current config changes + please delete `//CONFIGHASH` + + See: https://lancache.net/docs/advanced/config-hash/ for more details + EOF } -DETECTED_CACHE_KEY=`grep proxy_cache_key /etc/nginx/sites-available/cache.conf.d/root/30_cache_key.conf | awk '{print $2}'` +DETECTED_CACHE_KEY=$(grep proxy_cache_key /etc/nginx/sites-available/cache.conf.d/root/30_cache_key.conf | awk '{print $2}') NEWHASH="GENERICCACHE_VERSION=${GENERICCACHE_VERSION};CACHE_MODE=${CACHE_MODE};CACHE_SLICE_SIZE=${CACHE_SLICE_SIZE};CACHE_KEY=${DETECTED_CACHE_KEY}" if [ -d /data/cache/cache ]; then echo " Detected existing cache data, checking config hash for consistency" if [ -f /data/cache/CONFIGHASH ]; then - OLDHASH=`cat /data/cache/CONFIGHASH` - if [ ${OLDHASH} != ${NEWHASH} ]; then + OLDHASH=$(cat /data/cache/CONFIGHASH) + if [ "${OLDHASH}" != "${NEWHASH}" ]; then echo "ERROR: Detected CONFIGHASH does not match current CONFIGHASH" - echo " Detected: ${OLDHASH}" - echo " Current: ${NEWHASH}" - print_confighash_warning ${NEWHASH} - exit -1; + echo "Detected: ${OLDHASH}" + echo "Current: ${NEWHASH}" + print_confighash_warning "${NEWHASH}" + exit 1 else - echo " CONFIGHASH matches current configuration" + echo "CONFIGHASH matches current configuration" fi else - echo " Could not find CONFIGHASH for existing cachedata" - echo " This is either an upgrade from an older instance of Lancache" - echo " or CONFIGHASH has been deleted intentionally" - echo "" - echo " Creating CONFIGHASH from current live configuration" - echo " Current: ${NEWHASH}" - echo "" - echo " See: https://lancache.net/docs/advanced/config-hash/ for more details" + cat <<-EOF + Could not find CONFIGHASH for existing cachedata + This is either an upgrade from an older instance of Lancache + or CONFIGHASH has been deleted intentionally + + Creating CONFIGHASH from current live configuration + Current: ${NEWHASH} + + See: https://lancache.net/docs/advanced/config-hash/ for more details + EOF fi fi mkdir -p /data/cache/cache -echo ${NEWHASH} > /data/cache/CONFIGHASH +echo "${NEWHASH}" >/data/cache/CONFIGHASH diff --git a/overlay/hooks/entrypoint-pre.d/10_setup.sh b/overlay/hooks/entrypoint-pre.d/10_setup.sh old mode 100644 new mode 100755 index 039f645..6988a77 --- a/overlay/hooks/entrypoint-pre.d/10_setup.sh +++ b/overlay/hooks/entrypoint-pre.d/10_setup.sh @@ -2,23 +2,23 @@ set -e # Handle CACHE_MEM_SIZE deprecation -if [[ ! -z "${CACHE_MEM_SIZE}" ]]; then - CACHE_INDEX_SIZE=${CACHE_MEM_SIZE} +if [[ -n "${CACHE_MEM_SIZE}" ]]; then + CACHE_INDEX_SIZE=${CACHE_MEM_SIZE} fi # Preprocess UPSTREAM_DNS to allow for multiple resolvers using the same syntax as lancache-dns UPSTREAM_DNS="$(echo -n "${UPSTREAM_DNS}" | sed 's/[;]/ /g')" -echo "worker_processes ${NGINX_WORKER_PROCESSES};" > /etc/nginx/workers.conf +echo "worker_processes ${NGINX_WORKER_PROCESSES};" >/etc/nginx/workers.conf sed -i "s/^user .*/user ${WEBUSER};/" /etc/nginx/nginx.conf -sed -i "s/CACHE_INDEX_SIZE/${CACHE_INDEX_SIZE}/" /etc/nginx/conf.d/20_proxy_cache_path.conf +sed -i "s/CACHE_INDEX_SIZE/${CACHE_INDEX_SIZE}/" /etc/nginx/conf.d/20_proxy_cache_path.conf sed -i "s/CACHE_DISK_SIZE/${CACHE_DISK_SIZE}/" /etc/nginx/conf.d/20_proxy_cache_path.conf sed -i "s/MIN_FREE_DISK/${MIN_FREE_DISK}/" /etc/nginx/conf.d/20_proxy_cache_path.conf sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/conf.d/20_proxy_cache_path.conf -sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf +sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf sed -i "s/slice 1m;/slice ${CACHE_SLICE_SIZE};/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf -sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/cache.conf.d/10_root.conf -sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf.d/10_resolver.conf -sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf -sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/10_cache.conf -sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/20_upstream.conf +sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/cache.conf.d/10_root.conf +sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf.d/10_resolver.conf +sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf +sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/10_cache.conf +sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/20_upstream.conf diff --git a/overlay/hooks/entrypoint-pre.d/15_generate_maps.sh b/overlay/hooks/entrypoint-pre.d/15_generate_maps.sh old mode 100644 new mode 100755 index f35e475..6ac5e76 --- a/overlay/hooks/entrypoint-pre.d/15_generate_maps.sh +++ b/overlay/hooks/entrypoint-pre.d/15_generate_maps.sh @@ -7,50 +7,52 @@ echo "Bootstrapping Monolithic from ${CACHE_DOMAINS_REPO}" export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" cd /data/cachedomains if [[ ! -d .git ]]; then - git clone ${CACHE_DOMAINS_REPO} . + git clone "${CACHE_DOMAINS_REPO}" . fi if [[ "${NOFETCH:-false}" != "true" ]]; then # Disable error checking whilst we attempt to get latest set +e - git remote set-url origin ${CACHE_DOMAINS_REPO} + git remote set-url origin "${CACHE_DOMAINS_REPO}" git fetch origin || echo "Failed to update from remote, using local copy of cache_domains" - git reset --hard origin/${CACHE_DOMAINS_BRANCH} + git reset --hard "origin/${CACHE_DOMAINS_BRANCH}" # Reenable error checking set -e fi TEMP_PATH=$(mktemp -d) OUTPUTFILE=${TEMP_PATH}/outfile.conf -echo "map \"\$http_user_agent£££\$http_host\" \$cacheidentifier {" >> $OUTPUTFILE -echo " default \$http_host;" >> $OUTPUTFILE -echo " ~Valve\\/Steam\\ HTTP\\ Client\\ 1\.0£££.* steam;" >> $OUTPUTFILE +cat <<'EOF' >>"${OUTPUTFILE}" +map "$http_user_agent£££$http_host" $cacheidentifier { + default $http_host; + ~Valve\/Steam\ HTTP\ Client\ 1\.0£££.* steam; +EOF #Next line probably no longer needed as we are now regexing to victory #echo " hostnames;" >> $OUTPUTFILE -jq -r '.cache_domains | to_entries[] | .key' cache_domains.json | while read CACHE_ENTRY; do +jq -r '.cache_domains | to_entries[] | .key' cache_domains.json | while read -r CACHE_ENTRY; do #for each cache entry, find the cache indentifier - CACHE_IDENTIFIER=$(jq -r ".cache_domains[$CACHE_ENTRY].name" cache_domains.json) - jq -r ".cache_domains[$CACHE_ENTRY].domain_files | to_entries[] | .key" cache_domains.json | while read CACHEHOSTS_FILEID; do + CACHE_IDENTIFIER=$(jq -r ".cache_domains[${CACHE_ENTRY}].name" cache_domains.json) + jq -r ".cache_domains[${CACHE_ENTRY}].domain_files | to_entries[] | .key" cache_domains.json | while read -r CACHEHOSTS_FILEID; do #Get the key for each domain files - jq -r ".cache_domains[$CACHE_ENTRY].domain_files[$CACHEHOSTS_FILEID]" cache_domains.json | while read CACHEHOSTS_FILENAME; do + jq -r ".cache_domains[${CACHE_ENTRY}].domain_files[${CACHEHOSTS_FILEID}]" cache_domains.json | while read -r CACHEHOSTS_FILENAME; do #Get the actual file name - echo Reading cache ${CACHE_IDENTIFIER} from ${CACHEHOSTS_FILENAME} - cat ${CACHEHOSTS_FILENAME} | while read CACHE_HOST; do + echo "Reading cache ${CACHE_IDENTIFIER} from ${CACHEHOSTS_FILENAME}" + while read -r CACHE_HOST; do #for each file in the hosts file #remove all whitespace (mangles comments but ensures valid config files) - echo "host: $CACHE_HOST" + echo "host: ${CACHE_HOST}" CACHE_HOST=${CACHE_HOST// /} - echo "new host: $CACHE_HOST" - if [ ! "x${CACHE_HOST}" == "x" ]; then + echo "new host: ${CACHE_HOST}" + if [ -n "${CACHE_HOST}" ]; then #Use sed to replace . with \. and * with .* - REGEX_CACHE_HOST=$(sed -e "s#\.#\\\.#g" -e "s#\*#\.\*#g" <<< ${CACHE_HOST}) - echo " ~.*£££.*?${REGEX_CACHE_HOST} ${CACHE_IDENTIFIER};" >> $OUTPUTFILE + REGEX_CACHE_HOST=$(sed -e "s#\.#\\\.#g" -e "s#\*#\.\*#g" <<<"${CACHE_HOST}") + echo " ~.*£££.*?${REGEX_CACHE_HOST} ${CACHE_IDENTIFIER};" >>"${OUTPUTFILE}" fi - done + done <"${CACHEHOSTS_FILENAME}" done done done -echo "}" >> $OUTPUTFILE -cat $OUTPUTFILE -cp $OUTPUTFILE /etc/nginx/conf.d/30_maps.conf -rm -rf $TEMP_PATH +echo "}" >>"${OUTPUTFILE}" +cat "${OUTPUTFILE}" +cp "${OUTPUTFILE}" /etc/nginx/conf.d/30_maps.conf +rm -rf "${TEMP_PATH}" diff --git a/overlay/hooks/entrypoint-pre.d/20_perms_check.sh b/overlay/hooks/entrypoint-pre.d/20_perms_check.sh old mode 100644 new mode 100755 index b686cde..7a6868e --- a/overlay/hooks/entrypoint-pre.d/20_perms_check.sh +++ b/overlay/hooks/entrypoint-pre.d/20_perms_check.sh @@ -1,14 +1,20 @@ #!/bin/bash -if [ -d "/data/cache/cache" ]; then + +CACHE_DIR="/data/cache/cache" + +if [ -d "${CACHE_DIR}" ]; then echo "Running fast permissions check" - ls -l /data/cache/cache | tail --lines=+2 | grep -v ${WEBUSER} > /dev/null - if [[ $? -eq 0 || "$FORCE_PERMS_CHECK" == "true" ]]; then - echo "Doing full checking of permissions (This WILL take a long time on large caches)..." - find /data \! -user ${WEBUSER} -exec chown ${WEBUSER}:${WEBUSER} '{}' + - echo "Permissions ok" + if [[ "${FORCE_PERMS_CHECK}" == "true" ]]; then + echo "FORCE_PERMS_CHECK is set, proceeding with full permissions fix" + elif ! find "${CACHE_DIR}" -mindepth 1 ! -user "${WEBUSER}" | read -r; then + echo "Fast permissions check successful, if you have any permissions error try running with -e FORCE_PERMS_CHECK=true" + exit 0 else - echo "Fast permissions check successful, if you have any permissions error try running with -e FORCE_PERMS_CHECK = true" + echo "Some files are not owned by ${WEBUSER}" fi + echo "Doing full checking of permissions (This WILL take a long time on large caches)..." + find /data \! -user "${WEBUSER}" -exec chown "${WEBUSER}:" '{}' + + echo "Permissions ok" fi diff --git a/overlay/hooks/supervisord-pre.d/99_config_check.sh b/overlay/hooks/supervisord-pre.d/99_config_check.sh old mode 100644 new mode 100755 index cbf3956..316fee3 --- a/overlay/hooks/supervisord-pre.d/99_config_check.sh +++ b/overlay/hooks/supervisord-pre.d/99_config_check.sh @@ -4,14 +4,11 @@ echo "Currently configured config:" /scripts/getconfig.sh /etc/nginx/nginx.conf echo "Checking nginx config" -/usr/sbin/nginx -t - - [ $? -ne 0 ] || echo "Config check successful" +/usr/sbin/nginx -t && echo "Config check successful" echo "Ready for supervisord startup" -if [ -n "$CACHE_ROOT" ] -then - echo "Monitor ${CACHE_ROOT}/logs/access.log and ${CACHE_ROOT}/logs/error.log on the host for cache activity" +if [ -n "$CACHE_ROOT" ]; then + echo "Monitor ${CACHE_ROOT}/logs/access.log and ${CACHE_ROOT}/logs/error.log on the host for cache activity" else - echo "Monitor access.log and error.log on the host for cache activity" + echo "Monitor access.log and error.log on the host for cache activity" fi diff --git a/overlay/scripts/cache_test.sh b/overlay/scripts/cache_test.sh index 1bbe799..99e9a7f 100755 --- a/overlay/scripts/cache_test.sh +++ b/overlay/scripts/cache_test.sh @@ -1,24 +1,24 @@ #!/bin/bash set -e -pageload1=`curl http://ping1.lancache.net/api/timezone/ETC/GMT --resolve ping1.lancache.net:80:127.0.0.1` +pageload1=$(curl http://ping1.lancache.net/api/timezone/ETC/GMT --resolve ping1.lancache.net:80:127.0.0.1) sleep 2 -pageload2=`curl http://ping1.lancache.net/api/timezone/ETC/GMT --resolve ping1.lancache.net:80:127.0.0.1` +pageload2=$(curl http://ping1.lancache.net/api/timezone/ETC/GMT --resolve ping1.lancache.net:80:127.0.0.1) sleep 2 -pageload3=`curl http://ping2.lancache.net/api/timezone/ETC/GMT --resolve ping2.lancache.net:80:127.0.0.1` +pageload3=$(curl http://ping2.lancache.net/api/timezone/ETC/GMT --resolve ping2.lancache.net:80:127.0.0.1) sleep 2 -pageload4=`curl http://ping2.lancache.net/api/timezone/ETC/GMT --resolve ping2.lancache.net:80:127.0.0.1` +pageload4=$(curl http://ping2.lancache.net/api/timezone/ETC/GMT --resolve ping2.lancache.net:80:127.0.0.1) -if [ "$pageload1" == "$pageload2" ]; then - if [ "$pageload3" == "$pageload4" ]; then - if [ "$pageload1" == "$pageload3" ]; then +if [ "${pageload1}" == "${pageload2}" ]; then + if [ "${pageload3}" == "${pageload4}" ]; then + if [ "${pageload1}" == "${pageload3}" ]; then #In monolithic pages 1+3 should be different as there is no map for this test case echo "Error caching test page, pages 1+3 are identical" echo "pageload1:" - echo $pageload1 + echo "${pageload1}" echo "pageload3:" - echo $pageload3 + echo "${pageload3}" exit 3 else @@ -29,12 +29,11 @@ if [ "$pageload1" == "$pageload2" ]; then else echo "Error caching test page, pages 3+4 differed" - echo "pageload3:" - echo $pageload3 + echo "${pageload3}" echo "pageload4:" - echo $pageload4 + echo "${pageload4}" exit 2 fi @@ -42,12 +41,11 @@ if [ "$pageload1" == "$pageload2" ]; then else echo "Error caching test page, pages 1+2 differed" - echo "pageload1:" - echo $pageload1 + echo "${pageload1}" echo "pageload2:" - echo $pageload2 + echo "${pageload2}" exit 1 fi diff --git a/overlay/scripts/getconfig.sh b/overlay/scripts/getconfig.sh index 21c94f7..eea3bd4 100755 --- a/overlay/scripts/getconfig.sh +++ b/overlay/scripts/getconfig.sh @@ -1,39 +1,35 @@ #!/bin/bash get_file_contents() { - FILES=$1 - local FILE; - for FILE in $FILES; do - echo "# Including $FILE" - local LINE - while read LINE; do - CLEANLINE=`echo $LINE | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*\$//g'` - if [[ "$CLEANLINE" =~ ^include ]]; then - local CL_LEN - local INCUDE - CL_LEN=${#CLEANLINE}-9; - INCLUDE=${CLEANLINE:8:$CL_LEN} - get_file_contents "$INCLUDE" + local FILE + for FILE in "$@"; do + echo "# Including ${FILE}" + while IFS= read -r LINE; do + CLEANLINE=$(echo "${LINE}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + if [[ "${CLEANLINE}" =~ ^include[[:space:]]+(.+) ]]; then + local INCLUDE_EXPR="${BASH_REMATCH[1]}" + INCLUDE_EXPR="${INCLUDE_EXPR%;}" + eval "get_file_contents ${INCLUDE_EXPR}" else - echo $LINE + echo "${LINE}" fi - done < $FILE - echo "# Finished including $FILE" - + done <"${FILE}" + echo "# Finished including ${FILE}" done } - main() { + local ABS_PATH + ABS_PATH=$(readlink -f "${1}") || { + echo "Failed to resolve path: ${1}" >&2 + exit 1 + } - echo "NGINX CONFIG DUMP FOR $1" - - cd `dirname $1` + echo "NGINX CONFIG DUMP FOR ${ABS_PATH}" - get_file_contents $1 + cd "$(dirname "${ABS_PATH}")" || exit 1 + get_file_contents "${ABS_PATH}" } - - -main `readlink -f $1` +main "${1}" diff --git a/overlay/scripts/heartbeat.sh b/overlay/scripts/heartbeat.sh index fb17107..b734710 100755 --- a/overlay/scripts/heartbeat.sh +++ b/overlay/scripts/heartbeat.sh @@ -1,16 +1,20 @@ #!/bin/bash set -e -if [[ "$1" == "" ]]; then - BEATTIME=${BEAT_TIME} + +if [[ -n "${1}" ]]; then + BEATTIME="${1}" + [[ "${BEATTIME}" == 0 ]] && exit 0 else - BEATTIME=$1 - if [[ "$1" == 0 ]]; then - exit 0; - fi + # shellcheck disable=SC2153 + BEATTIME="${BEAT_TIME}" fi +if [[ -z "${BEATTIME}" || ! "${BEATTIME}" =~ ^[0-9]+([smhd])?$ ]]; then + echo "Error: BEATTIME must be a positive integer optionally followed by s, m, h, or d." >&2 + exit 1 +fi -while [ 1 ]; do - sleep $BEATTIME; - wget http://127.0.0.1/lancache-heartbeat -S -O - > /dev/null 2>&1 +while true; do + sleep "${BEATTIME}" + wget http://127.0.0.1/lancache-heartbeat -S -O - >/dev/null 2>&1 done diff --git a/run-tests.sh b/run-tests.sh index 3a1ff52..e29bb3c 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,9 +1,9 @@ #!/bin/bash -if [[ "$@" == *" -- "* ]]; then - SD_LOGLEVEL="-e SUPERVISORD_LOGLEVEL=INFO" -else - SD_LOGLEVEL="-- -e SUPERVISORD_LOGLEVEL=INFO" -fi +SD_LOGLEVEL=(-- -e SUPERVISORD_LOGLEVEL=INFO) -curl -fsSL https://raw.githubusercontent.com/lancachenet/test-suite/master/dgoss-tests.sh | bash -s -- --imagename="lancachenet/monolithic:goss-test" $@ $SD_LOGLEVEL -e GOSS_LOGLEVEL=DEBUG +for arg in "$@"; do + [[ "${arg}" == "--" ]] && SD_LOGLEVEL=(-e SUPERVISORD_LOGLEVEL=INFO) && break +done + +curl -fsSL https://raw.githubusercontent.com/lancachenet/test-suite/master/dgoss-tests.sh | bash -s -- --imagename="lancachenet/monolithic:goss-test" "$@" "${SD_LOGLEVEL[@]}" -e GOSS_LOGLEVEL="DEBUG"