udpate scripts

udpate scripts

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/TOTVS/mdmpublic.git/'


a cron job to post new things automatically

#!/bin/sh
set -e

git pull
nanoc
(
  cd output
  git commit . -m 'automatic compile'
  git push
)

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


fix(sharness): Initializing daemon... output

# Test framework for go-ipfs
#
# Copyright (c) 2014 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#
# We are using sharness (https://github.com/mlafeldt/sharness)
# which was extracted from the Git test framework.

# use the ipfs tool to test against

# add current directory to path, for ipfs tool.
PATH=$(pwd)/bin:${PATH}

# set sharness verbosity. we set the env var directly as
# it's too late to pass in --verbose, and --verbose is harder
# to pass through in some cases.
test "$TEST_VERBOSE" = 1 && verbose=t

# assert the `ipfs` we're using is the right one.
if test `which ipfs` != $(pwd)/bin/ipfs; then
	echo >&2 "Cannot find the tests' local ipfs tool."
	echo >&2 "Please check test and ipfs tool installation."
	exit 1
fi

SHARNESS_LIB="lib/sharness/sharness.sh"

. "$SHARNESS_LIB" || {
	echo >&2 "Cannot source: $SHARNESS_LIB"
	echo >&2 "Please check Sharness installation."
	exit 1
}

# overriding testcmp to make it use fsh (to see it better in output)
# have to do it twice so the first diff output doesnt show unless it's
# broken.
test_cmp() {
	diff -q "$@" >/dev/null || fsh diff -u "$@"
}

# Please put go-ipfs specific shell functions below

test "$TEST_NO_FUSE" != 1 && test_set_prereq FUSE
test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE

test_cmp_repeat_10_sec() {
	for i in 1 2 3 4 5 6 7 8 9 10
	do
		test_cmp "$1" "$2" >/dev/null && return
		sleep 1
	done
	test_cmp "$1" "$2"
}

test_wait_output_n_lines_60_sec() {
	echo "$2" >expected_waitn
	for i in 1 2 3 4 5 6 7 8 9 10
	do
		cat "$1" | wc -l | tr -d " " >actual_waitn
		test_cmp "expected_waitn" "actual_waitn" && return
		sleep 2
	done
	cat "$1" | wc -l | tr -d " " >actual_waitn
	test_cmp "expected_waitn" "actual_waitn"
}

test_init_ipfs() {

	test_expect_success "ipfs init succeeds" '
		export IPFS_PATH="$(pwd)/.go-ipfs" &&
		ipfs init -b=1024 > /dev/null
	'

	test_expect_success "prepare config" '
		mkdir mountdir ipfs ipns &&
		ipfs config Mounts.IPFS "$(pwd)/ipfs" &&
		ipfs config Mounts.IPNS "$(pwd)/ipns" &&
		ipfs bootstrap rm --all
	'

}

test_launch_ipfs_daemon() {

	test_expect_success FUSE "'ipfs daemon' succeeds" '
		ipfs daemon >actual 2>daemon_err &
	'

	test_expect_success FUSE "'ipfs daemon' output looks good" '
		IPFS_PID=$! &&
		echo "Initializing daemon..." >expected &&
		echo "API server listening on /ip4/127.0.0.1/tcp/5001" >>expected &&
		test_cmp_repeat_10_sec expected actual ||
		fsh cat daemon_err
	'
}

test_mount_ipfs() {

	# make sure stuff is unmounted first.
	test_expect_success FUSE "'ipfs mount' succeeds" '
		umount $(pwd)/ipfs || true &&
		umount $(pwd)/ipns || true &&
		ipfs mount >actual
	'

	test_expect_success FUSE "'ipfs mount' output looks good" '
		echo "IPFS mounted at: $(pwd)/ipfs" >expected &&
		echo "IPNS mounted at: $(pwd)/ipns" >>expected &&
		test_cmp expected actual
	'

}

test_launch_ipfs_daemon_and_mount() {

	test_init_ipfs
	test_launch_ipfs_daemon
	test_mount_ipfs

}

test_kill_repeat_10_sec() {
	for i in 1 2 3 4 5 6 7 8 9 10
	do
		kill $1
		sleep 1
		! kill -0 $1 2>/dev/null && return
	done
	! kill -0 $1 2>/dev/null
}

test_kill_ipfs_daemon() {

	test_expect_success FUSE "'ipfs daemon' is still running" '
		kill -0 $IPFS_PID
	'

	test_expect_success FUSE "'ipfs daemon' can be killed" '
		test_kill_repeat_10_sec $IPFS_PID
	'
}

# Test framework for go-ipfs
#
# Copyright (c) 2014 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#
# We are using sharness (https://github.com/mlafeldt/sharness)
# which was extracted from the Git test framework.

# use the ipfs tool to test against

# add current directory to path, for ipfs tool.
PATH=$(pwd)/bin:${PATH}

# set sharness verbosity. we set the env var directly as
# it's too late to pass in --verbose, and --verbose is harder
# to pass through in some cases.
test "$TEST_VERBOSE" = 1 && verbose=t

# assert the `ipfs` we're using is the right one.
if test `which ipfs` != $(pwd)/bin/ipfs; then
	echo >&2 "Cannot find the tests' local ipfs tool."
	echo >&2 "Please check test and ipfs tool installation."
	exit 1
fi

SHARNESS_LIB="lib/sharness/sharness.sh"

. "$SHARNESS_LIB" || {
	echo >&2 "Cannot source: $SHARNESS_LIB"
	echo >&2 "Please check Sharness installation."
	exit 1
}

# overriding testcmp to make it use fsh (to see it better in output)
# have to do it twice so the first diff output doesnt show unless it's
# broken.
test_cmp() {
	diff -q "$@" >/dev/null || fsh diff -u "$@"
}

# Please put go-ipfs specific shell functions below

test "$TEST_NO_FUSE" != 1 && test_set_prereq FUSE
test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE

test_cmp_repeat_10_sec() {
	for i in 1 2 3 4 5 6 7 8 9 10
	do
		test_cmp "$1" "$2" >/dev/null && return
		sleep 1
	done
	test_cmp "$1" "$2"
}

test_wait_output_n_lines_60_sec() {
	echo "$2" >expected_waitn
	for i in 1 2 3 4 5 6 7 8 9 10
	do
		cat "$1" | wc -l | tr -d " " >actual_waitn
		test_cmp "expected_waitn" "actual_waitn" && return
		sleep 2
	done
	cat "$1" | wc -l | tr -d " " >actual_waitn
	test_cmp "expected_waitn" "actual_waitn"
}

test_init_ipfs() {

	test_expect_success "ipfs init succeeds" '
		export IPFS_PATH="$(pwd)/.go-ipfs" &&
		ipfs init -b=1024 > /dev/null
	'

	test_expect_success "prepare config" '
		mkdir mountdir ipfs ipns &&
		ipfs config Mounts.IPFS "$(pwd)/ipfs" &&
		ipfs config Mounts.IPNS "$(pwd)/ipns" &&
		ipfs bootstrap rm --all
	'

}

test_launch_ipfs_daemon() {

	test_expect_success FUSE "'ipfs daemon' succeeds" '
		ipfs daemon >actual 2>daemon_err &
	'

	test_expect_success FUSE "'ipfs daemon' output looks good" '
		IPFS_PID=$! &&
		echo "API server listening on /ip4/127.0.0.1/tcp/5001" >expected &&
		test_cmp_repeat_10_sec expected actual ||
		fsh cat daemon_err
	'
}

test_mount_ipfs() {

	# make sure stuff is unmounted first.
	test_expect_success FUSE "'ipfs mount' succeeds" '
		umount $(pwd)/ipfs || true &&
		umount $(pwd)/ipns || true &&
		ipfs mount >actual
	'

	test_expect_success FUSE "'ipfs mount' output looks good" '
		echo "IPFS mounted at: $(pwd)/ipfs" >expected &&
		echo "IPNS mounted at: $(pwd)/ipns" >>expected &&
		test_cmp expected actual
	'

}

test_launch_ipfs_daemon_and_mount() {

	test_init_ipfs
	test_launch_ipfs_daemon
	test_mount_ipfs

}

test_kill_repeat_10_sec() {
	for i in 1 2 3 4 5 6 7 8 9 10
	do
		kill $1
		sleep 1
		! kill -0 $1 2>/dev/null && return
	done
	! kill -0 $1 2>/dev/null
}

test_kill_ipfs_daemon() {

	test_expect_success FUSE "'ipfs daemon' is still running" '
		kill -0 $IPFS_PID
	'

	test_expect_success FUSE "'ipfs daemon' can be killed" '
		test_kill_repeat_10_sec $IPFS_PID
	'
}


clean db script

clean db script

#!/bin/bash
MUSER="$1"
MPASS="$2"
MDB="$3"

# Detect paths
MYSQL=$(which mysql)
AWK=$(which awk)
GREP=$(which grep)

