[FLINK-9638][E2E Tests] Add helper script to run single test

This commit adds a helper script `run-single-test.sh` that allows you to run
a single test in the context of the text runner.

This provides you with
* Setup of ENV variables
* cleanup after test
* Nicer output

Usage: ./run-single-test.sh <path-to-test-script> [<arg1> <arg2> ...]

This closes #6197.

#!/usr/bin/env bash
################################################################################
#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

# This can be used to run a single test in the context of a test runnner
# Usage: ./run-single-test.sh test-scripts/my-test-case.sh

if [ $# -eq 0 ]; then
    echo "Usage: ./run-single-test.sh <path-to-test-script> [<arg1> <arg2> ...]"
    exit 1
fi

END_TO_END_DIR="`dirname \"$0\"`" # relative
END_TO_END_DIR="`( cd \"$END_TO_END_DIR\" && pwd )`" # absolutized and normalized
if [ -z "$END_TO_END_DIR" ] ; then
    # error; for some reason, the path is not accessible
    # to the script (e.g. permissions re-evaled after suid)
    exit 1  # fail
fi

export END_TO_END_DIR

if [ -z "$FLINK_DIR" ] ; then
    echo "You have to export the Flink distribution directory as FLINK_DIR"
    exit 1
fi

source "${END_TO_END_DIR}/test-scripts/test-runner-common.sh"

FLINK_DIR="`( cd \"$FLINK_DIR\" && pwd )`" # absolutized and normalized

echo "flink-end-to-end-test directory: $END_TO_END_DIR"
echo "Flink distribution directory: $FLINK_DIR"

run_test "$*" "$*"

exit 0

error: pathspec 'flink-end-to-end-tests/run-single-test.sh' did not match any file(s) known to git


GH #37 rhel6: make build-zato.sh work as non-root

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/zatosource/zato-build.git/'


LLVM build script

LLVM build script

#!/bin/bash -ex

# where LLVM source and install will live
export LLVM_TOP=$HOME/LLVM

# where LLVM is compiled
export LLVM_TMP=/tmp/$USER-llvm-build

mkdir -p $LLVM_TOP
mkdir -p $LLVM_TMP

cd $LLVM_TOP
git clone http://llvm.org/git/llvm.git git
cd $LLVM_TOP/git
git config branch.master.rebase true

cd $LLVM_TOP/git/tools
git clone http://llvm.org/git/clang.git

cd $LLVM_TOP/git/projects
git clone http://llvm.org/git/compiler-rt.git

cd $LLVM_TOP/git/projects
git clone http://llvm.org/git/openmp.git

cd $LLVM_TOP/git/projects
git clone http://llvm.org/git/libcxx.git
git clone http://llvm.org/git/libcxxabi.git

cd $LLVM_TOP/git/projects
git clone http://llvm.org/git/test-suite.git

cd $LLVM_TMP
cmake $LLVM_TOP/git  -G "Unix Makefiles" \
    -DCMAKE_INSTALL_PREFIX=$LLVM_TOP/HEAD \
    -DCMAKE_C_COMPILER=gcc \
    -DCMAKE_CXX_COMPILER=g++ \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_TARGETS_TO_BUILD=X86
make -j
make -j install

error: pathspec 'buildscripts/build-llvm-git.sh' did not match any file(s) known to git


Deploy script

Deploy script

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jacobthemyth/jacobthemyth.github.io.git/'


added demo deploy.sh

added demo deploy.sh

#!/bin/bash -e
# this should be run after check-build finishes.
# Deploy.sh is the script which is used to reconfigure and install the application to the fastrepo.
# We need to do this in order to keep the symbolic links in the deployed libraries correct.
# IE when we do integration, we install to /apprepo locally, but
# When applications are in the repo, they will be referred to by /cvmfs/<repo-name>
# So, especially if we are linking against things already in the repo, we need to recompile against these
# libraries in /cvmfs instead of /apprepo
. /etc/profile.d/modules.sh
# We now add the deploy module, which changes the path of $SOFT_DIR
module add deploy
cd ${WORKSPACE}/${NAME}-${VERSION}/build-${BUILD_NUMBER}
echo "All tests have passed, will now build into ${SOFT_DIR}"
#  Remove the previous configuration
rm -rf *
# Be sure to use the same config as in build.sh
CFLAGS=-fPIC ../configure --prefix ${SOFT_DIR} \
--enable-fft \
--enable-static \
--enable-cxx \
--enable-shared \
--enable-old-fft-full \
--enable-assert
make -j2
echo "Making install to $SOFT_DIR"
make install
# We are making the module for fastrepo
echo "Creating the modules file directory ${LIBRARIES_MODULES}/fastrepo/"
mkdir -p ${LIBRARIES_MODULES}/fastrepo/${NAME}
(
cat <<MODULE_FILE
#%Module1.0
## $NAME modulefile
##
proc ModulesHelp { } {
    puts stderr "       This module does nothing but alert the user"
    puts stderr "       that the [module-info name] module is not available"
}

module-whatis   "$NAME $VERSION : See https://github.com/SouthAfricaDigitalScience/gmp-deploy"
set GMP_VERSION   $VERSION
## We need to add this to the environment as well, else other modules won't pick it up.
setenv GMP_VERSION $::env(VERSION)
set GMP_DIR        $::env(CVMFS_DIR)/$::env(SITE)/$::env(OS)/$::env(ARCH)/$::env(NAME)/$GMP_VERSION
setenv GMP_DIR     $::env(CVMFS_DIR)/$::env(SITE)/$::env(OS)/$::env(ARCH)/$::env(NAME)/$GMP_VERSION
prepend-path LD_LIBRARY_PATH   \$GMP_DIR/lib
prepend-path GCC_INCLUDE_DIR   \$GMP_DIR/include
setenv CFLAGS "$::env(CFLAGS) -I\$GMP_DIR/include -L\$GMP_DIR/lib"
MODULE_FILE
) > ${LIBRARIES_MODULES}/${NAME}/${VERSION}

error: pathspec 'deploy.sh' did not match any file(s) known to git


deployment script created, to use those files in a separated folder... It avoids to have the .git in ~, cleaner

#! /bin/bash

SOURCE=$(dirname $(readlink -f $0))

files[0]='.gconf/apps/gnome-terminal'
files[1]='.ackrc'
files[2]='.bashrc'
files[3]='.config/awesome'
files[4]='.config/i3status'
files[5]='.config/geany'
files[6]='.scripts'
files[7]='.vimrc'
files[8]='.bash_aliases'
files[9]='.gitconfig'
files[10]='.vim'
files[11]='.i3'

for f in "${files[@]}"
do
	rm -rf $HOME/$f
	ln -s $SOURCE/$f $HOME/$f
done


Add deploy script

Add deploy script

git subtree push --prefix public origin gh-pages


[nixos] Add script for maintenance

[nixos] Add script for maintenance

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Pastafarianist/admin.git/'


following up on issue #33, added new script new-release.sh to push future releases

#!/bin/bash

set -e

version="$(date +%Y.%m)"
codename="$(random-word)"

echo "Push new release: ${version} - '${codename}' [y/N]: "
read res
if [ "${res}" == "y" ] || [ "${res}" == "Y" ]; then
    git tag --annotate "${version}" --message "Release: ${codename}" --sign
    git push
fi

error: pathspec 'new-release.sh' did not match any file(s) known to git


Hated typing 'subl .'. Insanity.

Hated typing 'subl .'. Insanity.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/fogine/dotfiles.git/'


fix nasty test bug

fix nasty test bug

#!/usr/bin/env bash

. "test/testlib.sh"

begin_test "pointer --file --stdin"
(
  set -e

  echo "simple" > some-file

  input="version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from STDIN

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee"

  [ "$expected" = "$(echo "$input" | git lfs pointer --file=some-file --stdin 2>&1)" ]
)
end_test

begin_test "pointer --file --stdin mismatch"
(
  set -e

  echo "simple" > some-file

  input="version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123"

  set +e
  output=$(echo "$input" | git lfs pointer --file=some-file --stdin 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from STDIN

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123

Git blob OID: 905bcc24b5dc074ab870f9944178e398eec3b470

Pointers do not match"

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --stdin"
(
  set -e

  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7" > valid-pointer

  output=$(cat valid-pointer | git lfs pointer --stdin 2>&1)
  expected="Pointer from STDIN

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --stdin without stdin"
(
  # this test doesn't work on Windows, it just operates like 'bad pointer' case
  # stdin isn't detectable as detached, it just times out with no content
  if [[ "$(is_stdin_attached)" == "0" ]]; then
    echo "Skipping pointer without stdin because STDIN attached"
    exit 0
  fi
  output=$(echo "" | git lfs pointer --stdin 2>&1)
  status=$?

  set -e

  expected="Cannot read from STDIN. The --stdin flag expects a pointer file from STDIN."

  [ "$expected" = "$output" ]

  [ "1" = "$status" ]
)

begin_test "pointer --stdin with bad pointer"
(
  output=$(echo "not a pointer" | git lfs pointer --stdin 2>&1)
  status=$?

  set -e

  expected="Pointer from STDIN

Not a valid Git LFS pointer file."

  [ "$expected" = "$output" ]

  [ "1" = "$status" ]
)

begin_test "pointer --file --pointer mismatch"
(
  set -e
  echo "simple" > some-file
  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123" > invalid-pointer

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from invalid-pointer

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123

Git blob OID: 905bcc24b5dc074ab870f9944178e398eec3b470

Pointers do not match"

  set +e
  output=$(git lfs pointer --file=some-file --pointer=invalid-pointer 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --file --pointer"
(
  set -e
  echo "simple" > some-file
  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7" > valid-pointer

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from valid-pointer

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee"

  [ "$expected" = "$(git lfs pointer --file=some-file --pointer=valid-pointer 2>&1)" ]
)
end_test

begin_test "pointer --pointer"
(
  set -e

  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7" > valid-pointer

  expected="Pointer from valid-pointer

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  [ "$expected" = "$(git lfs pointer --pointer=valid-pointer 2>&1)" ]
)
end_test

begin_test "pointer missing --pointer"
(
  output=$(git lfs pointer --pointer=missing-pointer 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]

  echo "$output"
  echo "$output" | grep "open missing-pointer:"
)
end_test

begin_test "pointer invalid --pointer"
(
  set -e

  echo "not a pointer" > some-pointer

  set +e
  output=$(git lfs pointer --pointer=some-pointer 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]

  expected="Pointer from some-pointer

Not a valid Git LFS pointer file."

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --file"
(
  set -e
  echo "simple" > some-file

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  [ "$expected" = "$(git lfs pointer --file=some-file 2>&1)" ]
)
end_test

begin_test "pointer without args"
(
  output=$(git lfs pointer 2>&1)
  status=$?
  set -e

  [ "Nothing to do!" = "$output" ]
  [ "1" = "$status" ]
)
end_test

#!/usr/bin/env bash

. "test/testlib.sh"

begin_test "pointer --file --stdin"
(
  set -e

  echo "simple" > some-file

  input="version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from STDIN

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee"

  [ "$expected" = "$(echo "$input" | git lfs pointer --file=some-file --stdin 2>&1)" ]
)
end_test

begin_test "pointer --file --stdin mismatch"
(
  set -e

  echo "simple" > some-file

  input="version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123"

  set +e
  output=$(echo "$input" | git lfs pointer --file=some-file --stdin 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from STDIN

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123

Git blob OID: 905bcc24b5dc074ab870f9944178e398eec3b470

Pointers do not match"

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --stdin"
(
  set -e

  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7" > valid-pointer

  output=$(cat valid-pointer | git lfs pointer --stdin 2>&1)
  expected="Pointer from STDIN

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --stdin without stdin"
(
  # this test doesn't work on Windows, it just operates like 'bad pointer' case
  # stdin isn't detectable as detached, it just times out with no content
  if [[ "$(is_stdin_attached)" == "0" ]]; then
    echo "Skipping pointer without stdin because STDIN attached"
    exit 0
  fi
  output=$(echo "" | git lfs pointer --stdin 2>&1)
  status=$?

  set -e

  expected="Cannot read from STDIN. The --stdin flag expects a pointer file from STDIN."

  [ "$expected" = "$output" ]

  [ "1" = "$status" ]
)

begin_test "pointer --stdin with bad pointer"
(
  output=$(echo "not a pointer" | git lfs pointer --stdin 2>&1)
  status=$?

  set -e

  expected="Pointer from STDIN

Not a valid Git LFS pointer file."

  [ "$expected" = "$output" ]

  [ "1" = "$status" ]
)

begin_test "pointer --file --pointer mismatch"
(
  set -e
  echo "simple" > some-file
  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123" > invalid-pointer

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from invalid-pointer

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 123

Git blob OID: 905bcc24b5dc074ab870f9944178e398eec3b470

Pointers do not match"

  set +e
  output=$(git lfs pointer --file=some-file --pointer=invalid-pointer 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --file --pointer"
(
  set -e
  echo "simple" > some-file
  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7" > valid-pointer

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee

Pointer from valid-pointer

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7

Git blob OID: e18acd45d7e3ce0451d1d637f9697aa508e07dee"

  [ "$expected" = "$(git lfs pointer --file=some-file --pointer=valid-pointer 2>&1)" ]
)
end_test

begin_test "pointer --pointer"
(
  set -e

  echo "version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7" > valid-pointer

  expected="Pointer from valid-pointer

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  [ "$expected" = "$(git lfs pointer --pointer=valid-pointer 2>&1)" ]
)
end_test

begin_test "pointer missing --pointer"
(
  output=$(git lfs pointer --pointer=missing-pointer 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]
  [[ "$output" == open missing-pointer:* ]]
)
end_test

begin_test "pointer invalid --pointer"
(
  set -e

  echo "not a pointer" > some-pointer

  set +e
  output=$(git lfs pointer --pointer=some-pointer 2>&1)
  status=$?
  set -e

  [ "1" = "$status" ]

  expected="Pointer from some-pointer

Not a valid Git LFS pointer file."

  [ "$expected" = "$output" ]
)
end_test

begin_test "pointer --file"
(
  set -e
  echo "simple" > some-file

  expected="Git LFS pointer for some-file

version https://git-lfs.github.com/spec/v1
oid sha256:6c17f2007cbe934aee6e309b28b2dba3c119c5dff2ef813ed124699efe319868
size 7"

  [ "$expected" = "$(git lfs pointer --file=some-file 2>&1)" ]
)
end_test

begin_test "pointer without args"
(
  output=$(git lfs pointer 2>&1)
  status=$?
  set -e

  [ "Nothing to do!" = "$output" ]
  [ "1" = "$status" ]
)
end_test


Adding supporting script

Adding supporting script

#!/bin/sh

for (( i=1; $i < 6; i=i+1 )) ; do
	txt="./train gesture$i.dat.scale";
    eval $txt

	txt="./predict gesture$i.dat.scale gesture$i.dat.scale.model tmp > out$i";
    eval $txt
done

error: pathspec 'SVM_static/SVMtest/liblinear.sh' did not match any file(s) known to git


Add script to run integration test

Add script to run integration test

#!/bin/bash

eval "$(aws ecr get-login --region us-east-1 --registry-id 137112412989)"
docker run --rm -v "$(pwd):/lambda" -w /src 137112412989.dkr.ecr.us-east-1.amazonaws.com/amazonlinux:2016.09 /bin/bash -c 'LD_LIBRARY_PATH=/lambda/.build/lambda/native/LinuxLibraries /lambda/.build/lambda/native/Lambda < /lambda/session_start.json'

error: pathspec 'Sample/run-integration-tests.sh' did not match any file(s) known to git


attempt to track down issue here

attempt to track down issue here

#!/usr/bin/env bash

koopa:::koopa_app() { # {{{1
    # """
    # Parse user input to 'koopa app'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa app <ARG>...'."
    fi
    case "$name" in
        clean)
            name='delete-broken-app-symlinks'
            ;;
        list)
            name='list-app-versions'
            ;;
        link)
            name='link-app'
            ;;
        prune)
            name='prune-apps'
            ;;
        unlink)
            name='unlink-app'
            ;;
    esac
    shift 1
    koopa:::run_function "$name" "$@"
    return 0
}

koopa:::koopa_configure() { # {{{1
    # """
    # Parse user input to 'koopa configure'.
    # @note Updated 2021-04-29.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa configure <ARG>...'."
    fi
    shift 1
    koopa:::run_function "configure-${name}" "$@"
    return 0
}

koopa:::koopa_header() { # {{{1
    # """
    # Parse user input to 'koopa header'.
    # @note Updated 2021-01-19.
    #
    # Useful for private scripts using koopa code outside of package.
    # """
    local arg ext file koopa_prefix subdir
    koopa::assert_has_args_eq "$#" 1
    arg="$(koopa::lowercase "${1:?}")"
    koopa_prefix="$(koopa::prefix)"
    subdir='lang'
    case "$arg" in
        bash|posix|zsh)
            subdir="${subdir}/shell"
            ext='sh'
            ;;
        r)
            ext='R'
            ;;
        *)
            koopa::invalid_arg "$arg"
            ;;
    esac
    file="${koopa_prefix}/${subdir}/${arg}/include/header.${ext}"
    koopa::assert_is_file "$file"
    koopa::print "$file"
    return 0
}

koopa:::koopa_install() { # {{{1
    # """
    # Parse user input to 'koopa install'.
    # @note Updated 2021-05-07.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_install_denylist)"
    while (("$#"))
    do
        case "$1" in
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa install <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        koopa:::run_function "install-${app}" "${app_args[@]}"
    done
    return 0
}

koopa:::koopa_install_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'app'
        'gnu-app'
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::koopa_link() { # {{{1
    # """
    # Parse user input to 'koopa link'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa link <ARG>...'."
    fi
    shift 1
    koopa:::run_function "link-${name}" "$@"
    return 0
}

koopa:::koopa_list() { # {{{1
    # """
    # Parse user input to 'koopa list'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        name='list'
    else
        name="list-${name}"
        shift 1
    fi
    koopa:::run_function "$name" "$@"
    return 0
}

koopa:::koopa_system() { # {{{1
    # """
    # Parse user input to 'koopa system'.
    # @note Updated 2021-03-01.
    # """
    local f
    f="${1:-}"
    if [[ -z "$f" ]]
    then
        koopa::stop "Missing argument: 'koopa system <ARG>...'."
    fi
    case "$f" in
        check)
            f='check-system'
            ;;
        info)
            f='sys-info'
            ;;
        log)
            f='view-latest-tmp-log-file'
            ;;
        path)
            koopa::print "$PATH"
            return 0
            ;;
        prefix)
            case "${2:-}" in
                '')
                    f='prefix'
                    ;;
                koopa)
                    f='prefix'
                    shift 1
                    ;;
                *)
                    f="${2}-prefix"
                    shift 1
                    ;;
            esac
            ;;
        pull)
            f='sys-git-pull'
            ;;
        homebrew-cask-version)
            f='get-homebrew-cask-version'
            ;;
        macos-app-version)
            f='get-macos-app-version'
            ;;
        version)
            f='get-version'
            ;;
        which)
            f='which-realpath'
            ;;
        brew-dump-brewfile | \
        brew-outdated | \
        delete-cache | \
        disable-passwordless-sudo | \
        disable-touch-id-sudo | \
        enable-passwordless-sudo | \
        enable-touch-id-sudo | \
        fix-sudo-setrlimit-error | \
        fix-zsh-permissions | \
        host-id | \
        os-string | \
        roff | \
        set-permissions | \
        variable | \
        variables)
            ;;
        *)
            koopa::invalid_arg "$*"
            ;;
    esac
    shift 1
    koopa:::run_function "$f" "$@"
    return 0
}

