diff --git a/CMakeLists.txt b/CMakeLists.txt index 87cbb8c29..7b69522b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ if(ENABLE_TEST_DEPENDENCIES) include(${CMAKE_SOURCE_DIR}/build/cmake/test/unbound.cmake) include(${CMAKE_SOURCE_DIR}/build/cmake/test/mongo-orchestration.cmake) include(${CMAKE_SOURCE_DIR}/build/cmake/test/lua-deps.cmake) + include(${CMAKE_SOURCE_DIR}/build/cmake/test/shellcheck.cmake) endif() include(${CMAKE_SOURCE_DIR}/build/cmake/test/lint.cmake) include(${CMAKE_SOURCE_DIR}/build/cmake/test/test-proxy.cmake) diff --git a/build/cmake/test/lint.cmake b/build/cmake/test/lint.cmake index 773d6a50e..e8726d895 100644 --- a/build/cmake/test/lint.cmake +++ b/build/cmake/test/lint.cmake @@ -6,8 +6,14 @@ add_custom_target( VERBATIM ) +add_custom_target( + shell-lint-target + COMMAND ${CMAKE_SOURCE_DIR}/test/scripts/shell-lint +) + add_custom_target( lint COMMAND ${CMAKE_BUILD_TOOL} all COMMAND ${CMAKE_BUILD_TOOL} lint-target + COMMAND ${CMAKE_BUILD_TOOL} shell-lint-target ) diff --git a/build/cmake/test/shellcheck.cmake b/build/cmake/test/shellcheck.cmake new file mode 100644 index 000000000..0182d4d82 --- /dev/null +++ b/build/cmake/test/shellcheck.cmake @@ -0,0 +1,11 @@ +ExternalProject_Add( + shellcheck + URL https://github.com/koalaman/shellcheck/archive/v${SHELLCHECK_VERSION}.tar.gz + URL_HASH MD5=${SHELLCHECK_HASH} + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND cabal sandbox init + COMMAND cabal update + COMMAND cabal install --reinstall --disable-library-profiling --disable-profiling --disable-optimization --disable-tests --disable-coverage --disable-benchmarks --disable-documentation + INSTALL_COMMAND cp /.cabal-sandbox/bin/shellcheck ${TEST_INSTALL_PREFIX}/bin/ +) diff --git a/build/cmake/versions.cmake b/build/cmake/versions.cmake index ee86de793..1f36922e7 100644 --- a/build/cmake/versions.cmake +++ b/build/cmake/versions.cmake @@ -75,6 +75,8 @@ set(RSYSLOG_VERSION 8.14.0) set(RSYSLOG_HASH 443b5b1d2b84f5cd429d06d230af7fb2352336fa6449cb6484dbd4418a7ae7c2) set(RUNIT_VERSION 2.1.2) set(RUNIT_HASH 6c985fbfe3a34608eb3c53dc719172c4) +set(SHELLCHECK_VERSION 0.4.3) +set(SHELLCHECK_HASH 27bacd94775b62c654a3a2f753da576e) # Don't move to TrafficServer 6 until we can verify keepalive behavior: # https://issues.apache.org/jira/browse/TS-3959 set(TRAFFICSERVER_VERSION 5.3.2) diff --git a/build/package/build_package b/build/package/build_package index 7a3022492..c93a2fbbf 100755 --- a/build/package/build_package +++ b/build/package/build_package @@ -2,72 +2,64 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)))" +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" -VERSION_STRING=$(cat $SOURCE_DIR/src/api-umbrella/version.txt) -VERSION_MATCHER="^([^-]+)(-(.+))?$" -if [[ $VERSION_STRING =~ $VERSION_MATCHER ]]; then - VERSION=${BASH_REMATCH[1]} - VERSION_PRE=${BASH_REMATCH[3]} -fi - -PACKAGE_ITERATION="1" -if [ -n "$VERSION_PRE" ]; then - PACKAGE_ITERATION="0.$PACKAGE_ITERATION.$VERSION_PRE" -fi +# shellcheck source=build/package/parse_version +source "$source_dir/build/package/parse_version" -source $SOURCE_DIR/build/package_dependencies.sh +# shellcheck source=build/package_dependencies.sh +source "$source_dir/build/package_dependencies.sh" if [ -f /etc/redhat-release ]; then - PACKAGE_TYPE="rpm" - RPM_DIST=$(rpm --query centos-release | grep -o "el[0-9]") + package_type="rpm" + rpm_dist=$(rpm --query centos-release | grep -o "el[0-9]") elif [ -f /etc/debian_version ]; then - PACKAGE_TYPE="deb" - PACKAGE_ITERATION="$PACKAGE_ITERATION~$(lsb_release --codename --short)" + package_type="deb" + package_iteration="$package_iteration~$(lsb_release --codename --short)" else echo "Unknown build system" exit 1 fi -FPM_ARGS=() -FPM_ARGS+=("--rpm-dist" "$RPM_DIST") -FPM_ARGS+=("-t" "$PACKAGE_TYPE") -FPM_ARGS+=("-s" "dir") -FPM_ARGS+=("--verbose") -FPM_ARGS+=("--license" "MIT") -FPM_ARGS+=("--version" "$VERSION") -FPM_ARGS+=("--iteration" "$PACKAGE_ITERATION") -if [ "$PACKAGE_TYPE" == "rpm" ]; then - FPM_ARGS+=("--rpm-dist" "$RPM_DIST") - FPM_ARGS+=("--rpm-compression" "xz") -elif [ "$PACKAGE_TYPE" == "deb" ]; then - FPM_ARGS+=("--deb-compression" "xz") - FPM_ARGS+=("--deb-no-default-config-files") +fpm_args=() +fpm_args+=("--rpm-dist" "$rpm_dist") +fpm_args+=("-t" "$package_type") +fpm_args+=("-s" "dir") +fpm_args+=("--verbose") +fpm_args+=("--license" "MIT") +fpm_args+=("--version" "$version") +fpm_args+=("--iteration" "$package_iteration") +if [ "$package_type" == "rpm" ]; then + fpm_args+=("--rpm-dist" "$rpm_dist") + fpm_args+=("--rpm-compression" "xz") +elif [ "$package_type" == "deb" ]; then + fpm_args+=("--deb-compression" "xz") + fpm_args+=("--deb-no-default-config-files") fi if [ "$PACKAGE" == "core" ]; then - for DEP in "${CORE_PACKAGE_DEPENDENCIES[@]}"; do - FPM_ARGS+=("-d" "$DEP") + for dep in "${core_package_dependencies[@]}"; do + fpm_args+=("-d" "$dep") done - FPM_ARGS+=("-C" "$WORK_DIR/package-dest-core") - FPM_ARGS+=("--name api-umbrella") - FPM_ARGS+=("--config-files" "etc/api-umbrella/api-umbrella.yml") - FPM_ARGS+=("--after-install" "$SOURCE_DIR/build/package/scripts/after-install") - FPM_ARGS+=("--before-remove" "$SOURCE_DIR/build/package/scripts/before-remove") - FPM_ARGS+=("--after-remove" "$SOURCE_DIR/build/package/scripts/after-remove") - FPM_ARGS+=("--directories" "/opt/api-umbrella") - FPM_ARGS+=("--directories" "/etc/api-umbrella") + fpm_args+=("-C" "$WORK_DIR/package-dest-core") + fpm_args+=("--name api-umbrella") + fpm_args+=("--config-files" "etc/api-umbrella/api-umbrella.yml") + fpm_args+=("--after-install" "$source_dir/build/package/scripts/after-install") + fpm_args+=("--before-remove" "$source_dir/build/package/scripts/before-remove") + fpm_args+=("--after-remove" "$source_dir/build/package/scripts/after-remove") + fpm_args+=("--directories" "/opt/api-umbrella") + fpm_args+=("--directories" "/etc/api-umbrella") elif [ "$PACKAGE" == "hadoop-analytics" ]; then - for DEP in "${HADOOP_ANALYTICS_PACKAGE_DEPENDENCIES[@]}"; do - FPM_ARGS+=("-d" "$DEP") + for dep in "${hadoop_analytics_package_dependencies[@]}"; do + fpm_args+=("-d" "$dep") done - FPM_ARGS+=("-C" "$WORK_DIR/package-dest-hadoop-analytics") - FPM_ARGS+=("--name api-umbrella-hadoop-analytics") - FPM_ARGS+=("--depends" "api-umbrella") + fpm_args+=("-C" "$WORK_DIR/package-dest-hadoop-analytics") + fpm_args+=("--name api-umbrella-hadoop-analytics") + fpm_args+=("--depends" "api-umbrella") fi -mkdir -p $WORK_DIR/package/build/$PACKAGE -cd $WORK_DIR/package/build/$PACKAGE -env XZ_OPT=-9 bundle exec fpm ${FPM_ARGS[*]} +mkdir -p "$WORK_DIR/package/build/$PACKAGE" +cd "$WORK_DIR/package/build/$PACKAGE" +env XZ_OPT=-9 bundle exec fpm "${fpm_args[@]}" diff --git a/build/package/docker_run b/build/package/docker_run index d9c7de823..8995e62da 100755 --- a/build/package/docker_run +++ b/build/package/docker_run @@ -2,27 +2,27 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)))" -DOCKER_IMAGE=${DIST/-/:} -CONTAINER_NAME="api-umbrella-package-$DIST" -CONTAINER_NAME=${CONTAINER_NAME//[^a-zA-Z0-9_.-]/} +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" +docker_image=${DIST/-/:} +container_name="api-umbrella-package-$DIST" +container_name=${container_name//[^a-zA-Z0-9_.-]/} # Make sure we have the latest base image. -docker pull $DOCKER_IMAGE +docker pull "$docker_image" # Wipe any previous build attempts. -EXISTING=$(docker ps -a -q --filter="name=$CONTAINER_NAME") -if [ "$EXISTING" != "" ]; then - docker rm -f $EXISTING +existing=$(docker ps -a -q --filter="name=$container_name") +if [ "$existing" != "" ]; then + docker rm -f "$existing" fi # Create the package inside the docker container for this distro. docker run \ - --name=$CONTAINER_NAME \ - --volume=$SOURCE_DIR:/api-umbrella \ + --name="$container_name" \ + --volume="$source_dir:/api-umbrella" \ --env="DIST=$DIST" \ --rm \ - $DOCKER_IMAGE \ + "$docker_image" \ /bin/bash -c "/api-umbrella/build/package/docker_script" echo "Completed package build for $DIST" diff --git a/build/package/docker_script b/build/package/docker_script index 07ddec5f6..f774fd63b 100755 --- a/build/package/docker_script +++ b/build/package/docker_script @@ -2,27 +2,27 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)))" +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" # Install any system dependencies for building. -$SOURCE_DIR/build/scripts/install_build_dependencies +"$source_dir/build/scripts/install_build_dependencies" # Wipe any cmake files in the source directory, so we can perform an # out-of-source build. -rm -rf $SOURCE_DIR/cmake_install.cmake $SOURCE_DIR/CMakeCache.txt $SOURCE_DIR/CMakeFiles $SOURCE_DIR/Makefile +rm -rf "$source_dir/cmake_install.cmake" "$source_dir/CMakeCache.txt" "$source_dir/CMakeFiles" "$source_dir/Makefile" # Perform an out-of-source build (so the same source directory can be used for # multiple parallel docker builds). -BUILD_DIR=/tmp/api-umbrella-$DIST -rm -rf $BUILD_DIR -mkdir -p $BUILD_DIR -cd $BUILD_DIR -$SOURCE_DIR/configure --enable-hadoop-analytics +build_dir="/tmp/api-umbrella-$DIST" +rm -rf "$build_dir" +mkdir -p "$build_dir" +cd "$build_dir" +"$source_dir/configure" --enable-hadoop-analytics make make package # Copy the packages for this distro back to the source directory so it's # available on the host machine, outside the docker build container. -rm -rf $SOURCE_DIR/build/work/package/current/$DIST -mkdir -p $SOURCE_DIR/build/work/package/current/$DIST -cp -r $BUILD_DIR/build/work/package/build/* $SOURCE_DIR/build/work/package/current/$DIST/ +rm -rf "$source_dir/build/work/package/current/$DIST" +mkdir -p "$source_dir/build/work/package/current/$DIST" +cp -r "$build_dir/build/work/package/build"/* "$source_dir/build/work/package/current/$DIST/" diff --git a/build/package/files/etc/init.d/api-umbrella b/build/package/files/etc/init.d/api-umbrella index ead458397..8075dbc42 100755 --- a/build/package/files/etc/init.d/api-umbrella +++ b/build/package/files/etc/init.d/api-umbrella @@ -16,67 +16,71 @@ # Short-Description: API Umbrella ### END INIT INFO -NAME=api-umbrella -DESC="API Umbrella" +name=api-umbrella +desc="API Umbrella" if [ -f /etc/rc.d/init.d/functions ]; then + # shellcheck disable=SC1091 . /etc/rc.d/init.d/functions elif [ -f /lib/lsb/init-functions ]; then + # shellcheck disable=SC1091 . /lib/lsb/init-functions fi if [ -f /etc/sysconfig/api-umbrella ]; then + # shellcheck disable=SC1091 . /etc/sysconfig/api-umbrella elif [ -f /etc/default/api-umbrella ]; then + # shellcheck disable=SC1091 . /etc/default/api-umbrella fi start() { if type log_daemon_msg > /dev/null 2>&1; then - log_daemon_msg "Starting $DESC" "$NAME" + log_daemon_msg "Starting $desc" "$name" else - echo -n $"Starting $NAME: " + echo -n $"Starting $name: " fi api-umbrella start - RETVAL=$? + retval=$? if type log_end_msg > /dev/null 2>&1; then - log_end_msg $RETVAL + log_end_msg $retval elif type success > /dev/null 2>&1; then - if [ $RETVAL -eq 0 ]; then - success $"$NAME startup" + if [ $retval -eq 0 ]; then + success $"$name startup" else - failure $"$NAME startup" + failure $"$name startup" fi echo fi - return $RETVAL + return $retval } stop() { if type log_daemon_msg > /dev/null 2>&1; then - log_daemon_msg "Stopping $DESC" "$NAME" + log_daemon_msg "Stopping $desc" "$name" else - echo -n $"Stopping $NAME: " + echo -n $"Stopping $name: " fi api-umbrella stop - RETVAL=$? + retval=$? if type log_end_msg > /dev/null 2>&1; then - log_end_msg $RETVAL + log_end_msg $retval elif type success > /dev/null 2>&1; then - if [ $RETVAL -eq 0 ]; then - success $"$NAME shutdown" + if [ $retval -eq 0 ]; then + success $"$name shutdown" else - failure $"$NAME shutdown" + failure $"$name shutdown" fi echo fi - return $RETVAL + return $retval } restart() { @@ -86,32 +90,32 @@ restart() { reload() { if type log_daemon_msg > /dev/null 2>&1; then - log_daemon_msg "Reloading $DESC" "$NAME" + log_daemon_msg "Reloading $desc" "$name" else - echo -n $"Reloading $NAME: " + echo -n $"Reloading $name: " fi api-umbrella reload - RETVAL=$? + retval=$? if type log_end_msg > /dev/null 2>&1; then - log_end_msg $RETVAL + log_end_msg $retval elif type success > /dev/null 2>&1; then - if [ $RETVAL -eq 0 ]; then - success $"$NAME reload" + if [ $retval -eq 0 ]; then + success $"$name reload" else - failure $"$NAME reload" + failure $"$name reload" fi echo fi - return $RETVAL + return $retval } status() { api-umbrella status - RETVAL=$? - return $RETVAL + retval=$? + return $retval } status_quiet() { @@ -139,7 +143,7 @@ case "$1" in restart ;; *) - echo "Usage: $NAME {start|stop|status|reload|restart|condrestart}" + echo "Usage: $name {start|stop|status|reload|restart|condrestart}" exit 1 ;; esac diff --git a/build/package/parse_version b/build/package/parse_version new file mode 100755 index 000000000..2b9d7bf9e --- /dev/null +++ b/build/package/parse_version @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e -u -x + +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" + +version_string=$(cat "$source_dir/src/api-umbrella/version.txt") +version_matcher="^([^-]+)(-(.+))?$" +if [[ $version_string =~ $version_matcher ]]; then + # shellcheck disable=SC2034 + version=${BASH_REMATCH[1]} + version_pre=${BASH_REMATCH[3]} +fi + +package_iteration="1" +if [ -n "$version_pre" ]; then + package_iteration="0.$package_iteration.$version_pre" +fi diff --git a/build/package/publish b/build/package/publish index b0ecfc477..700e11203 100755 --- a/build/package/publish +++ b/build/package/publish @@ -2,53 +2,52 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)))" - -source $SOURCE_DIR/src/api-umbrella/version.sh -VERSION="$API_UMBRELLA_VERSION_BASE" -ITERATION="$API_UMBRELLA_VERSION_PACKAGE_ITERATION" - -PACKAGES=( - build/package/dist/centos-6/api-umbrella-$VERSION-$ITERATION.el6.x86_64.rpm - build/package/dist/centos-7/api-umbrella-$VERSION-$ITERATION.el7.x86_64.rpm - build/package/dist/debian-7/api-umbrella_$VERSION-$ITERATION~wheezy_amd64.deb - build/package/dist/debian-8/api-umbrella_$VERSION-$ITERATION~jessie_amd64.deb - build/package/dist/ubuntu-12.04/api-umbrella_$VERSION-$ITERATION~precise_amd64.deb - build/package/dist/ubuntu-14.04/api-umbrella_$VERSION-$ITERATION~trusty_amd64.deb +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" + +# shellcheck source=build/package/parse_version +source "$source_dir/build/package/parse_version" + +packages=( + build/package/dist/centos-6/api-umbrella-$version-$package_iteration.el6.x86_64.rpm + build/package/dist/centos-7/api-umbrella-$version-$package_iteration.el7.x86_64.rpm + build/package/dist/debian-7/api-umbrella_$version-$package_iteration~wheezy_amd64.deb + build/package/dist/debian-8/api-umbrella_$version-$package_iteration~jessie_amd64.deb + build/package/dist/ubuntu-12.04/api-umbrella_$version-$package_iteration~precise_amd64.deb + build/package/dist/ubuntu-14.04/api-umbrella_$version-$package_iteration~trusty_amd64.deb ) -for PACKAGE in "${PACKAGES[@]}"; do - if [ ! -f "$PACKAGE" ]; then - echo "Expected package for current version does not exist: $PACKAGE" +for package in "${packages[@]}"; do + if [ ! -f "$package" ]; then + echo "Expected package for current version does not exist: $package" exit 1 fi done -for PACKAGE in "${PACKAGES[@]}"; do - CURL_ARGS=() - FILE_PATH=$(basename $PACKAGE) +for package in "${packages[@]}"; do + curl_args=() + file_path=$(basename "$package") - if [[ "$PACKAGE" == *"centos"* ]]; then - [[ "$FILE_PATH" =~ \.(el[0-9])\. ]] + if [[ "$package" == *"centos"* ]]; then + [[ "$file_path" =~ \.(el[0-9])\. ]] echo "${BASH_REMATCH[1]}" - REPO="api-umbrella-${BASH_REMATCH[1]}" - elif [[ "$PACKAGE" == *"debian"* ]]; then - REPO=api-umbrella-debian - elif [[ "$PACKAGE" == *"ubuntu"* ]]; then - REPO=api-umbrella-ubuntu + repo="api-umbrella-${BASH_REMATCH[1]}" + elif [[ "$package" == *"debian"* ]]; then + repo=api-umbrella-debian + elif [[ "$package" == *"ubuntu"* ]]; then + repo=api-umbrella-ubuntu fi - CURL_ARGS+=("--user" "$BINTRAY_USERNAME:$BINTRAY_API_KEY") - CURL_ARGS+=("--upload-file" "$PACKAGE") - CURL_ARGS+=("--fail") - if [[ "$PACKAGE" == *"debian"* || "$PACKAGE" == *"ubuntu"* ]]; then - [[ "$FILE_PATH" =~ ~([a-z]+)_ ]] - CURL_ARGS+=("-H" "X-Bintray-Debian-Distribution: ${BASH_REMATCH[1]}") - [[ "$FILE_PATH" =~ _([a-z0-9]+)\.deb ]] - CURL_ARGS+=("-H" "X-Bintray-Debian-Architecture: ${BASH_REMATCH[1]}") - CURL_ARGS+=("-H" "X-Bintray-Debian-Component: main") - FILE_PATH="pool/main/a/api-umbrella/$FILE_PATH" + curl_args+=("--user" "$BINTRAY_USERNAME:$BINTRAY_API_KEY") + curl_args+=("--upload-file" "$package") + curl_args+=("--fail") + if [[ "$package" == *"debian"* || "$package" == *"ubuntu"* ]]; then + [[ "$file_path" =~ ~([a-z]+)_ ]] + curl_args+=("-H" "X-Bintray-Debian-Distribution: ${BASH_REMATCH[1]}") + [[ "$file_path" =~ _([a-z0-9]+)\.deb ]] + curl_args+=("-H" "X-Bintray-Debian-Architecture: ${BASH_REMATCH[1]}") + curl_args+=("-H" "X-Bintray-Debian-Component: main") + file_path="pool/main/a/api-umbrella/$file_path" fi - curl -X PUT "${CURL_ARGS[@]}" "https://api.bintray.com/content/nrel/$REPO/api-umbrella/$VERSION/$FILE_PATH" + curl -X PUT "${curl_args[@]}" "https://api.bintray.com/content/nrel/$repo/api-umbrella/$version/$file_path" done diff --git a/build/package/scripts/after-install b/build/package/scripts/after-install index 56d4eb402..ce8b85867 100755 --- a/build/package/scripts/after-install +++ b/build/package/scripts/after-install @@ -2,17 +2,17 @@ set -e -u -CONFIGURE=false -RESTART_SERVICE=false +configure=false +restart_service=false case "$1" in # dpkg configure) - CONFIGURE=true + configure=true # Upgrade - if [ -n $2 ]; then - RESTART_SERVICE=true + if [ -n "$2" ]; then + restart_service=true fi ;; @@ -21,70 +21,70 @@ case "$1" in # rpm 1) # install - CONFIGURE=true + configure=true ;; 2) # upgrade - CONFIGURE=true + configure=true ;; esac -if [ "$CONFIGURE" = "true" ]; then - USER=api-umbrella - GROUP=api-umbrella - DEPLOY_USER=api-umbrella-deploy - DEPLOY_GROUP=api-umbrella-deploy +if [ "$configure" = "true" ]; then + user=api-umbrella + group=api-umbrella + deploy_user=api-umbrella-deploy + deploy_group=api-umbrella-deploy # Create the main user & group. - if ! getent group $GROUP > /dev/null; then - groupadd -r $GROUP + if ! getent group $group > /dev/null; then + groupadd -r $group fi - if ! getent passwd $USER > /dev/null; then - useradd -r -g $GROUP -s /sbin/nologin \ - -d /opt/api-umbrella -c "API Umbrella user" $USER + if ! getent passwd $user > /dev/null; then + useradd -r -g $group -s /sbin/nologin \ + -d /opt/api-umbrella -c "API Umbrella user" $user fi # Create the deploy user & group. - if ! getent group $DEPLOY_GROUP > /dev/null; then - groupadd -r $DEPLOY_GROUP + if ! getent group $deploy_group > /dev/null; then + groupadd -r $deploy_group fi - if ! getent passwd $DEPLOY_USER > /dev/null; then - useradd -r -g $DEPLOY_GROUP -s /bin/bash \ - -d /home/$DEPLOY_USER -c "API Umbrella deployment user" $DEPLOY_USER + if ! getent passwd $deploy_user > /dev/null; then + useradd -r -g $deploy_group -s /bin/bash \ + -d /home/$deploy_user -c "API Umbrella deployment user" $deploy_user fi # Add the deploy user to the app group, so the deploy user can read config # files. - if ! groups $DEPLOY_USER | grep -q -E "\s$GROUP(\s|$)"; then - usermod -a -G $GROUP $DEPLOY_USER + if ! groups $deploy_user | grep -q -E "\s$group(\s|$)"; then + usermod -a -G $group $deploy_user fi # Fix previously created deploy user that couldn't actually login. - if getent passwd $DEPLOY_USER | grep -q "/sbin/nologin"; then - usermod -d /home/$DEPLOY_USER -s /bin/bash $DEPLOY_USER + if getent passwd $deploy_user | grep -q "/sbin/nologin"; then + usermod -d /home/$deploy_user -s /bin/bash $deploy_user fi # Create an empty .ssh/authorized_keys file with proper permissions if it # doesn't already exist. - if [ ! -f /home/$DEPLOY_USER/.ssh/authorized_keys ]; then - mkdir -p /home/$DEPLOY_USER/.ssh - touch /home/$DEPLOY_USER/.ssh/authorized_keys - chown -R $DEPLOY_USER:$DEPLOY_GROUP /home/$DEPLOY_USER - chmod 700 /home/$DEPLOY_USER - chmod 700 /home/$DEPLOY_USER/.ssh - chmod 600 /home/$DEPLOY_USER/.ssh/authorized_keys + if [ ! -f /home/$deploy_user/.ssh/authorized_keys ]; then + mkdir -p /home/$deploy_user/.ssh + touch /home/$deploy_user/.ssh/authorized_keys + chown -R $deploy_user:$deploy_group /home/$deploy_user + chmod 700 /home/$deploy_user + chmod 700 /home/$deploy_user/.ssh + chmod 600 /home/$deploy_user/.ssh/authorized_keys fi # Set file permissions - chown -R $USER:$GROUP /opt/api-umbrella/etc /opt/api-umbrella/var - chown -R $DEPLOY_USER:$DEPLOY_GROUP /opt/api-umbrella/embedded/apps + chown -R $user:$group /opt/api-umbrella/etc /opt/api-umbrella/var + chown -R $deploy_user:$deploy_group /opt/api-umbrella/embedded/apps mkdir -p /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache - chown -R $USER:$DEPLOY_GROUP /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp + chown -R $user:$deploy_group /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp mkdir -p /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/ember-rails /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/assets /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/sass - chown -R $DEPLOY_USER:$GROUP /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/ember-rails /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/assets /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/sass + chown -R $deploy_user:$group /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/ember-rails /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/assets /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/sass chmod -R 775 /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/ember-rails /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/assets /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp/cache/sass chmod 1777 /opt/api-umbrella/embedded/apps/core/shared/src/api-umbrella/web-app/tmp if [ -d /opt/api-umbrella/embedded/kylin ]; then - chown $USER:$GROUP /opt/api-umbrella/embedded/kylin/tomcat/temp \ + chown $user:$group /opt/api-umbrella/embedded/kylin/tomcat/temp \ /opt/api-umbrella/embedded/kylin/tomcat/webapps \ /opt/api-umbrella/embedded/kylin/tomcat/logs fi @@ -108,7 +108,7 @@ if [ "$CONFIGURE" = "true" ]; then fi fi -if [ "$RESTART_SERVICE" = "true" ]; then +if [ "$restart_service" = "true" ]; then # On upgrades, restart the service if it's currently running. /etc/init.d/api-umbrella condrestart fi diff --git a/build/package/scripts/after-remove b/build/package/scripts/after-remove index 14f6e1ad1..f81599fb3 100755 --- a/build/package/scripts/after-remove +++ b/build/package/scripts/after-remove @@ -2,73 +2,73 @@ set -e -u -REMOVE_ACCOUNTS=false -REMOVE_DATA=false -REMOVE_FILES=false -REMOVE_SERVICE=false -RESTART_SERVICE=false +remove_accounts=false +remove_data=false +remove_files=false +remove_service=false +restart_service=false case "$1" in # dpkg remove) - REMOVE_FILES=true - REMOVE_SERVICE=true + remove_files=true + remove_service=true ;; purge) - REMOVE_ACCOUNTS=true - REMOVE_DATA=true + remove_accounts=true + remove_data=true ;; abort-install|abort-upgrade|disappear|failed-upgrade|upgrade) ;; # rpm 0) # uninstall - REMOVE_FILES=true + remove_files=true ;; 1) # upgrade - RESTART_SERVICE=true + restart_service=true ;; esac -if [ "$REMOVE_FILES" = "true" ]; then +if [ "$remove_files" = "true" ]; then rm -f /usr/bin/api-umbrella /var/log/api-umbrella rmdir /etc/api-umbrella > /dev/null 2>&1 || true # Delete directory if empty. fi -if [ "$REMOVE_SERVICE" = "true" ]; then +if [ "$remove_service" = "true" ]; then if command -v update-rc.d > /dev/null 2>&1; then update-rc.d api-umbrella remove > /dev/null fi fi -if [ "$REMOVE_DATA" = "true" ]; then +if [ "$remove_data" = "true" ]; then rm -rf /etc/api-umbrella /opt/api-umbrella fi -if [ "$REMOVE_ACCOUNTS" = "true" ]; then - USER=api-umbrella - GROUP=api-umbrella - DEPLOY_USER=api-umbrella-deploy - DEPLOY_GROUP=api-umbrella-deploy +if [ "$remove_accounts" = "true" ]; then + user=api-umbrella + group=api-umbrella + deploy_user=api-umbrella-deploy + deploy_group=api-umbrella-deploy - if getent passwd $DEPLOY_USER > /dev/null; then - userdel $DEPLOY_USER + if getent passwd $deploy_user > /dev/null; then + userdel $deploy_user fi - if getent passwd $USER > /dev/null; then - userdel $USER + if getent passwd $user > /dev/null; then + userdel $user fi - if getent group $DEPLOY_GROUP > /dev/null; then - groupdel $DEPLOY_GROUP + if getent group $deploy_group > /dev/null; then + groupdel $deploy_group fi - if getent group $GROUP > /dev/null; then - groupdel $GROUP + if getent group $group > /dev/null; then + groupdel $group fi fi -if [ "$RESTART_SERVICE" = "true" ]; then +if [ "$restart_service" = "true" ]; then # On upgrades, restart the service if it's currently running. /etc/init.d/api-umbrella condrestart fi diff --git a/build/package/scripts/before-remove b/build/package/scripts/before-remove index f9ea243de..8fda25624 100755 --- a/build/package/scripts/before-remove +++ b/build/package/scripts/before-remove @@ -2,31 +2,31 @@ set -e -u -STOP_SERVICE=false -REMOVE_SERVICE=false +stop_service=false +remove_service=false case "$1" in # dpkg remove) - STOP_SERVICE=true + stop_service=true ;; deconfigure|failed-upgrade|upgrade) ;; # rpm 0) # uninstall - STOP_SERVICE=true - REMOVE_SERVICE=true + stop_service=true + remove_service=true ;; 1) # upgrade ;; esac -if [ "$STOP_SERVICE" = "true" ]; then +if [ "$stop_service" = "true" ]; then /etc/init.d/api-umbrella stop || true fi -if [ "$REMOVE_SERVICE" = "true" ]; then +if [ "$remove_service" = "true" ]; then if command -v chkconfig > /dev/null 2>&1; then chkconfig --del api-umbrella fi diff --git a/build/package/verify/docker_run b/build/package/verify/docker_run index e73aa6390..e244e6666 100755 --- a/build/package/verify/docker_run +++ b/build/package/verify/docker_run @@ -2,27 +2,27 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd))))" -DOCKER_IMAGE=${DIST/-/:} -CONTAINER_NAME="api-umbrella-package-$DIST-verify" -CONTAINER_NAME=${CONTAINER_NAME//[^a-zA-Z0-9_.-]/} +source_dir="$(dirname "$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")")" +docker_image=${DIST/-/:} +container_name="api-umbrella-package-$DIST-verify" +container_name=${container_name//[^a-zA-Z0-9_.-]/} # Wipe any previous build attempts. -EXISTING=$(docker ps -a -q --filter="name=$CONTAINER_NAME") -if [ "$EXISTING" != "" ]; then - docker rm -f $EXISTING +existing=$(docker ps -a -q --filter="name=$container_name") +if [ "$existing" != "" ]; then + docker rm -f "$existing" fi # Run inside a privileged container so the ulimit settings that API Umbrella # v0.8 attempt work (needed so we can test upgrades from v0.8). docker run \ - --name=$CONTAINER_NAME \ - --volume=$SOURCE_DIR:/api-umbrella \ + --name="$container_name" \ + --volume="$source_dir:/api-umbrella" \ --env="DIST=$DIST" \ --tty \ --rm \ --privileged \ - $DOCKER_IMAGE \ + "$docker_image" \ /bin/bash -c "/api-umbrella/build/package/verify/docker_script" echo "Completed package verification for $DIST" diff --git a/build/package/verify/docker_script b/build/package/verify/docker_script index 88f91bd92..281a6e1c8 100755 --- a/build/package/verify/docker_script +++ b/build/package/verify/docker_script @@ -2,15 +2,15 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd))))" +source_dir="$(dirname "$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")")" # Install the local package that just got built. -CURRENT_PACKAGE=$SOURCE_DIR/build/work/package/current/$DIST/core/* +current_package_dir="$source_dir/build/work/package/current/$DIST/core" if command -v yum > /dev/null 2>&1; then - yum -y install $CURRENT_PACKAGE + yum -y install "$current_package_dir"/*.rpm elif command -v dpkg > /dev/null 2>&1; then apt-get update - dpkg -i $CURRENT_PACKAGE || apt-get install -y -f + dpkg -i "$current_package_dir"/*.deb || apt-get install -y -f else echo "Unknown build system" exit 1 @@ -48,14 +48,14 @@ gem install bundler --no-rdoc --no-ri # Perform an out-of-source build (so the same source directory can be used for # multiple parallel docker builds). -BUILD_DIR=/tmp/api-umbrella-$DIST -rm -rf $BUILD_DIR -mkdir -p $BUILD_DIR -cd $BUILD_DIR +build_dir=/tmp/api-umbrella-$DIST +rm -rf "$build_dir" +mkdir -p "$build_dir" +cd "$build_dir" # Install the test gem dependencies. -BUNDLE_GEMFILE=$SOURCE_DIR/build/package/verify/Gemfile BUNDLE_APP_CONFIG=$BUILD_DIR/.bundle bundle install --clean --path=$BUILD_DIR/bundle +BUNDLE_GEMFILE="$source_dir/build/package/verify/Gemfile" BUNDLE_APP_CONFIG="$build_dir/.bundle" bundle install --clean --path="$build_dir/bundle" # Run the serverspec suite. -cd $SOURCE_DIR/build/package/verify -BUNDLE_GEMFILE=$SOURCE_DIR/build/package/verify/Gemfile BUNDLE_APP_CONFIG=$BUILD_DIR/.bundle SOURCE_DIR=$SOURCE_DIR DIST=$DIST bundle exec rake spec +cd "$source_dir/build/package/verify" +BUNDLE_GEMFILE="$source_dir/build/package/verify/Gemfile" BUNDLE_APP_CONFIG="$build_dir/.bundle" SOURCE_DIR="$source_dir" DIST="$DIST" bundle exec rake spec diff --git a/build/package/verify/download_previous_packages b/build/package/verify/download_previous_packages index 9c7e5e791..bf33efba4 100755 --- a/build/package/verify/download_previous_packages +++ b/build/package/verify/download_previous_packages @@ -6,9 +6,9 @@ set -e -u -SOURCE_DIR="$(dirname $(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd))))" +source_dir="$(dirname "$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")")" -PREVIOUS_VERSIONS=( +previous_versions=( 0.8.0-1 0.9.0-1 0.10.0-1 @@ -16,7 +16,7 @@ PREVIOUS_VERSIONS=( 0.11.1-1 ) -DISTROS=( +distros=( centos-6 centos-7 ubuntu-12.04 @@ -25,91 +25,91 @@ DISTROS=( debian-8 ) -SOURCEFORGE_URL_ROOT="http://pilotfiber.dl.sourceforge.net/project/api-umbrella" -BINTRAY_URL_ROOT="https://bintray.com/artifact/download/nrel" -CHECKSUMS=$(cat $SOURCE_DIR/sha256sums.txt) +sourceforge_url_root="http://pilotfiber.dl.sourceforge.net/project/api-umbrella" +bintray_url_root="https://bintray.com/artifact/download/nrel" +checksums="$(cat "$source_dir/sha256sums.txt")" -for DIST in "${DISTROS[@]}"; do - for VERSION in "${PREVIOUS_VERSIONS[@]}"; do - FILENAME="" - URL_PREFIX="" - URL_FILENAME="" +for dist in "${distros[@]}"; do + for version in "${previous_versions[@]}"; do + filename="" + url_prefix="" + url_filename="" - case "$DIST" in + case "$dist" in centos-6) - FILENAME="api-umbrella-${VERSION}.el6.x86_64.rpm" - if [ "$VERSION" == "0.8.0-1" ]; then - URL_PREFIX="$SOURCEFORGE_URL_ROOT/el/6" + filename="api-umbrella-${version}.el6.x86_64.rpm" + if [ "$version" == "0.8.0-1" ]; then + url_prefix="$sourceforge_url_root/el/6" else - URL_PREFIX="$BINTRAY_URL_ROOT/api-umbrella-el6" + url_prefix="$bintray_url_root/api-umbrella-el6" fi ;; centos-7) - FILENAME="api-umbrella-${VERSION}.el7.x86_64.rpm" - if [ "$VERSION" == "0.8.0-1" ]; then - URL_PREFIX="$SOURCEFORGE_URL_ROOT/el/7" + filename="api-umbrella-${version}.el7.x86_64.rpm" + if [ "$version" == "0.8.0-1" ]; then + url_prefix="$sourceforge_url_root/el/7" else - URL_PREFIX="$BINTRAY_URL_ROOT/api-umbrella-el7" + url_prefix="$bintray_url_root/api-umbrella-el7" fi ;; ubuntu-12.04) - FILENAME="api-umbrella_${VERSION}~precise_amd64.deb" - if [ "$VERSION" == "0.8.0-1" ]; then - URL_FILENAME="api-umbrella_${VERSION}_amd64.deb" - URL_PREFIX="$SOURCEFORGE_URL_ROOT/ubuntu/12.04" + filename="api-umbrella_${version}~precise_amd64.deb" + if [ "$version" == "0.8.0-1" ]; then + url_filename="api-umbrella_${version}_amd64.deb" + url_prefix="$sourceforge_url_root/ubuntu/12.04" else - URL_PREFIX="$BINTRAY_URL_ROOT/api-umbrella-ubuntu/pool/main/a/api-umbrella" + url_prefix="$bintray_url_root/api-umbrella-ubuntu/pool/main/a/api-umbrella" fi ;; ubuntu-14.04) - FILENAME="api-umbrella_${VERSION}~trusty_amd64.deb" - if [ "$VERSION" == "0.8.0-1" ]; then - URL_FILENAME="api-umbrella_${VERSION}_amd64.deb" - URL_PREFIX="$SOURCEFORGE_URL_ROOT/ubuntu/14.04" + filename="api-umbrella_${version}~trusty_amd64.deb" + if [ "$version" == "0.8.0-1" ]; then + url_filename="api-umbrella_${version}_amd64.deb" + url_prefix="$sourceforge_url_root/ubuntu/14.04" else - URL_PREFIX="$BINTRAY_URL_ROOT/api-umbrella-ubuntu/pool/main/a/api-umbrella" + url_prefix="$bintray_url_root/api-umbrella-ubuntu/pool/main/a/api-umbrella" fi ;; debian-7) - FILENAME="api-umbrella_${VERSION}~wheezy_amd64.deb" - if [ "$VERSION" == "0.8.0-1" ]; then - URL_FILENAME="api-umbrella_${VERSION}_amd64.deb" - URL_PREFIX="$SOURCEFORGE_URL_ROOT/debian/7" + filename="api-umbrella_${version}~wheezy_amd64.deb" + if [ "$version" == "0.8.0-1" ]; then + url_filename="api-umbrella_${version}_amd64.deb" + url_prefix="$sourceforge_url_root/debian/7" else - URL_PREFIX="$BINTRAY_URL_ROOT/api-umbrella-debian/pool/main/a/api-umbrella" + url_prefix="$bintray_url_root/api-umbrella-debian/pool/main/a/api-umbrella" fi ;; debian-8) - FILENAME="api-umbrella_${VERSION}~jessie_amd64.deb" - if [ "$VERSION" == "0.8.0-1" ]; then + filename="api-umbrella_${version}~jessie_amd64.deb" + if [ "$version" == "0.8.0-1" ]; then # No Debian 8 packages for API Umbrella v0.8. - FILENAME="" + filename="" else - URL_PREFIX="$BINTRAY_URL_ROOT/api-umbrella-debian/pool/main/a/api-umbrella" + url_prefix="$bintray_url_root/api-umbrella-debian/pool/main/a/api-umbrella" fi ;; esac - if [ -n "$FILENAME" ]; then - if [ -z "$URL_FILENAME" ]; then - URL_FILENAME="$FILENAME" + if [ -n "$filename" ]; then + if [ -z "$url_filename" ]; then + url_filename="$filename" fi - DOWNLOAD_DIR="$SOURCE_DIR/build/work/package/archives/$VERSION/$DIST/core" - DOWNLOAD_PATH="$DOWNLOAD_DIR/$FILENAME" - echo $DOWNLOAD_PATH - if [ ! -f "$DOWNLOAD_PATH" ]; then - URL="$URL_PREFIX/$URL_FILENAME" - mkdir -p $DOWNLOAD_DIR - echo $URL - curl -f -L -o $DOWNLOAD_PATH -C - $URL + download_dir="$source_dir/build/work/package/archives/$version/$dist/core" + download_path="$download_dir/$filename" + echo "$download_path" + if [ ! -f "$download_path" ]; then + url="$url_prefix/$url_filename" + mkdir -p "$download_dir" + echo "$url" + curl -f -L -o "$download_path" -C - "$url" fi - cd $DOWNLOAD_DIR - FILE_CHECKSUM=$(openssl dgst -sha256 $FILENAME) - if [[ -z "$FILE_CHECKSUM" ]] || [[ $CHECKSUMS != *$FILE_CHECKSUM* ]]; then - echo "Checksum mismatch for $DOWNLOAD_PATH" - echo $FILE_CHECKSUM + cd "$download_dir" + file_checksum=$(openssl dgst -sha256 $filename) + if [[ -z "$file_checksum" ]] || [[ $checksums != *$file_checksum* ]]; then + echo "Checksum mismatch for $download_path" + echo "$file_checksum" echo "Verify that the file downloaded successfully." exit 1 fi diff --git a/build/package/verify/spec/localhost/service_spec.rb b/build/package/verify/spec/localhost/service_spec.rb index b6f950cbc..cf1646955 100644 --- a/build/package/verify/spec/localhost/service_spec.rb +++ b/build/package/verify/spec/localhost/service_spec.rb @@ -119,9 +119,9 @@ def ensure_uninstalled def install_package(version) if(version == :current) - package_path = "#{ENV["SOURCE_DIR"]}/build/work/package/current/#{ENV["DIST"]}/core/*" + package_path = "#{ENV["source_dir"]}/build/work/package/current/#{ENV["DIST"]}/core/*" else - package_path = "#{ENV["SOURCE_DIR"]}/build/work/package/archives/#{version}/#{ENV["DIST"]}/core/*" + package_path = "#{ENV["source_dir"]}/build/work/package/archives/#{version}/#{ENV["DIST"]}/core/*" end case(os[:family]) diff --git a/build/package_dependencies.sh b/build/package_dependencies.sh index 192e3393e..0c2089ca3 100644 --- a/build/package_dependencies.sh +++ b/build/package_dependencies.sh @@ -1,5 +1,7 @@ +#!/bin/bash + if [ -f /etc/redhat-release ]; then - CORE_PACKAGE_DEPENDENCIES=( + core_package_dependencies=( # General bash glibc @@ -31,10 +33,10 @@ if [ -f /etc/redhat-release ]; then # For pkill/pgrep used for legacy status/stop commands. procps ) - HADOOP_ANALYTICS_PACKAGE_DEPENDENCIES=( + hadoop_analytics_package_dependencies=( java-1.8.0-openjdk-headless ) - CORE_BUILD_DEPENDENCIES=( + core_build_dependencies=( autoconf automake bzip2 @@ -62,11 +64,11 @@ if [ -f /etc/redhat-release ]; then unzip xz ) - HADOOP_ANALYTICS_BUILD_DEPENDENCIES=( + hadoop_analytics_build_dependencies=( java-1.8.0-openjdk-devel ) elif [ -f /etc/debian_version ]; then - CORE_PACKAGE_DEPENDENCIES=( + core_package_dependencies=( # General bash libc6 @@ -94,10 +96,10 @@ elif [ -f /etc/debian_version ]; then # For pkill/pgrep used for legacy status/stop commands. procps ) - HADOOP_ANALYTICS_PACKAGE_DEPENDENCIES=( + hadoop_analytics_package_dependencies=( openjdk-7-jre-headless ) - CORE_BUILD_DEPENDENCIES=( + core_build_dependencies=( autoconf automake bzip2 @@ -125,23 +127,24 @@ elif [ -f /etc/debian_version ]; then unzip xz-utils ) - HADOOP_ANALYTICS_BUILD_DEPENDENCIES=( + hadoop_analytics_build_dependencies=( openjdk-7-jdk-headless ) if lsb_release --codename --short | grep wheezy; then - CORE_PACKAGE_DEPENDENCIES+=("libffi5") + core_package_dependencies+=("libffi5") else - CORE_PACKAGE_DEPENDENCIES+=("libffi6") + core_package_dependencies+=("libffi6") fi else echo "Unknown build system" exit 1 fi -ALL_DEPENDENCIES=( - "${CORE_PACKAGE_DEPENDENCIES[*]}" - "${HADOOP_ANALYTICS_PACKAGE_DEPENDENCIES[*]}" - "${CORE_BUILD_DEPENDENCIES[*]}" - "${HADOOP_ANALYTICS_BUILD_DEPENDENCIES[*]}" +# shellcheck disable=SC2034 +all_dependencies=( + "${core_package_dependencies[*]}" + "${hadoop_analytics_package_dependencies[*]}" + "${core_build_dependencies[*]}" + "${hadoop_analytics_build_dependencies[*]}" ) diff --git a/build/scripts/distclean b/build/scripts/distclean index fbc93e619..bf0b37e0f 100755 --- a/build/scripts/distclean +++ b/build/scripts/distclean @@ -2,26 +2,26 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)))" +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" -if [ ! -f $SOURCE_DIR/CMakeLists.txt ]; then +if [ ! -f "$source_dir/CMakeLists.txt" ]; then echo "Can't find root source directory" exit 1 fi -rm -rf $SOURCE_DIR/CMakeCache.txt \ - $SOURCE_DIR/CMakeFiles \ - $SOURCE_DIR/Makefile \ - $SOURCE_DIR/build/package/.bundle \ - $SOURCE_DIR/build/package/vendor \ - $SOURCE_DIR/build/scripts/.bundle \ - $SOURCE_DIR/build/scripts/vendor \ - $SOURCE_DIR/build/work \ - $SOURCE_DIR/cmake_install.cmake \ - $SOURCE_DIR/install_manifest.txt \ - $SOURCE_DIR/src/api-umbrella/hadoop-analytics/*/dependency-reduced-pom.xml \ - $SOURCE_DIR/src/api-umbrella/web-app/log \ - $SOURCE_DIR/src/api-umbrella/web-app/tmp/* \ - $SOURCE_DIR/test/config/.overrides.yml \ - $SOURCE_DIR/test/node_modules \ - $SOURCE_DIR/test/tmp/* +rm -rf "$source_dir/CMakeCache.txt" \ + "$source_dir/CMakeFiles" \ + "$source_dir/Makefile" \ + "$source_dir/build/package/.bundle" \ + "$source_dir/build/package/vendor" \ + "$source_dir/build/scripts/.bundle" \ + "$source_dir/build/scripts/vendor" \ + "$source_dir/build/work" \ + "$source_dir/cmake_install.cmake" \ + "$source_dir/install_manifest.txt" \ + "$source_dir/src/api-umbrella/hadoop-analytics"/*/dependency-reduced-pom.xml \ + "$source_dir/src/api-umbrella/web-app/log" \ + "$source_dir/src/api-umbrella/web-app/tmp"/* \ + "$source_dir/test/config/.overrides.yml" \ + "$source_dir/test/node_modules" \ + "$source_dir/test/tmp"/* diff --git a/build/scripts/install_build_dependencies b/build/scripts/install_build_dependencies index 40d40bb1f..647b54b0f 100755 --- a/build/scripts/install_build_dependencies +++ b/build/scripts/install_build_dependencies @@ -2,9 +2,10 @@ set -e -u -x -SOURCE_DIR="$(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)))" +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" -source $SOURCE_DIR/build/package_dependencies.sh +# shellcheck source=build/package_dependencies.sh +source "$source_dir/build/package_dependencies.sh" if [ -f /etc/redhat-release ]; then # Building Go libraries from gopkg.in (which Mora has a dependency on), @@ -17,10 +18,10 @@ if [ -f /etc/redhat-release ]; then fi fi - yum -y install ${ALL_DEPENDENCIES[*]} + yum -y install "${all_dependencies[@]}" elif [ -f /etc/debian_version ]; then apt-get update - apt-get -y install ${ALL_DEPENDENCIES[*]} + apt-get -y install "${all_dependencies[@]}" else echo "Unknown build system" exit 1 diff --git a/build/scripts/outdated b/build/scripts/outdated index 6a9fd7899..5280a3952 100755 --- a/build/scripts/outdated +++ b/build/scripts/outdated @@ -152,6 +152,9 @@ repos = { "runit" => { :http => "http://smarden.org/runit/install.html", }, + "shellcheck" => { + :git => "https://github.com/koalaman/shellcheck.git", + }, "trafficserver" => { :git => "https://github.com/apache/trafficserver.git", :constraint => "~> 5.3.2", diff --git a/src/api-umbrella/web-app/script/static_site_deploy b/src/api-umbrella/web-app/script/static_site_deploy deleted file mode 100755 index 9db192af2..000000000 --- a/src/api-umbrella/web-app/script/static_site_deploy +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Exit on any errors -set -e - -# Print the executed commands -set -v - -# Clone if new -if [ ! -d $CHECKOUT_DIR ]; then - git clone $GIT_URL $CHECKOUT_DIR -fi - -# Pull the latest down -cd $CHECKOUT_DIR -git fetch -git reset --hard $GIT_COMMIT -git submodule update --init --recursive - -# Install dependencies -bundle install --path=vendor/bundle - -# Make sure the site can compile and pass any tests. -bundle exec rake test - -# Deploy ahoy! -bundle exec cap $DEPLOY_ENV deploy diff --git a/templates/etc/perp/.boot/rc.log b/templates/etc/perp/.boot/rc.log new file mode 100755 index 000000000..f2487aeaa --- /dev/null +++ b/templates/etc/perp/.boot/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log start perpd diff --git a/templates/etc/perp/.boot/rc.log.mustache b/templates/etc/perp/.boot/rc.log.mustache deleted file mode 100755 index 9f9154cd8..000000000 --- a/templates/etc/perp/.boot/rc.log.mustache +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -LOG_DIR="{{log_dir}}/perpd" -LOG_OPTS="-ttt" -LOG_CONFIG="s0\nn0" -RUN_OPTS="" -{{#user}} -RUN_OPTS="$RUN_OPTS -u {{user}}" -{{/user}} - -mkdir -p $LOG_DIR -echo $LOG_CONFIG > $LOG_DIR/config -chmod 0755 $LOG_DIR -{{#user}} -chown -R {{user}}:{{group}} $LOG_DIR -{{/user}} - -exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR diff --git a/templates/etc/perp/.boot/rc.perp.mustache b/templates/etc/perp/.boot/rc.perp.mustache index de293efce..37128d0b5 100755 --- a/templates/etc/perp/.boot/rc.perp.mustache +++ b/templates/etc/perp/.boot/rc.perp.mustache @@ -1,17 +1,19 @@ -#!/bin/sh -e +#!/bin/bash -e # rc.perp: perpd startup script for perpboot # === ### --- configure --- -PERPD_OPTS="" +perpd_args=() ### --- script --- # Attempt to set hard limit values (if not root, this will generate a warning). # The runlimit call below will set the soft values to the maximum hard limit # allowed (regardless of whether root or not). -ulimit -Hn {{rlimits.nofile}} || true -ulimit -Hu {{rlimits.nproc}} || true +# shellcheck disable=SC2039 +ulimit -Hn "{{rlimits.nofile}}" || true +# shellcheck disable=SC2039 +ulimit -Hu "{{rlimits.nproc}}" || true ## exec perpd: ## * options as configured above @@ -21,6 +23,6 @@ ulimit -Hu {{rlimits.nproc}} || true exec \ runchoom \ runlimit -F ./rlimit.conf \ - perpd ${PERPD_OPTS} ${PERP_BASE} + perpd "${perpd_args[@]}" "${PERP_BASE}" ### EOF diff --git a/templates/etc/perp/elasticsearch/rc.log b/templates/etc/perp/elasticsearch/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/elasticsearch/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/elasticsearch/rc.log.mustache b/templates/etc/perp/elasticsearch/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/elasticsearch/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/elasticsearch/rc.main.mustache b/templates/etc/perp/elasticsearch/rc.main.mustache index adca4f73b..95d18b8fe 100755 --- a/templates/etc/perp/elasticsearch/rc.main.mustache +++ b/templates/etc/perp/elasticsearch/rc.main.mustache @@ -1,17 +1,18 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="-e rc.env" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=("-e" "rc.env") + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS elasticsearch + exec runtool "${run_args[@]}" elasticsearch fi exit 0 diff --git a/templates/etc/perp/flume/rc.log b/templates/etc/perp/flume/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/flume/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/flume/rc.log.mustache b/templates/etc/perp/flume/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/flume/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/flume/rc.main.mustache b/templates/etc/perp/flume/rc.main.mustache index 655a4f336..5205f10fe 100755 --- a/templates/etc/perp/flume/rc.main.mustache +++ b/templates/etc/perp/flume/rc.main.mustache @@ -1,21 +1,22 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="-e rc.env" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=("-e" "rc.env") + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS {{_embedded_root_dir}}/flume/bin/flume-ng \ + exec runtool "${run_args[@]}" "{{_embedded_root_dir}}/flume/bin/flume-ng" \ agent \ --name api-umbrella-agent \ - --conf {{_embedded_root_dir}}/flume/conf \ - --conf-file {{etc_dir}}/flume.properties \ + --conf "{{_embedded_root_dir}}/flume/conf" \ + --conf-file "{{etc_dir}}/flume.properties" \ -Dflume.root.logger=INFO,console fi diff --git a/templates/etc/perp/geoip-auto-updater/rc.log b/templates/etc/perp/geoip-auto-updater/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/geoip-auto-updater/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/geoip-auto-updater/rc.log.mustache b/templates/etc/perp/geoip-auto-updater/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/geoip-auto-updater/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/geoip-auto-updater/rc.main.mustache b/templates/etc/perp/geoip-auto-updater/rc.main.mustache index b8a4b69b2..6d308c34a 100755 --- a/templates/etc/perp/geoip-auto-updater/rc.main.mustache +++ b/templates/etc/perp/geoip-auto-updater/rc.main.mustache @@ -1,13 +1,13 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." - RUN_OPTS="-e rc.env" - exec runtool $RUN_OPTS {{_src_root_dir}}/bin/api-umbrella-geoip-auto-updater + run_args=("-e" "rc.env") + exec runtool "${run_args[@]}" "{{_src_root_dir}}/bin/api-umbrella-geoip-auto-updater" fi exit 0 diff --git a/templates/etc/perp/kylin/rc.log b/templates/etc/perp/kylin/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/kylin/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/kylin/rc.log.mustache b/templates/etc/perp/kylin/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/kylin/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/kylin/rc.main.mustache b/templates/etc/perp/kylin/rc.main.mustache index d2616172d..63ab751c0 100755 --- a/templates/etc/perp/kylin/rc.main.mustache +++ b/templates/etc/perp/kylin/rc.main.mustache @@ -1,17 +1,18 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="-e rc.env" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=("-e" "rc.env") + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS {{etc_dir}}/perp/kylin/rc.run + exec runtool "${run_args[@]}" "{{etc_dir}}/perp/kylin/rc.run" fi exit 0 diff --git a/templates/etc/perp/mongod/rc.log b/templates/etc/perp/mongod/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/mongod/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/mongod/rc.log.mustache b/templates/etc/perp/mongod/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/mongod/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/mongod/rc.main.mustache b/templates/etc/perp/mongod/rc.main.mustache index f98e19f06..58b839603 100755 --- a/templates/etc/perp/mongod/rc.main.mustache +++ b/templates/etc/perp/mongod/rc.main.mustache @@ -1,17 +1,18 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=() + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS mongod --config {{etc_dir}}/mongod.conf + exec runtool "${run_args[@]}" mongod --config "{{etc_dir}}/mongod.conf" fi exit 0 diff --git a/templates/etc/perp/mora/rc.log b/templates/etc/perp/mora/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/mora/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/mora/rc.log.mustache b/templates/etc/perp/mora/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/mora/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/mora/rc.main.mustache b/templates/etc/perp/mora/rc.main.mustache index 32e0616d8..49d838038 100755 --- a/templates/etc/perp/mora/rc.main.mustache +++ b/templates/etc/perp/mora/rc.main.mustache @@ -1,17 +1,18 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=() + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS mora -config {{etc_dir}}/mora.properties + exec runtool "${run_args[@]}" mora -config "{{etc_dir}}/mora.properties" fi exit 0 diff --git a/templates/etc/perp/nginx-reloader/rc.log b/templates/etc/perp/nginx-reloader/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/nginx-reloader/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/nginx-reloader/rc.log.mustache b/templates/etc/perp/nginx-reloader/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/nginx-reloader/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/nginx-reloader/rc.main.mustache b/templates/etc/perp/nginx-reloader/rc.main.mustache index cad941291..fb28e58a7 100755 --- a/templates/etc/perp/nginx-reloader/rc.main.mustache +++ b/templates/etc/perp/nginx-reloader/rc.main.mustache @@ -1,13 +1,13 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." - RUN_OPTS="-e rc.env" - exec runtool $RUN_OPTS {{_src_root_dir}}/bin/api-umbrella-nginx-reloader + run_args=("-e" "rc.env") + exec runtool "${run_args[@]}" "{{_src_root_dir}}/bin/api-umbrella-nginx-reloader" fi exit 0 diff --git a/templates/etc/perp/nginx/rc.log b/templates/etc/perp/nginx/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/nginx/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/nginx/rc.log.mustache b/templates/etc/perp/nginx/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/nginx/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/nginx/rc.main.mustache b/templates/etc/perp/nginx/rc.main.mustache index 07a6b9c78..d868a6728 100755 --- a/templates/etc/perp/nginx/rc.main.mustache +++ b/templates/etc/perp/nginx/rc.main.mustache @@ -1,13 +1,13 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." - RUN_OPTS="-e rc.env -c {{_src_root_dir}}" - exec runtool $RUN_OPTS nginx -p {{_src_root_dir}}/ -c {{etc_dir}}/nginx/router.conf + run_args=("-e" "rc.env" "-c" "{{_src_root_dir}}") + exec runtool "${run_args[@]}" nginx -p "{{_src_root_dir}}/" -c "{{etc_dir}}/nginx/router.conf" fi exit 0 diff --git a/templates/etc/perp/presto/rc.log b/templates/etc/perp/presto/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/presto/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/presto/rc.log.mustache b/templates/etc/perp/presto/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/presto/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/presto/rc.main.mustache b/templates/etc/perp/presto/rc.main.mustache index fb10c2620..e8a6296eb 100755 --- a/templates/etc/perp/presto/rc.main.mustache +++ b/templates/etc/perp/presto/rc.main.mustache @@ -1,20 +1,21 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=() + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS {{_embedded_root_dir}}/presto/bin/launcher run \ - --node-config={{etc_dir}}/presto/node.properties \ - --jvm-config={{etc_dir}}/presto/jvm.config \ - --config={{etc_dir}}/presto/config.properties + exec runtool "${run_args[@]}" "{{_embedded_root_dir}}/presto/bin/launcher" run \ + --node-config="{{etc_dir}}/presto/node.properties" \ + --jvm-config="{{etc_dir}}/presto/jvm.config" \ + --config="{{etc_dir}}/presto/config.properties" fi exit 0 diff --git a/templates/etc/perp/rc.log.mustache b/templates/etc/perp/rc.log.mustache new file mode 100755 index 000000000..9131ee378 --- /dev/null +++ b/templates/etc/perp/rc.log.mustache @@ -0,0 +1,35 @@ +#!/bin/bash + +if [ "${1}" = "start" ]; then + api_umbrella_log_dir="{{log_dir}}" + api_umbrella_user="{{user}}" + api_umbrella_group="{{group}}" + + # Set arguments for runtool. + run_args=() + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi + + # Set arguments for svlogd. + log_dir="$api_umbrella_log_dir/${2}" + log_args=("-ttt" "$log_dir") + + # Create the log directory. + mkdir -p "$log_dir" + + # Define a configuration file for svlogd to disable internal log rotation + # (since we'll rely on the system and logrotated for that). + log_config="s0\nn0" + echo $log_config > "$log_dir/config" + + # Set permissions. + chmod 0755 "$log_dir" + if [ -n "$api_umbrella_user" ]; then + chown -R $api_umbrella_user:$api_umbrella_group "$log_dir" + fi + + exec runtool "${run_args[@]}" svlogd "${log_args[@]}" +fi + +exit 0 diff --git a/templates/etc/perp/rsyslog/rc.log b/templates/etc/perp/rsyslog/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/rsyslog/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/rsyslog/rc.log.mustache b/templates/etc/perp/rsyslog/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/rsyslog/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/rsyslog/rc.main.mustache b/templates/etc/perp/rsyslog/rc.main.mustache index ecfda25cb..dc2543025 100755 --- a/templates/etc/perp/rsyslog/rc.main.mustache +++ b/templates/etc/perp/rsyslog/rc.main.mustache @@ -3,21 +3,22 @@ # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=() + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi exec \ - runtrap rsyslogd ${0} \ - runtool $RUN_OPTS \ + runtrap rsyslogd "${0}" \ + runtool "${run_args[@]}" \ rsyslogd \ -n \ - -f {{etc_dir}}/rsyslog.conf \ - -i {{run_dir}}/rsyslogd.pid + -f "{{etc_dir}}/rsyslog.conf" \ + -i "{{run_dir}}/rsyslogd.pid" fi # Use runtrap to handle the normal SIGTERM perp sends when rsyslogd is supposed @@ -26,14 +27,15 @@ fi # file a bug with rsyslog, but as a workaround, send a few SIGTERMs to rsyslogd # to try to get it to shutdown cleanly. If it can't, then escalate to more # harsh kill signals. -if test ${1} = "trap" && test ${5} = "SIGTERM"; then +if [ "${1}" = "trap" ] && [ "${5}" = "SIGTERM" ]; then echo "stopping ${2}..." - PID=${3} - SIGNALS=(TERM TERM TERM TERM TERM TERM INT QUIT ABRT KILL) - for SIGNAL in "${SIGNALS[@]}"; do - echo "attempting to stop ${2} (pid $PID) with signal $SIGNAL" - kill -$SIGNAL $PID - if ps --no-headers -p $PID | grep -v defunct > /dev/null; then + pid="${3}" + signals=(TERM TERM TERM TERM TERM TERM INT QUIT ABRT KILL) + for signal in "${signals[@]}"; do + echo "attempting to stop ${2} (pid $pid) with signal $signal" + kill "-$signal" "$pid" + # shellcheck disable=SC2009 + if ps --no-headers -p "$pid" | grep -v defunct > /dev/null; then sleep 1 else break diff --git a/templates/etc/perp/test-env-mongo-orchestration/rc.log b/templates/etc/perp/test-env-mongo-orchestration/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/test-env-mongo-orchestration/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/test-env-mongo-orchestration/rc.log.mustache b/templates/etc/perp/test-env-mongo-orchestration/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/test-env-mongo-orchestration/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/test-env-mongo-orchestration/rc.main.mustache b/templates/etc/perp/test-env-mongo-orchestration/rc.main.mustache index e1344395f..204ea7d7e 100755 --- a/templates/etc/perp/test-env-mongo-orchestration/rc.main.mustache +++ b/templates/etc/perp/test-env-mongo-orchestration/rc.main.mustache @@ -1,20 +1,21 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" PATH="{{_test_env_install_dir}}/sbin:{{_test_env_install_dir}}/bin:$PATH" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=() + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi exec \ - runtrap test-env-mongo-orchestration ${0} \ - runtool $RUN_OPTS \ + runtrap test-env-mongo-orchestration "${0}" \ + runtool "${run_args[@]}" \ mongo-orchestration \ --no-fork \ --port 13089 \ @@ -25,12 +26,12 @@ fi # mongo-orchestration doesn't respond properly to SIGTERM (which is what # perpboot sends on exit), so trap signals and then trigger a SIGQUIT, which # mongo-orchestration does respond to. -if test ${1} = "trap" && test ${4} = "15"; then +if [ "${1}" = "trap" ] && [ "${4}" = "15" ]; then echo "stopping ${2}..." - kill -3 ${3} + kill -3 "${3}" fi -if test ${1} = "reset"; then +if [ "${1}" = "reset" ]; then echo "cleaning up ${2}..." # mongo-orchestration also doesn't always seem the best at ensuring all the # mongod processes it spawns are stopped when exiting. So perform an extra diff --git a/templates/etc/perp/test-env-unbound/rc.log b/templates/etc/perp/test-env-unbound/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/test-env-unbound/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/test-env-unbound/rc.log.mustache b/templates/etc/perp/test-env-unbound/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/test-env-unbound/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/test-env-unbound/rc.main.mustache b/templates/etc/perp/test-env-unbound/rc.main.mustache index 343092c29..b46cf1e4e 100755 --- a/templates/etc/perp/test-env-unbound/rc.main.mustache +++ b/templates/etc/perp/test-env-unbound/rc.main.mustache @@ -1,18 +1,19 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" PATH="{{_test_env_install_dir}}/sbin:{{_test_env_install_dir}}/bin:$PATH" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=() + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS unbound -c {{etc_dir}}/test-env/unbound/unbound.conf + exec runtool "${run_args[@]}" unbound -c "{{etc_dir}}/test-env/unbound/unbound.conf" fi exit 0 diff --git a/templates/etc/perp/trafficserver/rc.log b/templates/etc/perp/trafficserver/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/trafficserver/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/trafficserver/rc.log.mustache b/templates/etc/perp/trafficserver/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/trafficserver/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/trafficserver/rc.main.mustache b/templates/etc/perp/trafficserver/rc.main.mustache index ed6a60f96..3b364ad30 100755 --- a/templates/etc/perp/trafficserver/rc.main.mustache +++ b/templates/etc/perp/trafficserver/rc.main.mustache @@ -1,17 +1,18 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="-e rc.env" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=("-e" "rc.env") + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS traffic_cop --stdout + exec runtool "${run_args[@]}" traffic_cop --stdout fi exit 0 diff --git a/templates/etc/perp/web-delayed-job/rc.log b/templates/etc/perp/web-delayed-job/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/web-delayed-job/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/web-delayed-job/rc.log.mustache b/templates/etc/perp/web-delayed-job/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/web-delayed-job/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/web-delayed-job/rc.main.mustache b/templates/etc/perp/web-delayed-job/rc.main.mustache index 919499727..987d497ce 100755 --- a/templates/etc/perp/web-delayed-job/rc.main.mustache +++ b/templates/etc/perp/web-delayed-job/rc.main.mustache @@ -1,17 +1,18 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="-e rc.env -c {{_src_root_dir}}/src/api-umbrella/web-app" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=("-e" "rc.env" "-c" "{{_src_root_dir}}/src/api-umbrella/web-app") + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS bundle exec ./script/delayed_job --pid-dir={{run_dir}} --queues=mailers run + exec runtool "${run_args[@]}" bundle exec ./script/delayed_job --pid-dir="{{run_dir}}" --queues=mailers run fi exit 0 diff --git a/templates/etc/perp/web-puma/rc.log b/templates/etc/perp/web-puma/rc.log new file mode 100755 index 000000000..a5f0cccdb --- /dev/null +++ b/templates/etc/perp/web-puma/rc.log @@ -0,0 +1,2 @@ +#!/bin/bash +exec ../rc.log "$@" diff --git a/templates/etc/perp/web-puma/rc.log.mustache b/templates/etc/perp/web-puma/rc.log.mustache deleted file mode 100755 index 3b205ec8e..000000000 --- a/templates/etc/perp/web-puma/rc.log.mustache +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -if test ${1} = "start"; then - LOG_DIR="{{log_dir}}/${2}" - LOG_OPTS="-ttt" - LOG_CONFIG="s0\nn0" - RUN_OPTS="" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} - - mkdir -p $LOG_DIR - echo $LOG_CONFIG > $LOG_DIR/config - chmod 0755 $LOG_DIR - {{#user}} - chown -R {{user}}:{{group}} $LOG_DIR - {{/user}} - - exec runtool $RUN_OPTS svlogd $LOG_OPTS $LOG_DIR -fi - -exit 0 diff --git a/templates/etc/perp/web-puma/rc.main.mustache b/templates/etc/perp/web-puma/rc.main.mustache index c461ad6a6..ee6290f01 100755 --- a/templates/etc/perp/web-puma/rc.main.mustache +++ b/templates/etc/perp/web-puma/rc.main.mustache @@ -1,25 +1,26 @@ -#!/bin/sh +#!/bin/bash # Redirect stderr to stdout exec 2>&1 -if test ${1} = "start"; then +if [ "${1}" = "start" ]; then echo "starting ${2}..." + api_umbrella_user="{{user}}" - RUN_OPTS="-e rc.env -c {{_src_root_dir}}/src/api-umbrella/web-app" - {{#user}} - RUN_OPTS="$RUN_OPTS -u {{user}}" - {{/user}} + run_args=("-e" "rc.env" "-c" "{{_src_root_dir}}/src/api-umbrella/web-app") + if [ -n "$api_umbrella_user" ]; then + run_args+=("-u" "$api_umbrella_user") + fi - exec runtool $RUN_OPTS \ + exec runtool "${run_args[@]}" \ bundle exec puma \ -q \ - --dir {{_src_root_dir}}/src/api-umbrella/web-app \ + --dir "{{_src_root_dir}}/src/api-umbrella/web-app" \ --prune-bundler \ - -e {{app_env}} \ - -w {{web.puma.workers}} \ - -t {{web.puma.min_threads}}:{{web.puma.max_threads}} \ - -b unix://{{run_dir}}/web-puma.sock + -e "{{app_env}}" \ + -w "{{web.puma.workers}}" \ + -t "{{web.puma.min_threads}}:{{web.puma.max_threads}}" \ + -b "unix://{{run_dir}}/web-puma.sock" fi exit 0 diff --git a/test/circle_parallel b/test/circle_parallel index 68352553a..60c1fb541 100755 --- a/test/circle_parallel +++ b/test/circle_parallel @@ -1,10 +1,10 @@ #!/bin/bash -set -e -set -x + +set -e -u -x # Always run the lint tests on the first node (since these are quick and only # need to be run on a single node). -if [ $CIRCLE_NODE_INDEX -eq "0" ]; then +if [ "$CIRCLE_NODE_INDEX" -eq "0" ]; then make lint fi @@ -19,33 +19,33 @@ fi # first (the first is dedicated to the Rails tests). # # If we don't have multiple nodes, run all the tests on the single node -if [ $CIRCLE_NODE_INDEX -gt "0" ] || [ $CIRCLE_NODE_TOTAL -lt "2" ]; then - MOCHA_NODE_TOTAL=$CIRCLE_NODE_TOTAL - MOCHA_NODE_INDEX=$CIRCLE_NODE_INDEX +if [ "$CIRCLE_NODE_INDEX" -gt "0" ] || [ "$CIRCLE_NODE_TOTAL" -lt "2" ]; then + mocha_node_total="$CIRCLE_NODE_TOTAL" + mocha_node_index="$CIRCLE_NODE_INDEX" - if [ $CIRCLE_NODE_TOTAL -gt "1" ]; then + if [ "$CIRCLE_NODE_TOTAL" -gt "1" ]; then # Subtract 1 from the totals available, since the first is being used only # for Rails. - ((MOCHA_NODE_TOTAL=MOCHA_NODE_TOTAL-1)) || true - ((MOCHA_NODE_INDEX=MOCHA_NODE_INDEX-1)) || true + ((mocha_node_total=mocha_node_total-1)) || true + ((mocha_node_index=mocha_node_index-1)) || true fi # Split the test files into even groups depending on how many nodes are # available. - INDEX=0 - NODE_FILES=() - for TEST_FILE in $(cd test && find ./server ./integration -name "*.js" | sort); do - if [ $(($INDEX % $MOCHA_NODE_TOTAL)) -eq $MOCHA_NODE_INDEX ]; then - NODE_FILES+=" $TEST_FILE" + index=0 + node_files=() + for test_file in $(cd test && find ./server ./integration -name "*.js" | sort); do + if [ $((index % mocha_node_total)) -eq $mocha_node_index ]; then + node_files+=" $test_file" fi - ((INDEX=INDEX+1)) || true + ((index=index+1)) || true done # Run the integration/gatekeeper tests. - make test-proxy MOCHA_FILES="${NODE_FILES[@]}" + make test-proxy MOCHA_FILES="${node_files[*]}" fi # Run the Rails tests on the first node. -if [ $CIRCLE_NODE_INDEX -eq "0" ]; then +if [ "$CIRCLE_NODE_INDEX" -eq "0" ]; then make test-web-app fi diff --git a/test/scripts/shell-lint b/test/scripts/shell-lint new file mode 100755 index 000000000..ce7220dc8 --- /dev/null +++ b/test/scripts/shell-lint @@ -0,0 +1,36 @@ +#!/bin/bash + +set -e -u + +source_dir="$(dirname "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")")" + +PATH="$source_dir/build/work/test-env/bin:$PATH" + +# Ignore certain vendored files for linting. +ignore_files=( + "configure" + "templates/etc/perp/kylin/rc.run.mustache" +) + +shells=( + "sh" + "bash" +) + +for shell in "${shells[@]}"; do + readarray -t shell_files < <(git grep -l "^#\!/bin/$shell") + + if [ "${#shell_files[@]}" != 0 ]; then + for ignore in "${ignore_files[@]}"; do + if [ "${#shell_files[@]}" != 0 ]; then + shell_files=(${shell_files[@]/#$ignore}) + fi + done + + if [ "${#shell_files[@]}" != 0 ]; then + echo -n "Linting ($shell): ${shell_files[*]}... " + shellcheck -s "$shell" "${shell_files[@]}" + echo "Valid" + fi + fi +done