if [ $# -ne 3 ]
then
	echo "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}"
	echo "Drops all tables from a MySQL"
	exit 1
fi

TABLES=$($MYSQL -u $MUSER -p$MPASS $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' )

$MYSQL -u $MUSER -p$MPASS -$MDB -e "SET FOREIGN_KEY_CHECKS = 0;"
for t in $TABLES
do
	echo "Deleting $t table from $MDB database..."
	$MYSQL -u $MUSER -p$MPASS $MDB -e "drop table $t"
done
$MYSQL -u $MUSER -p$MPASS -$MDB -e "SET FOREIGN_KEY_CHECKS = 1;"

#!/bin/bash
MUSER="$1"
MPASS="$2"
MDB="$3"

# Detect paths
MYSQL=$(which mysql)
AWK=$(which awk)
GREP=$(which grep)

if [ $# -ne 3 ]
then
	echo "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}"
	echo "Drops all tables from a MySQL"
	exit 1
fi

TABLES=$($MYSQL -u $MUSER -p$MPASS $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' )

for t in $TABLES
do
	echo "Deleting $t table from $MDB database..."
	$MYSQL -u $MUSER -p$MPASS $MDB -e "drop table $t"
done


exit on failure

exit on failure

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/bborbe/aptly_utils.git/'


file path

file path

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/lostpupil/banana-toolkit.git/'


Fix rpm buils

Fix rpm buils

remote: Repository unavailable due to DMCA takedown.
remote: See the takedown notice for more details:
remote:   https://github.com/github/dmca/blob/master/2019/03/2019-03-19-Fontsmith.md.
fatal: unable to access 'https://github.com/iQuarK/client-web-app.js.git/': The requested URL returned error: 403


add git hook

add git hook

#!/bin/sh

# git-hooks-install.sh
# by wilsonmar at gmail.com
# After the repo is cloned, this bash script copies
# scripts in the repo's hooks folder into the .git/hooks
# and sets permissions.

fancy_echo() { # to add blank line between echo statements:
  local fmt="$1"; shift
  # shellcheck disable=SC2059
  printf "\n$fmt\n" "$@"
}

fancy_echo "Remove *.sample files ..."
del .git/hooks/*.sample

fancy_echo "Copy hooks/git-commit into .git/hooks  ..."
cp hooks/prepare-commit-msg .git/hooks
chmod +x .git/hooks/prepare-commit-msg

#cp hooks/git-commit  .git/hooks
#chmod +x .git/hooks/git-commit

cp hooks/git-push  .git/hooks
chmod +x .git/hooks/git-push

cp hooks/git-rebase  .git/hooks
chmod +x .git/hooks/git-rebase

ls .git/hooks

fancy_echo "Done with status $? (0=OK)."

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


Update for pgpointcloud

Update for pgpointcloud

USR_LOCAL="/usr/local"
USR="/usr"
OPT="/opt/local"
TIFF_HOME=$USR_LOCAL
LASZIP_HOME=$USR_LOCAL
LIBXML2_HOME=$OPT
GEOTIFF_HOME=$USR_LOCAL
P2G_HOME=$USR_LOCAL
SO_EXT=dylib
EMBED=ON
CC=/usr/bin/gcc
CXX=/usr/bin/g++
CPPCLAGS=-I/usr/pgsql-9.2/include

ORACLE_HOME=$HOME/oracle
export ORACLE_HOME
CONFIG="Unix Makefiles"

if ! [ -z "$1" ]; then
    CONFIG="$1"
fi

cmake   -G "$CONFIG"  \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
        -DCMAKE_INSTALL_PREFIX=${HOME}/pdal \
        -DPDAL_EMBED_BOOST=${EMBED} \
        -DWITH_GDAL=ON \
        -DWITH_ICONV=ON \
        -DWITH_ORACLE=OFF \
        -DWITH_GEOTIFF=ON \
        -DWITH_LASZIP=OFF \
        -DWITH_LIBXML2=ON \
        -DWITH_PYTHON=ON \
        -DWITH_FLANN=OFF \
        -DWITH_P2G=OFF \
        -DWITH_SOCI=OFF \
        -DWITH_PGPOINTCLOUD=ON \
        -DGEOTIFF_INCLUDE_DIR=${GEOTIFF_HOME}/include \
        -DGEOTIFF_LIBRARY=${GEOTIFF_HOME}/lib/libgeotiff.${SO_EXT} \
        -DICONV_INCLUDE_DIR=/usr/include \
        -DLIBXML2_INCLUDE_DIR=${LIBXML2_HOME}/include/libxml2 \
        -DLIBXML2_LIBRARIES=${LIBXML2_HOME}/lib/libxml2.${SO_EXT} \
        -DTIFF_INCLUDE_DIR=/${TIFF_HOME}/include \
        -DTIFF_LIBRARY=${TIFF_HOME}/lib/libtiff.${SO_EXT} \
	-DPOSTGRESQL_INCLUDE_DIR=${USR_LOCAL}/pgsql/9.2/include \
	-DPOSTGRESQL_LIBRARIES=${USR_LOCAL}/pgsql/9.2/lib/libpq.${SO_EXT} \
	../PDAL

# -DLASZIP_INCLUDE_DIR=${LASZIP_HOME}/include \
# -DLASZIP_LIBRARY=${LASZIP_HOME}/lib/liblaszip.${SO_EXT} \
# -DUSE_PDAL_PLUGIN_SOCI=ON \
# -DUSE_PDAL_PLUGIN_PCD=ON \
# -DUSE_PDAL_PLUGIN_OCI=ON \
# -DUSE_PDAL_PLUGIN_TEXT=ON \

USR_LOCAL="/usr/local"
USR="/usr"
OPT="/opt/local"
TIFF_HOME=$USR_LOCAL
LASZIP_HOME=$USR_LOCAL
LIBXML2_HOME=$OPT
GEOTIFF_HOME=$USR_LOCAL
P2G_HOME=$USR_LOCAL
SO_EXT=dylib
EMBED=OFF
CC=/usr/bin/gcc
CXX=/usr/bin/g++
CPPCLAGS=-I/usr/pgsql/9.2/include

ORACLE_HOME=$HOME/oracle
export ORACLE_HOME
CONFIG="Unix Makefiles"

if ! [ -z "$1" ]; then
    CONFIG="$1"
fi

cmake   -G "$CONFIG"  \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
        -DCMAKE_INSTALL_PREFIX=${HOME}/pdal \
        -DPDAL_EMBED_BOOST=${EMBED} \
        -DWITH_GDAL=ON \
        -DWITH_ICONV=ON \
        -DWITH_ORACLE=OFF \
        -DWITH_GEOTIFF=ON \
        -DWITH_LASZIP=OFF \
        -DWITH_LIBXML2=ON \
        -DWITH_PYTHON=ON \
        -DWITH_FLANN=OFF \
        -DWITH_P2G=ON \
        -DGEOTIFF_INCLUDE_DIR=${GEOTIFF_HOME}/include/ \
        -DGEOTIFF_LIBRARY=${GEOTIFF_HOME}/lib/libgeotiff.${SO_EXT} \
        -DICONV_INCLUDE_DIR=/usr/include \
        -DP2G_INCLUDE_DIR=${P2G_HOME}/include \
        -DP2G_LIBRARY=${P2G_HOME}/lib/libpts2grd.${SO_EXT} \
        -DLIBXML2_INCLUDE_DIR=${LIBXML2_HOME}/include/libxml2 \
        -DLIBXML2_LIBRARIES=${LIBXML2_HOME}/lib/libxml2.${SO_EXT} \
        -DTIFF_INCLUDE_DIR=/${TIFF_HOME}/include \
        -DTIFF_LIBRARY=${TIFF_HOME}/lib/libtiff.${SO_EXT} \
        -DWITH_SOCI=ON \
	-DSOCI_INCLUDE_DIR=${USR_LOCAL}/include/soci\;${USR_LOCAL}/pgsql/9.2/include \
	-DSOCI_LIBRARY=${USR_LOCAL}/lib/libsoci_core.${SO_EXT} \
	-DSOCI_postgresql_PLUGIN=${USR_LOCAL}/lib/libsoci_postgresql.${SO_EXT} ../PDAL

#        -DLASZIP_INCLUDE_DIR=${LASZIP_HOME}/include \
#        -DLASZIP_LIBRARY=${LASZIP_HOME}/lib/liblaszip.${SO_EXT} \
    # -DUSE_PDAL_PLUGIN_SOCI=ON \
    # -DUSE_PDAL_PLUGIN_PCD=ON \
    # -DUSE_PDAL_PLUGIN_OCI=ON \
    # -DUSE_PDAL_PLUGIN_TEXT=ON \


Create pushToGithub.sh

Create pushToGithub.sh

echo -e "Pushing build to github-pages"

cp dist/canvashs*.tar.gz $HOME/canvashs.tar.gz

cd $HOME
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis"

git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com:CanvasHS/Canvas.hs.git gh-pages > /dev/null

cd gh-pages/dists
cp $HOME/canvashs*.tar.gz canvashs-${TRAVIS_BUILD_NUMBER}.tar

git add .
git commit -m "Travis build $TRAVIS_BUILD_NUMBER pushed to gh-pages"
git push -fq origin gh-pages > /dev/null

echo -e "build pushed to gh-pages"

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


change build number

change build number

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/Notoh/RankedCvC.git/'


Adapt rustup for unattended installation

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/gabibbo97/uni-esperimenti-noweb.git/'


update default PS1

update default PS1

#!/bin/bash -e

function displayUsage()
{
    local -r scriptName="$(basename "${BASH_SOURCE[0]}")"

    echo -e "\033[1;33m"
    echo    "SYNOPSIS :"
    echo    "    ${scriptName}"
    echo    "        --help"
    echo    "        --profile-file-name    <PROFILE_FILE_NAME>"
    echo    "        --host-name            <HOST_NAME>"
    echo    "        --users                <USERS>"
    echo -e "\033[1;35m"
    echo    "DESCRIPTION :"
    echo    "    --help                 Help page"
    echo    "    --profile-file-name    Profile file name such as '.profile', '.bash_profile', '.bashrc' (optional)"
    echo    "    --host-name            Custom host name (optional). Default to current host name"
    echo    "    --users                List of users separated by commas or spaces (optional). Default to current user"
    echo -e "\033[1;36m"
    echo    "EXAMPLES :"
    echo    "    ./${scriptName} --help"
    echo    "    ./${scriptName}"
    echo    "    ./${scriptName}"
    echo    "        --users 'user1, user2, user3'"
    echo    "    ./${scriptName}"
    echo    "        --host-name 'my-server.com'"
    echo    "    ./${scriptName}"
    echo    "        --host-name 'my-server.com'"
    echo    "        --users 'user1 user2 user3'"
    echo    "    ./${scriptName}"
    echo    "        --profile-file-name '.bash_profile'"
    echo    "        --host-name 'my-server.com'"
    echo    "        --users 'user1 user2 user3'"
    echo -e "\033[0m"

    exit "${1}"
}

function install()
{
    local -r profileFileName="${1}"
    local -r hostName="${2}"
    local users=(${3//,/ })

    # Reformat PS1

    if [[ "$(isEmptyString "${hostName}")" = 'false' ]]
    then
        PS1_ROOT_PROMPT="$(replaceString "${PS1_ROOT_PROMPT}" '\\h' "${hostName}")"
        PS1_USER_PROMPT="$(replaceString "${PS1_USER_PROMPT}" '\\h' "${hostName}")"
    fi

    # Add Current User To List When Array Is Empty

    if [[ "${#users[@]}" -lt '1' ]]
    then
        users=("$(whoami)")
    fi

    # Update Prompt

    local user=''

    for user in "${users[@]}"
    do
        # Use Auto Detect Profile File Path Or Use Specified Profile File Name

        local profileFilePath
        profileFilePath="$(getProfileFilePath "${user}")"

        if [[ "$(isEmptyString "${profileFileName}")" = 'false' ]]
        then
            profileFilePath="$(getUserHomeFolder "${user}")/${profileFileName}"
        fi

        # Update Profile File Path

        if [[ "$(isEmptyString "${profileFilePath}")" = 'false' ]]
        then
            if [[ "$(whoami)" = "${user}" ]]
            then
                local prompt="export PS1=\"${PS1_ROOT_PROMPT}\""
            else
                local prompt="export PS1=\"${PS1_USER_PROMPT}\""
            fi

            echo -e "Updating '\033[1;32m${profileFilePath}\033[0m'"

            if [[ ! -f "${profileFilePath}" ]]
            then
                touch "${profileFilePath}"
                chown "${user}:${user}" "${profileFilePath}"
            fi

            appendToFileIfNotFound "${profileFilePath}" "${prompt}" "${prompt}" 'false' 'false' 'true'
        else
            warn "WARN : profile '${user}' not found"
        fi
    done

    # Update Default Prompt

    prompt="export PS1=\"${PS1_USER_PROMPT}\""

    appendToFileIfNotFound '/etc/skel/.profile' "${prompt}" "${prompt}" 'false' 'false' 'true'
}

function main()
{
    local -r appPath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

    source "${appPath}/../../../libraries/util.bash"
    source "${appPath}/../attributes/default.bash"

    while [[ "${#}" -gt '0' ]]
    do
        case "${1}" in
            --help)
                displayUsage 0
                ;;

            --profile-file-name)
                shift

                if [[ "${#}" -gt '0' ]]
                then
                    local -r profileFileName="$(trimString "${1}")"
                fi

                ;;

            --host-name)
                shift

                if [[ "${#}" -gt '0' ]]
                then
                    local -r hostName="$(trimString "${1}")"
                fi

                ;;

            --users)
                shift

                if [[ "${#}" -gt '0' ]]
                then
                    local -r users="$(trimString "${1}")"
                fi

                ;;

            *)
                shift
                ;;
        esac
    done

    checkRequireSystem
    checkRequireRootUser

    header 'INSTALLING PS1'

    install "${profileFileName}" "${hostName}" "${users}"
    installCleanUp
}

main "${@}"

#!/bin/bash -e

function displayUsage()
{
    local -r scriptName="$(basename "${BASH_SOURCE[0]}")"

    echo -e "\033[1;33m"
    echo    "SYNOPSIS :"
    echo    "    ${scriptName}"
    echo    "        --help"
    echo    "        --profile-file-name    <PROFILE_FILE_NAME>"
    echo    "        --host-name            <HOST_NAME>"
    echo    "        --users                <USERS>"
    echo -e "\033[1;35m"
    echo    "DESCRIPTION :"
    echo    "    --help                 Help page"
    echo    "    --profile-file-name    Profile file name such as '.profile', '.bash_profile', '.bashrc' (optional)"
    echo    "    --host-name            Custom host name (optional). Default to current host name"
    echo    "    --users                List of users separated by commas or spaces (optional). Default to current user"
    echo -e "\033[1;36m"
    echo    "EXAMPLES :"
    echo    "    ./${scriptName} --help"
    echo    "    ./${scriptName}"
    echo    "    ./${scriptName}"
    echo    "        --users 'user1, user2, user3'"
    echo    "    ./${scriptName}"
    echo    "        --host-name 'my-server.com'"
    echo    "    ./${scriptName}"
    echo    "        --host-name 'my-server.com'"
    echo    "        --users 'user1 user2 user3'"
    echo    "    ./${scriptName}"
    echo    "        --profile-file-name '.bash_profile'"
    echo    "        --host-name 'my-server.com'"
    echo    "        --users 'user1 user2 user3'"
    echo -e "\033[0m"

    exit "${1}"
}

function install()
{
    local -r profileFileName="${1}"
    local -r hostName="${2}"
    local users=(${3//,/ })

    # Reformat PS1

    if [[ "$(isEmptyString "${hostName}")" = 'false' ]]
    then
        PS1_ROOT_PROMPT="$(replaceString "${PS1_ROOT_PROMPT}" '\\h' "${hostName}")"
        PS1_USER_PROMPT="$(replaceString "${PS1_USER_PROMPT}" '\\h' "${hostName}")"
    fi

    # Add Current User To List When Array Is Empty

    if [[ "${#users[@]}" -lt '1' ]]
    then
        users=("$(whoami)")
    fi

    # Update Prompt

    local user=''

    for user in "${users[@]}"
    do
        # Use Auto Detect Profile File Path Or Use Specified Profile File Name

        local profileFilePath
        profileFilePath="$(getProfileFilePath "${user}")"

        if [[ "$(isEmptyString "${profileFileName}")" = 'false' ]]
        then
            profileFilePath="$(getUserHomeFolder "${user}")/${profileFileName}"
        fi

        # Update Profile File Path

        if [[ "$(isEmptyString "${profileFilePath}")" = 'false' ]]
        then
            if [[ "$(whoami)" = "${user}" ]]
            then
                local prompt="export PS1=\"${PS1_ROOT_PROMPT}\""
            else
                local prompt="export PS1=\"${PS1_USER_PROMPT}\""
            fi

            echo -e "Updating '\033[1;32m${profileFilePath}\033[0m'"

            if [[ ! -f "${profileFilePath}" ]]
            then
                touch "${profileFilePath}"
                chown "${user}:${user}" "${profileFilePath}"
            fi

            appendToFileIfNotFound "${profileFilePath}" "${prompt}" "${prompt}" 'false' 'false' 'true'
        else
            warn "WARN : profile '${user}' not found"
        fi
    done
}

function main()
{
    local -r appPath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

    source "${appPath}/../../../libraries/util.bash"
    source "${appPath}/../attributes/default.bash"

    while [[ "${#}" -gt '0' ]]
    do
        case "${1}" in
            --help)
                displayUsage 0
                ;;

            --profile-file-name)
                shift

                if [[ "${#}" -gt '0' ]]
                then
                    local -r profileFileName="$(trimString "${1}")"
                fi

                ;;

            --host-name)
                shift

                if [[ "${#}" -gt '0' ]]
                then
                    local -r hostName="$(trimString "${1}")"
                fi

                ;;

            --users)
                shift

                if [[ "${#}" -gt '0' ]]
                then
                    local -r users="$(trimString "${1}")"
                fi

                ;;

            *)
                shift
                ;;
        esac
    done

    checkRequireSystem
    checkRequireRootUser

    header 'INSTALLING PS1'

    install "${profileFileName}" "${hostName}" "${users}"
    installCleanUp
}

main "${@}"


selinux commands so we do not have to run selinux in permissive

# selinux ... allow the web server to serve comanage-registry..

# for comanage registry
semanage fcontext -a -t httpd_sys_content_t "/srv/comanage/.*"
restorecon -Rv /srv/comanage

# you will have to run this every time you upgrade.
semanage fcontext -a -t httpd_sys_rw_content_t "/srv/comanage/comanage-registry-1.0.5/local/tmp(/.*)?"
restorecon -Rv /srv/comanage/comanage-registry-1.0.5/local/tmp

# for shibboleth
semanage fcontext -a -t httpd_sys_rw_content_t "/var/cache/shibboleth(/.*)?"
restorecon -Rv /var/cache/shibboleth

semanage fcontext -a -f s -t httpd_var_run_t /var/run/shibboleth/shibd.sock
restorecon -Rv /var/run/shibboleth/shibd.sock

error: pathspec 'RHEL7/comanage/comanage_shib_selinux_commands.sh' did not match any file(s) known to git


add: build script

add: build script

cd /var/www/html/
rm -r js/ css/
cd /var/www/html/client/src
vue build
cd ../../
cp -rf dist/* .
rm -r dist

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


Added 'CONFIGURATION' flag to jenkins_build script.

Also added libevent dependency to jenkins build.

In jenkins we can now provide 3 options for the `CONFIGURATION`
environment variable that are: ` ` for the default build,
`--enable-libevent` for libevent, and `--enable-libevent --enable-ssl`
for SSL.

Review: https://reviews.apache.org/r/36646

#!/bin/bash

set -xe

# This is the script used by ASF Jenkins to build and check Mesos for
# a given OS and compiler combination.

# Require the following environment variables to be set.
: ${OS:?"Environment variable 'OS' must be set"}
: ${COMPILER:?"Environment variable 'COMPILER' must be set"}
: ${CONFIGURATION:?"Environment variable 'CONFIGURATION' must be set"}

# Change to the root of Mesos repo for docker build context.
MESOS_DIRECTORY=$( cd "$( dirname "$0" )/.." && pwd )
cd $MESOS_DIRECTORY

# TODO(vinod): Once ASF CI supports Docker 1.5 use a custom name for
# Dockerfile to avoid overwriting Dockerfile (if it exists) at the root
# of the repo.
DOCKERFILE="Dockerfile"

rm -f $DOCKERFILE # Just in case a stale one exists.

# Helper function that appends instructions to docker file.
function append_dockerfile {
   echo $1 >> $DOCKERFILE
}

# TODO(vinod): Add support for Fedora and Debian.
case $OS in
  centos*)
    # NOTE: Currently we only support CentOS7+ due to the
    # compiler versions needed to compile Mesos.

    append_dockerfile "FROM $OS"

    # Install dependencies.

    append_dockerfile "RUN yum groupinstall -y 'Development Tools'"
    append_dockerfile "RUN yum install -y epel-release" # Needed for clang.
    append_dockerfile "RUN yum install -y clang git maven"
    append_dockerfile "RUN yum install -y java-1.7.0-openjdk-devel python-devel zlib-devel libcurl-devel openssl-devel cyrus-sasl-devel cyrus-sasl-md5 apr-devel subversion-devel apr-utils-devel libevent-devel"

    # Add an unprivileged user.
    append_dockerfile "RUN adduser mesos"
   ;;
  ubuntu*)
    # NOTE: Currently we only support Ubuntu13.10+ due to the
    # compiler versions needed to compile Mesos.

    append_dockerfile "FROM $OS"

    # Install dependencies.
    append_dockerfile "RUN apt-get update"
    append_dockerfile "RUN apt-get -y install build-essential clang git maven autoconf libtool"
    append_dockerfile "RUN apt-get -y install openjdk-7-jdk python-dev python-boto libcurl4-nss-dev libsasl2-dev libapr1-dev libsvn-dev libevent-dev"

    # Add an unpriviliged user.
    append_dockerfile "RUN adduser --disabled-password --gecos '' mesos"

    # Disable any tests failing on Ubuntu.
    append_dockerfile "ENV GTEST_FILTER -FsTest.FileSystemTableRead"
    ;;
  *)
    echo "Unknown OS $OS"
    exit 1
    ;;
esac

case $COMPILER in
  gcc)
    append_dockerfile "ENV CC gcc"
    append_dockerfile "ENV CXX g++"
    ;;
  clang)
    append_dockerfile "ENV CC clang"
    append_dockerfile "ENV CXX clang++"
    ;;
  *)
    echo "Unknown Compiler $COMPILER"
    exit 1
    ;;
esac

# Set working directory.
append_dockerfile "WORKDIR mesos"

# Copy Mesos source tree into the image.
append_dockerfile "COPY . /mesos/"

# NOTE: We run all the tests as unprivileged 'mesos' user because
# we need to fix cgroups related tests to work inside Docker; certain
# tests (e.g., ContainerizerTest) enable cgroups isolation if the user
# is 'root'.
# TODO(vinod): Fix cgroups tests to work inside Docker.
append_dockerfile "RUN chown -R mesos /mesos"
append_dockerfile "USER mesos"

# Build and check Mesos.
append_dockerfile "CMD ./bootstrap && ./configure $CONFIGURATION && DISTCHECK_CONFIGURE_FLAGS=\"$CONFIGURATION\" GLOG_v=1 MESOS_VERBOSE=1 make -j8 distcheck"

# Generate a random image tag.
TAG=mesos-`date +%s`-$RANDOM

# Build the Docker imeage.
# TODO(vinod): Instead of building Docker images on the fly host the
# images on DockerHub and use them.
docker build -t $TAG .

# Set a trap to delete the image on exit.
trap "docker rmi $TAG" EXIT

# Uncomment below to print kernel log incase of failures.
# trap "dmesg" ERR

# Now run the image.
# NOTE: We run in 'privileged' mode to circumvent permission issues
# with AppArmor. See https://github.com/docker/docker/issues/7276.
docker run --privileged --rm $TAG

#!/bin/bash

set -xe

# This is the script used by ASF Jenkins to build and check Mesos for
# a given OS and compiler combination.

# Require the following environment variables to be set.
: ${OS:?"Environment variable 'OS' must be set"}
: ${COMPILER:?"Environment variable 'COMPILER' must be set"}

# Change to the root of Mesos repo for docker build context.
MESOS_DIRECTORY=$( cd "$( dirname "$0" )/.." && pwd )
cd $MESOS_DIRECTORY

# TODO(vinod): Once ASF CI supports Docker 1.5 use a custom name for
# Dockerfile to avoid overwriting Dockerfile (if it exists) at the root
# of the repo.
DOCKERFILE="Dockerfile"

rm -f $DOCKERFILE # Just in case a stale one exists.

# Helper function that appends instructions to docker file.
function append_dockerfile {
   echo $1 >> $DOCKERFILE
}

# TODO(vinod): Add support for Fedora and Debian.
case $OS in
  centos*)
    # NOTE: Currently we only support CentOS7+ due to the
    # compiler versions needed to compile Mesos.

    append_dockerfile "FROM $OS"

    # Install dependencies.

    append_dockerfile "RUN yum groupinstall -y 'Development Tools'"
    append_dockerfile "RUN yum install -y epel-release" # Needed for clang.
    append_dockerfile "RUN yum install -y clang git maven"
    append_dockerfile "RUN yum install -y java-1.7.0-openjdk-devel python-devel zlib-devel libcurl-devel openssl-devel cyrus-sasl-devel cyrus-sasl-md5 apr-devel subversion-devel apr-utils-devel"

    # Add an unprivileged user.
    append_dockerfile "RUN adduser mesos"
   ;;
  ubuntu*)
    # NOTE: Currently we only support Ubuntu13.10+ due to the
    # compiler versions needed to compile Mesos.

    append_dockerfile "FROM $OS"

    # Install dependencies.
    append_dockerfile "RUN apt-get update"
    append_dockerfile "RUN apt-get -y install build-essential clang git maven autoconf libtool"
    append_dockerfile "RUN apt-get -y install openjdk-7-jdk python-dev python-boto libcurl4-nss-dev libsasl2-dev libapr1-dev libsvn-dev"

    # Add an unpriviliged user.
    append_dockerfile "RUN adduser --disabled-password --gecos '' mesos"

    # Disable any tests failing on Ubuntu.
    append_dockerfile "ENV GTEST_FILTER -FsTest.FileSystemTableRead"
    ;;
  *)
    echo "Unknown OS $OS"
    exit 1
    ;;
esac

case $COMPILER in
  gcc)
    append_dockerfile "ENV CC gcc"
    append_dockerfile "ENV CXX g++"
    ;;
  clang)
    append_dockerfile "ENV CC clang"
    append_dockerfile "ENV CXX clang++"
    ;;
  *)
    echo "Unknown Compiler $COMPILER"
    exit 1
    ;;
esac

# Set working directory.
append_dockerfile "WORKDIR mesos"

# Copy Mesos source tree into the image.
append_dockerfile "COPY . /mesos/"

# NOTE: We run all the tests as unprivileged 'mesos' user because
# we need to fix cgroups related tests to work inside Docker; certain
# tests (e.g., ContainerizerTest) enable cgroups isolation if the user
# is 'root'.
# TODO(vinod): Fix cgroups tests to work inside Docker.
append_dockerfile "RUN chown -R mesos /mesos"
append_dockerfile "USER mesos"

# Build and check Mesos.
# TODO(vinod): Add support for non-default configuration options.
append_dockerfile "CMD ./bootstrap && ./configure && GLOG_v=1 MESOS_VERBOSE=1 make -j8 distcheck"

# Generate a random image tag.
TAG=mesos-`date +%s`-$RANDOM

# Build the Docker imeage.
# TODO(vinod): Instead of building Docker images on the fly host the
# images on DockerHub and use them.
docker build -t $TAG .

# Set a trap to delete the image on exit.
trap "docker rmi $TAG" EXIT

# Uncomment below to print kernel log incase of failures.
# trap "dmesg" ERR

# Now run the image.
# NOTE: We run in 'privileged' mode to circumvent permission issues
# with AppArmor. See https://github.com/docker/docker/issues/7276.
docker run --privileged --rm $TAG


A minor update

A minor update

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/bus710/scripts.git/'


A minor update

A minor update


Create ubuntu_bashrc.sh

Create ubuntu_bashrc.sh

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/qper/SmAl-Env.git/'


Revert "install-qibuild.sh: prefix version with 3"

No longer necessary
This reverts commit 48285f1ba2b53ca16b287ac014987515851e4b8c.

Change-Id: Ie87e83a44a394d0b73b56c0cc751ecd61e5696bb

#!/bin/sh
## Copyright (c) 2012, 2013 Aldebaran Robotics. All rights reserved.
## Use of this source code is governed by a BSD-style license that can be
## found in the COPYING file.
##

# Create a simple launcher for QiBuild scipts.
# They will install in /usr/local/bin, but
# sources will stay where they are.
# Note: on distros where /usr/bin/python is Python 3, you should
# set PYTHON env var to python2

DESTDIR="/usr/local/bin"

create_launcher() {
  full_path="$1"
  name="$2"
  shift
  shift
  args="$@"

  if [ -z $PYTHON ]; then
    PYTHON=python
  fi

  if readlink -f . >/dev/null 2>/dev/null ; then
      p=$(dirname "$(readlink -f ${0} 2>/dev/null)")
  else
      p=$(dirname "${0}")
      p=$PWD/$p
  fi
  #echo "QiBuild directory: $p"

  cat <<EOF >"${DESTDIR}/${name}"
#!/bin/sh

python "${p}/${full_path}" ${args} "\$@"
EOF
  chmod 755 "${DESTDIR}/${name}"
  echo "Installed: ${DESTDIR}/${name}"
}

localinst=no
if ! mkdir -p "${DESTDIR}" 2>/dev/null ; then
  localinst=yes
fi

if ! touch "${DESTDIR}"/.tmp_test 2>/dev/null ; then
  localinst=yes
else
  rm -f "${DESTDIR}/.tmp_test"
fi

if [ "$localinst" = "yes" ] ; then
  echo WARNING: ${DESTDIR} is not writable
  echo =====================
  echo installing into ~/.local/bin
  echo You should add ~/.local/bin to your PATH
  echo =====================
  echo
  DESTDIR=~/.local/bin
  mkdir -p "${DESTDIR}"
fi

create_launcher python/bin/qibuild      qibuild
create_launcher python/bin/qitoolchain  qitoolchain
create_launcher python/bin/qisrc        qisrc
create_launcher python/bin/qidoc        qidoc
create_launcher python/bin/qilinguist   qilinguist
create_launcher python/bin/qicd.py      qicd.py

#aliases
create_launcher python/bin/qibuild      qc           configure
create_launcher python/bin/qibuild      qd           deploy
create_launcher python/bin/qibuild      qm           make
create_launcher python/bin/qibuild      qo           open
echo "Make sure ${DESTDIR} is in your PATH."

#!/bin/sh
## Copyright (c) 2012, 2013 Aldebaran Robotics. All rights reserved.
## Use of this source code is governed by a BSD-style license that can be
## found in the COPYING file.
##

# Create a simple launcher for QiBuild scipts.
# They will install in /usr/local/bin, but
# sources will stay where they are.
# Note: on distros where /usr/bin/python is Python 3, you should
# set PYTHON env var to python2

DESTDIR="/usr/local/bin"

create_launcher() {
  full_path="$1"
  name="$2"
  shift
  shift
  args="$@"

  if [ -z $PYTHON ]; then
    PYTHON=python
  fi

  if readlink -f . >/dev/null 2>/dev/null ; then
      p=$(dirname "$(readlink -f ${0} 2>/dev/null)")
  else
      p=$(dirname "${0}")
      p=$PWD/$p
  fi
  #echo "QiBuild directory: $p"

  cat <<EOF >"${DESTDIR}/${name}"
#!/bin/sh

python "${p}/${full_path}" ${args} "\$@"
EOF
  chmod 755 "${DESTDIR}/${name}"
  echo "Installed: ${DESTDIR}/${name}"
}

localinst=no
if ! mkdir -p "${DESTDIR}" 2>/dev/null ; then
  localinst=yes
fi

if ! touch "${DESTDIR}"/.tmp_test 2>/dev/null ; then
  localinst=yes
else
  rm -f "${DESTDIR}/.tmp_test"
fi

if [ "$localinst" = "yes" ] ; then
  echo WARNING: ${DESTDIR} is not writable
  echo =====================
  echo installing into ~/.local/bin
  echo You should add ~/.local/bin to your PATH
  echo =====================
  echo
  DESTDIR=~/.local/bin
  mkdir -p "${DESTDIR}"
fi

create_launcher python/bin/qibuild      qibuild3
create_launcher python/bin/qitoolchain  qitoolchain3
create_launcher python/bin/qisrc        qisrc3
create_launcher python/bin/qidoc        qidoc3
create_launcher python/bin/qilinguist   qilinguist3
create_launcher python/bin/qicd.py      qicd.py3

#aliases
create_launcher python/bin/qibuild      qc3           configure
create_launcher python/bin/qibuild      qd3           deploy
create_launcher python/bin/qibuild      qm3           make
create_launcher python/bin/qibuild      qo3           open
echo "Make sure ${DESTDIR} is in your PATH."


Solved go-swagger not installing

Solved go-swagger not installing

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/jig/myubuntu.git/'


Corrected go-swagger not installing

Corrected go-swagger not installing


Added youtube-dl to brew packages

Added youtube-dl to brew packages

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/ryanmeasel/dotfiles.git/'


修改队列控制器

修改队列控制器

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/lzhui/hui.git/'


command-not-found package in ubuntu

command-not-found package in ubuntu

# Uses the command-not-found package zsh support
# as seen in http://www.porcheron.info/command-not-found-for-zsh/
# this is installed in Ubuntu

source /etc/zsh_command_not_found


Andy's new easypack

Andy's new easypack

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/veritas-shine/minix3-rpi.git/'


gh-230 EMR step script to upgrade the version of a running Gaffer instance

#!/bin/bash -xe

SLIDER_VERSION=0.92.0-incubating
SLIDER_ACCUMULO_BRANCH=branches/branch-0.92
ACCUMULO_VERSION=1.7.2
GAFFER_VERSION=0.7.8
GAFFER_TOOLS_VERSION=0.7.8
MAVEN_VERSION=3.5.0

CLUSTER_NAME=""
WAIT_HANDLE_URL=""

while [[ $# -gt 0 ]]; do
	key="$1"

	case $key in
		-a|--accumulo)
			ACCUMULO_VERSION=$2
			shift
			;;
		-g|--gaffer)
			GAFFER_VERSION=$2
			shift
			;;
		-s|--slider)
			SLIDER_VERSION=$2
			shift
			;;
		-t|--gaffer-tools)
			GAFFER_TOOLS_VERSION=$2
			shift
			;;
		-w|--wait-handle-url)
			WAIT_HANDLE_URL=$2
			shift
			;;
		*)
			CLUSTER_NAME=$1
			;;
	esac
	shift
done

if [[ "$WAIT_HANDLE_URL" ]]; then
	function awsSignal {
		/opt/aws/bin/cfn-signal -e $? "$WAIT_HANDLE_URL"
	}
	trap awsSignal EXIT
fi

if [ "$CLUSTER_NAME" == "" ]; then
	echo "Usage: $0 <clusterName> [-a <accumuloVersion>] [-g <gafferVersion>] [-t <gafferToolsVersion>] [-s <sliderVersion>] [-w <awsWaitHandleUrl>]"
	exit 1
fi

DST=~/slider-$CLUSTER_NAME
if [ ! -d $DST ]; then
	echo "Unable to find an existing Gaffer instance in: $DST"
	exit 1
fi

# Double check a Slider app with the requested name does already exist
cd $DST
if ! ./slider exists $CLUSTER_NAME; then
	echo "A slider app called $CLUSTER_NAME does not exist!"
	exit 1
fi

# Stop the Gaffer instance
./slider stop $CLUSTER_NAME

# Ensure some dependencies are installed
PKGS_TO_INSTALL=()

if ! which xmlstarlet >/dev/null 2>&1; then
	PKGS_TO_INSTALL+=(xmlstarlet)
fi

if ! which git >/dev/null 2>&1; then
	PKGS_TO_INSTALL+=(git)
fi

if [ ${#PKGS_TO_INSTALL[@]} -gt 0 ]; then
	echo "Installing ${PKGS_TO_INSTALL[@]} ..."
	sudo yum install -y ${PKGS_TO_INSTALL[@]}
fi

# Install Apache Maven
export PATH=$DST/apache-maven-$MAVEN_VERSION/bin:$PATH
MAVEN_DOWNLOAD_URL=http://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz
if [ ! -d "apache-maven-$MAVEN_VERSION" ]; then
	echo "Downloading Apache Maven $MAVEN_VERSION from $MAVEN_DOWNLOAD_URL"
	curl -fLO $MAVEN_DOWNLOAD_URL
	tar -xf apache-maven-$MAVEN_VERSION-bin.tar.gz
	rm -f apache-maven-$MAVEN_VERSION-bin.tar.gz
fi

# Install Apache Slider
SLIDER_DOWNLOAD_URL=https://repo1.maven.org/maven2/org/apache/slider/slider-assembly/$SLIDER_VERSION/slider-assembly-$SLIDER_VERSION-all.tar.gz
if [ ! -d "slider-$SLIDER_VERSION" ]; then
	echo "Downloading Apache Slider $SLIDER_VERSION from $SLIDER_DOWNLOAD_URL"
	curl -fLO $SLIDER_DOWNLOAD_URL
	tar -xf slider-assembly-$SLIDER_VERSION-all.tar.gz
	ln -s slider-$SLIDER_VERSION/bin/slider slider

	# Configure Slider with location of ZooKeeper
	echo "Configuring Slider with location of ZooKeeper ($HOSTNAME)..."
	xmlstarlet ed --inplace \
		-s "/configuration" -t elem -n zkProperty -v "" \
		-s "/configuration/zkProperty" -t elem -n name -v "hadoop.registry.zk.quorum" \
		-s "/configuration/zkProperty" -t elem -n value -v "$HOSTNAME" \
		-r "/configuration/zkProperty" -v property \
		./slider-$SLIDER_VERSION/conf/slider-client.xml
fi

# Set location of Hadoop config
export HADOOP_CONF_DIR=/etc/hadoop/conf

# Set location of JDK
export JAVA_HOME=/etc/alternatives/java_sdk

# Install Accumulo application package
mkdir -p accumulo-pkg
cd accumulo-pkg

ACCUMULO_PKG_BUILD_URL1=https://raw.githubusercontent.com/gchq/gaffer-tools/gaffer-tools-$GAFFER_TOOLS_VERSION/slider/scripts/build_accumulo_package.sh
ACCUMULO_PKG_BUILD_URL2=https://raw.githubusercontent.com/gchq/gaffer-tools/$GAFFER_TOOLS_VERSION/slider/scripts/build_accumulo_package.sh

if [ ! -f "slider-accumulo-app-package-$ACCUMULO_VERSION.zip" ]; then
	echo "Building Accumulo Slider Application Package..."
	echo "Trying to download Accumulo build script from $ACCUMULO_PKG_BUILD_URL1"
	if ! curl -fLO $ACCUMULO_PKG_BUILD_URL1; then
		echo "Trying to download Accumulo build script from $ACCUMULO_PKG_BUILD_URL2"
		curl -fLO $ACCUMULO_PKG_BUILD_URL2
	fi

	if [ ! -f ./build_accumulo_package.sh ]; then
		echo "Failed to download the build_accumulo_package.sh script from the gaffer-tools github repo!"
		exit 1
	fi

	echo "Running Accumulo build script..."
	chmod +x ./build_accumulo_package.sh
	./build_accumulo_package.sh $SLIDER_ACCUMULO_BRANCH $ACCUMULO_VERSION . --build-native
fi

# Build and install Gaffer
cd $DST

if ! curl -fL -o /dev/null https://repo1.maven.org/maven2/uk/gov/gchq/gaffer/gaffer2/$GAFFER_VERSION/gaffer2-$GAFFER_VERSION.pom; then
	echo "Building Gaffer from branch $GAFFER_VERSION..."
	git clone -b $GAFFER_VERSION --depth 1 https://github.com/gchq/Gaffer.git
	cd Gaffer
	mvn clean install -Pquick -pl store-implementation/accumulo-store/ --also-make

	GAFFER_POM_VERSION=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)
	echo "Detected Gaffer version as $GAFFER_POM_VERSION"

	# Tidy up
	cd ..
	rm -rf Gaffer
else
	echo "Will use Gaffer $GAFFER_VERSION from Maven Central..."
	GAFFER_POM_VERSION=$GAFFER_VERSION
fi

# Install gaffer-slider
mkdir -p $DST/gaffer-slider
cd $DST/gaffer-slider

# Make sure we only use a pre-built version of gaffer-slider if it has been built for the requested version of Gaffer
if [[ "$GAFFER_VERSION" == "$GAFFER_POM_VERSION" && "$GAFFER_VERSION" == "$GAFFER_TOOLS_VERSION" ]]; then
	curl -fL -o gaffer-slider-$GAFFER_TOOLS_VERSION.zip https://repo1.maven.org/maven2/uk/gov/gchq/gaffer/slider/$GAFFER_TOOLS_VERSION/slider-$GAFFER_TOOLS_VERSION.zip
	curl -fL -o gaffer-slider-$GAFFER_TOOLS_VERSION.jar https://repo1.maven.org/maven2/uk/gov/gchq/gaffer/slider/$GAFFER_TOOLS_VERSION/slider-$GAFFER_TOOLS_VERSION.jar
fi

if [[ ! -f gaffer-slider-$GAFFER_TOOLS_VERSION.zip || ! -f gaffer-slider-$GAFFER_TOOLS_VERSION.jar ]]; then
	echo "Building gaffer-slider from gaffer-tools branch $GAFFER_TOOLS_VERSION..."
	cd $DST
	git clone -b $GAFFER_TOOLS_VERSION --depth 1 https://github.com/gchq/gaffer-tools.git
	cd gaffer-tools/slider
	mvn clean package -Pquick -Dgaffer.version=$GAFFER_POM_VERSION

	GAFFER_SLIDER_POM_VERSION=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' ../pom.xml)
	echo "Detected gaffer-slider version as $GAFFER_SLIDER_POM_VERSION"

	cp target/slider-$GAFFER_SLIDER_POM_VERSION.jar $DST/gaffer-slider/gaffer-slider-$GAFFER_SLIDER_POM_VERSION.jar
	cp target/gaffer-slider-$GAFFER_SLIDER_POM_VERSION.zip $DST/gaffer-slider/

	# Tidy up
	cd ../../
	rm -rf gaffer-tools
else
	echo "Will use gaffer-slider $GAFFER_TOOLS_VERSION from Maven Central..."
	GAFFER_SLIDER_POM_VERSION=$GAFFER_TOOLS_VERSION
fi

echo "Upgrading Gaffer instance..."
hadoop fs -rm .slider/cluster/$CLUSTER_NAME/appdef/appPkg.zip
hadoop fs -rm .slider/cluster/$CLUSTER_NAME/addons/Gaffer/addon_Gaffer.zip
./slider update $CLUSTER_NAME \
	--appdef ./accumulo-pkg/slider-accumulo-app-package-$ACCUMULO_VERSION.zip \
	--addon Gaffer ./gaffer-slider/gaffer-slider-$GAFFER_SLIDER_POM_VERSION.zip \
	--template ./gaffer-slider/appConfig.json \
	--resources ./gaffer-slider/resources.json \
	--debug

echo "Starting Gaffer instance..."
./slider start $CLUSTER_NAME

CONFIG_DIR=$DST/etc
echo "Updating configuration in $CONFIG_DIR..."
cd $CONFIG_DIR
echo "$SLIDER_VERSION" >slider.version
echo "$ACCUMULO_VERSION" >accumulo.version
echo "$GAFFER_POM_VERSION" >gaffer.version
echo "$GAFFER_VERSION" >gaffer.branch
echo "$GAFFER_TOOLS_VERSION" >gaffer-tools.branch
echo "$GAFFER_SLIDER_POM_VERSION" >gaffer-slider.version

cd $DST
rm -rf accumulo
echo "Waiting for deployed Gaffer instance to be ready..."
MAX_ATTEMPTS=30
INTERVAL=10

for (( i=0; i<=$MAX_ATTEMPTS; i++ )); do
	if ./install-accumulo-client.sh; then
		echo "Gaffer instance is ready :D"
		exit 0
	else
		echo "Gaffer instance is not ready yet, sleeping for $INTERVAL secs..."
		sleep $INTERVAL
	fi
done

echo "Gaffer instance is still not ready, deployment must have failed..."
exit 1

error: pathspec 'deployment/aws/tests/migration-tests/emr-step-scripts/upgrade-gaffer-instance.sh' did not match any file(s) known to git


Add: Task to make sure docker-gen keeps running

#!/bin/bash

DOCKER_GEN_CONTAINER=app-pixelcloud-nginx_proxy-nginx_gen
DOCKER_GEN_RUNNING="$($(which docker) inspect -f '{{.State.Running}}' $DOCKER_GEN_CONTAINER)"

if [ "$DOCKER_GEN_RUNNING" != "true" ]; then
    $(which docker) restart "$DOCKER_GEN_CONTAINER"
    echo "$DOCKER_GEN_CONTAINER" restarted
    echo
fi

error: pathspec 'nginx-proxy/tasks/docker-gen-watch.sh' did not match any file(s) known to git


an ugly hack until we're 100% stable

an ugly hack until we're 100% stable

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/gsora/polo-lendbot.git/'


add dump db script

add dump db script

#!/bin/sh

DB="shici"
cd ..
mkdir -p backup
cd backup
OUTPUT="dump-shici-$(date +"%Y-%m-%d_%H_%M_%S").sql"

echo "db dump require MySQL root password."
mysqldump --user=root -p --skip-opt --add-drop-table --default-character-set=utf8 --quick $DB > $OUTPUT

tar czvf $OUTPUT.tar.gz $OUTPUT

rm -f $OUTPUT

echo "db dumped in ../backup"

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


More Travis testing

More Travis testing

sed -i 's|\[mysqld\]|\[mysqld\]\
lower_case_table_names = 1\
character-set-server=utf8\
collation-server=utf8_general_ci|g' /etc/mysql/my.cnf


Smaller binaries * Disables CGO and some other things

#!/bin/bash

GITVERSION=`git describe --always`
SOURCEDIR=$1
SPLUGINFOLDER=$2
SPLUGIN=$3
BUILDDIR=$SOURCEDIR/build
PLUGINDIR=plugin
BINDIR=$BUILDDIR/bin
COLLECTORDIR=$BUILDDIR/$PLUGINDIR/collector
PUBLISHERDIR=$BUILDDIR/$PLUGINDIR/publisher
PROCESSORDIR=$BUILDDIR/$PLUGINDIR/processor
BUILDCMD='go build -a -ldflags "-w"'

echo
echo "****  Pulse Build ($GITVERSION)  ****"
echo

# Disable CGO for builds
export CGO_ENABLED=0

# Clean build bin dir
rm -rf $BINDIR/*

# Make dir
mkdir -p $BINDIR
mkdir -p $COLLECTORDIR
mkdir -p $PUBLISHERDIR
mkdir -p $PROCESSORDIR

# Binaries
#
echo "Source Dir = $SOURCEDIR"
echo " Building Pulse Agent"
go build -ldflags "-w -X main.gitversion $GITVERSION" -o $BINDIR/pulse-agent . || exit 1

if [ "$SPLUGIN" ] && [ -n "$SPLUGINFOLDER" ]
then
	echo " Building Plugin: $SPLUGIN"
	# Built-in single plugin building
	cd $SOURCEDIR/plugin/$SPLUGINFOLDER/
	target=./$SPLUGIN/
	destination=$BUILDDIR/$PLUGINDIR/$SPLUGINFOLDER/$SPLUGIN
	echo "    $SPLUGIN => $destination"
	$BUILDCMD -o $destination $target || exit 2
	cd $SOURCEDIR
else
	# Clean build
	rm -rf $COLLECTORDIR/*
	echo " Building Collector Plugin(s)"
	# Built-in Collector Plugin building
	cd $SOURCEDIR/$PLUGINDIR/collector
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $COLLECTORDIR/$d"
			$BUILDCMD -o $COLLECTORDIR/$d ./$d/ || exit 2
		fi
	done

	# Publisher build
	rm -rf $PUBLISHERDIR/*
	echo " Building Publisher Plugin(s)"
	cd $SOURCEDIR/$PLUGINDIR/publisher
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $PUBLISHERDIR/$d"
			$BUILDCMD -o $PUBLISHERDIR/$d ./$d/ || exit 2
		fi
	done

	# Processor build
	rm -rf $PROCESSORDIR/*
	echo " Building Processor Plugin(s)"
	cd $SOURCEDIR/$PLUGINDIR/processor
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $PROCESSORDIR/$d"
			$BUILDCMD -o $PROCESSORDIR/$d ./$d/ || exit 2
		fi
	done

	# pulse-ctl
	echo " Building cmd(s)"
	cd $SOURCEDIR/cmd
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $BINDIR/$d"
			$BUILDCMD -o $BINDIR/$d ./$d/ || exit 3
		fi
	done

	cd $SOURCEDIR
fi

echo
echo "*******************"

#!/bin/bash

echo "****  Pulse Build  ****"
echo

SOURCEDIR=$1
SPLUGINFOLDER=$2
SPLUGIN=$3
BUILDDIR=$SOURCEDIR/build
PLUGINDIR=plugin
BINDIR=$BUILDDIR/bin
COLLECTORDIR=$BUILDDIR/$PLUGINDIR/collector
PUBLISHERDIR=$BUILDDIR/$PLUGINDIR/publisher
PROCESSORDIR=$BUILDDIR/$PLUGINDIR/processor

# Clean build bin dir
rm -rf $BINDIR/*

# Make dir
mkdir -p $BINDIR
mkdir -p $COLLECTORDIR
mkdir -p $PUBLISHERDIR
mkdir -p $PROCESSORDIR

# Binaries
#
echo "Source Dir = $SOURCEDIR"
echo "$SPLUGIN"
echo "$SPLUGINFOLDER"
echo " Building Pulse Agent"
go build -ldflags "-X main.gitversion `git describe --always`" -o $BINDIR/pulse-agent . || exit 1

if [ "$SPLUGIN" ] && [ -n "$SPLUGINFOLDER" ]
then
	echo " Building Plugin: $SPLUGIN"
	# Built-in single plugin building
	cd $SOURCEDIR/plugin/$SPLUGINFOLDER/
	target=./$SPLUGIN/
	destination=$BUILDDIR/$PLUGINDIR/$SPLUGINFOLDER/$SPLUGIN
	echo "    $SPLUGIN => $destination"
	go build -o $destination $target || exit 2
	cd $SOURCEDIR
else
	# Clean build
	rm -rf $COLLECTORDIR/*
	echo " Building Collector Plugin(s)"
	# Built-in Collector Plugin building
	cd $SOURCEDIR/$PLUGINDIR/collector
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $COLLECTORDIR/$d"
			go build -o $COLLECTORDIR/$d ./$d/ || exit 2
			# chmod -x ../../$COLLECTORDIR/$d / for testing non-executable builds
		fi
	done

	# Publisher build
	rm -rf $PUBLISHERDIR/*
	echo " Building Publisher Plugin(s)"
	cd $SOURCEDIR/$PLUGINDIR/publisher
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $PUBLISHERDIR/$d"
			go build -o $PUBLISHERDIR/$d ./$d/ || exit 2
			# chmod -x ../../$PUBLISHERDIR/$d / for testing non-executable builds
		fi
	done

	# Processor build
	rm -rf $PROCESSORDIR/*
	echo " Building Processor Plugin(s)"
	cd $SOURCEDIR/$PLUGINDIR/processor
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $PROCESSORDIR/$d"
			go build -o $PROCESSORDIR/$d ./$d/ || exit 2
			# chmod -x ../../$PROCESSORDIR/$d / for testing non-executable builds
		fi
	done

	# pulse-ctl
	echo " Building cmd(s)"
	cd $SOURCEDIR/cmd
	for d in *; do
		if [[ -d $d ]]; then
			echo "    $d => $BINDIR/$d"
			go build -ldflags "-X main.gitversion `git describe --always`" -o $BINDIR/$d ./$d/ || exit 3
		fi
	done

	cd $SOURCEDIR
fi

echo
echo "*******************"


Alias to use git up with ruby 2.2.0

Alias to use git up with ruby 2.2.0

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/davidmatas/dotfiles.git/'


Add support for installation on Kali Linux 2.0

Signed-off-by: Brian Torres-Gil <f381b8ab4c5dbdaf14689858a8463cfb6a41dfdb@paloaltonetworks.com>

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/cyli/docker.git/'


detached starting script added

detached starting script added

erl -pa deps/*/ebin apps/*/ebin -sasl errlog_type error -s vchat_app -config etc/app.config -detached -setcookie curlybob -sname webrtcexample

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


Add a publish.sh script.

Add a publish.sh script.

#!/usr/bin/env bash
# Publishes an irc.dart release
./tool/build.dart publish
VERSION=`cat pubspec.yaml | grep 'version:' | sed 's/version://'`
echo Releasing ${VERSION}
git add .
git tag v${VERSION}
git commit -m "v${VERSION}"
git push --tags origin master

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


more verbose travis test output

more verbose travis test output

#!/bin/bash
set -e

rm -rf audit-logging/build
rm -rf audit-test/build

echo "Testing $TRAVIS_BRANCH"
./gradlew clean check install --stacktrace

EXIT_STATUS=0
echo "Publishing archives for branch $TRAVIS_BRANCH"
if [[ -n $TRAVIS_TAG ]] || [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then

  echo "Publishing archives"

  if [[ -n $TRAVIS_TAG ]]; then
      echo "Publishing to Bintray.."
      ./gradlew audit-logging:bintrayUpload -S || EXIT_STATUS=$?
  else
      echo "Publishing to Grails Artifactory"
      ./gradlew audit-logging:publish -S || EXIT_STATUS=$?
  fi

  echo "Building docs and publish to gh-pages branch.."

  ./gradlew docs --stacktrace || EXIT_STATUS=$?

  git config --global user.name "$GIT_NAME"
  git config --global user.email "$GIT_EMAIL"
  git config --global credential.helper "store --file=~/.git-credentials"
  echo "https://$GH_TOKEN:@github.com" > ~/.git-credentials

  echo " "
  echo "** Updating gh-pages branch **"
  cd audit-logging/build
  git clone https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git -b gh-pages gh-pages --single-branch > /dev/null
  cd gh-pages

  # prepare index.html
  mv ../docs/index.html ../docs/plugin.html
  mv ../docs/ghpages.html ../docs/index.html

  # If this is the master branch then update the snapshot
  if [[ $TRAVIS_BRANCH == 'master' ]]; then
    mkdir -p snapshot
    cp -r ../docs/. ./snapshot/
    git add snapshot/*
  fi

    # If there is a tag present then this becomes the latest
    if [[ -n $TRAVIS_TAG ]]; then
        mkdir -p latest
        cp -r ../docs/. ./latest/
        git add latest/*

        version="$TRAVIS_TAG"
        version=${version:1}
        majorVersion=${version:0:4}
        majorVersion="${majorVersion}x"

        mkdir -p "$version"
        cp -r ../docs/. "./$version/"
        git add "$version/*"

        mkdir -p "$majorVersion"
        cp -r ../docs/. "./$majorVersion/"
        git add "$majorVersion/*"

    fi

    git commit -a -m "Updating docs for Travis build: https://travis-ci.org/$TRAVIS_REPO_SLUG/builds/$TRAVIS_BUILD_ID"
    git push origin HEAD
    cd ..
    rm -rf gh-pages
fi
exit $EXIT_STATUS

#!/bin/bash
set -e

rm -rf audit-logging/build
rm -rf audit-test/build

./gradlew -q clean check install --stacktrace

EXIT_STATUS=0
echo "Publishing archives for branch $TRAVIS_BRANCH"
if [[ -n $TRAVIS_TAG ]] || [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then

  echo "Publishing archives"

  if [[ -n $TRAVIS_TAG ]]; then
      echo "Publishing to Bintray.."
      ./gradlew audit-logging:bintrayUpload -S || EXIT_STATUS=$?
  else
      echo "Publishing to Grails Artifactory"
      ./gradlew audit-logging:publish -S || EXIT_STATUS=$?
  fi

  echo "Building docs and publish to gh-pages branch.."

  ./gradlew docs --stacktrace || EXIT_STATUS=$?

  git config --global user.name "$GIT_NAME"
  git config --global user.email "$GIT_EMAIL"
  git config --global credential.helper "store --file=~/.git-credentials"
  echo "https://$GH_TOKEN:@github.com" > ~/.git-credentials

  echo " "
  echo "** Updating gh-pages branch **"
  cd audit-logging/build
  git clone https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git -b gh-pages gh-pages --single-branch > /dev/null
  cd gh-pages

  # prepare index.html
  mv ../docs/index.html ../docs/plugin.html
  mv ../docs/ghpages.html ../docs/index.html

  # If this is the master branch then update the snapshot
  if [[ $TRAVIS_BRANCH == 'master' ]]; then
    mkdir -p snapshot
    cp -r ../docs/. ./snapshot/
    git add snapshot/*
  fi

    # If there is a tag present then this becomes the latest
    if [[ -n $TRAVIS_TAG ]]; then
        mkdir -p latest
        cp -r ../docs/. ./latest/
        git add latest/*

        version="$TRAVIS_TAG"
        version=${version:1}
        majorVersion=${version:0:4}
        majorVersion="${majorVersion}x"

        mkdir -p "$version"
        cp -r ../docs/. "./$version/"
        git add "$version/*"

        mkdir -p "$majorVersion"
        cp -r ../docs/. "./$majorVersion/"
        git add "$majorVersion/*"

    fi

    git commit -a -m "Updating docs for Travis build: https://travis-ci.org/$TRAVIS_REPO_SLUG/builds/$TRAVIS_BUILD_ID"
    git push origin HEAD
    cd ..
    rm -rf gh-pages
fi
exit $EXIT_STATUS


Added gitignore plugin ( for gitignore.io )

function gi() { curl http://gitignore.io/api/$@ ;}

_gitignireio_get_command_list() {
  curl -s http://gitignore.io/api/list | tr "," "\n"
}

_gitignireio () {
  compadd `_gitignireio_get_command_list`
}

compdef _gitignireio gi

error: pathspec 'custom/plugins/gitignore/gitignore.plugin.zsh' did not match any file(s) known to git


Also clean artifacts in new location.

Also clean artifacts in new location.

# Log files
export RESTYOUT=/tmp/resty.out
export RESTYERR=/tmp/resty.err

#   $1 = Test Description
start_xml_results() {
  # Set total number of tests
  export TOTALCOUNT="0"

  if [ -n "${1}" ] ; then
    tnick="${1}"
  else
    tnick="FreeNAS QA Tests"
  fi

  export XMLRESULTS="/tmp/.results.xml.$$"
  cat >${XMLRESULTS} << EOF
<?xml version="1.0" encoding="UTF-8"?>
  <testsuite tests="TOTALTESTS" name="${tnick}">
EOF
}

#          $1 = true/false
#          $2 = error message
#  $CLASSNAME = Sub class of test results
#   $TESTNAME = Specific test name
# $TESTSTDOUT = stdout file of test results
# $TESTSTDERR = stderr file of test results
add_xml_result() {

  # If called when no tests have been setup, we can safely return
  if [ -z "$TESTNAME" ] ; then return 0 ; fi

  if [ -n "$TIMESTART" -a "$TIMESTART" != "0" ] ; then
    TIMEEND=`date +%s`
    TIMEELAPSED=`expr $TIMEEND - $TIMESTART`
  fi

  if [ "$1" = "true" ] ; then
    cat >>${XMLRESULTS} << EOF
    <testcase classname="$CLASSNAME" name="$TESTNAME" time="$TIMEELAPSED">
EOF
  elif [ "$1" = "skipped" ] ; then
    cat >>${XMLRESULTS} << EOF
    <testcase classname="$CLASSNAME" name="$TESTNAME"><skipped/>
EOF
  else
    # Failed!
    cat >>${XMLRESULTS} << EOF
    <testcase classname="$CLASSNAME" name="$TESTNAME" time="$TIMEELAPSED">
        <failure type="failure">$2</failure>
EOF
  fi

# Optional stdout / stderr logs
  if [ -n "$TESTSTDOUT" -a -e "$TESTSTDOUT" ] ; then
    echo -e "         <system-out>Command Run:\n$TESTCMD\n\nResponse:\n" >> ${XMLRESULTS}
    echo "`cat $TESTSTDOUT | sed 's|<||g' | sed 's|>||g' | tr -d '\r'`</system-out>" >> ${XMLRESULTS}
  fi
  if [ -n "$TESTSTDERR" -a -e "$TESTSTDERR" ] ; then
    echo "         <system-err>`cat $TESTSTDERR | sed 's|<||g' | sed 's|>||g' | tr -d '\r'`</system-err>" >> ${XMLRESULTS}
  fi

  # Close the error tag
  cat >> ${XMLRESULTS} << EOF
    </testcase>
EOF

  unset TESTNAME TESTSTDOUT TESTSTDERR TESTCMD
}

# $1 = Optional tag for results file
finish_xml_results() {
  if [ -z "$1" ] ; then
    rTag="tests"
  else
    rTag="$1"
  fi

  cat >>${XMLRESULTS} << EOF
</testsuite>
EOF

  # Set the total number of tests run
  sed -i '' "s|TOTALTESTS|$1|g" ${XMLRESULTS}

  # Move results to pre-defined location
  if [ -n "$WORKSPACE" ] ; then
    if [ ! -d "${WORKSPACE}/results" ] ; then
      mkdir -p "${WORKSPACE}/results"
      chown jenkins:jenkins "${WORKSPACE}/results"
    fi
    tStamp=$(date +%s)
    echo "Saving jUnit results to: ${WORKSPACE}/results/freenas-results-${rTag}.xml"
    mv "${XMLRESULTS}" "${WORKSPACE}/results/freenas-results-${rTag}.xml"
    chown jenkins:jenkins "${WORKSPACE}/results/freenas-results-${rTag}.xml"
  else
    echo "Saving jUnit results to: /tmp/test-results.xml"
    mv ${XMLRESULTS} /tmp/test-results.xml
  fi
}

clean_artifacts()
{
  # Move artifacts to pre-defined location
    echo "Cleaning previous artifacts"
    rm -rf "${WORKSPACE}/artifacts/${FNASBDIR}"
}

save_artifacts_on_fail()
{
  # Move artifacts to pre-defined location
  if [ -n "$ARTIFACTONFAIL" ] ; then
      if [ -n "$WORKSPACE" ] ; then
        if [ ! -d "${WORKSPACE}/artifacts/${FNASBDIR}" ] ; then
          mkdir -p "${WORKSPACE}/artifacts/${FNASBDIR}"
          chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
      fi
    fi
    echo "Saving artifacts to: ${WORKSPACE}/artifacts${FNASBDIR}"
    cp -R "${ARTIFACTONFAIL}" "${WORKSPACE}/artifacts/${FNASBDIR}"
    chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
  else
    echo "Skip saving artificats on failure / ARTIFACTONFAIL not set"
  fi
}

save_artifacts_on_success()
{
  # Move artifacts to pre-defined location
  if [ -n "$ARTIFACTONSUCCESS" ] ; then
    if [ -n "$WORKSPACE" ] ; then
      if [ ! -d "${WORKSPACE}/artifacts/${FNASBDIR}" ] ; then
        mkdir -p "${WORKSPACE}/artifacts/${FNASBDIR}"
        chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
      fi
    fi
    echo "Saving artifacts to: ${WORKSPACE}/artifacts${FNASBDIR}"
    cp -R "${ARTIFACTONFAIL}" "${WORKSPACE}/artifacts/${FNASBDIR}"
    chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
  else
    echo "Skip saving artificats on success / ARTIFACTONSUCCESS not set"
  fi
}

# $1 = RESTY type to run
# $2 = RESTY URL
# $3 = JSON to pass to RESTY
rest_request()
{
  export TESTCMD="$2 $3"

  case $1 in
  DELETE) DELETE ${2} "${3}" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
     GET) GET ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
   PATCH) PATCH ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
     PUT) PUT ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
    POST) POST ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
   TRACE) POST ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
       *) echo "Unknown RESTY command: $1" ; return 1 ;;
  esac

  # Shouldn't get here
  return 1;
}

# $1 = Command to run
# $2 = Command to run if $1 fails
# $3 = Optional timeout
rc_test()
{
  export TESTCMD="$1"
  export TESTSTDOUT="/tmp/.cmdTestStdOut"
  export TESTSTDERR="/tmp/.cmdTestStdErr"
  touch $TESTSTDOUT
  touch $TESTSTDERR

  if [ -z "$3" ] ; then
    ${1} >${TESTSTDOUT} 2>${TESTSTDERR}
    if [ $? -ne 0 ] ; then
       echo_fail
       eval "${2}"
       echo "Failed running: $1"
       return 1
    fi
    echo_ok
    return 0
  fi

  # Running with timeout
  ( ${1} >${TESTSTDOUT} 2>${TESTSTDERR} ; echo $? > /tmp/.rc-result.$$ ) &
  echo "$!" > /tmp/.rc-pid.$$
  timeout=0
  while :
  do
    # See if the process stopped yet
    pgrep -F /tmp/.rc-pid.$$ >/dev/null 2>/dev/null
    if [ $? -ne 0 ] ; then
      # Check if it was 0
      if [ "$(cat /tmp/.rc-result.$$)" = "0" ] ; then
        echo_ok
        rm /tmp/.rc-result.$$
        return 0
      fi
      rm /tmp/.rc-result.$$
      break
    fi

    # Check the timeout
    sleep 1
    timeout=$(expr $timeout + 1)
    if [ $timeout -gt $3 ] ; then break; fi
  done

  kill -9 $(cat /tmp/.rc-pid.$$)
  rm /tmp/.rc-pid.$$
  rm /tmp/.rc-result.$$ 2>/dev/null
  echo_fail
  eval "${2}"
  echo "Timeout running: $1"
  return 1
}

echo_ok()
{
  echo -e " - OK"
  add_xml_result "true" "Valid test response"
}

echo_fail()
{
  if [ -z "$1" ] ; then
    errStr="Invalid test repsonse!"
  else
    errStr="$1"
  fi

  echo -e " - FAILED"
  add_xml_result "false" "$errStr"
}

echo_skipped()
{
  echo -e " - SKIPPED"
  add_xml_result "skipped" "Skipped test!"
}

# Check for $1 REST response, error out if not found
check_rest_response()
{
  export TESTSTDOUT="$RESTYOUT"
  export TESTSTDERR="$RESTYERR"

  grep -q "$1" ${RESTYERR}
  if [ $? -ne 0 ] ; then
    cat ${RESTYERR}
    cat ${RESTYOUT}
    echo_fail
    return 1
  fi

  echo_ok
  return 0
}

check_rest_response_continue()
{
  grep -q "$1" ${RESTYERR}
  return $?
}

set_test_group_text()
{
  GROUPTEXT="$1"
  CLASSNAME="$1"
  TOTALTESTS="$2"
  TCOUNT=0
}

echo_test_title()
{
  TESTNAME="$1"
  TCOUNT=`expr $TCOUNT + 1`
  TOTALCOUNT=`expr $TOTALCOUNT + 1`
  TIMESTART=`date +%s`
  sync
  echo -e "Running $GROUPTEXT ($TCOUNT/$TOTALTESTS) - $1\c"
}

# Set the IP address of REST
set_ip()
{
  set_test_group_text "Networking Configuration" "5"

  echo_test_title "Setting IP address: ${ip} on em0"
  rest_request "POST" "/network/interface/" '{ "int_ipv4address": "'"${ip}"'", "int_name": "internal", "int_v4netmaskbit": "24", "int_interface": "em0" }'
  check_rest_response "201 CREATED"

  # Wait 30 seconds before trying more REST queries again
  sleep 30

  if [ -n "$BRIDGEIP" ] ; then
    # Using the bridged adapter settings
    echo_test_title "Setting bridged IP on em1"
    rest_request "POST" "/network/interface/" '{ "int_ipv4address": "'"${BRIDGEIP}"'", "int_name": "ext", "int_v4netmaskbit": "'"${BRIDGENETMASK}"'", "int_interface": "em1" }'
    check_rest_response "201 CREATED"

    # Set the global config stuff
    echo_test_title "Setting default route and DNS"
    rest_request "PUT" "/network/globalconfiguration/" '{ "gc_domain": "'"${BRIDGEDOMAIN}"'", "gc_ipv4gateway": "'"${BRIDGEGW}"'", "gc_hostname": "'"${BRIDGEHOST}"'", "gc_nameserver1": "'"${BRIDGEDNS}"'" }'
    check_rest_response "200 OK"
  else
    # Using the NAT mode
    echo_test_title "Setting DHCP on em1"
    rest_request "POST" "/network/interface/" '{ "int_dhcp": true, "int_name": "ext", "int_interface": "em1" }'
    check_rest_response "201 CREATED"
  fi

  echo_test_title "Rebooting VM"
  rest_request "POST" "/system/reboot/" "''"
  # Disabled the response check, seems the reboot happens fast enough to
  # prevent a valid response sometimes
  #check_rest_response "202 ACCEPTED"
  echo_ok

  echo_test_title "Waiting for reboot"
  sleep 20
  wait_for_avail
  echo_ok
}

wait_for_avail()
{
  count=0
  while :
  do
    GET /storage/disk/ -v 2>${RESTYERR} >${RESTYOUT}
    check_rest_response_continue "200 OK"
    if [ $? -eq 0 ] ; then break; fi
    echo -e ".\c"
    sleep 60
    if [ $count -gt 12 ] ; then
       echo_fail
       exit 1
    fi
    count=`expr $count + 1`
  done
}

run_module() {
  unset REQUIRES

  # Source the module now
  cd ${TDIR}
  . ./${1}
  if [ $? -ne 0 ] ; then
    echo "Failed sourcing ${1}"
    FAILEDMODULES="${FAILEDMODULES}:::${1}:::"
    return 1
  fi

  # Make sure any required module have been run first
  local modreq="$REQUIRES"
  local nofails="true"
  if [ -n "$modreq" ] ; then
    for i in $modreq
    do
      # Check if this module has already been run
      echo $RUNMODULES | grep -q ":::${i}:::"
      if [ $? -eq 0 ] ; then continue; fi

      echo $FAILEDMODULES | grep -q ":::${i}:::"
      if [ $? -eq 0 ] ; then
	CLASSNAME="$1"
	TESTNAME="all"
	TIMESTART="0"
        TOTALCOUNT=`expr $TOTALCOUNT + 1`
        echo "***** Skipping test module: $1 ($i failed) *****"
        add_xml_result "skipped" "Skipped due to $i requirement failing"
        FAILEDMODULES="${FAILEDMODULES}:::${1}:::"
        return 1
      fi

      # Need to run another module first
      echo "***** Running module dependancy: $i *****"
      run_module "$i" "quiet"
      if [ $? -ne 0 ] ; then
        nofails="false"
      fi
    done
  fi

  if [ "$nofails" = "false" ] ; then
    CLASSNAME="$1"
    TESTNAME="all"
    TIMESTART="0"
    TOTALCOUNT=`expr $TOTALCOUNT + 1`
    echo "***** Skipping test module: $1 (Dep failed) *****"
    add_xml_result "skipped" "Skipped test module: $i requirement failing"
    return 1
  fi

  # Run the target module
  if [ -z "$2" ] ; then
    echo "***** Running module: $1 *****"
  fi
  eval "${1}_init"
  if [ $? -ne 0 ] ; then
    echo "Failed on test module: $1"
    FAILEDMODULES="${FAILEDMODULES}:::${1}:::"
    return 1
  fi

  # Save that this test was already run
  RUNMODULES="${RUNMODULES}:::${1}:::"
  return 0
}

# Read through the test modules and start running them
read_module_dir() {
  cd ${TDIR}
  if [ $? -ne 0 ] ; then
    echo "Missing test module dir"
    exit 1
  fi

  RUNMODULES=""
  ANYFAILS="false"

  for module in `ls`
  do
    # Skip the README, other files should be valid though
    if [ "$module" = "README" ] ; then continue ; fi
    if [ "$module" = "example" ] ; then continue ; fi

    # Check if this module has already been run
    echo $RUNMODULES | grep -q ":::${module}:::"
    if [ $? -eq 0 ] ; then continue ; fi

    # Check if this module has already been skipped
    echo $FAILEDMODULES | grep -q ":::${module}:::"
    if [ $? -eq 0 ] ; then continue ; fi

    run_module "$module"
    if [ $? -ne 0 ] ; then
      ANYFAILS="true"
    fi
  done

  if [ "$ANYFAILS" = "true" ] ; then return 1; fi
  return 0
}

# Do a TrueNAS HA failover
# $1 = reboot/panic
trigger_ha_failover() {
  case $1 in
    reboot) do_ha_reboot ;;
     panic) do_ha_panic ;;
         *) do_ha_reboot ;;
  esac
}

do_ha_panic() {
  export SSHPASS="$LIVEPASS"
  echo_test_title "Simulating kernel panic"
  sshpass -e ssh -o StrictHostKeyChecking=no ${LIVEUSER}@${LIVEHOST} sysctl debug.kdb.panic=1 >/dev/null 2>/dev/null
  echo_ok
  sleep 10

  echo_test_title "Waiting for active node response"
  sleep 20
  wait_for_avail
  echo_ok
}

do_ha_reboot() {
  echo_test_title "Rebooting to promote passive node to active"
  rest_request "POST" "/system/reboot/" "''"
  echo_ok

  echo_test_title "Waiting for active node response"
  sleep 20
  wait_for_avail
  echo_ok
}

do_ha_status() {
  # Verify each node is now in a normal state
  count=0
  while :
  do
    # Check the status of each node to make sure all nodes are online
    echo_test_title "Checking the alert level for each node"
    rest_request "GET" "/system/alert/" ""
    check_rest_response "200 OK"
    NODESTATUS=$(cat ${RESTYOUT} | ${JSAWK} 'return this.message')
    echo "NODESTATUS: $NODESTATUS"
    echo $NODESTATUS | grep -q 'Failed to check failover status with the other node: timed out'
    if [ $? -ne 0 ] ; then
      break
    else
      sleep 30
    fi
    count=$(expr $count + 1)
    if [ $count -gt 20 ] ;
    then
      echo_fail
      finish_xml_results
      exit 1
    fi
  done
}

# Log files
export RESTYOUT=/tmp/resty.out
export RESTYERR=/tmp/resty.err

#   $1 = Test Description
start_xml_results() {
  # Set total number of tests
  export TOTALCOUNT="0"

  if [ -n "${1}" ] ; then
    tnick="${1}"
  else
    tnick="FreeNAS QA Tests"
  fi

  export XMLRESULTS="/tmp/.results.xml.$$"
  cat >${XMLRESULTS} << EOF
<?xml version="1.0" encoding="UTF-8"?>
  <testsuite tests="TOTALTESTS" name="${tnick}">
EOF
}

#          $1 = true/false
#          $2 = error message
#  $CLASSNAME = Sub class of test results
#   $TESTNAME = Specific test name
# $TESTSTDOUT = stdout file of test results
# $TESTSTDERR = stderr file of test results
add_xml_result() {

  # If called when no tests have been setup, we can safely return
  if [ -z "$TESTNAME" ] ; then return 0 ; fi

  if [ -n "$TIMESTART" -a "$TIMESTART" != "0" ] ; then
    TIMEEND=`date +%s`
    TIMEELAPSED=`expr $TIMEEND - $TIMESTART`
  fi

  if [ "$1" = "true" ] ; then
    cat >>${XMLRESULTS} << EOF
    <testcase classname="$CLASSNAME" name="$TESTNAME" time="$TIMEELAPSED">
EOF
  elif [ "$1" = "skipped" ] ; then
    cat >>${XMLRESULTS} << EOF
    <testcase classname="$CLASSNAME" name="$TESTNAME"><skipped/>
EOF
  else
    # Failed!
    cat >>${XMLRESULTS} << EOF
    <testcase classname="$CLASSNAME" name="$TESTNAME" time="$TIMEELAPSED">
        <failure type="failure">$2</failure>
EOF
  fi

# Optional stdout / stderr logs
  if [ -n "$TESTSTDOUT" -a -e "$TESTSTDOUT" ] ; then
    echo -e "         <system-out>Command Run:\n$TESTCMD\n\nResponse:\n" >> ${XMLRESULTS}
    echo "`cat $TESTSTDOUT | sed 's|<||g' | sed 's|>||g' | tr -d '\r'`</system-out>" >> ${XMLRESULTS}
  fi
  if [ -n "$TESTSTDERR" -a -e "$TESTSTDERR" ] ; then
    echo "         <system-err>`cat $TESTSTDERR | sed 's|<||g' | sed 's|>||g' | tr -d '\r'`</system-err>" >> ${XMLRESULTS}
  fi

  # Close the error tag
  cat >> ${XMLRESULTS} << EOF
    </testcase>
EOF

  unset TESTNAME TESTSTDOUT TESTSTDERR TESTCMD
}

# $1 = Optional tag for results file
finish_xml_results() {
  if [ -z "$1" ] ; then
    rTag="tests"
  else
    rTag="$1"
  fi

  cat >>${XMLRESULTS} << EOF
</testsuite>
EOF

  # Set the total number of tests run
  sed -i '' "s|TOTALTESTS|$1|g" ${XMLRESULTS}

  # Move results to pre-defined location
  if [ -n "$WORKSPACE" ] ; then
    if [ ! -d "${WORKSPACE}/results" ] ; then
      mkdir -p "${WORKSPACE}/results"
      chown jenkins:jenkins "${WORKSPACE}/results"
    fi
    tStamp=$(date +%s)
    echo "Saving jUnit results to: ${WORKSPACE}/results/freenas-results-${rTag}.xml"
    mv "${XMLRESULTS}" "${WORKSPACE}/results/freenas-results-${rTag}.xml"
    chown jenkins:jenkins "${WORKSPACE}/results/freenas-results-${rTag}.xml"
  else
    echo "Saving jUnit results to: /tmp/test-results.xml"
    mv ${XMLRESULTS} /tmp/test-results.xml
  fi
}

clean_artifacts()
{
  # Move artifacts to pre-defined location
    echo "Cleaning previous artifacts"
    rm -rf "${WORKSPACE}/artifacts/"
}

save_artifacts_on_fail()
{
  # Move artifacts to pre-defined location
  if [ -n "$ARTIFACTONFAIL" ] ; then
      if [ -n "$WORKSPACE" ] ; then
        if [ ! -d "${WORKSPACE}/artifacts/${FNASBDIR}" ] ; then
          mkdir -p "${WORKSPACE}/artifacts/${FNASBDIR}"
          chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
      fi
    fi
    echo "Saving artifacts to: ${WORKSPACE}/artifacts/${FNASBDIR}"
    cp -R "${ARTIFACTONFAIL}" "${WORKSPACE}/artifacts/${FNASBDIR}"
    chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
  else
    echo "Skip saving artificats on failure / ARTIFACTONFAIL not set"
  fi
}

save_artifacts_on_success()
{
  # Move artifacts to pre-defined location
  if [ -n "$ARTIFACTONSUCCESS" ] ; then
    if [ -n "$WORKSPACE" ] ; then
      if [ ! -d "${WORKSPACE}/artifacts/${FNASBDIR}" ] ; then
        mkdir -p "${WORKSPACE}/artifacts/${FNASBDIR}"
        chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
      fi
    fi
    echo "Saving artifacts to: ${WORKSPACE}/artifacts/${FNASBDIR}"
    cp -R "${ARTIFACTONFAIL}" "${WORKSPACE}/artifacts/${FNASBDIR}"
    chown jenkins:jenkins "${WORKSPACE}/artifacts/${FNASBDIR}"
  else
    echo "Skip saving artificats on success / ARTIFACTONSUCCESS not set"
  fi
}

# $1 = RESTY type to run
# $2 = RESTY URL
# $3 = JSON to pass to RESTY
rest_request()
{
  export TESTCMD="$2 $3"

  case $1 in
  DELETE) DELETE ${2} "${3}" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
     GET) GET ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
   PATCH) PATCH ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
     PUT) PUT ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
    POST) POST ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
   TRACE) POST ${2} "$3" -v >${RESTYOUT} 2>${RESTYERR} ; return $? ;;
       *) echo "Unknown RESTY command: $1" ; return 1 ;;
  esac

  # Shouldn't get here
  return 1;
}

# $1 = Command to run
# $2 = Command to run if $1 fails
# $3 = Optional timeout
rc_test()
{
  export TESTCMD="$1"
  export TESTSTDOUT="/tmp/.cmdTestStdOut"
  export TESTSTDERR="/tmp/.cmdTestStdErr"
  touch $TESTSTDOUT
  touch $TESTSTDERR

  if [ -z "$3" ] ; then
    ${1} >${TESTSTDOUT} 2>${TESTSTDERR}
    if [ $? -ne 0 ] ; then
       echo_fail
       eval "${2}"
       echo "Failed running: $1"
       return 1
    fi
    echo_ok
    return 0
  fi

  # Running with timeout
  ( ${1} >${TESTSTDOUT} 2>${TESTSTDERR} ; echo $? > /tmp/.rc-result.$$ ) &
  echo "$!" > /tmp/.rc-pid.$$
  timeout=0
  while :
  do
    # See if the process stopped yet
    pgrep -F /tmp/.rc-pid.$$ >/dev/null 2>/dev/null
    if [ $? -ne 0 ] ; then
      # Check if it was 0
      if [ "$(cat /tmp/.rc-result.$$)" = "0" ] ; then
        echo_ok
        rm /tmp/.rc-result.$$
        return 0
      fi
      rm /tmp/.rc-result.$$
      break
    fi

    # Check the timeout
    sleep 1
    timeout=$(expr $timeout + 1)
    if [ $timeout -gt $3 ] ; then break; fi
  done

  kill -9 $(cat /tmp/.rc-pid.$$)
  rm /tmp/.rc-pid.$$
  rm /tmp/.rc-result.$$ 2>/dev/null
  echo_fail
  eval "${2}"
  echo "Timeout running: $1"
  return 1
}

echo_ok()
{
  echo -e " - OK"
  add_xml_result "true" "Valid test response"
}

echo_fail()
{
  if [ -z "$1" ] ; then
    errStr="Invalid test repsonse!"
  else
    errStr="$1"
  fi

  echo -e " - FAILED"
  add_xml_result "false" "$errStr"
}

echo_skipped()
{
  echo -e " - SKIPPED"
  add_xml_result "skipped" "Skipped test!"
}

# Check for $1 REST response, error out if not found
check_rest_response()
{
  export TESTSTDOUT="$RESTYOUT"
  export TESTSTDERR="$RESTYERR"

  grep -q "$1" ${RESTYERR}
  if [ $? -ne 0 ] ; then
    cat ${RESTYERR}
    cat ${RESTYOUT}
    echo_fail
    return 1
  fi

  echo_ok
  return 0
}

check_rest_response_continue()
{
  grep -q "$1" ${RESTYERR}
  return $?
}

set_test_group_text()
{
  GROUPTEXT="$1"
  CLASSNAME="$1"
  TOTALTESTS="$2"
  TCOUNT=0
}

echo_test_title()
{
  TESTNAME="$1"
  TCOUNT=`expr $TCOUNT + 1`
  TOTALCOUNT=`expr $TOTALCOUNT + 1`
  TIMESTART=`date +%s`
  sync
  echo -e "Running $GROUPTEXT ($TCOUNT/$TOTALTESTS) - $1\c"
}

# Set the IP address of REST
set_ip()
{
  set_test_group_text "Networking Configuration" "5"

  echo_test_title "Setting IP address: ${ip} on em0"
  rest_request "POST" "/network/interface/" '{ "int_ipv4address": "'"${ip}"'", "int_name": "internal", "int_v4netmaskbit": "24", "int_interface": "em0" }'
  check_rest_response "201 CREATED"

  # Wait 30 seconds before trying more REST queries again
  sleep 30

  if [ -n "$BRIDGEIP" ] ; then
    # Using the bridged adapter settings
    echo_test_title "Setting bridged IP on em1"
    rest_request "POST" "/network/interface/" '{ "int_ipv4address": "'"${BRIDGEIP}"'", "int_name": "ext", "int_v4netmaskbit": "'"${BRIDGENETMASK}"'", "int_interface": "em1" }'
    check_rest_response "201 CREATED"

    # Set the global config stuff
    echo_test_title "Setting default route and DNS"
    rest_request "PUT" "/network/globalconfiguration/" '{ "gc_domain": "'"${BRIDGEDOMAIN}"'", "gc_ipv4gateway": "'"${BRIDGEGW}"'", "gc_hostname": "'"${BRIDGEHOST}"'", "gc_nameserver1": "'"${BRIDGEDNS}"'" }'
    check_rest_response "200 OK"
  else
    # Using the NAT mode
    echo_test_title "Setting DHCP on em1"
    rest_request "POST" "/network/interface/" '{ "int_dhcp": true, "int_name": "ext", "int_interface": "em1" }'
    check_rest_response "201 CREATED"
  fi

  echo_test_title "Rebooting VM"
  rest_request "POST" "/system/reboot/" "''"
  # Disabled the response check, seems the reboot happens fast enough to
  # prevent a valid response sometimes
  #check_rest_response "202 ACCEPTED"
  echo_ok

  echo_test_title "Waiting for reboot"
  sleep 20
  wait_for_avail
  echo_ok
}

wait_for_avail()
{
  count=0
  while :
  do
    GET /storage/disk/ -v 2>${RESTYERR} >${RESTYOUT}
    check_rest_response_continue "200 OK"
    if [ $? -eq 0 ] ; then break; fi
    echo -e ".\c"
    sleep 60
    if [ $count -gt 12 ] ; then
       echo_fail
       exit 1
    fi
    count=`expr $count + 1`
  done
}

run_module() {
  unset REQUIRES

  # Source the module now
  cd ${TDIR}
  . ./${1}
  if [ $? -ne 0 ] ; then
    echo "Failed sourcing ${1}"
    FAILEDMODULES="${FAILEDMODULES}:::${1}:::"
    return 1
  fi

  # Make sure any required module have been run first
  local modreq="$REQUIRES"
  local nofails="true"
  if [ -n "$modreq" ] ; then
    for i in $modreq
    do
      # Check if this module has already been run
      echo $RUNMODULES | grep -q ":::${i}:::"
      if [ $? -eq 0 ] ; then continue; fi

      echo $FAILEDMODULES | grep -q ":::${i}:::"
      if [ $? -eq 0 ] ; then
	CLASSNAME="$1"
	TESTNAME="all"
	TIMESTART="0"
        TOTALCOUNT=`expr $TOTALCOUNT + 1`
        echo "***** Skipping test module: $1 ($i failed) *****"
        add_xml_result "skipped" "Skipped due to $i requirement failing"
        FAILEDMODULES="${FAILEDMODULES}:::${1}:::"
        return 1
      fi

      # Need to run another module first
      echo "***** Running module dependancy: $i *****"
      run_module "$i" "quiet"
      if [ $? -ne 0 ] ; then
        nofails="false"
      fi
    done
  fi

  if [ "$nofails" = "false" ] ; then
    CLASSNAME="$1"
    TESTNAME="all"
    TIMESTART="0"
    TOTALCOUNT=`expr $TOTALCOUNT + 1`
    echo "***** Skipping test module: $1 (Dep failed) *****"
    add_xml_result "skipped" "Skipped test module: $i requirement failing"
    return 1
  fi

  # Run the target module
  if [ -z "$2" ] ; then
    echo "***** Running module: $1 *****"
  fi
  eval "${1}_init"
  if [ $? -ne 0 ] ; then
    echo "Failed on test module: $1"
    FAILEDMODULES="${FAILEDMODULES}:::${1}:::"
    return 1
  fi

  # Save that this test was already run
  RUNMODULES="${RUNMODULES}:::${1}:::"
  return 0
}

# Read through the test modules and start running them
read_module_dir() {
  cd ${TDIR}
  if [ $? -ne 0 ] ; then
    echo "Missing test module dir"
    exit 1
  fi

  RUNMODULES=""
  ANYFAILS="false"

  for module in `ls`
  do
    # Skip the README, other files should be valid though
    if [ "$module" = "README" ] ; then continue ; fi
    if [ "$module" = "example" ] ; then continue ; fi

    # Check if this module has already been run
    echo $RUNMODULES | grep -q ":::${module}:::"
    if [ $? -eq 0 ] ; then continue ; fi

    # Check if this module has already been skipped
    echo $FAILEDMODULES | grep -q ":::${module}:::"
    if [ $? -eq 0 ] ; then continue ; fi

    run_module "$module"
    if [ $? -ne 0 ] ; then
      ANYFAILS="true"
    fi
  done

  if [ "$ANYFAILS" = "true" ] ; then return 1; fi
  return 0
}

# Do a TrueNAS HA failover
# $1 = reboot/panic
trigger_ha_failover() {
  case $1 in
    reboot) do_ha_reboot ;;
     panic) do_ha_panic ;;
         *) do_ha_reboot ;;
  esac
}

do_ha_panic() {
  export SSHPASS="$LIVEPASS"
  echo_test_title "Simulating kernel panic"
  sshpass -e ssh -o StrictHostKeyChecking=no ${LIVEUSER}@${LIVEHOST} sysctl debug.kdb.panic=1 >/dev/null 2>/dev/null
  echo_ok
  sleep 10

  echo_test_title "Waiting for active node response"
  sleep 20
  wait_for_avail
  echo_ok
}

do_ha_reboot() {
  echo_test_title "Rebooting to promote passive node to active"
  rest_request "POST" "/system/reboot/" "''"
  echo_ok

  echo_test_title "Waiting for active node response"
  sleep 20
  wait_for_avail
  echo_ok
}

do_ha_status() {
  # Verify each node is now in a normal state
  count=0
  while :
  do
    # Check the status of each node to make sure all nodes are online
    echo_test_title "Checking the alert level for each node"
    rest_request "GET" "/system/alert/" ""
    check_rest_response "200 OK"
    NODESTATUS=$(cat ${RESTYOUT} | ${JSAWK} 'return this.message')
    echo "NODESTATUS: $NODESTATUS"
    echo $NODESTATUS | grep -q 'Failed to check failover status with the other node: timed out'
    if [ $? -ne 0 ] ; then
      break
    else
      sleep 30
    fi
    count=$(expr $count + 1)
    if [ $count -gt 20 ] ;
    then
      echo_fail
      finish_xml_results
      exit 1
    fi
  done
}


Create bash script for importing git repositories

#!/bin/bash

shy init
shy author name "git2shy importer"

IFS=$'\n'
for line in $(git rev-list --first-parent --reverse --pretty=oneline HEAD); do
	sha1=$(echo $line | cut -d " " -f 1)
	msg=$(echo $line | cut -d " " -f 2-)

	git checkout $sha1
	shy add .
	shy commit "$msg (import $sha1 from git)"
done

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


fix bug: replace "type master;" only once

export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

PPATH=`dirname $0`
if [ -f "$PPATH/../master.conf" ]; then
        . $PPATH/../master.conf
        . $PPATH/../xdenv
fi

export MASTER_PATH=${XBAYDNS_CHROOT_PATH}/etc
export SLAVE_PATH=${XDPREFIX}/home/xbaydns/slave/named/etc

mkdir -p $SLAVE_PATH
rm -f $SLAVE_PATH/acl/*
cp -rf $MASTER_PATH/acl $SLAVE_PATH
rm -f $SLAVE_PATH/view/*
cp -rf $MASTER_PATH/view $SLAVE_PATH

find $SLAVE_PATH/view/ -type f | xargs -Iaa sed -i.master -e "s/type master;/type slave;\n        masters{ ${MASTER_IP}; };/g" aa
find $SLAVE_PATH/view/ -type f | xargs -Iaa sed -i.master -e "s/server .* { keys \(.*\) };[ ]*$/server ${MASTER_IP} { keys \1 };/g" -e "N;/server .* { keys \(.*\) };[ ]*$/D" aa
rm $SLAVE_PATH/view/*.master

export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

PPATH=`dirname $0`
if [ -f "$PPATH/../master.conf" ]; then
        . $PPATH/../master.conf
        . $PPATH/../xdenv
fi

export MASTER_PATH=${XBAYDNS_CHROOT_PATH}/etc
export SLAVE_PATH=${XDPREFIX}/home/xbaydns/slave/named/etc
echo "SLAVE_PATH",$SLAVE_PATH
mkdir -p $SLAVE_PATH
rm -f $SLAVE_PATH/acl/*
cp -rf $MASTER_PATH/acl $SLAVE_PATH
rm -f $SLAVE_PATH/view/*
cp -rf $MASTER_PATH/view $SLAVE_PATH
find $SLAVE_PATH/view/ -type f | xargs -Iaa sed -i.master -e s/"type master;"/"type slave;\n        masters{ ${MASTER_IP}; };"/g -e "s/server .* { keys \(.*\) };[ ]*$/server ${MASTER_IP} { keys \1 };/g" -e "N;/server .* { keys \(.*\) };[ ]*$/D" aa
rm $SLAVE_PATH/view/*.master


yum: update the version of MeCab (0.98 -> 0.994)

refs #1455

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/hiroyuki-sato/groonga.git/'


Remove buggy dot-dot-dot output for pip install

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/puttarajubr/commcare-hq.git/'


Run boost ICU hack when using ICU (vs. building ICU).

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/libtetcoin/libtetcoin-build.git/'


added nodejs + npm support

added nodejs + npm support

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/webceyhan/devbox-base.git/'


Issue #2559335 by epophoto, cilefen, andrewmk: password-hash.sh is hardcoded to use "/usr/bin/php"

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/lincgr/Prueba.git/'


Disable V-38660 for OpenStack-CI

Disable V-38660 for OpenStack-CI

Change-Id: I09826fb00d0bf7a862d9b51b4273b29a882f131d

#!/usr/bin/env bash
# Copyright 2014, Rackspace US, Inc.
#
# Licensed 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.

## Shell Opts ----------------------------------------------------------------
set -e -u

## Variables -----------------------------------------------------------------
DEPLOY_AIO=${DEPLOY_AIO:-false}
COMMAND_LOGS=${COMMAND_LOGS:-"/openstack/log/ansible_cmd_logs/"}

## Main ----------------------------------------------------------------------
function run_play_book_exit_message {
echo -e "\e[1;5;97m*** NOTICE ***\e[0m

The \"\e[1;31m${0}\e[0m\" script has exited. This script is no longer needed from now on.
If you need to re-run parts of the stack, adding new nodes to the environment,
or have encountered an error you will no longer need this application to
interact with the environment. All jobs should be executed out of the
\"\e[1;33m${PLAYBOOK_DIR}\e[0m\" directory using the \"\e[1;32mopenstack-ansible\e[0m\"
command line wrapper.

For more information about OpenStack-Ansible please review our documentation at:
  \e[1;36mhttp://docs.openstack.org/developer/openstack-ansible\e[0m

Additionally if there's ever a need for information on common operational tasks please
see the following information:
  \e[1;36mhttp://docs.openstack.org/developer/openstack-ansible/developer-docs/ops.html\e[0m

If you ever have any questions please join the community conversation on IRC at
#openstack-ansible on freenode.
"
}

function playbook_run {
  for root_include in $(awk -F'include:' '{print $2}' setup-everything.yml); do
    for include in $(awk -F'include:' '{print $2}' "${root_include}"); do
      echo "[Executing \"${include}\" playbook]"
      if [[ "${DEPLOY_AIO}" = true ]] && [[ "${include}" == "security-hardening.yml" ]]; then
        # NOTE(mattt): We have to skip V-38462 as openstack-infra are now building
        #              images with apt config Apt::Get::AllowUnauthenticated set
        #              to true.
        # NOTE(mhayden): Skipping V-38660 since it breaks the Xenial gate. The
        #                CI Xenial image has non-SNMPv3 configurations.
        install_bits "${include}" --skip-tag V-38462,V-38660
      else
        install_bits "${include}"
      fi
    done
  done
}

trap run_play_book_exit_message EXIT

info_block "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh

# Initiate the deployment
pushd "playbooks"
  PLAYBOOK_DIR="$(pwd)"

  # Execute setup everything
  playbook_run

  if [[ "${DEPLOY_AIO}" = true ]]; then
    # Log some data about the instance and the rest of the system
    log_instance_info

    # Log repo data
    mkdir -p "${COMMAND_LOGS}/repo_data"
    ansible 'repo_all[0]' -m raw \
                          -a 'find  /var/www/repo/os-releases -type l' \
                          -t "${COMMAND_LOGS}/repo_data"

    openstack-ansible os-tempest-install.yml
    print_report
  fi
popd

#!/usr/bin/env bash
# Copyright 2014, Rackspace US, Inc.
#
# Licensed 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.

## Shell Opts ----------------------------------------------------------------
set -e -u

## Variables -----------------------------------------------------------------
DEPLOY_AIO=${DEPLOY_AIO:-false}
COMMAND_LOGS=${COMMAND_LOGS:-"/openstack/log/ansible_cmd_logs/"}

## Main ----------------------------------------------------------------------
function run_play_book_exit_message {
echo -e "\e[1;5;97m*** NOTICE ***\e[0m

The \"\e[1;31m${0}\e[0m\" script has exited. This script is no longer needed from now on.
If you need to re-run parts of the stack, adding new nodes to the environment,
or have encountered an error you will no longer need this application to
interact with the environment. All jobs should be executed out of the
\"\e[1;33m${PLAYBOOK_DIR}\e[0m\" directory using the \"\e[1;32mopenstack-ansible\e[0m\"
command line wrapper.

For more information about OpenStack-Ansible please review our documentation at:
  \e[1;36mhttp://docs.openstack.org/developer/openstack-ansible\e[0m

Additionally if there's ever a need for information on common operational tasks please
see the following information:
  \e[1;36mhttp://docs.openstack.org/developer/openstack-ansible/developer-docs/ops.html\e[0m

If you ever have any questions please join the community conversation on IRC at
#openstack-ansible on freenode.
"
}

function playbook_run {
  for root_include in $(awk -F'include:' '{print $2}' setup-everything.yml); do
    for include in $(awk -F'include:' '{print $2}' "${root_include}"); do
      echo "[Executing \"${include}\" playbook]"
      if [[ "${DEPLOY_AIO}" = true ]] && [[ "${include}" == "security-hardening.yml" ]]; then
        # NOTE(mattt): We have to skip V-38462 as openstack-infra are now building
        #              images with apt config Apt::Get::AllowUnauthenticated set
        #              to true.
        install_bits "${include}" --skip-tag V-38462
      else
        install_bits "${include}"
      fi
    done
  done
}

trap run_play_book_exit_message EXIT

info_block "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh

# Initiate the deployment
pushd "playbooks"
  PLAYBOOK_DIR="$(pwd)"

  # Execute setup everything
  playbook_run

  if [[ "${DEPLOY_AIO}" = true ]]; then
    # Log some data about the instance and the rest of the system
    log_instance_info

    # Log repo data
    mkdir -p "${COMMAND_LOGS}/repo_data"
    ansible 'repo_all[0]' -m raw \
                          -a 'find  /var/www/repo/os-releases -type l' \
                          -t "${COMMAND_LOGS}/repo_data"

    openstack-ansible os-tempest-install.yml
    print_report
  fi
popd


updated droplet script

updated droplet 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/intrepion/intrepion.com.git/'


#45 test tokudb release tarballs with the mysql sandbox

#!/usr/bin/env bash

# for all tokudb binary tarballs, verify that we can create and run the tarball using the MySQL sandbox.

function expand() {
    echo $* | tr ,: " "
}

let n=0
for f in *.md5; do
    if [[ $f =~ (.*).tar.gz.md5 ]] ; then
        mysqlbuild=${BASH_REMATCH[1]}
    else
        exit 1
    fi

    md5sum --check $f
    if [ $? != 0 ] ; then exit 1; fi
    make_sandbox --add_prefix=test$n- $mysqlbuild.tar.gz -- --sandbox_directory=test$n
    if [ $? != 0 ] ; then exit 1; fi
    pushd $HOME/sandboxes
    if [ $? = 0 ] ; then
        ./use_all 'show engines'
        ./use_all 'create table test.t (a int primary key, b bigint, c varchar(256), d blob(500000), clustering key(b))'
        ./use_all 'show create table test.t'
	./stop_all
	popd
    fi
    let n=n+1
done

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


Adds update-bundle script

Adds update-bundle script

if [ ! -z "$INFO_PLIST" ]; then
  /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $TRAVIS_BUILD_NUMBER" "$INFO_PLIST"
  echo "Set CFBundleVersion to $TRAVIS_BUILD_NUMBER"
fi

if [ ! -z "$BUNDLE_IDENTIFIER" ]; then
  /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $BUNDLE_IDENTIFIER" "$INFO_PLIST"
  echo "Set CFBundleIdentifier to $BUNDLE_IDENTIFIER"
fi

if [ ! -z "$BUNDLE_DISPLAY_NAME" ]; then
  /usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $BUNDLE_DISPLAY_NAME" "$INFO_PLIST"
  echo "Set CFBundleDisplayName to $BUNDLE_DISPLAY_NAME"
fi

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


Source to align and pretty.

Source to align and pretty.

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/loustler/my-setting.git/'