koopa:::koopa_uninstall() { # {{{1
    # """
    # Parse user input to 'koopa uninstall'.
    # @note Updated 2021-05-07.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_uninstall_denylist)"
    while (("$#"))
    do
        case "$1" in
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa uminstall <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        koopa:::run_function "uninstall-${app}" "${app_args[@]}"
    done
    return 0
}

koopa:::koopa_uninstall_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::koopa_update() { # {{{1
    # """
    # Parse user input to 'koopa update'.
    # @note Updated 2021-03-01.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_update_denylist)"
    while (("$#"))
    do
        case "$1" in
            # Renamers ---------------------------------------------------------
            system|user)
                pos+=("koopa-${name}")
                ;;
            # Defunct ----------------------------------------------------------
            --fast)
                koopa::defunct 'koopa update'
                ;;
            --source-ip=*)
                koopa::defunct 'koopa configure system --source-ip=SOURCE_IP'
                ;;
            --system)
                koopa::defunct 'koopa update system'
                ;;
            --user)
                koopa::defunct 'koopa update user'
                ;;
            # General catchers -------------------------------------------------
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    # Pass to 'koopa::update_koopa' by default.
    [[ "${#pos[@]}" -eq 0 ]] && pos=('koopa')
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa update <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        koopa:::run_function "update-${app}" "${app_args[@]}"
    done
    return 0
}

koopa:::koopa_update_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::run_function() { # {{{1
    # """
    # Lookup and execute a koopa function automatically.
    # @note Updated 2020-11-18.
    # """
    local name fun
    koopa::assert_has_args "$#"
    name="${1:?}"
    fun="$(koopa:::which_function "$name")"
    koopa::assert_is_function "$fun"
    shift 1
    "$fun" "$@"
    return 0
}

# FIXME This is failing to detect 'koopa::linux_configure_system' correctly
# in clean Alpine Docker install.
koopa:::which_function() { # {{{1
    # """
    # Locate a koopa function automatically.
    # @note Updated 2021-05-11.
    # """
    local fun os_id
    koopa::assert_has_args_eq "$#" 1
    fun="${1:?}"
    fun="${fun//-/_}"
    os_id="$(koopa::os_id)"
    if koopa::is_function "koopa::${os_id}_${fun}"
    then
        fun="koopa::${os_id}_${fun}"
    elif koopa::is_rhel_like && \
        koopa::is_function "koopa::rhel_${fun}"
    then
        fun="koopa::rhel_${fun}"
    elif koopa::is_debian_like && \
        koopa::is_function "koopa::debian_${fun}"
    then
        fun="koopa::debian_${fun}"
    elif koopa::is_fedora_like && \
        koopa::is_function "koopa::fedora_${fun}"
    then
        fun="koopa::fedora_${fun}"
    elif koopa::is_linux && \
        koopa::is_function "koopa::linux_${fun}"
    then
        fun="koopa::linux_${fun}"
    else
        fun="koopa::${fun}"
    fi
    if ! koopa::is_function "$fun"
    then
        koopa::stop "Unsupported command (${fun})."  # FIXME
    fi
    koopa::print "$fun"
    return 0
}

koopa::koopa() { # {{{1
    # """
    # Main koopa function, corresponding to 'koopa' binary.
    # @note Updated 2021-05-04.
    #
    # Need to update corresponding Bash completion file in
    # 'etc/completion/koopa.sh'.
    # """
    koopa::assert_has_args "$#"
    case "$1" in
        --version|-V)
            f='version'
            shift 1
            ;;
        app | \
        configure | \
        header | \
        install | \
        link | \
        list | \
        system | \
        uninstall | \
        update)
            # Note that the ':' is necessary here to call the internal functions
            # defined above.
            f=":koopa_${1}"
            shift 1
            ;;
        test)
            f="$1"
            shift 1
            ;;
        # Soft deprecated args {{{2
        # ----------------------------------------------------------------------
        check | \
        check-system)
            f='check-system'
            shift 1
            ;;
        home)
            f='prefix'
            shift 1
            ;;
        info)
            f='sys-info'
            shift 1
            ;;
        prefix | \
        version)
            f="$1"
            shift 1
            ;;
        # Defunct args / error catching {{{2
        # ----------------------------------------------------------------------
        app-prefix)
            koopa::defunct 'koopa system prefix app'
            ;;
        cellar-prefix)
            koopa::defunct 'koopa system prefix app'
            ;;
        conda-prefix)
            koopa::defunct 'koopa system prefix conda'
            ;;
        config-prefix)
            koopa::defunct 'koopa system prefix config'
            ;;
        delete-cache)
            koopa::defunct 'koopa system delete-cache'
            ;;
        fix-zsh-permissions)
            koopa::defunct 'koopa system fix-zsh-permissions'
            ;;
        get-homebrew-cask-version)
            koopa::defunct 'koopa system homebrew-cask-version'
            ;;
        get-macos-app-version)
            koopa::defunct 'koopa system macos-app-version'
            ;;
        get-version)
            koopa::defunct 'koopa system version'
            ;;
        help)
            koopa::defunct 'koopa --help'
            ;;
        host-id)
            koopa::defunct 'koopa system host-id'
            ;;
        make-prefix)
            koopa::defunct 'koopa system prefix make'
            ;;
        os-string)
            koopa::defunct 'koopa system os-string'
            ;;
        r-home)
            koopa::defunct 'koopa system prefix r'
            ;;
        roff)
            koopa::defunct 'koopa system roff'
            ;;
        set-permissions)
            koopa::defunct 'koopa system set-permissions'
            ;;
        update-r-config)
            koopa::defunct 'koopa update r-config'
            ;;
        upgrade)
            koopa::defunct 'koopa update'
            ;;
        variable)
            koopa::defunct 'koopa system variable'
            ;;
        variables)
            koopa::defunct 'koopa system variables'
            ;;
        which-realpath)
            koopa::defunct 'koopa system which'
            ;;
        *)
            koopa::invalid_arg "$*"
            ;;
    esac
    fun="koopa::${f//-/_}"
    koopa::assert_is_function "$fun"
    "$fun" "$@"
    return 0
}

#!/usr/bin/env bash

koopa:::koopa_app() { # {{{1
    # """
    # Parse user input to 'koopa app'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa app <ARG>...'."
    fi
    case "$name" in
        clean)
            name='delete-broken-app-symlinks'
            ;;
        list)
            name='list-app-versions'
            ;;
        link)
            name='link-app'
            ;;
        prune)
            name='prune-apps'
            ;;
        unlink)
            name='unlink-app'
            ;;
    esac
    shift 1
    koopa:::run_function "$name" "$@"
    return 0
}

koopa:::koopa_configure() { # {{{1
    # """
    # Parse user input to 'koopa configure'.
    # @note Updated 2021-04-29.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa configure <ARG>...'."
    fi
    shift 1
    koopa:::run_function "configure-${name}" "$@"
    return 0
}

koopa:::koopa_header() { # {{{1
    # """
    # Parse user input to 'koopa header'.
    # @note Updated 2021-01-19.
    #
    # Useful for private scripts using koopa code outside of package.
    # """
    local arg ext file koopa_prefix subdir
    koopa::assert_has_args_eq "$#" 1
    arg="$(koopa::lowercase "${1:?}")"
    koopa_prefix="$(koopa::prefix)"
    subdir='lang'
    case "$arg" in
        bash|posix|zsh)
            subdir="${subdir}/shell"
            ext='sh'
            ;;
        r)
            ext='R'
            ;;
        *)
            koopa::invalid_arg "$arg"
            ;;
    esac
    file="${koopa_prefix}/${subdir}/${arg}/include/header.${ext}"
    koopa::assert_is_file "$file"
    koopa::print "$file"
    return 0
}

koopa:::koopa_install() { # {{{1
    # """
    # Parse user input to 'koopa install'.
    # @note Updated 2021-05-07.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_install_denylist)"
    while (("$#"))
    do
        case "$1" in
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa install <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        koopa:::run_function "install-${app}" "${app_args[@]}"
    done
    return 0
}

koopa:::koopa_install_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'app'
        'gnu-app'
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::koopa_link() { # {{{1
    # """
    # Parse user input to 'koopa link'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa link <ARG>...'."
    fi
    shift 1
    koopa:::run_function "link-${name}" "$@"
    return 0
}

koopa:::koopa_list() { # {{{1
    # """
    # Parse user input to 'koopa list'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        name='list'
    else
        name="list-${name}"
        shift 1
    fi
    koopa:::run_function "$name" "$@"
    return 0
}

koopa:::koopa_system() { # {{{1
    # """
    # Parse user input to 'koopa system'.
    # @note Updated 2021-03-01.
    # """
    local f
    f="${1:-}"
    if [[ -z "$f" ]]
    then
        koopa::stop "Missing argument: 'koopa system <ARG>...'."
    fi
    case "$f" in
        check)
            f='check-system'
            ;;
        info)
            f='sys-info'
            ;;
        log)
            f='view-latest-tmp-log-file'
            ;;
        path)
            koopa::print "$PATH"
            return 0
            ;;
        prefix)
            case "${2:-}" in
                '')
                    f='prefix'
                    ;;
                koopa)
                    f='prefix'
                    shift 1
                    ;;
                *)
                    f="${2}-prefix"
                    shift 1
                    ;;
            esac
            ;;
        pull)
            f='sys-git-pull'
            ;;
        homebrew-cask-version)
            f='get-homebrew-cask-version'
            ;;
        macos-app-version)
            f='get-macos-app-version'
            ;;
        version)
            f='get-version'
            ;;
        which)
            f='which-realpath'
            ;;
        brew-dump-brewfile | \
        brew-outdated | \
        delete-cache | \
        disable-passwordless-sudo | \
        disable-touch-id-sudo | \
        enable-passwordless-sudo | \
        enable-touch-id-sudo | \
        fix-sudo-setrlimit-error | \
        fix-zsh-permissions | \
        host-id | \
        os-string | \
        roff | \
        set-permissions | \
        variable | \
        variables)
            ;;
        *)
            koopa::invalid_arg "$*"
            ;;
    esac
    shift 1
    koopa:::run_function "$f" "$@"
    return 0
}

koopa:::koopa_uninstall() { # {{{1
    # """
    # Parse user input to 'koopa uninstall'.
    # @note Updated 2021-05-07.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_uninstall_denylist)"
    while (("$#"))
    do
        case "$1" in
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa uminstall <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        koopa:::run_function "uninstall-${app}" "${app_args[@]}"
    done
    return 0
}

koopa:::koopa_uninstall_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::koopa_update() { # {{{1
    # """
    # Parse user input to 'koopa update'.
    # @note Updated 2021-03-01.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_update_denylist)"
    while (("$#"))
    do
        case "$1" in
            # Renamers ---------------------------------------------------------
            system|user)
                pos+=("koopa-${name}")
                ;;
            # Defunct ----------------------------------------------------------
            --fast)
                koopa::defunct 'koopa update'
                ;;
            --source-ip=*)
                koopa::defunct 'koopa configure system --source-ip=SOURCE_IP'
                ;;
            --system)
                koopa::defunct 'koopa update system'
                ;;
            --user)
                koopa::defunct 'koopa update user'
                ;;
            # General catchers -------------------------------------------------
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    # Pass to 'koopa::update_koopa' by default.
    [[ "${#pos[@]}" -eq 0 ]] && pos=('koopa')
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa update <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        koopa:::run_function "update-${app}" "${app_args[@]}"
    done
    return 0
}

koopa:::koopa_update_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::run_function() { # {{{1
    # """
    # Lookup and execute a koopa function automatically.
    # @note Updated 2020-11-18.
    # """
    local name fun
    koopa::assert_has_args "$#"
    name="${1:?}"
    fun="$(koopa:::which_function "$name")"
    koopa::assert_is_function "$fun"
    shift 1
    "$fun" "$@"
    return 0
}

# FIXME This is failing to detect 'koopa::linux_configure_system' correctly
# in clean Alpine Docker install.
koopa:::which_function() { # {{{1
    # """
    # Locate a koopa function automatically.
    # @note Updated 2021-05-11.
    # """
    local fun os_id
    koopa::assert_has_args_eq "$#" 1
    fun="${1:?}"
    fun="${fun//-/_}"
    os_id="$(koopa::os_id)"
    if koopa::is_function "koopa::${os_id}_${fun}"
    then
        fun="koopa::${os_id}_${fun}"
    elif koopa::is_rhel_like && \
        koopa::is_function "koopa::rhel_${fun}"
    then
        fun="koopa::rhel_${fun}"
    elif koopa::is_debian_like && \
        koopa::is_function "koopa::debian_${fun}"
    then
        fun="koopa::debian_${fun}"
    elif koopa::is_fedora_like && \
        koopa::is_function "koopa::fedora_${fun}"
    then
        fun="koopa::fedora_${fun}"
    elif koopa::is_linux && \
        koopa::is_function "koopa::linux_${fun}"
    then
        fun="koopa::linux_${fun}"
    else
        fun="koopa::${fun}"
    fi
    if ! koopa::is_function "$fun"
    then
        koopa::stop 'Unsupported command.'
    fi
    koopa::print "$fun"
    return 0
}

koopa::koopa() { # {{{1
    # """
    # Main koopa function, corresponding to 'koopa' binary.
    # @note Updated 2021-05-04.
    #
    # Need to update corresponding Bash completion file in
    # 'etc/completion/koopa.sh'.
    # """
    koopa::assert_has_args "$#"
    case "$1" in
        --version|-V)
            f='version'
            shift 1
            ;;
        app | \
        configure | \
        header | \
        install | \
        link | \
        list | \
        system | \
        uninstall | \
        update)
            # Note that the ':' is necessary here to call the internal functions
            # defined above.
            f=":koopa_${1}"
            shift 1
            ;;
        test)
            f="$1"
            shift 1
            ;;
        # Soft deprecated args {{{2
        # ----------------------------------------------------------------------
        check | \
        check-system)
            f='check-system'
            shift 1
            ;;
        home)
            f='prefix'
            shift 1
            ;;
        info)
            f='sys-info'
            shift 1
            ;;
        prefix | \
        version)
            f="$1"
            shift 1
            ;;
        # Defunct args / error catching {{{2
        # ----------------------------------------------------------------------
        app-prefix)
            koopa::defunct 'koopa system prefix app'
            ;;
        cellar-prefix)
            koopa::defunct 'koopa system prefix app'
            ;;
        conda-prefix)
            koopa::defunct 'koopa system prefix conda'
            ;;
        config-prefix)
            koopa::defunct 'koopa system prefix config'
            ;;
        delete-cache)
            koopa::defunct 'koopa system delete-cache'
            ;;
        fix-zsh-permissions)
            koopa::defunct 'koopa system fix-zsh-permissions'
            ;;
        get-homebrew-cask-version)
            koopa::defunct 'koopa system homebrew-cask-version'
            ;;
        get-macos-app-version)
            koopa::defunct 'koopa system macos-app-version'
            ;;
        get-version)
            koopa::defunct 'koopa system version'
            ;;
        help)
            koopa::defunct 'koopa --help'
            ;;
        host-id)
            koopa::defunct 'koopa system host-id'
            ;;
        make-prefix)
            koopa::defunct 'koopa system prefix make'
            ;;
        os-string)
            koopa::defunct 'koopa system os-string'
            ;;
        r-home)
            koopa::defunct 'koopa system prefix r'
            ;;
        roff)
            koopa::defunct 'koopa system roff'
            ;;
        set-permissions)
            koopa::defunct 'koopa system set-permissions'
            ;;
        update-r-config)
            koopa::defunct 'koopa update r-config'
            ;;
        upgrade)
            koopa::defunct 'koopa update'
            ;;
        variable)
            koopa::defunct 'koopa system variable'
            ;;
        variables)
            koopa::defunct 'koopa system variables'
            ;;
        which-realpath)
            koopa::defunct 'koopa system which'
            ;;
        *)
            koopa::invalid_arg "$*"
            ;;
    esac
    fun="koopa::${f//-/_}"
    koopa::assert_is_function "$fun"
    "$fun" "$@"
    return 0
}


track benchmark

track benchmark

#!/usr/bin/env bash

if [ "$#" -lt 3 ]; then
    echo "Requires a parameter for num trainers, num threads, and batch size"
    exit 1
fi

NUM_TRAINERS=$1; shift
NUM_THREADS=$1; shift
BATCH_SIZE=$1; shift

NAME="benchmark_${NUM_TRAINERS}_${NUM_THREADS}_${BATCH_SIZE}"

bash "${ITHEMAL_HOME}/learning/pytorch/experiments/baserun.sh" "${NAME}" --mode benchmark --trainers "${NUM_TRAINERS}" --threads "${NUM_THREADS}" --batch-size "${BATCH_SIZE}" "${@}"

error: pathspec 'learning/pytorch/experiments/benchmark.sh' did not match any file(s) known to git


Add Chapter 2.3 exercises

Add Chapter 2.3 exercises

#Chapter 2.3
#Exercise 1: Use the echo command and the redirect > operator to make a file called foo.txt containing the text "hello, world". Then, using the cp command, make a copy of foo.txt called bar.txt. Usint the diff command, confirm that the contents of both files are the same.
$ echo "hello, world" > foo.txt
$ cp foo.txt bar.txt
$ diff foo.txt bar.txt

#Exercise 2: By combining the cat command and the redirect operator >, create a copy of foo.txt called baz.txt without using the cp command.
$ cat foo.txt > baz.txt

#Exercise 3: Create a file called quux.txt containing the contents of foo.txt followed by the contents of bar.txt
$ cat foo.txt bar.txt > quux.txt

#Exercise 4: How do rm nonexistent and rm -f nonexistent differ for a nonexistent file?

error: pathspec 'command-line/chapter2-3.sh' did not match any file(s) known to git


Don't bother installing openocd when in CI.

#!/usr/bin/env bash

set -e

die() {
    echo >&2 "$@"
    exit 1
}

_pushd() {
    pushd $1 > /dev/null
}

_popd() {
    popd > /dev/null
}

_wait() {
    if [ -z $CI ]; then
        echo "Press Enter when done"
        read
    fi
}

KERNEL=`uname`
if [ ${KERNEL:0:7} == "MINGW32" ]; then
    die "Sorry, the bootstrap script doesn't support Windows - try Cygwin."
elif [ ${KERNEL:0:6} == "CYGWIN" ]; then
    OS="cygwin"
elif [ $KERNEL == "Darwin" ]; then
    OS="mac"
else
    OS="linux"
fi

download() {
    url=$1
    filename=$2
    if [ $OS == "cygwin" ]; then
        curl $url -L --O $filename
    else
        wget $url -O $filename
    fi
}

echo "Updating Git submodules..."

git submodule update --init --quiet

echo "Storing all downloaded dependencies in the \"dependencies\" folder"

DEPENDENCIES_FOLDER="dependencies"
mkdir -p $DEPENDENCIES_FOLDER

echo "Installing dependencies for building for chipKIT Max32 platform"

if [ -z "$MPIDE_DIR" ] || ! test -e $MPIDE_DIR; then

    if [ $OS == "cygwin" ]; then
        MPIDE_BASENAME="mpide-0023-windows-20120903"
        MPIDE_FILE="$MPIDE_BASENAME".zip
        EXTRACT_COMMAND="unzip -q"
    elif [ $OS == "mac" ]; then
        # TODO how can we install this locally to the mpide directory? alternatively,
        # what if we just used the linux version in OS X?
        MPIDE_BASENAME=mpide-0023-macosx-20120903
        MPIDE_FILE="$MPIDE_BASENAME".dmg
    else
        MPIDE_BASENAME=mpide-0023-linux-20120903
        MPIDE_FILE="$MPIDE_BASENAME".tgz
        EXTRACT_COMMAND="tar -xzf"
    fi

    MPIDE_URL=https://github.com/downloads/chipKIT32/chipKIT32-MAX/$MPIDE_FILE

    _pushd $DEPENDENCIES_FOLDER
    if ! test -e $MPIDE_FILE
    then
        echo "Downloaded MPIDE..."
        download $MPIDE_URL $MPIDE_FILE
    fi

    if ! test -d mpide
    then
        echo "Installing MPIDE to local folder..."
        $EXTRACT_COMMAND $MPIDE_FILE
        mv $MPIDE_BASENAME mpide
        echo "MPIDE installed"
    fi

    if [ $OS == "cygwin" ]; then
        chmod a+x mpide/hardware/pic32/compiler/pic32-tools/bin/*
        chmod a+x -R mpide/hardware/pic32/compiler/pic32-tools/pic32mx/
    fi
    _popd

fi

## chipKIT libraries for USB, CAN and Ethernet

CHIPKIT_LIBRARY_AGREEMENT_URL="http://www.digilentinc.com/Agreement.cfm?DocID=DSD-0000318"
CHIPKIT_LIBRARY_DOWNLOAD_URL="http://www.digilentinc.com/Data/Documents/Product%20Documentation/chipKIT%20Network%20and%20USB%20Libs.zip"
CHIPKIT_ZIP_FILE="chipkit.zip"

_pushd $DEPENDENCIES_FOLDER
if ! test -e chipkit.zip
then
    echo
    if [ -z $CI ]; then
        echo "By running this command, you agree to Microchip's licensing agreement at $CHIPKIT_LIBRARY_AGREEMENT_URL"
        echo "Press Enter to verify you have read the license agreement."
        read
    fi
    download $CHIPKIT_LIBRARY_DOWNLOAD_URL $CHIPKIT_ZIP_FILE
fi
_popd

_pushd src/libs
for LIBRARY in chipKITUSBDevice chipKITCAN chipKITEthernet; do
    if ! test -d $LIBRARY
    then
        unzip ../../dependencies/$CHIPKIT_ZIP_FILE "$LIBRARY/*"
    fi
done
_popd

### Patch libraries to avoid problems in case sensitive operating systems
### See https://github.com/chipKIT32/chipKIT32-MAX/issues/146
### and https://github.com/chipKIT32/chipKIT32-MAX/issues/199

# If the patch is already applied, patch will error out, so disable quit on
# error temporarily
set +e
_pushd src/libs
_pushd chipKITUSBDevice
patch -p1 -sNi ../../../script/chipKITUSBDevice-case.patch > /dev/null
_popd

_pushd chipKITCAN
patch -p1 -sNi ../../../script/chipKITCAN-case.patch > /dev/null
_popd

_popd
set -e

# ARM / LPC17XX Dependencies

if ! command -v arm-none-eabi-gcc >/dev/null 2>&1; then

    ## Download GCC compiler for ARM Embedded

    GCC_ARM_BASENAME="gcc-arm-none-eabi-4_7-2012q4-20121208"
    if [ $OS == "linux" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-linux.tar.bz2"
    elif [ $OS == "mac" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-mac.tar.bz2"
    elif [ $OS == "cygwin" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-win32.exe"
    fi

    GCC_ARM_URL="https://launchpad.net/gcc-arm-embedded/4.7/4.7-2012-q4-major/+download/$GCC_ARM_FILE"
    GCC_ARM_DIR="gcc-arm-embedded"

    _pushd $DEPENDENCIES_FOLDER
    if ! test -e $GCC_ARM_FILE
    then
        download $GCC_ARM_URL $GCC_ARM_FILE
    fi

    mkdir -p $GCC_ARM_DIR
    _pushd $GCC_ARM_DIR
    if [ $OS == "cygwin" ]; then
        GCC_INNER_DIR="/cygdrive/c/Program Files/GNU Tools ARM Embedded/4.7 2012q4/"
        INSTALL_COMMAND="cygstart.exe ../$GCC_ARM_FILE; echo -n \"Press Enter when the GCC for ARM Embedded installer is finished\"; read"
    else
        GCC_INNER_DIR="gcc-arm-none-eabi-4_7-2012q4"
        INSTALL_COMMAND="tar -xjf ../$GCC_ARM_FILE"
    fi

    if ! test -d "$GCC_INNER_DIR"
    then
        $INSTALL_COMMAND
    fi

    if ! test -d arm-none-eabi
    then
        cp -R "$GCC_INNER_DIR"/* .
    fi

    _popd
    _popd

fi

if [ -z $CI ] && ! command -v openocd >/dev/null 2>&1; then

    ## Download OpenOCD for flashing ARM via JTAG
    _pushd $DEPENDENCIES_FOLDER

    OPENOCD_BASENAME="openocd-0.6.1"
    if [ $OS == "linux" ]; then
        DISTRO=`lsb_release -si`

        if [ $DISTRO == "arch" ]; then
            sudo pacman -S openocd
        elif [ $DISTRO == "Ubuntu" ]; then
            sudo apt-get update -qq
            sudo apt-get install openocd
        else
            echo "Missing OpenOCD - install it using your distro's package manager or build from source"
            _wait
        fi
    elif [ $OS == "osx" ]; then

        OPENOCD_FILE="$OPENOCD_BASENAME.tar.bz2"
        OPENOCD_DOWNLOAD_URL="http://downloads.sourceforge.net/project/openocd/openocd/0.6.1/$OPENOCD_FILE"

        # look for homebrew
        brew install libftdi libusb
        download $OPENOCD_DOWNLOAD_URL $OPENOCD_FILE
        tar -xjf $OPENOCD_FILE
        _pushd $OPENOCD_BASENAME

        ./configure --enable-ft2232_libftdi
        make
        sudo make install

        # TODO modify ftdi kernel module
        _popd
    elif [ $OS == "cygwin" ]; then
        echo
        echo "Missing OpenOCD and it's not trivial to install in Windows - you won't be able to program the ARM platform"
    fi
    _popd

fi

# TODO how can we check if it's installed. "ld -lcheck" doesn't work on all
# platforms and what if you're on a 64-bit box and have the 32-bit version of
# 'check' installed?
echo "The 'check' library is required for the test suite. There's no \
reliable way to detect if it is installed, so we are going to try and \
re-install just in case"

if [ $OS == "cygwin" ]; then
    echo "May be missing the 'check' library - run the Cygwin installer again and select the 'check' package (http://cygwin.com/install.html)"
    _wait
elif [ $OS == "linux" ]; then
    DISTRO=`lsb_release -si`

    if [ $DISTRO == "arch" ]; then
        if [ "x86_64" == `uname -m` ]; then
            CHECK_PACKAGE="check"
            echo "The 32-bit version of the 'check' library is available from the AUR if you don't already have it installed."
        else
            CHECK_PACKAGE="check"
            sudo pacman --needed -S check
        fi
    elif [ $DISTRO == "Ubuntu" ]; then
        sudo apt-get update -qq
        sudo apt-get install check
    else
        echo "May be missing the 'check' library - install it using your distro's package manager or build from source"
    fi
elif [ $OS == "osx" ]; then
    brew install check
fi

if ! command -v python >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        echo "Missing Python - run the Cygwin installer again and select the 'python' and 'python-argparse' package (http://cygwin.com/install.html)"
        _wait
    elif [ $OS == "linux" ]; then
        DISTRO=`lsb_release -si`

        if [ $DISTRO == "arch" ]; then
            sudo pacman -S python
        elif [ $DISTRO == "Ubuntu" ]; then
            sudo apt-get install python
        else
            echo "Missing Python - install it using your distro's package manager or build from source"
            _wait
        fi
     fi
fi

echo
echo "All dependencies installed, ready to compile."

#!/usr/bin/env bash

set -e

die() {
    echo >&2 "$@"
    exit 1
}

_pushd() {
    pushd $1 > /dev/null
}

_popd() {
    popd > /dev/null
}

_wait() {
    if [ -z $CI ]; then
        echo "Press Enter when done"
        read
    fi
}

KERNEL=`uname`
if [ ${KERNEL:0:7} == "MINGW32" ]; then
    die "Sorry, the bootstrap script doesn't support Windows - try Cygwin."
elif [ ${KERNEL:0:6} == "CYGWIN" ]; then
    OS="cygwin"
elif [ $KERNEL == "Darwin" ]; then
    OS="mac"
else
    OS="linux"
fi

download() {
    url=$1
    filename=$2
    if [ $OS == "cygwin" ]; then
        curl $url -L --O $filename
    else
        wget $url -O $filename
    fi
}

echo "Updating Git submodules..."

git submodule update --init --quiet

echo "Storing all downloaded dependencies in the \"dependencies\" folder"

DEPENDENCIES_FOLDER="dependencies"
mkdir -p $DEPENDENCIES_FOLDER

echo "Installing dependencies for building for chipKIT Max32 platform"

if [ -z "$MPIDE_DIR" ] || ! test -e $MPIDE_DIR; then

    if [ $OS == "cygwin" ]; then
        MPIDE_BASENAME="mpide-0023-windows-20120903"
        MPIDE_FILE="$MPIDE_BASENAME".zip
        EXTRACT_COMMAND="unzip -q"
    elif [ $OS == "mac" ]; then
        # TODO how can we install this locally to the mpide directory? alternatively,
        # what if we just used the linux version in OS X?
        MPIDE_BASENAME=mpide-0023-macosx-20120903
        MPIDE_FILE="$MPIDE_BASENAME".dmg
    else
        MPIDE_BASENAME=mpide-0023-linux-20120903
        MPIDE_FILE="$MPIDE_BASENAME".tgz
        EXTRACT_COMMAND="tar -xzf"
    fi

    MPIDE_URL=https://github.com/downloads/chipKIT32/chipKIT32-MAX/$MPIDE_FILE

    _pushd $DEPENDENCIES_FOLDER
    if ! test -e $MPIDE_FILE
    then
        echo "Downloaded MPIDE..."
        download $MPIDE_URL $MPIDE_FILE
    fi

    if ! test -d mpide
    then
        echo "Installing MPIDE to local folder..."
        $EXTRACT_COMMAND $MPIDE_FILE
        mv $MPIDE_BASENAME mpide
        echo "MPIDE installed"
    fi

    if [ $OS == "cygwin" ]; then
        chmod a+x mpide/hardware/pic32/compiler/pic32-tools/bin/*
        chmod a+x -R mpide/hardware/pic32/compiler/pic32-tools/pic32mx/
    fi
    _popd

fi

## chipKIT libraries for USB, CAN and Ethernet

CHIPKIT_LIBRARY_AGREEMENT_URL="http://www.digilentinc.com/Agreement.cfm?DocID=DSD-0000318"
CHIPKIT_LIBRARY_DOWNLOAD_URL="http://www.digilentinc.com/Data/Documents/Product%20Documentation/chipKIT%20Network%20and%20USB%20Libs.zip"
CHIPKIT_ZIP_FILE="chipkit.zip"

_pushd $DEPENDENCIES_FOLDER
if ! test -e chipkit.zip
then
    echo
    if [ -z $CI ]; then
        echo "By running this command, you agree to Microchip's licensing agreement at $CHIPKIT_LIBRARY_AGREEMENT_URL"
        echo "Press Enter to verify you have read the license agreement."
        read
    fi
    download $CHIPKIT_LIBRARY_DOWNLOAD_URL $CHIPKIT_ZIP_FILE
fi
_popd

_pushd src/libs
for LIBRARY in chipKITUSBDevice chipKITCAN chipKITEthernet; do
    if ! test -d $LIBRARY
    then
        unzip ../../dependencies/$CHIPKIT_ZIP_FILE "$LIBRARY/*"
    fi
done
_popd

### Patch libraries to avoid problems in case sensitive operating systems
### See https://github.com/chipKIT32/chipKIT32-MAX/issues/146
### and https://github.com/chipKIT32/chipKIT32-MAX/issues/199

# If the patch is already applied, patch will error out, so disable quit on
# error temporarily
set +e
_pushd src/libs
_pushd chipKITUSBDevice
patch -p1 -sNi ../../../script/chipKITUSBDevice-case.patch > /dev/null
_popd

_pushd chipKITCAN
patch -p1 -sNi ../../../script/chipKITCAN-case.patch > /dev/null
_popd

_popd
set -e

# ARM / LPC17XX Dependencies

if ! command -v arm-none-eabi-gcc >/dev/null 2>&1; then

    ## Download GCC compiler for ARM Embedded

    GCC_ARM_BASENAME="gcc-arm-none-eabi-4_7-2012q4-20121208"
    if [ $OS == "linux" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-linux.tar.bz2"
    elif [ $OS == "mac" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-mac.tar.bz2"
    elif [ $OS == "cygwin" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-win32.exe"
    fi

    GCC_ARM_URL="https://launchpad.net/gcc-arm-embedded/4.7/4.7-2012-q4-major/+download/$GCC_ARM_FILE"
    GCC_ARM_DIR="gcc-arm-embedded"

    _pushd $DEPENDENCIES_FOLDER
    if ! test -e $GCC_ARM_FILE
    then
        download $GCC_ARM_URL $GCC_ARM_FILE
    fi

    mkdir -p $GCC_ARM_DIR
    _pushd $GCC_ARM_DIR
    if [ $OS == "cygwin" ]; then
        GCC_INNER_DIR="/cygdrive/c/Program Files/GNU Tools ARM Embedded/4.7 2012q4/"
        INSTALL_COMMAND="cygstart.exe ../$GCC_ARM_FILE; echo -n \"Press Enter when the GCC for ARM Embedded installer is finished\"; read"
    else
        GCC_INNER_DIR="gcc-arm-none-eabi-4_7-2012q4"
        INSTALL_COMMAND="tar -xjf ../$GCC_ARM_FILE"
    fi

    if ! test -d "$GCC_INNER_DIR"
    then
        $INSTALL_COMMAND
    fi

    if ! test -d arm-none-eabi
    then
        cp -R "$GCC_INNER_DIR"/* .
    fi

    _popd
    _popd

fi

if ! command -v openocd >/dev/null 2>&1; then

    ## Download OpenOCD for flashing ARM via JTAG
    _pushd $DEPENDENCIES_FOLDER

    OPENOCD_BASENAME="openocd-0.6.1"
    if [ $OS == "linux" ]; then
        DISTRO=`lsb_release -si`

        if [ $DISTRO == "arch" ]; then
            sudo pacman -S openocd
        elif [ $DISTRO == "Ubuntu" ]; then
            sudo apt-get install openocd
        else
            echo "Missing OpenOCD - install it using your distro's package manager or build from source"
            _wait
        fi
    elif [ $OS == "osx" ]; then

        OPENOCD_FILE="$OPENOCD_BASENAME.tar.bz2"
        OPENOCD_DOWNLOAD_URL="http://downloads.sourceforge.net/project/openocd/openocd/0.6.1/$OPENOCD_FILE"

        # look for homebrew
        brew install libftdi libusb
        download $OPENOCD_DOWNLOAD_URL $OPENOCD_FILE
        tar -xjf $OPENOCD_FILE
        _pushd $OPENOCD_BASENAME

        ./configure --enable-ft2232_libftdi
        make
        sudo make install

        # TODO modify ftdi kernel module
        _popd
    elif [ $OS == "cygwin" ]; then
        echo
        echo "Missing OpenOCD and it's not trivial to install in Windows - you won't be able to program the ARM platform"
    fi
    _popd

fi

# TODO how can we check if it's installed. "ld -lcheck" doesn't work on all
# platforms and what if you're on a 64-bit box and have the 32-bit version of
# 'check' installed?
echo "The 'check' library is required for the test suite. There's no \
reliable way to detect if it is installed, so we are going to try and \
re-install just in case"

if [ $OS == "cygwin" ]; then
    echo "May be missing the 'check' library - run the Cygwin installer again and select the 'check' package (http://cygwin.com/install.html)"
    _wait
elif [ $OS == "linux" ]; then
    DISTRO=`lsb_release -si`

    if [ $DISTRO == "arch" ]; then
        if [ "x86_64" == `uname -m` ]; then
            CHECK_PACKAGE="check"
            echo "The 32-bit version of the 'check' library is available from the AUR if you don't already have it installed."
        else
            CHECK_PACKAGE="check"
            sudo pacman --needed -S check
        fi
    elif [ $DISTRO == "Ubuntu" ]; then
        sudo apt-get update -qq
        sudo apt-get install check
    else
        echo "May be missing the 'check' library - install it using your distro's package manager or build from source"
    fi
elif [ $OS == "osx" ]; then
    brew install check
fi

if ! command -v python >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        echo "Missing Python - run the Cygwin installer again and select the 'python' and 'python-argparse' package (http://cygwin.com/install.html)"
        _wait
    elif [ $OS == "linux" ]; then
        DISTRO=`lsb_release -si`

        if [ $DISTRO == "arch" ]; then
            sudo pacman -S python
        elif [ $DISTRO == "Ubuntu" ]; then
            sudo apt-get install python
        else
            echo "Missing Python - install it using your distro's package manager or build from source"
            _wait
        fi
     fi
fi

echo
echo "All dependencies installed, ready to compile."


Update bootstrapped version of GCC for ARM embedded.

#!/usr/bin/env bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd $DIR/..

source $DIR/bootstrap_for_flashing.sh

CYGWIN_PACKAGES="make, gcc-core, patchutils, git, unzip, python, check, curl, libsasl2, python-setuptools"

if [ $OS == "windows" ]; then
    die "Sorry, the bootstrap script for compiling from source doesn't support the Windows console - try Cygwin."
fi

if [ $OS == "mac" ] && ! command -v brew >/dev/null 2>&1; then
    echo "Installing Homebrew..."
    ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
fi

if ! command -v make >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        _cygwin_error "make"
    elif [ $OS == "mac" ]; then
            die "Missing 'make' - install the Xcode CLI tools"
    else
        if [ $DISTRO == "arch" ]; then
            $SUDO_CMD pacman -S base-devel
        elif [ $DISTRO == "Ubuntu" ]; then
            $SUDO_CMD apt-get update -qq
            $SUDO_CMD apt-get install build-essential -y
        fi
    fi
fi

if ! command -v git >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        _cygwin_error "git"
    elif [ $OS == "mac" ] || [ $OS == "linux" ]; then
        _install git
    fi
fi

echo "Updating Git submodules..."

# git submodule update is a shell script and expects some lines to fail
set +e
git submodule sync
if ! git submodule update --init --recursive --quiet; then
    echo "Unable to update git submodules - try running \"git submodule update --init --recursive\" to see the full error"
    echo "If git complains that it \"Needed a single revision\", run \"rm -rf src/libs\" and then try the bootstrap script again"
    if [ $OS == "cygwin" ]; then
        echo "In Cygwin this may be true (ignore if you know ca-certifications is installed:"
        _cygwin_error "ca-certificates"
    fi
    die
fi
set -e

echo "Installing dependencies for running test suite..."

if [ -z $CI ] && ! command -v lcov >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        echo "Missing lcov - Cygwin doesn't have a packaged version of lcov, and it's only required to calculate test suite coverage. We'll skip it."
    elif [ $OS == "mac" ]; then
        brew install lcov
    else
        if [ $DISTRO == "arch" ]; then
            echo "Missing lcov - install from the AUR."
            _wait
        elif [ $DISTRO == "Ubuntu" ]; then
            $SUDO_CMD apt-get update -qq
            $SUDO_CMD apt-get install lcov -y
        fi
    fi
fi

if [ $OS == "mac" ]; then
    _pushd $DEPENDENCIES_FOLDER
    LLVM_BASENAME=clang+llvm-3.2-x86_64-apple-darwin11
    LLVM_FILE=$LLVM_BASENAME.tar.gz
    LLVM_URL=http://llvm.org/releases/3.2/$LLVM_FILE

    if ! test -e $LLVM_FILE
    then
        echo "Downloading LLVM 3.2..."
        download $LLVM_URL $LLVM_FILE
    fi

    if ! test -d $LLVM_BASENAME
    then
        echo "Installing LLVM 3.2 to local folder..."
        tar -xzf $LLVM_FILE
        echo "LLVM 3.2 installed"
    fi

    _popd
fi

echo "Installing dependencies for building for chipKIT Max32 platform"

## chipKIT libraries for USB, CAN and Network

CHIPKIT_LIBRARY_AGREEMENT_URL="http://www.digilentinc.com/Agreement.cfm?DocID=DSD-0000318"
CHIPKIT_LIBRARY_DOWNLOAD_URL="http://www.digilentinc.com/Data/Documents/Product%20Documentation/chipKIT%20Network%20and%20USB%20Libs.zip"
CHIPKIT_ZIP_FILE="chipkit.zip"

_pushd $DEPENDENCIES_FOLDER
if ! test -e chipkit.zip
then
    echo
    if [ -z $CI ]; then
        echo "By running this command, you agree to Microchip's licensing agreement at $CHIPKIT_LIBRARY_AGREEMENT_URL"
        echo "Press Enter to verify you have read the license agreement."
        read
    fi
    download $CHIPKIT_LIBRARY_DOWNLOAD_URL $CHIPKIT_ZIP_FILE
fi
_popd

_pushd src/libs
for LIBRARY in chipKITUSBDevice chipKITCAN chipKITEthernet; do
    if ! test -d $LIBRARY
    then
        echo "Installing chipKIT library $LIBRARY..."
        unzip ../../dependencies/$CHIPKIT_ZIP_FILE "$LIBRARY/*"
    fi
done
_popd

### Patch libraries to avoid problems in case sensitive operating systems
### See https://github.com/chipKIT32/chipKIT32-MAX/issues/146
### and https://github.com/chipKIT32/chipKIT32-MAX/issues/199

echo "Patching case-sensitivity bugs in chipKIT libraries..."

if [ $OS == "cygwin" ] && ! [ -e /usr/bin/patch ]; then
    _cygwin_error "patchutils"
fi

# If the patch is already applied, patch will error out, so disable quit on
# error temporarily
set +e
_pushd src/libs
_pushd chipKITUSBDevice
patch -p1 -sNi ../../../script/chipKITUSBDevice-case.patch > /dev/null
_popd

_pushd chipKITCAN
patch -p1 -sNi ../../../script/chipKITCAN-case.patch > /dev/null
_popd

_popd
set -e

# ARM / LPC17XX Dependencies

if ! command -v arm-none-eabi-gcc >/dev/null 2>&1; then

    echo "Installing GCC for ARM Embedded..."

    GCC_ARM_BASENAME="gcc-arm-none-eabi-4_7-2013q3-20130916"
    if [ $OS == "linux" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-linux.tar.bz2"
    elif [ $OS == "mac" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-mac.tar.bz2"
    elif [ $OS == "cygwin" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-win32.exe"
    fi

    GCC_ARM_URL="https://launchpad.net/gcc-arm-embedded/4.7/4.7-2013-q3-update/+download/$GCC_ARM_FILE"
    GCC_ARM_DIR="gcc-arm-embedded"

    _pushd $DEPENDENCIES_FOLDER
    if ! test -e $GCC_ARM_FILE
    then
        download $GCC_ARM_URL $GCC_ARM_FILE
    fi

    mkdir -p $GCC_ARM_DIR
    _pushd $GCC_ARM_DIR
    if [ $OS == "cygwin" ]; then
        chmod a+x ../$GCC_ARM_FILE
        INSTALL_COMMAND="cygstart.exe ../$GCC_ARM_FILE"
        PROGRAM_FILES_BASE="/cygdrive/c/"
        PROGRAM_FILES="Program Files"
        PROGRAM_FILES_64="Program Files (x86)"
        TRAILING_DIRNAME="GNU Tools ARM Embedded/4.7 2013q3/"
        GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES_64/$TRAILING_DIRNAME"
        if ! test -d "$GCC_INNER_DIR"; then
            GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES/$TRAILING_DIRNAME"
        fi
    else
        GCC_INNER_DIR="gcc-arm-none-eabi-4_7-2013q3"
        INSTALL_COMMAND="tar -xjf ../$GCC_ARM_FILE"
    fi

    if ! test -d "$GCC_INNER_DIR"
    then
        $INSTALL_COMMAND
        if [ $OS == "cygwin" ]; then
            echo -n "Press Enter when the GCC for ARM Embedded installer is finished"
            read
        fi
    fi

    if [ $OS == "cygwin" ]; then
        GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES_64/$TRAILING_DIRNAME"
        if ! test -d "$GCC_INNER_DIR"; then
            GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES/$TRAILING_DIRNAME"
            if ! test -d "$GCC_INNER_DIR"; then
                die "GCC for ARM isn't installed in the expected location."
            fi
        fi
    fi

    if ! test -d arm-none-eabi; then
        echo "Copying GCC binaries to local dependencies folder..."
        cp -R "$GCC_INNER_DIR"/* .
    fi

    _popd
    _popd

fi

if [ -z $CI ] && ! command -v openocd >/dev/null 2>&1; then

    ## Download OpenOCD for flashing ARM via JTAG
    _pushd $DEPENDENCIES_FOLDER

    echo "Installing OpenOCD..."
    if [ $OS == "linux" ]; then
        _install "openocd"
    elif [ $OS == "mac" ]; then
        _install libftdi
        _install libusb
        set +e
        brew install --enable-ft2232_libftdi open-ocd
        set -e
    elif [ $OS == "cygwin" ]; then
        echo
        echo "Missing OpenOCD and it's not trivial to install in Windows - you won't be able to program the ARM platform (not required for the chipKIT translator)"
    fi
    _popd
fi

FTDI_USB_DRIVER_PLIST=/System/Library/Extensions/FTDIUSBSerialDriver.kext/Contents/Info.plist
if [ -z $CI ]  && [ $OS == "mac" ] && [ -e $FTDI_USB_DRIVER_PLIST ]; then
    if grep -q "Olimex OpenOCD JTAG A" $FTDI_USB_DRIVER_PLIST; then
        $SUDO_CMD sed -i "" -e "/Olimex OpenOCD JTAG A/{N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;d;}" $FTDI_USB_DRIVER_PLIST
        FTDI_USB_DRIVER_MODULE=/System/Library/Extensions/FTDIUSBSerialDriver.kext/
        # Driver may not be loaded yet, but that's OK - don't exit on error.
        set +e
        $SUDO_CMD kextunload $FTDI_USB_DRIVER_MODULE
        set -e
        $SUDO_CMD kextload $FTDI_USB_DRIVER_MODULE
    fi
fi

if [ $OS == "cygwin" ] && ! command -v ld >/dev/null 2>&1; then
    _cygwin_error "gcc4"
fi

if ! ld -lcheck -o /tmp/checkcheck 2>/dev/null; then
    echo "Installing the check unit testing library..."

    _install "check"
fi

if ! command -v python >/dev/null 2>&1; then
    echo "Installing Python..."
    _install "python"
fi

if ! python -c "import argparse"; then
    if [ $OS == "cygwin" ]; then
        _cygwin_error "python-argparse"
    fi
fi

if ! command -v pip >/dev/null 2>&1; then
    echo "Installing Pip..."
    if ! command -v easy_install >/dev/null 2>&1; then
        die "easy_install not available, can't install pip"
    fi

    $SUDO_CMD easy_install pip
fi

$SUDO_CMD pip install -U pip
$SUDO_CMD pip install --pre -Ur script/pip-requirements.txt

popd

echo
echo "${bldgreen}All developer dependencies installed, ready to compile.$txtrst"

#!/usr/bin/env bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd $DIR/..

source $DIR/bootstrap_for_flashing.sh

CYGWIN_PACKAGES="make, gcc-core, patchutils, git, unzip, python, check, curl, libsasl2, python-setuptools"

if [ $OS == "windows" ]; then
    die "Sorry, the bootstrap script for compiling from source doesn't support the Windows console - try Cygwin."
fi

if [ $OS == "mac" ] && ! command -v brew >/dev/null 2>&1; then
    echo "Installing Homebrew..."
    ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
fi

if ! command -v make >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        _cygwin_error "make"
    elif [ $OS == "mac" ]; then
            die "Missing 'make' - install the Xcode CLI tools"
    else
        if [ $DISTRO == "arch" ]; then
            $SUDO_CMD pacman -S base-devel
        elif [ $DISTRO == "Ubuntu" ]; then
            $SUDO_CMD apt-get update -qq
            $SUDO_CMD apt-get install build-essential -y
        fi
    fi
fi

if ! command -v git >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        _cygwin_error "git"
    elif [ $OS == "mac" ] || [ $OS == "linux" ]; then
        _install git
    fi
fi

echo "Updating Git submodules..."

# git submodule update is a shell script and expects some lines to fail
set +e
git submodule sync
if ! git submodule update --init --recursive --quiet; then
    echo "Unable to update git submodules - try running \"git submodule update --init --recursive\" to see the full error"
    echo "If git complains that it \"Needed a single revision\", run \"rm -rf src/libs\" and then try the bootstrap script again"
    if [ $OS == "cygwin" ]; then
        echo "In Cygwin this may be true (ignore if you know ca-certifications is installed:"
        _cygwin_error "ca-certificates"
    fi
    die
fi
set -e

echo "Installing dependencies for running test suite..."

if [ -z $CI ] && ! command -v lcov >/dev/null 2>&1; then
    if [ $OS == "cygwin" ]; then
        echo "Missing lcov - Cygwin doesn't have a packaged version of lcov, and it's only required to calculate test suite coverage. We'll skip it."
    elif [ $OS == "mac" ]; then
        brew install lcov
    else
        if [ $DISTRO == "arch" ]; then
            echo "Missing lcov - install from the AUR."
            _wait
        elif [ $DISTRO == "Ubuntu" ]; then
            $SUDO_CMD apt-get update -qq
            $SUDO_CMD apt-get install lcov -y
        fi
    fi
fi

if [ $OS == "mac" ]; then
    _pushd $DEPENDENCIES_FOLDER
    LLVM_BASENAME=clang+llvm-3.2-x86_64-apple-darwin11
    LLVM_FILE=$LLVM_BASENAME.tar.gz
    LLVM_URL=http://llvm.org/releases/3.2/$LLVM_FILE

    if ! test -e $LLVM_FILE
    then
        echo "Downloading LLVM 3.2..."
        download $LLVM_URL $LLVM_FILE
    fi

    if ! test -d $LLVM_BASENAME
    then
        echo "Installing LLVM 3.2 to local folder..."
        tar -xzf $LLVM_FILE
        echo "LLVM 3.2 installed"
    fi

    _popd
fi

echo "Installing dependencies for building for chipKIT Max32 platform"

## chipKIT libraries for USB, CAN and Network

CHIPKIT_LIBRARY_AGREEMENT_URL="http://www.digilentinc.com/Agreement.cfm?DocID=DSD-0000318"
CHIPKIT_LIBRARY_DOWNLOAD_URL="http://www.digilentinc.com/Data/Documents/Product%20Documentation/chipKIT%20Network%20and%20USB%20Libs.zip"
CHIPKIT_ZIP_FILE="chipkit.zip"

_pushd $DEPENDENCIES_FOLDER
if ! test -e chipkit.zip
then
    echo
    if [ -z $CI ]; then
        echo "By running this command, you agree to Microchip's licensing agreement at $CHIPKIT_LIBRARY_AGREEMENT_URL"
        echo "Press Enter to verify you have read the license agreement."
        read
    fi
    download $CHIPKIT_LIBRARY_DOWNLOAD_URL $CHIPKIT_ZIP_FILE
fi
_popd

_pushd src/libs
for LIBRARY in chipKITUSBDevice chipKITCAN chipKITEthernet; do
    if ! test -d $LIBRARY
    then
        echo "Installing chipKIT library $LIBRARY..."
        unzip ../../dependencies/$CHIPKIT_ZIP_FILE "$LIBRARY/*"
    fi
done
_popd

### Patch libraries to avoid problems in case sensitive operating systems
### See https://github.com/chipKIT32/chipKIT32-MAX/issues/146
### and https://github.com/chipKIT32/chipKIT32-MAX/issues/199

echo "Patching case-sensitivity bugs in chipKIT libraries..."

if [ $OS == "cygwin" ] && ! [ -e /usr/bin/patch ]; then
    _cygwin_error "patchutils"
fi

# If the patch is already applied, patch will error out, so disable quit on
# error temporarily
set +e
_pushd src/libs
_pushd chipKITUSBDevice
patch -p1 -sNi ../../../script/chipKITUSBDevice-case.patch > /dev/null
_popd

_pushd chipKITCAN
patch -p1 -sNi ../../../script/chipKITCAN-case.patch > /dev/null
_popd

_popd
set -e

# ARM / LPC17XX Dependencies

if ! command -v arm-none-eabi-gcc >/dev/null 2>&1; then

    echo "Installing GCC for ARM Embedded..."

    GCC_ARM_BASENAME="gcc-arm-none-eabi-4_7-2012q4-20121208"
    if [ $OS == "linux" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-linux.tar.bz2"
    elif [ $OS == "mac" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-mac.tar.bz2"
    elif [ $OS == "cygwin" ]; then
        GCC_ARM_FILE="$GCC_ARM_BASENAME-win32.exe"
    fi

    GCC_ARM_URL="https://launchpad.net/gcc-arm-embedded/4.7/4.7-2012-q4-major/+download/$GCC_ARM_FILE"
    GCC_ARM_DIR="gcc-arm-embedded"

    _pushd $DEPENDENCIES_FOLDER
    if ! test -e $GCC_ARM_FILE
    then
        download $GCC_ARM_URL $GCC_ARM_FILE
    fi

    mkdir -p $GCC_ARM_DIR
    _pushd $GCC_ARM_DIR
    if [ $OS == "cygwin" ]; then
        chmod a+x ../$GCC_ARM_FILE
        INSTALL_COMMAND="cygstart.exe ../$GCC_ARM_FILE"
        PROGRAM_FILES_BASE="/cygdrive/c/"
        PROGRAM_FILES="Program Files"
        PROGRAM_FILES_64="Program Files (x86)"
        TRAILING_DIRNAME="GNU Tools ARM Embedded/4.7 2012q4/"
        GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES_64/$TRAILING_DIRNAME"
        if ! test -d "$GCC_INNER_DIR"; then
            GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES/$TRAILING_DIRNAME"
        fi
    else
        GCC_INNER_DIR="gcc-arm-none-eabi-4_7-2012q4"
        INSTALL_COMMAND="tar -xjf ../$GCC_ARM_FILE"
    fi

    if ! test -d "$GCC_INNER_DIR"
    then
        $INSTALL_COMMAND
        if [ $OS == "cygwin" ]; then
            echo -n "Press Enter when the GCC for ARM Embedded installer is finished"
            read
        fi
    fi

    if [ $OS == "cygwin" ]; then
        GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES_64/$TRAILING_DIRNAME"
        if ! test -d "$GCC_INNER_DIR"; then
            GCC_INNER_DIR="$PROGRAM_FILES_BASE/$PROGRAM_FILES/$TRAILING_DIRNAME"
            if ! test -d "$GCC_INNER_DIR"; then
                die "GCC for ARM isn't installed in the expected location."
            fi
        fi
    fi

    if ! test -d arm-none-eabi; then
        echo "Copying GCC binaries to local dependencies folder..."
        cp -R "$GCC_INNER_DIR"/* .
    fi

    _popd
    _popd

fi

if [ -z $CI ] && ! command -v openocd >/dev/null 2>&1; then

    ## Download OpenOCD for flashing ARM via JTAG
    _pushd $DEPENDENCIES_FOLDER

    echo "Installing OpenOCD..."
    if [ $OS == "linux" ]; then
        _install "openocd"
    elif [ $OS == "mac" ]; then
        _install libftdi
        _install libusb
        set +e
        brew install --enable-ft2232_libftdi open-ocd
        set -e
    elif [ $OS == "cygwin" ]; then
        echo
        echo "Missing OpenOCD and it's not trivial to install in Windows - you won't be able to program the ARM platform (not required for the chipKIT translator)"
    fi
    _popd
fi

FTDI_USB_DRIVER_PLIST=/System/Library/Extensions/FTDIUSBSerialDriver.kext/Contents/Info.plist
if [ -z $CI ]  && [ $OS == "mac" ] && [ -e $FTDI_USB_DRIVER_PLIST ]; then
    if grep -q "Olimex OpenOCD JTAG A" $FTDI_USB_DRIVER_PLIST; then
        $SUDO_CMD sed -i "" -e "/Olimex OpenOCD JTAG A/{N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;N;d;}" $FTDI_USB_DRIVER_PLIST
        FTDI_USB_DRIVER_MODULE=/System/Library/Extensions/FTDIUSBSerialDriver.kext/
        # Driver may not be loaded yet, but that's OK - don't exit on error.
        set +e
        $SUDO_CMD kextunload $FTDI_USB_DRIVER_MODULE
        set -e
        $SUDO_CMD kextload $FTDI_USB_DRIVER_MODULE
    fi
fi

if [ $OS == "cygwin" ] && ! command -v ld >/dev/null 2>&1; then
    _cygwin_error "gcc4"
fi

if ! ld -lcheck -o /tmp/checkcheck 2>/dev/null; then
    echo "Installing the check unit testing library..."

    _install "check"
fi

if ! command -v python >/dev/null 2>&1; then
    echo "Installing Python..."
    _install "python"
fi

if ! python -c "import argparse"; then
    if [ $OS == "cygwin" ]; then
        _cygwin_error "python-argparse"
    fi
fi

if ! command -v pip >/dev/null 2>&1; then
    echo "Installing Pip..."
    if ! command -v easy_install >/dev/null 2>&1; then
        die "easy_install not available, can't install pip"
    fi

    $SUDO_CMD easy_install pip
fi

$SUDO_CMD pip install -U pip
$SUDO_CMD pip install --pre -Ur script/pip-requirements.txt

popd

echo
echo "${bldgreen}All developer dependencies installed, ready to compile.$txtrst"


mac: add setup script

mac: add setup script

#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# Disable creation of .DS_Store files from Finder.
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

error: pathspec 'script/mac-setup.sh' did not match any file(s) known to git


Execute zip with "-q" for quiet"

Execute zip with "-q" for quiet"

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/RedTroop/Cubes_2.git/'


ask for "return" when syncing iCloud

ask for "return" when syncing iCloud

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/vitorgalvao/dotfiles.git/'


Initial commit on scripts

Initial commit on scripts

#!/bin/bash
[[ -f ~/.node_managerrc ]] && source ~/.node_managerrc

# Help text
HELP=`cat <<-EOF
Usage: $0 [options] [UID]\n
\n
-n| --name           \t\t The name of the node_group.\n
\t                   \t\t *Required to create a new group.\n\n
-x| --ensure         \t\t Set to [present|absent] for existence.\n
\t                   \t\t Default: present\n\n
-d| --description      \t Description of group.\n\n
-e| --environment      \t Puppet environment for group.\n
\t                   \t\t Default: production\n\n
-o| --override         \t Set to [true|false] for environment group.\n
\t                   \t\t Default: false\n\n
-p| --parent         \t\t Parent group UID.\n
\t                   \t\t Default: 00000000-0000-4000-8000-000000000000\n\n
-c| --classes        \t\t Hash of classes and parameters.\n
\t                   \t\t Example: '{ "vim": {} }'\n\n
-r| --rules          \t\t Array of rules for matching.\n
\t                   \t\t Example: '["or", ["=", "name", "node.whatsaranjit.com"]]'\n\n
-v| --variables        \t Variables to set in the group.\n
\t                   \t\t Example: '{ "foo": "bar" }'\n\n
-h| --help           \t\t Display this help message.\n
EOF`

# Defaults
MASTER="${MASTER:-`hostname -f`}"
PORT="${PORT:-4433}"

# File to catch response headers
DUMP=$(mktemp)
CURL="/usr/bin/curl -s -k -D ${DUMP}"
CLASSIFIER_URL="https://${MASTER}:${PORT}/classifier-api/v1/groups"

# Get all groups
if [[ $# -eq 0 ]]; then
  $CURL -X GET \
  -H "Content-Type: application/json" \
  -H "X-Authentication: ${TOKEN}" \
  $CLASSIFIER_URL \
  | python -m json.tool 2> /dev/null \
  || (>&2 echo "Unable to hit API!"; exit 1)
# Get single group
elif [[ $# -eq 1 ]]; then
  if [[ "$1" == "--help" || "$1" == "-h" ]]; then
    echo -e $HELP
    exit 0
  fi
  $CURL -X GET \
  -H "Content-Type: application/json" \
  -H "X-Authentication: ${TOKEN}" \
  "${CLASSIFIER_URL}/${1}" \
  | python -m json.tool 2> /dev/null \
  || (>&2 echo "Unable to hit API!"; exit 1)
# Create/update groups
else
  DATA='{'
  while [[ $# -gt 1 ]]; do
    key="$1"

    case $key in
      -h|--help)
        echo -e $HELP
        exit 0
      shift
      ;;
      -x|--ensure)
      ENSURE="$2"
      shift
      ;;
      -n|--name)
      NAME="$2"
      DATA="${DATA} \"name\": \"${NAME}\","
      shift
      ;;
      -d|--description)
      DESCRIPTION="$2"
      DATA="${DATA} \"description\": \"${DESCRIPTION}\","
      shift
      ;;
      -e|--environment)
      ENVIRONMENT="$2"
      DATA="${DATA} \"environment\": \"${ENVIRONMENT}\","
      shift
      ;;
      -o|--override)
      OVERRIDE="$2"
      DATA="${DATA} \"environment_trumps\": ${OVERRIDE},"
      shift
      ;;
      -p|--parent)
      PARENT="$2"
      DATA="${DATA} \"parent\": \"${PARENT}\","
      shift
      ;;
      -c|--classes)
      CLASSES="$2"
      DATA="${DATA} \"classes\": ${CLASSES},"
      shift
      ;;
      -r|--rule)
      RULE="$2"
      DATA="${DATA} \"rule\": $RULE,"
      shift
      ;;
      -v|--variables)
      VARIABLES="$2"
      DATA="${DATA} \"variables\": $VARIABLES,"
      shift
      ;;
      *)
        (>&2 echo "Invalid options supplied!"); exit 1
      ;;
    esac
    shift
  done
  # Set defaults if they weren't given
  if [[ -z $PARENT ]]; then
    DATA="${DATA} \"parent\": \"00000000-0000-4000-8000-000000000000\","
  fi
  if [[ -z $CLASSES ]]; then
    DATA="${DATA} \"classes\": {},"
  fi
  # Remove trailing comma
  DATA=`sed 's/,$//' <<< $DATA`
  DATA="${DATA} }"
  # Last arg, if given, is the group ID
  ID=$1
  if [[ ! -z $ID ]]; then
    URL="${CLASSIFIER_URL}/${ID}"
  else
    URL=$CLASSIFIER_URL
  fi
  # Do cURL with JSON data
  if [[ "$ENSURE" == "absent" ]]; then
    $CURL -X DELETE \
    -H "Content-Type: application/json" \
    -H "X-Authentication: ${TOKEN}" \
    $URL \
    || (>&2 echo "Unable to hit API!"; exit 1)
  else
    $CURL -X POST \
    -H "Content-Type: application/json" \
    -H "X-Authentication: ${TOKEN}" \
    --data "${DATA}" \
    $URL \
    | python -m json.tool 2> /dev/null || (
      NEWID=`grep 'Location' $DUMP | cut -d '/' -f5`
      if [[ ! -z $NEWID ]]; then
        echo "New group ID: ${NEWID}"
      else
        (>&2 echo "Unable to hit API!"); exit 1
      fi
    )
  fi
fi

CODE=`grep 'HTTP/' $DUMP | cut -d ' ' -f2`

# All good
if [[ "$CODE" -eq '200' ]]; then
  exit 0
# Successful creation
elif [[ "$CODE" -eq '201' ]]; then
  exit 2
# Successful delete
elif [[ "$CODE" -eq '204' ]]; then
  echo "${ID} removed"
  exit 2
# Successful creation
elif [[ "$CODE" -eq '303' ]]; then
  exit 2
# Bad schema
elif [[ "$CODE" -eq '400' ]]; then
  exit 1
# ID not found
elif [[ "$CODE" -eq '404' ]]; then
  exit 1
# Violating uniqueness
elif [[ "$CODE" -eq '422' ]]; then
  exit 4
# Huh?
else
  exit 1
fi

error: pathspec 'scripts/node_group.sh' did not match any file(s) known to git