conpaas-director: add functional test for taskfarm

git-svn-id: 2deb3340141ac69a26c0f89cf6cbd56f19c97dea@4817 ef35cc4a-2640-4bbf-98bc-65920db7d8ae

#!/bin/sh

start_service() {
    service_type=$1
    manager_ip=`cpsclient.py create $1 | awk '{ print $5 }' | sed s/...$//`
    sid=`cpsclient.py list | grep $manager_ip | awk '{ print $2 }'`
    return $sid
}

wait_for_running() {
    sid=$1

    while [ -z "`cpsclient.py info $sid | grep 'state: RUNNING'`" ]
    do
        sleep 2
    done
}

# Create and start service
echo "Taskfarm functional test started" | ts

start_service "taskfarm"
taskfarm_sid="$?"

echo "Taskfarm service created" | ts

wait_for_running $taskfarm_sid

echo "Taskfarm service running" | ts

# Creating BOT file
seq 70 | sed s/^.*/'sleep 1 \; echo "slept for 1 seconds" >> \/tmp\/log'/ > file.bot

# Uploading BOT file
cpsclient.py upload_bot $taskfarm_sid file.bot /tmp/ | sed s/.$// | ts

# Removing BOT file
rm file.bot

# Waiting for all the tasks to be completed
while [ -z "`cpsclient.py info $taskfarm_sid | grep 'completed tasks: 70'`" ]
do
    sleep 10
    echo "Waiting for tasks completion" | ts
done

cpsclient.py terminate $taskfarm_sid | ts

error: pathspec 'conpaas-director/functional-tests/taskfarm/run-test.sh' did not match any file(s) known to git


Wrapper script

Wrapper script

NOW=$(date +"%Y-%m-%d")
OUTFOLDER="$NOW-CM-promoter"
CMFILENAME="$NOW-human-NBPF-CM-promoter-900"
mkdir $OUTFOLDER

./get-human-NBPF-promoter-regions -fasta=$CMFILENAME.fa -cm -upstream=900
mafft --globalpair --thread 8 $CMFILENAME.fa > $CMFILENAME.aln
hmmbuild -n NBPF_CM --dna --cpu 8 $CMFILENAME.hmm $CMFILENAME.aln

mv *.fa $OUTFOLDER
mv *.aln $OUTFOLDER
mv *.hmm $OUTFOLDER

error: pathspec 'get-CM-promoter-regions.sh' did not match any file(s) known to git


Bumped Go to v1.12.6

Bumped Go to v1.12.6

fatal: unable to access 'https://github.com/jig/myubuntu.git/': The requested URL returned error: 403


First, incomplete cut of the test script.

#!/bin/bash

##
# Bash script to automate the regression testing of FITS.
#
# author Carl Wilson carl@openplanetsfoundation.org
#
# This initial cut is intended to be run from the root
# directory of a FITS development branch.  Given the path
# to a FITS testing tool and a path to test corpora the script:
#
#	* Checks that there's no uncommitted code.
#   * Checks that there you're not on master.
#	* Builds the current branch and generates test output.
#   * Checks out the master commit that's the source of this branch.
#	* Builds FITS and generates the more test output.
#	* Use the FITS testing tool to compare the output.
#	* If successful, i.e. the output is unchanged report success.
#   * If unsuccessful use git-bisect to find the last good commit.
##

ANT_SUCCESSFUL="SUCCESSFUL"
# Globals to hold the checked param vals
paramFitsToolLoc=
paramCorporaLoc=
# Check the passed params to avoid disapointment
checkParams () {
# Ensure we have the correct number of params
	if [[ "$#" -ne 2 ]]
	then
		echo "$# Two parameters expected: $1"
		exit 1
	fi

	paramFitsToolLoc="$1"
	paramCorporaLoc="$2"

# Check that the FITS testing tool exists
	if  [[ ! -e "$paramFitsToolLoc" ]]
	then
		echo "FITS Testing tool not found: $paramFitsToolLoc"
		exit 1;
	fi

# Check that the corpora directory exists
	if  [[ ! -d "$paramCorporaLoc" ]]
	then
		echo "Output corpora directory not found: $paramCorporaLoc"
		exit 1;
	fi
}

# Check we're in a git repository, and there's no uncommitted changes
checkGitStatus() {
	gitstatus=$(git status -z 2>&1)
	while IFS= read -r
	do
		# Check we're in a git repo
		isNotGitRepoFatal "$REPLY"

		# Other output means there's changes to commit
		if [[ ! -z "$REPLY" ]]
		then
			echo "There are uncommitted changes in this repo: $REPLY EXIT NEEDED HERE";
			# exit 1;
		fi
	done <<< "$gitstatus"
}

# Check we've got a master branch and it's not checked out,
# intended to be run on a development branch
checkMaster() {
	gitbranch=$(git branch 2>&1)
	currentBranchRegEx="^\* (.*)$"
	masterBranchRegEx="^[ ]*master$"
	masterFound=0
	while IFS= read -r
	do
		if [[ $REPLY =~ $currentBranchRegEx ]]
		then
			currentBranch="${BASH_REMATCH[1]}"
		elif [[ $REPLY =~ $masterBranchRegEx ]]
		then
				masterFound=1
		fi
	done <<< "$gitbranch"
	if [[ $currentBranch =~ $masterBranchRegEx ]]
	then
		echo "Current branch is master, please check out another branch."
		exit 1;
	fi
	if (( masterFound == 0 ))
	then
		echo "No master branch found to test against"
	fi
}

findMergeBaseHash() {
	gitshow=$(git show --pretty=format:"%H" `git merge-base "$currentBranch" master` 2>&1)
	shaRegEx="^[0-9a-f]{40}$"
	while IFS= read -r
	do
		if [[ $REPLY =~ $shaRegEx ]]
		then
			mergeBaseHash=$REPLY
		fi
	done <<< "$gitshow"
}

# Test param string for not a git repo output and exit if found
isNotGitRepoFatal() {
	notGitRegEx="^fatal: Not a git repository"
	if [[ $1 =~ $notGitRegEx ]]
	then
		echo "$1"
		exit 1;
	fi
}

buildFits() {
	cd ~/dev/git-hub/openplanets/fits
	antCommand=$(ant clean 2>&1)
	wasAntSuccessful "$antCommand"
	antStatus=$?
	if (( ! $antStatus == 1 ))
	then
		echo "ant status: $antSatus"
	fi

	antCommand=$(ant compile 2>&1)
	wasAntSuccessful "$antCommand"
	if (( ! $antStatus == 1 ))
	then
		echo "ant status: $antSatus"
	fi

	ant release <<< "release"
}

wasAntSuccessful() {
	antCommand=$1
	buildRegEx="^BUILD ([A-Z]*)$"
	antStatus="UNKOWN"
	while IFS= read -r
	do
		if [[ $REPLY =~ $buildRegEx ]]
		then
			antStatus="${BASH_REMATCH[1]}"
		fi
	done <<< "$antCommand"

	if [[ $antStatus == $ANT_SUCCESSFUL ]]
	then
		return 1;
	fi

	return 0;
}

checkParams "$@";
checkGitStatus;
echo "In git repo ${PWD##*/}"
checkMaster;
echo "Current branch: $currentBranch"
findMergeBaseHash;
buildFits;

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


Added Yii basic command completion

Added Yii basic command completion

# Yii basic command completion

_yii_get_command_list () {
	protected/yiic | awk '/^ - [a-z]+/ { print $2 }'
}

_yii () {
  if [ -f protected/yiic ]; then
    compadd `_yii_get_command_list`
  fi
}

compdef _yii protected/yiic
compdef _yii yiic

# Aliases
alias yiic='protected/yiic'

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


tests: Add main test for alias of a parameter like string

#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2020 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
#  * Redistributions of source code must retain the above copyright notice, this list of conditions
#    and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright notice, this list of
#    conditions and the following disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
#    may be used to endorse or promote products derived from this software without specific prior
#    written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------

alias '$foo'='echo alias'
foo=(echo param)

BUFFER='$foo'

expected_region_highlight=(
  '1 4 alias' # $foo
)

error: pathspec 'highlighters/main/test-data/alias-parameter.zsh' did not match any file(s) known to git


kill docker cache for the dir that was created by the git clone

#!/bin/bash -e
####
# based on https://gist.github.com/jdoconnor/32ef0314cecb80157c4e
# based on https://gist.github.com/jeffery/1115504
# Helper script to update the Last modified timestamp of files in a Git SCM
# Projects working Copy
#
# When you clone a Git repository, it sets the timestamp of all the files to the
# time when you cloned the repository.
#
# This becomes a problem when you want the cloned repository, which is part of a
# Web application have a proper cacheing mechanism so that it can re-cache files
# (into a webtree) that have been modified since the last cache.
#
# @see http://stackoverflow.com/questions/1964470/whats-the-equivalent-of-use-commit-times-for-git
#
# Author: Jeffery Fernandez <jeffery@fernandez.net.au>
# Modified by: Jay OConnor <jaydoconnor@gmail.com>
####

# Make sure we are not running this on a bare Repository
echo $(pwd)
REPO_TYPE=`git config --list|egrep ^core.bare | awk -F '=' '{ print $2 }'`
if [ "$REPO_TYPE" == "true" ]
then
  echo "Cannot run this script on a bare Repository" && exit 1
fi

echo "Updating Git Repository Last Modified Time-stamp"

# Obtain the Operating System
OS=${OS:-`uname`}

# Get the last revision hash of a particular file in the git repository
getFileLastRevision()
{
  git rev-list HEAD "$1" | head -n 1
}

# Extract the actual last modified timestamp of the file and Update the time-stamp
updateFileTimeStamp()
{
  # Extract the file revision
  FILE_REVISION_HASH=`getFileLastRevision "$1"`

  # Get the File last modified time
  FILE_MODIFIED_TIME=`git show --pretty=format:%ai --abbrev-commit ${FILE_REVISION_HASH} | head -n 1`

  # Extract the last modified timestamp, differently for Linux, FreeBSD and Mac OS X
  if [ "$OS" = 'Linux' ]
  then
    # for displaying the date in readable format
    #FORMATTED_TIMESTAMP=`date --date="${FILE_MODIFIED_TIME}" +'%d-%m-%Y %H:%M:%S %z'`
    #echo "Modified: ${FILE_MODIFIED_TIME} | ${FORMATTED_TIMESTAMP} > ${1}"

    # Modify the last modified timestamp
    touch -d "${FILE_MODIFIED_TIME}" $2

  elif [ "$OS" = 'Darwin' ] || [ "$OS" = 'FreeBSD' ]
  then
    # Format the date for updating the timestamp
    FORMATTED_TIMESTAMP=`date -j -f '%Y-%m-%d %H:%M:%S %z' "${FILE_MODIFIED_TIME}" +'%Y%m%d%H%M.%S'`
    # echo "Modified: ${FILE_MODIFIED_TIME} | ${FORMATTED_TIMESTAMP} > ${1}"

    # Modify the last modified timestamp
    touch -t  "${FORMATTED_TIMESTAMP}" $2

  else
    echo "Unknown Operating System to perform timestamp update" >&2
    exit 1
  fi
}

# Backup and update the "Internal Field Separator" to a newline. This is so that
# we can deal with spaces in file names in the for loop below
IFS_BAK=$IFS
IFS="
"

# update all of the directries timestamps.  This is safe because docker will evaluate files as well
find . -type d | xargs touch -t 7805200000

# Loop through and fix timestamps on all files in our checked-out repository
for file in $(git ls-files)
do
  updateFileTimeStamp "${file}" "${file}"
done

# Revert the default delimiter
IFS=$IFS_BAK
IFS_BAK=

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


added mi_light project

added mi_light project

g++ -Ofast -mfpu=vfp -mfloat-abi=hard -march=ARMv7-A -mtune=ARM1176JZF-S -I /usr/local/include -L /usr/local/lib -lrf24-bcm PL1167_nRF24.cpp MiLightRadio.cpp openmili.cpp -o openmilight
g++ -Ofast -mfpu=vfp -mfloat-abi=hard -march=ARMv7-A -mtune=ARM1176JZF-S -I /usr/local/include -L /usr/local/lib -lrf24-bcm PL1167_nRF24.cpp MiLightRadio.cpp send_cmd.cpp -o send_cmd

error: pathspec '11_mi_light/comp.sh' did not match any file(s) known to git


Fix formatting tests to exclude Godeps

Fix formatting tests to exclude Godeps

#!/bin/bash

DIRS=`ls -l . | egrep '^d' | awk '{print $9}'`

DIRS=`echo $DIRS | sed "s/Godeps//g"`

# and finally loop over the cleaned up directory list.
for DIR in $DIRS
do
	if [[ -n "$(gofmt -l ${DIR})" ]]; then
		echo "Bad formatting, run make format-gosuper to fix it."
		exit 1
	fi
done
echo "Formatting test passed."

#!/bin/bash

if [[ -n "$(gofmt -l .)" ]]; then
	echo "Bad formatting, run make format-gosuper to fix it."
	exit 1
else
	echo "Formatting test passed."
fi


Add haskell package

Add haskell package

#!/bin/sh

# for editor
cabal install ghc-mod

error: pathspec 'home/.setup/cabal_setup.sh' did not match any file(s) known to git


Added wording to say where gogs would be running

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/jedediahfrey/FreeNAS-Gogs.git/'


change source path to .bin

change source path to .bin

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/termiwon/ohz_env.git/'


Script to save data from pc to gcp storage

#!/bin/bash

#TODO verificar o mimetype
#se começar com inode inode/directory é um diretório, qualquer outra coisa que começar com inode deve dar erro
#qualquer outra coisa deve ser um arquivo, então pensar em uma forma de sincronizar

#TODO verificar se um diretório já esta sendo sincronizado com o pai
#por exemplo, existe /home/filipe/Documentos, se tentar adicionar /home/filipe/Documentos/Planilhas deve retornar erro pois
#o diretorio acima já esta sendo salvo

FILE_WITH_PATHS=$HOME/.savemypc
BUCKET_NAME=filipenos
PC_NAME=$(cat /etc/hostname)

log() {
  echo "[SAVE-MY-PC]" $@
}

print_help() {
  echo "Usage $1 (add|show|show-remote|save)"
  exit 1
}

is_empty() {
  if [ -z $1 ]; then
    log "[ERROR] empty"
    exit 1
  fi
}

check_file_exists() {
  is_empty $1
  if [ ! -f $1 ]; then
    log "[ERROR] File $1 not exists"
    exit 1
  fi
}

check_path_exists() {
  is_empty $1
  if [ ! -d $1 ]; then
    log "[ERROR] Path $1 not exists"
    exit 1
  fi
}

add_path() {
  log "Add $1 to save"
  check_path_exists $1
  dir=$(dirname "${1}")
  file="$dir/$file"$(basename "${1}")
  grep -q -s "$file" $FILE_WITH_PATHS
  if [ $? -gt 0 ]; then
    log "Path added successfully!"
    echo $file >> $FILE_WITH_PATHS
  else
    log "[ERROR] Path already added"
  fi
}

show_paths() {
  log "Listing paths to save remote"
  check_file_exists $FILE_WITH_PATHS
  cat $FILE_WITH_PATHS
}

show_remote() {
  log "Listing paths on remote bucket"
  gsutil ls "gs://$BUCKET_NAME/$PC_NAME/"
}

check_dependencies() {
  log "Check if dependencies are instaled"
  which gsutil > /dev/null
  if [ $? -gt 0 ]; then
    log "[ERROR] gsutil command not found"
    exit 1
  fi
}

mime_type() {
  mimetype --output-format "%m" examples.desktop
}

save_my_pc() {
  check_dependencies
  check_file_exists $FILE_WITH_PATHS

  log "Saving pc data to $PC_NAME"
  while read l;
  do
    dir=$(basename $l)
    log "Saving path $dir"
    check_path_exists "$l"
    gsutil -m rsync -d -r "$l" "gs://$BUCKET_NAME/$pcname/$dir"
  done < $FILE_WITH_PATHS
}

if [ $# -eq 0 ]; then
  print_help
fi

while [ $# -gt 0 ]; do
  case "$1" in
    add)
      shift
      add_path $1
      ;;
    show)
      show_paths
      ;;
    show-remote)
      show_remote
      ;;
    save)
      save_my_pc
      ;;
    -h|--help|help|*)
      print_help
      ;;
  esac
  shift
done

error: pathspec 'bin/save-my-pc.sh' did not match any file(s) known to git


Create aws.mkssh-priv.sh

Create aws.mkssh-priv.sh

#!/usr/bin/env bash

# Create Assible from AWS Enviroment

INVfile=aws.ssh-jumpfile
SSHkey='/home/ubuntu/.aws/m3DEVaws.pem'
SSHuid='ubuntu'

MASTER=$(aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,PrivateIpAddress]' \
   --filter "Name=tag:Name,Values=AWSCLI v1.2 master" --output text | tr '\t' ' ')

WORKERS=$(aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,PrivateIpAddress]' --filter "Name=tag:Project,Value
s=HP-DEMO" "Name=instance-state-name,Values=running" --output text | tr '\t' ' ')

echo '[Master]' > $INVfile
 while IFS=' ' read instanceID PrivateIpAddr; do
     echo "ssh -i ${SSHkey} ${SSHuid}@${PrivateIpAddr}"
 done <<< "$MASTER" >> $INVfile ; echo >> $INVfile

echo '[Workers]' >> $INVfile
 while IFS=' ' read instanceID PrivateIpAddr; do
     echo "ssh -i ${SSHkey} ${SSHuid}@${PrivateIpAddr}"
 done <<< "$WORKERS" >> $INVfile

cat $INVfile | ccze -A

exit 0;

error: pathspec 'aws.mkssh-priv.sh' did not match any file(s) known to git


Move get script from init branch to master

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/dawikur/mnl.git/'


add unitex-core-test.sh a custom tool to run unitex core tests

#!/usr/bin/env bash
# =============================================================================
# Unitex/GramLab Core Integration Tests
# https://github.com/UnitexGramLab/unitex-core-tests
# =============================================================================
# Copyright (C) 2016 Université Paris-Est Marne-la-Vallée <unitex-devel@univ-mlv.fr>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
#
# cristian.martinez@univ-paris-est.fr (martinec)
#
# =============================================================================
# Script code must be ShellCheck-compliant for information about how to run
# ShellCheck locally @see http://www.shellcheck.net/about.html
# e.g shellcheck -s sh setup
# =============================================================================
# seconds since 1970-01-01 00:00:00 UTC
START_SECONDS=$(date +%s)
# Start date timestamp e.g. Fri Mar 22 00:10:29 CET 2013
TIMESTAMP_START_C="$(date -d now)"
# =============================================================================
# Constants
# =============================================================================
UNITEX_TEST_SCRIPT_NAME=$(basename -- "$0")                 # This script name
UNITEX_TEST_CODENAME="Unitex/GramLab Core Integration Tests"
UNITEX_TEST_REPOSITORY="https://github.com/UnitexGramLab/unitex-core-tests"
UNITEX_CORE_REPOSITORY="https://github.com/UnitexGramLab/unitex-core"
# =============================================================================
# Script working directory
# =============================================================================
# Working directory snippet from @source http://stackoverflow.com/a/17744637/2042871
UNITEX_TEST_SCRIPT_FILE=$(cd -P -- "$(dirname -- "$0")" && pwd -P) &&\
UNITEX_TEST_SCRIPT_FILE="$UNITEX_TEST_SCRIPT_FILE/$UNITEX_TEST_SCRIPT_NAME"

# Resolve symlinks snippet from @source http://stackoverflow.com/a/697552/2042871
while [ -h "$UNITEX_TEST_SCRIPT_FILE" ]; do
    UNITEX_TEST_SCRIPT_DIR=$(dirname -- "$UNITEX_TEST_SCRIPT_FILE")
    UNITEX_TEST_SCRIPT_SYM=$(readlink   "$UNITEX_TEST_SCRIPT_FILE")
    UNITEX_TEST_SCRIPT_FILE="$(cd "$UNITEX_TEST_SCRIPT_DIR"  &&\
                                  cd "$(dirname  -- "$UNITEX_TEST_SCRIPT_SYM")" &&\
                                 pwd)/$(basename -- "$UNITEX_TEST_SCRIPT_SYM")"
done  # [ -h "$UNITEX_TEST_SCRIPT_FILE" ]
# =============================================================================
# Set-up working directory
UNITEX_TEST_SCRIPT_BASEDIR="$(dirname  -- "$UNITEX_TEST_SCRIPT_FILE")"
# Default workspace is the working directory
UNITEX_TEST_LOG_WORKSPACE="$UNITEX_TEST_SCRIPT_BASEDIR"
# =============================================================================
# Script name
UNITEX_TEST_SCRIPT_NAME=${0##*/}
# =============================================================================
# Minimal Bash version
UNITEX_TEST_MINIMAL_BASH_VERSION_STRING="4.2.0"
UNITEX_TEST_MINIMAL_BASH_VERSION_NUMBER=$((4 * 100000 + 2 * 1000 + 0))
# =============================================================================
# Default trap signals
# shellcheck disable=SC2034
UNITEX_TEST_SIGNAL_INT=INT
# shellcheck disable=SC2034
UNITEX_TEST_SIGNAL_QUIT=QUIT
# shellcheck disable=SC2034
UNITEX_TEST_SIGNAL_TERM=TERM
# shellcheck disable=SC2034
UNITEX_TEST_SIGNAL_EXIT=EXIT
# =============================================================================
# Default commands
UNITEX_TEST_TOOL_BIN="UnitexToolLogger"
UNITEX_TEST_TOOL_PRINTF=$( command -v printf        ||\
                           command -v /bin/echo     ||\
                           command -v /usr/ucb/echo ||\
                           command -v echo          || echo "echo" )
UNITEX_TEST_TOOL_VALGRIND="valgrind"
# =============================================================================
# Reset in case getopts has been used previously in the shell
# This is from @source http://bash.cumulonim.biz/BashFAQ%282f%29035.html
OPTIND=1
# =============================================================================
# shellcheck disable=SC2034
{
# Default constants
UNITEX_TEST_LINE_STRING=$(head -c 80 < /dev/zero | tr '\0' '=' || echo "")
# VT100 Colors
UNITEX_TEST_CONSOLE_COLOR_BLACK="\033[22;30m"
UNITEX_TEST_CONSOLE_COLOR_BLUE="\033[22;34m"
UNITEX_TEST_CONSOLE_COLOR_BROWN="\033[22;33m"
UNITEX_TEST_CONSOLE_COLOR_CYAN="\033[22;36m"
UNITEX_TEST_CONSOLE_COLOR_DARKGRAY="\033[01;30m"
UNITEX_TEST_CONSOLE_COLOR_GRAY="\033[22;37m"
UNITEX_TEST_CONSOLE_COLOR_GREEN="\033[22;32m"
UNITEX_TEST_CONSOLE_COLOR_LIGHTBLUE="\033[01;34m"
UNITEX_TEST_CONSOLE_COLOR_LIGHTCYAN="\033[01;36m"
UNITEX_TEST_CONSOLE_COLOR_LIGHTGREEN="\033[01;32m"
UNITEX_TEST_CONSOLE_COLOR_LIGHTMAGENTA="\033[01;35m"
UNITEX_TEST_CONSOLE_COLOR_LIGHTRED="\033[01;31m"
UNITEX_TEST_CONSOLE_COLOR_MAGENTA="\033[22;35m"
UNITEX_TEST_CONSOLE_COLOR_RED="\033[22;31m"
UNITEX_TEST_CONSOLE_COLOR_WHITE="\033[01;37m"
UNITEX_TEST_CONSOLE_COLOR_YELLOW="\033[01;33m"
# VT100 common
UNITEX_TEST_CONSOLE_CLEAR_CURRENT_LN=" \r\033[2K"
UNITEX_TEST_CONSOLE_RESET="\033[0m"
}
# =============================================================================
# Counters
UNITEX_TEST_COMMAND_EXECUTION_ERROR_COUNT=0
UNITEX_TEST_COMMAND_EXECUTION_COUNT=0
UNITEX_TEST_LOG_MESSAGE_COUNT=0
UNITEX_TEST_FINISH_WITH_ERROR_COUNT=0
UNITEX_TEST_LOG_LEVEL_COUNTER=(0 0 0 0 0 0 0 0)
# =============================================================================
# shellcheck disable=SC2034
UNITEX_TEST_CURRENT_STDOUT=/dev/stdout
# shellcheck disable=SC2034
UNITEX_TEST_PREVIOUS_STDOUT=/dev/stdout
# =============================================================================
# Default variables
UNITEX_TEST_LOG_FILE_EXT=".log"
UNITEX_TEST_ULP_EXTENSION=".ulp"
UNITEX_TEST_TARGET="$UNITEX_TEST_SCRIPT_BASEDIR"
# =============================================================================
# Default params
UNITEX_TEST_MEMORY_ERRORS=0
UNITEX_TEST_NON_REGRESSION=1
UNITEX_TEST_PRINT_EXECUTION_LOGS=0
UNITEX_TEST_USE_ANSI_COLORS=1
UNITEX_TEST_VERBOSITY=1
# =============================================================================
# Default error codes
UNITEX_TEST_DEFAULT_ERROR_CODE=1
UNITEX_TEST_MEMORY_ERROR_CODE=66
# has defined on unitex-core/Error.h
UNITEX_TEST_RUNLOG_COMPARE_ERROR_CODE=80
UNITEX_TEST_RUNLOG_WARNING_CODE=79
# =============================================================================
# Portable echo function
# @source http://www.etalabs.net/sh_tricks.html
# =============================================================================
echo () (
  fmt=%s end=\\n IFS=" "

  while [ $# -gt 1 ] ; do
   case "$1" in
    [!-]*|-*[!ne]*) break;;
    *ne*|*en*) fmt=%b end=;;
    *n*) end=;;
    *e*) fmt=%b;;
   esac
   shift
  done

  $UNITEX_TEST_TOOL_PRINTF "$fmt$end" "$*"
)
# =============================================================================
# check bash version
# ATTENTION NEVER USE LOG FUNCTIONS FROM HERE !
check_bash_version() {
  local -r bash_version_string="${BASH_VERSION%%[^0-9.]*}"
  local -r bash_version_major="${BASH_VERSINFO[0]}"
  local -r bash_version_minor="${BASH_VERSINFO[1]}"
  local -r bash_version_patch="${BASH_VERSINFO[2]}"

  #          $bash_version_major * (major <= +INF)
  # 100000 + $bash_version_minor * (minor <= 99)
  # 1000   + $bash_version_patch   (patch <= 999)
  local -r bash_version_number=$(echo "$bash_version_major  * 100000 \
                                     + $bash_version_minor  * 1000 + \
                                       $bash_version_patch" | bc)

  # check bash version
  if [ "$bash_version_number" -lt "$UNITEX_TEST_MINIMAL_BASH_VERSION_NUMBER" ]; then
    echo "Bad Bash version: Required($UNITEX_TEST_MINIMAL_BASH_VERSION_STRING) - Using($bash_version_string)"
    exit $UNITEX_TEST_DEFAULT_ERROR_CODE
  fi
}
# =============================================================================
# setup_script_traps
setup_script_traps() {
  # Create an array list composed by all variables having the prefix
  # UNITEX_TEST_SIGNAL_
  SCRIPT_SIGNAL_LIST=$(set -o posix ; set         |\
                       grep "UNITEX_TEST_SIGNAL_" |\
                       cut -d= -f2)
  SCRIPT_SIGNAL_LIST=( $SCRIPT_SIGNAL_LIST )
  local script_signal
  for script_signal in "${SCRIPT_SIGNAL_LIST[@]}"
  do
    # shellcheck disable=SC2064
    trap "die_with_critical_error \"Caught signal\" \"A $script_signal signal was received at line \$LINENO\"" $script_signal
  done
}
# =============================================================================
# print usage options
usage() {
    echo "Usage:"
    echo "  $UNITEX_TEST_SCRIPT_NAME [OPTIONS] [DIRECTORY|ULP_FILE]"
    echo "Options:"
    echo "  -M n  : enable or disable memory error detection tests"
    echo "          default=$UNITEX_TEST_MEMORY_ERRORS"
    echo "  -R n  : enable or disable non-regression tests"
    echo "          default=$UNITEX_TEST_NON_REGRESSION"
    echo "  -c n  : use or not ANSI color codes"
    echo "          default=$UNITEX_TEST_USE_ANSI_COLORS"
    echo "  -p n  : print execution logs to stdout"
    echo "          0 print none"
    echo "          1 print if error"
    echo "          2 always print"
    echo "          default=$UNITEX_TEST_PRINT_EXECUTION_LOGS"
    echo "  -v n  : manually set the verbosity level 0...7"
    echo "          0 (%%) [debug]       debug message"
    echo "          1 (II) [info]rmation purely informational message"
    echo "          2 (!!) [notice]      normal but significant condition"
    echo "          3 (WW) [warning]     warning condition"
    echo "          4 (EE) [error]       error condition"
    echo "          5 (CC) [critical]    critical condition"
    echo "          6 (^^) [alert]       action must be taken immediately"
    echo "          7 (@@) [panic]       unusable condition"
    echo "          default=$UNITEX_TEST_VERBOSITY"
    echo "  -h    : display this help and exit"
    exit $UNITEX_TEST_DEFAULT_ERROR_CODE
}  # usage()
# =============================================================================
# Logger levels e.g. log_[level_name] "action" "details"
# =============================================================================
# 0. (%%) [debug]       debug message
# 1. (II) [info]rmation purely informational message
# 2. (!!) [notice]      normal but significant condition
# 3. (WW) [warning]     warning condition
# 4. (EE) [error]       error condition
# 5. (CC) [critical]    critical condition
# 6. (^^) [alert]       action must be taken immediately
# 7. (@@) [panic]       unusable condition
# 8                     not a logging message
# =============================================================================
UNITEX_TEST_LOG_LEVEL_ALIAS=("%%" "II" "!!" "WW" "EE" "CC" "^^" "@@" "")
UNITEX_TEST_LOG_LEVEL_NAME=("Debug" "Information" "Notice" "Warning" \
                             "Error" "Critical" "Alert"  "Panic" "")
# =============================================================================
# debug log
log_debug()    { log 0  "${UNITEX_TEST_LOG_LEVEL_ALIAS[0]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_WHITE";      }

# information log
log_info()     { log 1  "${UNITEX_TEST_LOG_LEVEL_ALIAS[1]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_BROWN";      }

# notice log
log_notice()   { log 2  "${UNITEX_TEST_LOG_LEVEL_ALIAS[2]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_LIGHTGREEN"; }

# warning log
log_warn()     { log 3  "${UNITEX_TEST_LOG_LEVEL_ALIAS[3]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_YELLOW";     }

# error log
log_error()    { log 4  "${UNITEX_TEST_LOG_LEVEL_ALIAS[4]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_RED";        }

# critical log
log_critical() { log 5  "${UNITEX_TEST_LOG_LEVEL_ALIAS[5]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_LIGHTRED";   }

# alert log
log_alert()    { log 6  "${UNITEX_TEST_LOG_LEVEL_ALIAS[6]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_LIGHTRED";   }

# panic log
log_panic()    { log 7  "${UNITEX_TEST_LOG_LEVEL_ALIAS[7]}" "$1" "$2" "$3" "$UNITEX_TEST_CONSOLE_COLOR_LIGHTRED";   }

# none log
log_none()     { log 8  "${UNITEX_TEST_LOG_LEVEL_ALIAS[8]}" "$1"  ""  "";                                      }
# =============================================================================
# UNITEX_TEST_LOG_FORMAT
# printf formatted string
# 1 : log message level : !!, II, WW, EE, ??                       -b1-4
# 2 : stage name : User Manual, Core Components, IDE Java ...      -b6-20
# 3 : action                                                       -b23-43
# 4 : description                                                  -b44-
#                            1       2      3     4
UNITEX_TEST_LOG_FORMAT_COLOR="%b(%.2s)%b %b[%-4s]%b  %-20s : %s\n"
UNITEX_TEST_LOG_FORMAT_NO_COLOR="(%.2s) [%-4s]  %-20s : %s\n"
#                             1    4 6    20  23  44
# =============================================================================
# Push directory with logging check
push_directory() {
 if [ -d "$1" ]; then
  pushd "$1" > /dev/null
 else
  log_warn "Directory not found" "directory $1 doesn't exist"
 fi
}  # push_directory()
# =============================================================================
# Pop directory without error message
pop_directory() {
 popd > /dev/null
} # pop_directory
# =============================================================================
# Notify fails by verbosity level
notify_fail_log_level_count() {
  for i in "${!UNITEX_TEST_LOG_LEVEL_COUNTER[@]}"; do
    # shellcheck disable=SC2086
    if [ $UNITEX_TEST_VERBOSITY -eq 0 -a $i -le 7 ]; then
      log_debug "${UNITEX_TEST_LOG_LEVEL_NAME[$i]} messages" \
                "${UNITEX_TEST_LOG_LEVEL_COUNTER[$i]}"
    elif [ $i -ge 3  -a $i -le 7 ]; then
      if [ ${UNITEX_TEST_LOG_LEVEL_COUNTER[$i]} -ge 1 ]; then
        log_info "${UNITEX_TEST_LOG_LEVEL_NAME[$i]} messages" \
                 "${UNITEX_TEST_LOG_LEVEL_COUNTER[$i]}"
      fi
    fi
  done
}
# =============================================================================
# Notify fails execution count
notify_fail_command_execution_count() {
  if [ $UNITEX_TEST_COMMAND_EXECUTION_ERROR_COUNT -ge 1 ]; then
    log_info  "Command execution" \
    "$UNITEX_TEST_COMMAND_EXECUTION_ERROR_COUNT/$UNITEX_TEST_COMMAND_EXECUTION_COUNT fails"
  fi
}
# =============================================================================
notify_elapsed_time() {
  TIMESTAMP_FINISH_A=$(date +'%F %T %z')
  END_SECONDS=$(date +%s)
  DIFF_SECONDS=$(( END_SECONDS - START_SECONDS ))
  TOTAL_ELAPSED_TIME=$(echo -n $DIFF_SECONDS | awk '{print strftime("%H:%M:%S", $1,1)}')

  # notify that the work was done
  log_info "Overall elapsed time" "$TOTAL_ELAPSED_TIME"
}
# =============================================================================
count_issues_until_now() {
  local __issues_variable=${1:?Output variable name required}
  local issues_count=$UNITEX_TEST_COMMAND_EXECUTION_ERROR_COUNT

  # check if script is complete with no errors
  # 3=Message Error and 7=Message Panic
  for i in "${!UNITEX_TEST_LOG_LEVEL_COUNTER[@]}"; do
    # shellcheck disable=SC2086
    if [ $i -ge 3 -a $i -le 7 ]; then
      # shellcheck disable=SC2086
      if [ ${UNITEX_TEST_LOG_LEVEL_COUNTER[$i]} -ge 1 ]; then
        issues_count=$(( issues_count + UNITEX_TEST_LOG_LEVEL_COUNTER[i] ))
      fi
    fi
  done

  # shellcheck disable=SC2140
  eval "$__issues_variable"="'$issues_count'"
}  # count_issues_until_now
# =============================================================================
notify_finish() {
  # notify number of messages for each log level >= warning
  notify_fail_log_level_count

  # notify number of fail executions
  notify_fail_command_execution_count

  # notify elapsed time
  notify_elapsed_time

  # count errors until now
  count_issues_until_now UNITEX_TEST_FINISH_WITH_ERROR_COUNT

  # Remove files (e.g *$UNITEX_TEST_UNTRACED.log) with zero size from the logger workspace
  # test first if logger workspace path exists
  if [ -d "$UNITEX_TEST_LOG_WORKSPACE" ]; then
    push_directory "$UNITEX_TEST_LOG_WORKSPACE"
    {
      find "$UNITEX_TEST_LOG_WORKSPACE" -size 0 | \
           while read f; do rm -f "$f" ; done
    } & wait
    pop_directory
  fi

  # final message
  if [ $UNITEX_TEST_FINISH_WITH_ERROR_COUNT -eq 0 ]; then
    log_notice "Happy ending"   "$TIMESTAMP_FINISH_A"
  else
    log_info "Unhappy ending" "$TIMESTAMP_FINISH_A"
  fi
}
# =============================================================================
clean_exit() {
  # reset traps
  # shellcheck disable=SC2046
  trap - $(printf "%s "  "${SCRIPT_SIGNAL_LIST[@]}")

  # notify that the process is finished
  notify_finish

  # restore streams
  pop_streams

  # exit
  exit $UNITEX_TEST_FINISH_WITH_ERROR_COUNT
}
# =============================================================================
# exit with critical error
die_with_critical_error() {
  # print message
  log_critical "$@"

  # exit with error
  clean_exit
}  # die_with_critical_error
# =============================================================================
# main logging function
# avoid call this function directly, use instead :
# log_[level] "message" "description"
# 1:LEVEL, 2:ALIAS, 3:MESSAGE, 4:DESCRIPTION; 5: TEST STATUS; 6: COLOR
log() {
  if [ "$1" -ge $UNITEX_TEST_VERBOSITY -a "$1" -le 7 ]; then
    {
      # Increment log level counter
      (( UNITEX_TEST_LOG_LEVEL_COUNTER[$1]++ ))

      # Increment the number of logged messages
      (( UNITEX_TEST_LOG_MESSAGE_COUNT++ ))

      # if test status is empty print the number of the message
      if [ ${#5} -eq 0 -a "$3" == "Executing" ]; then
        UNITEX_TEST_STATUS=$($UNITEX_TEST_TOOL_PRINTF "%0.4d" "$UNITEX_TEST_LOG_MESSAGE_COUNT")
      else
        UNITEX_TEST_STATUS="$5"
      fi

      if [ $UNITEX_TEST_USE_ANSI_COLORS -eq 1 ]; then
        # shellcheck disable=SC2059
        $UNITEX_TEST_TOOL_PRINTF "$UNITEX_TEST_LOG_FORMAT_COLOR" "$6" "$2" "$UNITEX_TEST_CONSOLE_RESET" "$6" "$UNITEX_TEST_STATUS" "$UNITEX_TEST_CONSOLE_RESET" "$3" "$4"
      else
        $UNITEX_TEST_TOOL_PRINTF "$UNITEX_TEST_LOG_FORMAT_NO_COLOR" "$2" "$UNITEX_TEST_STATUS" "$3" "$4"
      fi
    } >&3
  # log_none messages are not formatted, we send them directly to the STDOUT!
  elif [ "$1" -eq 8 ]; then
    echo "$3" >&3
  fi
}
# =============================================================================
# Create a temporary directory in $2 (or /tmp) prefixed by 'uct'
# and concatenate to a random sequence
create_temporal_directory() {
  local  __output_variable=$1
  local  __tmpdir="/tmp"

  # setup __tmpdir_argument
  if [ $# -ge 2 ]; then
     if [ -d "$2" ]; then
        local  __tmpdir="$2"
     else
        log_warn "Directory not found" "directory $2 doesn't exist"
    fi
  fi

  local  my_temporal_directory
  my_temporal_directory=$(mktemp -d --tmpdir="$__tmpdir"       \
       "uct"XXXXX) || {
        die_with_critical_error "Build error" "Failed to create a temporal directory in $my_temporal_directory";
  }

  # normalize path
  my_temporal_directory="$(readlink -f "$my_temporal_directory")"

  # shellcheck disable=SC2140
  eval "$__output_variable"="'$my_temporal_directory'"
}  # create_temporal_directory
# =============================================================================
# process command line
process_command_line() {
  # parse command line
  while getopts "M:R:c:p:v:h?" opt; do
      case "$opt" in
        M)  case $OPTARG in
               (*[!0-1]*|'') echo "./$UNITEX_TEST_SCRIPT_NAME: -M bad value. Valid values are [0-1]"  ;;
            esac
            UNITEX_TEST_MEMORY_ERRORS=$OPTARG
            ;;
        R)  case $OPTARG in
               (*[!0-1]*|'') echo "./$UNITEX_TEST_SCRIPT_NAME: -R bad value. Valid values are [0-1]"  ;;
            esac
            UNITEX_TEST_NON_REGRESSION=$OPTARG
            ;;
        c)  case $OPTARG in
               (*[!0-1]*|'') echo "./$UNITEX_TEST_SCRIPT_NAME: -c bad value. Valid values are [0-1]"  ;;
            esac
            UNITEX_TEST_USE_ANSI_COLORS=$OPTARG
            ;;
        p)  case $OPTARG in
               (*[!0-2]*|'') echo "./$UNITEX_TEST_SCRIPT_NAME: -p bad value. Valid values are [0...2]" ;;
            esac
            UNITEX_TEST_PRINT_EXECUTION_LOGS=$OPTARG
            ;;
        v)  case $OPTARG in
               (*[!0-7]*|'') echo "./$UNITEX_TEST_SCRIPT_NAME: -v bad value. Valid values are [0...7]" ;;
            esac
            UNITEX_TEST_VERBOSITY=$OPTARG
            ;;
        h|\?)
            usage
            ;;
      esac
  done

  shift $((OPTIND-1))

  [ "$1" = "--" ] && shift

  # the last argument would be a directory, a .ulp file or nothing
  if [ $# -gt 1 ]; then
    echo "./$UNITEX_TEST_SCRIPT_NAME: too many arguments"
    usage
  fi

  # if exists, the last argument is a directory or a .ulp file
  if [ $# -eq 1 ]; then
    UNITEX_TEST_TARGET="$(readlink -f "$1")"
  fi

  if   [ -d "$UNITEX_TEST_TARGET" ]; then
    UNITEX_TEST_FILES="$(find -L   "$UNITEX_TEST_TARGET"                           \
                        -not -name ".*"                                            \
                             -name "*$UNITEX_TEST_ULP_EXTENSION"                   \
                             -type f -print                                       |\
                         sort)"
  elif [ -f "$UNITEX_TEST_TARGET" ]; then
    case "$UNITEX_TEST_TARGET" in
      *$UNITEX_TEST_ULP_EXTENSION) UNITEX_TEST_FILES="$UNITEX_TEST_TARGET" ;;
      *)                           echo "Only $UNITEX_TEST_ULP_EXTENSION files are supported" &&\
                                   exit $UNITEX_TEST_DEFAULT_ERROR_CODE    ;;
    esac
  else
    echo "./$UNITEX_TEST_SCRIPT_NAME: bad argument: \"$1\""
    usage
  fi

  # count the number of characters on UNITEX_TEST_FILES
  UNITEX_TEST_FILES_SIZE=${#UNITEX_TEST_FILES}
  # check if there are tests to perform
  if [ "$UNITEX_TEST_FILES_SIZE" -eq 0 ]; then
    echo "Directory $UNITEX_TEST_TARGET doesn't contain any supported file (with $UNITEX_TEST_ULP_EXTENSION extension)"
    exit $UNITEX_TEST_DEFAULT_ERROR_CODE
  fi

  # UNITEX_BIN environment variable could overwrite UNITEX_TEST_TOOL_BIN
  if [ -n "${UNITEX_BIN+1}" ]; then
     # use the environment config
     UNITEX_TEST_TOOL_BIN="$UNITEX_BIN"
  fi

  # UNITEX_TEST_TOOL_BIN
  UNITEX_TEST_TOOL_BIN="$(readlink -f "$UNITEX_TEST_TOOL_BIN")"

  # if UnitexToolLogger doesn't exist
  if [ ! -e "$UNITEX_TEST_TOOL_BIN" ]; then
    echo "$(basename "$UNITEX_TEST_TOOL_BIN") not found"
    echo "try e.g. export UNITEX_BIN=/foo/bar/App/$(basename "$UNITEX_TEST_TOOL_BIN")"
    exit $UNITEX_TEST_DEFAULT_ERROR_CODE
  fi

  if [ "$UNITEX_TEST_MEMORY_ERRORS" -eq 1 ]; then
    command -v "${UNITEX_TEST_TOOL_VALGRIND}" > /dev/null ||\
    {
      echo "./$UNITEX_TEST_SCRIPT_NAME: $UNITEX_TEST_TOOL_VALGRIND not found"
      echo "  On OS-X, use brew install --HEAD valgrind"
      echo "  On Debian/Ubuntu, use apt-get install valgrind"
      echo "  On Fedora/RHEL, use yum install valgrind"
      echo "  To install Valgrind from sources check http://goo.gl/1Ccqxy"
      exit $UNITEX_TEST_DEFAULT_ERROR_CODE
    }
  fi
}  # function process_command_line()
# =============================================================================
# temporally save std output/error
push_streams() {
  # Save standard output(1->3) and standard error(2->4)
  exec 3>&1 4>&2
}  # function push_streams()
# =============================================================================
# Restore original outputs and close unused descriptors
pop_streams() {
  # Restore original stdout/stderr
  exec 1>&3 2>&4
  # Close the unused descriptors
  exec 3>&- 4>&-
}
# =============================================================================
# Redirect standart output to a file
# Never call logger functions or die_with_critical_error from here
redirect_stdout() {
  REDIRECT_TO_PARTIALNAME="$UNITEX_TEST_LOG_WORKSPACE/$1"

  if [ "$UNITEX_TEST_CURRENT_STDOUT" != \
       "$REDIRECT_TO_PARTIALNAME$UNITEX_TEST_LOG_FILE_EXT" ];then
    if [ -e "$REDIRECT_TO_PARTIALNAME$UNITEX_TEST_LOG_FILE_EXT" -a \
         -s "$REDIRECT_TO_PARTIALNAME$UNITEX_TEST_LOG_FILE_EXT" ] ; then
        FILENAME_SUFFIX_COUNTER=1
        while [[ -e $REDIRECT_TO_PARTIALNAME.$FILENAME_SUFFIX_COUNTER$UNITEX_TEST_LOG_FILE_EXT ]] ; do
            let FILENAME_SUFFIX_COUNTER++
        done
        REDIRECT_TO_PARTIALNAME=$REDIRECT_TO_PARTIALNAME.$FILENAME_SUFFIX_COUNTER
    fi

    # shellcheck disable=SC2034
    UNITEX_TEST_PREVIOUS_STDOUT="$UNITEX_TEST_CURRENT_STDOUT"
    UNITEX_TEST_CURRENT_STDOUT="$REDIRECT_TO_PARTIALNAME$UNITEX_TEST_LOG_FILE_EXT"
    # Redirect standard output to a log file
    exec 1> "$UNITEX_TEST_CURRENT_STDOUT"
  fi
}
# =============================================================================
# Redirect standart output and error to a file
redirect_std() {
  redirect_to_filename="$1"
  # Redirect standard output to a log file
  redirect_stdout "$redirect_to_filename"

  # Redirect standart error to the same log file
  exec 2>&1

  # Silent when NO_LOG_DEBUG is passed
  if [ $# -eq 1 ]; then
    log_debug "Streaming into" "$UNITEX_TEST_CURRENT_STDOUT"
  fi
}
# =============================================================================
# exec_logged_command "command_name" "command_args"
exec_logged_command() {
  # binary command name
  command_name="$1"
  shift

  # all the rest are parameters
  command_args="$*"

  # pretty_command_args
  # 1. anonymize passwords      (--password *****) and users (--username *****)
  # 2. anonymize mail addresses (foo-at-bar.com => foo-at-b**.com)
  # 3. anonymize paths          (foo/bar        => bar)
  pretty_command_args=$(echo "$command_args" |\
  sed 's%\(user\(name\)\?\|pass\(word\)\?\)\( \)\+\([^ ]\+\)%\1 ********%g' |\
  sed -e :a -e 's/@\([^* .][^* .]\)\(\**\)[^* .]\([^*]*\.[^* .]*\)$/@\1\2*\3/;ta' |\
  sed -e "s|$UNITEX_TEST_SCRIPT_BASEDIR/||g" )

  # test if command_name isn't empty
  if [ ! "$command_name" ]; then
     die_with_critical_error "Aborting" "Trying to execute empty command"
  fi

  # test if command exists
  command -v "$command_name" > /dev/null || \
  {
    die_with_critical_error "Aborting" "$command_name is required but it's not installed"
  }

  # redirect stdout and stderr to logfile
  # starting 1.4.0 redirect_std_name is defined here as
  redirect_std_name=$(printf "%0.3d_%s"                       \
                      "$((UNITEX_TEST_LOG_MESSAGE_COUNT+1))" \
                      "$(basename "$command_name")")
  # do not to use especial characters on the file name
  redirect_std_name="$($UNITEX_TEST_TOOL_PRINTF  "${redirect_std_name,,}" | sed -e 's/[^a-z0-9_-]/_/g')"
  redirect_std "$redirect_std_name"

  # create command line array
  command_line=( $command_name "$command_args" )

  MAX_COMMAND_LINE_LENGTH=119
  pretty_command_name=$(basename "$command_name")
  pretty_command_line=$($UNITEX_TEST_TOOL_PRINTF "$pretty_command_name $pretty_command_args" | \
                        cut -c 1-$MAX_COMMAND_LINE_LENGTH)

  if [[ ${#pretty_command_line} -ge $MAX_COMMAND_LINE_LENGTH ]]; then
    pretty_command_line="$pretty_command_line..."
  fi

  COMMAND_START_SECONDS=$(date +%s)
  COMMAND_TIMESTAMP_START_C="$(date -d now)"

  # command logging header
  echo "# Command Logging $COMMAND_TIMESTAMP_START_C"
  # shellcheck disable=SC2001
  echo "# $(echo "$UNITEX_TEST_CURRENT_STDOUT" | sed "s|$UNITEX_TEST_SCRIPT_BASEDIR/\?||g")"
  echo "# $pretty_command_name $pretty_command_args"

  # logging information
  log_notice "Executing" "$pretty_command_line"

  {
    # execute command
    eval "${command_line[@]}"

    # save return code
    exit_status=$?
  }

  # elapsed time
  COMMAND_END_SECONDS=$(date +%s)
  COMMAND_DIFF_SECONDS=$(( COMMAND_END_SECONDS - COMMAND_START_SECONDS ))
  COMMAND_ELAPSED_TIME=$($UNITEX_TEST_TOOL_PRINTF $COMMAND_DIFF_SECONDS | awk '{print strftime("%H:%M:%S", $1,1)}')

  # Increment command execution counter
  (( UNITEX_TEST_COMMAND_EXECUTION_COUNT++ ))

  # test return code
  if [ $exit_status -ne 0 ]; then
    log_debug "Error executing" "$pretty_command_line"
    echo      "# Finished with errors"
    echo      "# Return status : $exit_status"
    # Increment fail execution counter
    (( UNITEX_TEST_COMMAND_EXECUTION_ERROR_COUNT++ ))
  else
    echo      "# Successfully finished"
  fi

  # command logging footer
  echo "# Elapsed time  : $COMMAND_ELAPSED_TIME"

  # restore stdout and stderr
  if [ ! -z "$UNITEX_TEST_CURRENT_STAGE" ]; then
    # All untraced execution commands, i.e. not running thorough
    # exec_logged_command call, will be kept in an .untraced.log file
    redirect_std_name=$(printf "%s_%0.3d_%s"                    \
                      "untraced"                                \
                      "$((UNITEX_TEST_LOG_MESSAGE_COUNT + 1))"  \
                      "$command_name")
    redirect_std_name="$($UNITEX_TEST_TOOL_PRINTF  "${redirect_std_name,,}" | sed -e 's/[^a-z0-9_-]/_/g')"
    redirect_std "$redirect_std_name" NO_LOG_DEBUG
  fi

  # print the logged command execution if -p1 and errors or -p2
  if [[ ($exit_status -ne 0 && $UNITEX_TEST_PRINT_EXECUTION_LOGS -ge 1) ||\
        ($exit_status -eq 0 && $UNITEX_TEST_PRINT_EXECUTION_LOGS -ge 2) ]]; then
    cat "$UNITEX_TEST_CURRENT_STDOUT" >&3
  fi

  # return the status
  return $exit_status
}
# =============================================================================
unitex_tests_run() {
  UNITEX_TEST_HAS_ERRORS=0
  UNITEXTOOLLOGGER_EXECUTION_SUMMARY_FULLNAME="$UNITEX_TEST_LOG_WORKSPACE/execution_summary$UNITEX_TEST_LOG_FILE_EXT"
  UNITEXTOOLLOGGER_EXECUTION_SUMMARY_FILENAME=$(basename "$UNITEXTOOLLOGGER_EXECUTION_SUMMARY_FULLNAME")
  UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME="$UNITEX_TEST_LOG_WORKSPACE/error_summary$UNITEX_TEST_LOG_FILE_EXT"
  UNITEXTOOLLOGGER_ERROR_SUMMARY_FILENAME=$(basename "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME")

  # non-regression tests
  if [ "$UNITEX_TEST_NON_REGRESSION" -eq 1 ]; then
    log_info "Running logs" "Preparing to replay all ULPs files"
    while read -r i ; do
      log_debug "Running" "$i"
      UNITEX_TEST_CURRENT_TEST_NAME=$(basename "$i")
      RUNLOG_EXECUTION_FAIL=0
      RUNLOG_EXIT_STATUS=0
      exec_logged_command "$UNITEX_TEST_TOOL_BIN"                              \
                          RunLog "\"$i\""                                      \
                          -s "$UNITEXTOOLLOGGER_EXECUTION_SUMMARY_FULLNAME"    \
                          -e "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once"   \
                          --cleanlog || {
                            # save return code
                            RUNLOG_EXIT_STATUS=$?
                            RUNLOG_EXECUTION_FAIL=1
                          }
      if [ $RUNLOG_EXECUTION_FAIL -ne 0 ]; then
        # RunLog warning return code is equal to 79
        if   [  $RUNLOG_EXIT_STATUS -eq $UNITEX_TEST_RUNLOG_WARNING_CODE ]; then
          log_warn  "Warning detected" "RunLog detected a warning while replaying $UNITEX_TEST_CURRENT_TEST_NAME" "WARN"
        # RunLog error return code is equal to 80
        elif [  $RUNLOG_EXIT_STATUS -eq $UNITEX_TEST_RUNLOG_COMPARE_ERROR_CODE ]; then
          log_error "Regression detected" "RunLog detected a regression while replaying $UNITEX_TEST_CURRENT_TEST_NAME" "FAIL"
          UNITEX_TEST_HAS_ERRORS=1
        else
          log_error "Error detected" "RunLog detected an error while replaying $UNITEX_TEST_CURRENT_TEST_NAME" "FAIL"
          UNITEX_TEST_HAS_ERRORS=1
        fi
      else
        log_notice  "Successful execution" "RunLog does not detect any regression while replaying $UNITEX_TEST_CURRENT_TEST_NAME" "PASS"
      fi

      if [ -f "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once" ]; then
        UNITEX_TEST_HAS_ERRORS=1
        cat   "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once" >> "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME"
        rm -f "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once"
      fi
    done < <(echo "$UNITEX_TEST_FILES")
  fi  # if [ "$UNITEX_TEST_NON_REGRESSION" -eq 1 ]; then

  # memcheck + non-regression tests
  if [ $UNITEX_TEST_HAS_ERRORS      -eq 0 -a \
       "$UNITEX_TEST_MEMORY_ERRORS" -eq 1 ]; then
    log_info "Running Valgrind" "Preparing to replay all ULPs files using Valgrind"
    while read -r i ; do
      log_debug "Running valgrind" "$i"
      UNITEX_TEST_CURRENT_TEST_NAME=$(basename "$i")
      VALGRIND_LOG_NAME=$(basename "$i" | sed -e 's/[^A-Za-z0-9_-]/_/g')
      VALGRIND_LOG_FULLNAME="$UNITEX_TEST_LOG_WORKSPACE/valgrind.$VALGRIND_LOG_NAME$UNITEX_TEST_LOG_FILE_EXT"
      VALGRIND_EXECUTION_FAIL=0
      # save valgrind return code
      VALGRIND_EXIT_STATUS=0
      exec_logged_command "$UNITEX_TEST_TOOL_VALGRIND"                                \
                          --tool=memcheck                                             \
                          --error-exitcode=$UNITEX_TEST_MEMORY_ERROR_CODE             \
                          --leak-check=full                                           \
                          --vex-iropt-level=1                                         \
                          --show-reachable=yes                                        \
                          --track-origins=yes                                         \
                          "$UNITEX_TEST_TOOL_BIN"                                     \
                          RunLog "\"$i\""                                             \
                          -s "$UNITEXTOOLLOGGER_EXECUTION_SUMMARY_FULLNAME"           \
                          -e "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once"          \
                          --cleanlog || {
                            VALGRIND_EXIT_STATUS=$?
                            VALGRIND_EXECUTION_FAIL=1
                          }

      if [ $VALGRIND_EXECUTION_FAIL -ne 0 ]; then
        # Valgrind memcheck return code is equal to 66
        if [  $VALGRIND_EXIT_STATUS -eq $UNITEX_TEST_MEMORY_ERROR_CODE ]; then
          log_error "Memory error" "Valgrind detect a memory error when replaying $UNITEX_TEST_CURRENT_TEST_NAME" "FAIL"
        else
          log_error "Regression detected" "RunLog detected a regression while replaying $UNITEX_TEST_CURRENT_TEST_NAME with Valgrind" "FAIL"
        fi
        UNITEX_TEST_HAS_ERRORS=1
      else
        log_notice  "Successful execution" "Valgrind does not detect any memory errors replaying $UNITEX_TEST_CURRENT_TEST_NAME" "PASS"
        rm -f "$VALGRIND_LOG_FULLNAME"
      fi

      if [ -f "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once" ]; then
        log_warn  "Regression detected" "RunLog under Valgrind detected a regression while replaying $UNITEX_TEST_CURRENT_TEST_NAME" "FAIL"
        UNITEX_TEST_HAS_ERRORS=1
        cat   "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once" >> "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME"
        rm -f "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME.once"
      else
        log_debug  "Successful execution"  "RunLog under Valgrind does not detect any regression while replaying $UNITEX_TEST_CURRENT_TEST_NAME"
      fi
    done < <(echo "$UNITEX_TEST_FILES")  # for i in "$UNITEX_TEST_TARGET"
  fi  # $UNITEX_TEST_HAS_ERRORS -eq 0 "$UNITEX_TEST_MEMORY_ERRORS" -eq 1

  if [ -e "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME" -a \
       -s "$UNITEXTOOLLOGGER_ERROR_SUMMARY_FULLNAME" ]; then
    log_warn "Regressions detected" \
             "Some regression tests did not complete successfully, see $UNITEX_TEST_LOG_RELATIVE_WORKSPACE/$UNITEXTOOLLOGGER_ERROR_SUMMARY_FILENAME for more details"
  else
    log_info "No regression" \
             "All logs were successfully replayed, see $UNITEX_TEST_LOG_RELATIVE_WORKSPACE/$UNITEXTOOLLOGGER_EXECUTION_SUMMARY_FILENAME for more details"
  fi
}  # function stage_unitex_core_logs_run()
# =============================================================================
# print log header
log_header() {
  {
    echo -e "# $UNITEX_TEST_CODENAME $TIMESTAMP_START_C\n"                     \
            "\r# Markers:\n"                                                   \
            "\r# (%%) debug, (II) information, (!!) notice,   (WW) warning,\n" \
            "\r# (EE) error, (CC) critical,    (^^) alert,    (@@) panic"
  } >&3
  if [ -n "${UNITEX_CORE_GIT_REVISION+1}" ]; then
     log_info "Unitex Core" "$UNITEX_CORE_REPOSITORY/commit/$UNITEX_CORE_GIT_REVISION"
  else
   log_info "Unitex Core" "$($UNITEX_BIN VersionInfo -s)"
  fi
  log_info "Unitex Core Tests"   "$UNITEX_TEST_REPOSITORY/commit/$(git describe --always HEAD)"
}
# =============================================================================
# create a temporal workspace
create_temporal_workspace() {
  mkdir -p "$UNITEX_TEST_SCRIPT_BASEDIR/$UNITEX_TEST_LOG_FILE_EXT"
  create_temporal_directory UNITEX_TEST_LOG_WORKSPACE "$UNITEX_TEST_SCRIPT_BASEDIR/$UNITEX_TEST_LOG_FILE_EXT"
  if [ ! -d "$UNITEX_TEST_LOG_WORKSPACE" ]; then
    die_with_critical_error "Unrecoverable error" "Error creating temporal workspace directory"
  fi
  UNITEX_TEST_LOG_RELATIVE_WORKSPACE=$($UNITEX_TEST_TOOL_PRINTF "$UNITEX_TEST_LOG_WORKSPACE" |\
                                       sed -e "s|$UNITEX_TEST_SCRIPT_BASEDIR/||g" )
}
# =============================================================================
# main
# =============================================================================
# create a temporal workspace
create_temporal_workspace

# process command line arguments in $@
process_command_line "$@"

# check minimal allowed bash version
check_bash_version

# push streams
push_streams

# install interrupt (INT) and terminate (TERM) traps
setup_script_traps

# print log header
log_header

# run tests
unitex_tests_run

# clean exit
clean_exit

error: pathspec 'unitex-core-test.sh' did not match any file(s) known to git


add updateDocsFolder script

add updateDocsFolder script

and a hook that calls it

Signed-off-by: Ryan1729 <94d48eb26deaf2479098821c91f188298c441e83@gmail.com>

#!/bin/bash

cp index.html ./docs

cp *.js ./docs

cp -r sounds ./docs

echo "docs/ updated"

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


hack: make.sh: remove not used function

hack: make.sh: remove not used function

Signed-off-by: Antonio Murdaca <f9809039ea4850e75dcb8d80b778844aa463358f@redhat.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/'


19: removeFromBintray.sh

19: removeFromBintray.sh

Task-Url: https://github.com/LorenzoBettini/jbase/issues/issue/19

#!/bin/bash
# remove p2 metadata artifacts from bintray remote path
#Sample Usage: removeFromBintray.sh apikey remotePath
API=https://api.bintray.com

BINTRAY_API_KEY=$1
PATH_TO_REPOSITORY=$2

BINTRAY_USER=lorenzobettini
BINTRAY_REPO=xtext-jbase

function main() {
remove_p2_metadata
}

function remove_p2_metadata() {
echo "${BINTRAY_USER}"
echo "${BINTRAY_API_KEY}"
echo "${BINTRAY_REPO}"
echo "${PCK_NAME}"
echo "${PCK_VERSION}"
echo "${PATH_TO_REPOSITORY}"

echo "Removing metadata content.jar..."
curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/content.jar"
echo ""
echo "Removing metadata artifacts.jar..."
curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/artifacts.jar"
echo ""
echo "Removing metadata compositeContent.xml..."
curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/compositeContent.xml"
echo ""
echo "Removing metadata compositeArtifacts.xml..."
curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/compositeArtifacts.xml"
echo ""
echo "Removing metadata p2.index..."
curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BINTRAY_USER}/${BINTRAY_REPO}/${PATH_TO_REPOSITORY}/p2.index"
echo ""

}

main "$@"

error: pathspec 'jbase.parent/tools/removeFromBintray.sh' did not match any file(s) known to git


Add Aliases

Add Aliases

#!/usr/bin/env bash
#
#   Aliases for generic commands
#
#   Author: Thierry 'Epagneul' Lagasse <epagneul@dogstudio.be>
#   Since: Apr 2015
#
# -----------------------------------------------------------------------------

alias ls='ls -G'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

alias l='clear; ls -la'
alias duh='du -hs'
alias tree="find . | sed 's/[^/]*\//|   /g;s/| *\([^| ]\)/+--- \1/'"
alias wget="wget -c"

alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'

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


Initial configuration for installing into presets

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/PhasesResearchLab/install-atomate.git/'


Add gvm full install if missing

Add gvm full install if missing

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/ernestas-poskus/dot13.git/'


Add aliases to homebrew

Add aliases to homebrew

if [[ "$OSTYPE" != (darwin)* ]]; then
  return 1
fi

#------------------------------------------------
# Aliases
#------------------------------------------------

# Homebrew
alias brewc='brew cleanup'
alias brewC='brew cleanup --force'
alias brewi='brew install'
alias brewl='brew list'
alias brews='brew search'
alias brewu='brew update && brew upgrade --all'
alias brewx='brew remove'

# Homebrew Cask
alias cask='brew cask'
alias caskc='brew cask cleanup --outdated'
alias caskC='brew cask cleanup'
alias caski='brew cask install'
alias caskl='brew cask list'
alias casks='brew cask search'
alias caskx='brew cask uninstall'

error: pathspec 'zsh/modules/homebrew.zsh' did not match any file(s) known to git


Add support for one mandatory positional argument (for action: add or index)

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/matrey/historize.git/'


Create setup-heroku.sh script

Create setup-heroku.sh script

#!/bin/bash
git remote add heroku https://git.heroku.com/api-hackclub.git
wget https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz
sudo mkdir -p /usr/local/lib /usr/local/bin
sudo tar -xvzf heroku-linux-amd64.tar.gz -C /usr/local/lib
sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku

cat > ~/.netrc << EOF
machine api.heroku.com
  login $HEROKU_LOGIN
  password $HEROKU_API_KEY
machine git.heroku.com
  login $HEROKU_LOGIN
  password $HEROKU_API_KEY
EOF

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


iwyu: add a build script

iwyu: add a build script

#!/bin/bash -ex

# cmake prefix path is meant to be valid in a Travis env

git pull -r
mkdir -p workdir
cd workdir
cmake \
    -G 'Unix Makefiles' \
    -DCMAKE_INSTALL_PREFIX=$PWD/../instdir \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7 \
    ..
make -j8
make install

# vim:set shiftwidth=4 expandtab:

error: pathspec 'include-what-you-use/up.sh' did not match any file(s) known to git


Update install.sh

Update install.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/bugra9/test.git/'


Small script to loop the tests.

Small script to loop the tests.

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


Script for starting tmux with detached session

#!/bin/sh

SESSION=$1
if [ "X$1" -eq "X" ]; then
    SESSION=$USER
fi

if tmux has-session -t $SESSION; then
    tmux attach -t $SESSION
fi

tmux new-session -s $SESSION

error: pathspec 'bin/start-tmux.sh' did not match any file(s) known to git


加入bing-wallpaper.sh

加入bing-wallpaper.sh

#!/usr/bin/env bash

readonly SCRIPT=$(basename "$0")
readonly VERSION='0.1.1'

usage() {
cat <<EOF
Usage:
  $SCRIPT [options]
  $SCRIPT -h | --help
  $SCRIPT --version

Options:
  -f --force                     Force download of picture. This will overwrite
                                 the picture if the filename already exists.
  -s --ssl                       Communicate with bing.com over SSL.
  -q --quiet                     Do not display log messages.
  -n --filename <file name>      The name of the downloaded picture. Defaults to
                                 the upstream name.
  -p --picturedir <picture dir>  The full path to the picture download dir.
                                 Will be created if it does not exist.
                                 [default: $HOME/Pictures/bing-wallpapers/]
  -h --help                      Show this screen.
  --version                      Show version.
EOF
}

print_message() {
    if [ ! "$QUIET" ]; then
        printf "%s\n" "${1}"
    fi
}

# Defaults
PICTURE_DIR="$HOME/Pictures/bing-wallpapers/"

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

    case $key in
        -p|--picturedir)
            PICTURE_DIR="$2"
            shift
            ;;
        -n|--filename)
            FILENAME="$2"
            shift
            ;;
        -f|--force)
            FORCE=true
            ;;
        -s|--ssl)
            SSL=true
            ;;
        -q|--quiet)
            QUIET=true
            ;;
        -h|--help)
            usage
            exit 0
            ;;
        --version)
            printf "%s\n" $VERSION
            exit 0
            ;;
        *)
            (>&2 printf "Unknown parameter: %s\n" "$1")
            usage
            exit 1
            ;;
    esac
    shift
done

# Set options
[ $QUIET ] && CURL_QUIET='-s'
[ $SSL ]   && PROTO='https'   || PROTO='http'

# Create picture directory if it doesn't already exist
mkdir -p "${PICTURE_DIR}"

# Parse bing.com and acquire picture URL(s)
urls=( $(curl -sL $PROTO://www.bing.com | \
    grep -Eo "url:'.*?'" | \
    sed -e "s/url:'\([^']*\)'.*/$PROTO:\/\/bing.com\1/" | \
    sed -e "s/\\\//g") )

for p in "${urls[@]}"; do
    if [ -z "$FILENAME" ]; then
        filename=$(echo "$p"|sed -e "s/.*\/\(.*\)/\1/")
    else
        filename="$FILENAME"
    fi
    if [ $FORCE ] || [ ! -f "$PICTURE_DIR/$filename" ]; then
        print_message "Downloading: $filename..."
        curl $CURL_QUIET -Lo "$PICTURE_DIR/$filename" "$p"
    else
        print_message "Skipping: $filename..."
    fi
done

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


Log env of each build; fix package -> pkgname when grepping for md5s.

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/cryptarch/linux-from-scratch.git/'


empty shell file for test implementation

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


lib.bash: tone down the log prefix

lib.bash: tone down the log prefix

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/grawity/hacks.git/'


get default HDFS_URI from settings.py

get default HDFS_URI from settings.py

#!/bin/bash

HDFS_DIR="/user/bigdata/SSCI/"
# HDFS_URI="hdfs://xd-namenode.xdata.data-tactics-corp.com:8020/"
HDFS_URI="$(python -c 'import tabular_predDB.settings as S; print S.Hadoop.default_hdfs_uri')"

# print script usage
usage() {
    cat <<EOF
usage: $0 options

    VMware automation functions

    OPTIONS:
    -h      Show this message
    -b      WHICH_BINARY=$WHICH_BINARY
    -d      HDFS_DIR=$HDFS_DIR
    -u      HDFS_URI=$HDFS_URI
EOF
exit
}

#Process the arguments
while getopts hb:d:u: opt
do
    case "$opt" in
        h) usage;;
        b) WHICH_BINARY=$OPTARG;;
	d) HDFS_DIR=$OPTARG;;
        u) HDFS_URI=$OPTARG;;
    esac
done

# determine if VPN exists
get_vpn_status() {
    this_dir="$(dirname $0)"
    rel_dir="$this_dir/../python_utils/"
    echo "$(python ${rel_dir}/xnet_utils.py assert_vpn_is_connected)"
}

# make sure you can get to XNET
assert_vpn_status() {
    vpn_status=$(get_vpn_status)
    if [[ ! -z $(get_vpn_status) ]]; then
        echo "!!!!!!!"
        echo "Can't detect VPN connection"
        echo "Connect to VPN with: sudo vpnc-connect"
        echo "EXITING without sending!!!"
        echo "!!!!!!!"
        exit
    fi
}

# make sure you know what to call the jar file
if [[ -z $WHICH_BINARY ]]; then
    echo "USAGE: bash build_and_push.sh -b <WHICH_BINARY>"
    echo "WHICH_BINARY is a required argument!!!"
    echo "EXITING without sending!!!"
    exit
fi

# setup
this_dir="$(dirname $(readlink -f $0))"
CODE_REL_DIR="$this_dir/../.."
export PYTHONPATH=$CODE_REL_DIR:$PYTHONPATH

# create binary
cd $CODE_REL_DIR/tabular_predDB/binary_creation
rm -rf build
python setup.py build >build.out 2>build.err
# FIXME: find a better way to do this; works on 20130307 VM to use on XDATA cluster
LARGEST_LAPACK_LITE=$(locate lapack_lite | xargs ls -al | sort -k 4 | head -n 1 | awk '{print $NF}')
if [[ ! -z $LARGEST_LAPACK_LITE ]]; then
    TARGET_LAPACK_LITE=build/exe.linux-x86_64-2.7/numpy.linalg.lapack_lite.so
    cp $LARGEST_LAPACK_LITE $TARGET_LAPACK_LITE
fi
(cd build/exe.linux-x86_64-2.7 && jar cvf ../../${WHICH_BINARY}.jar *)

# prep HDFS
hadoop fs -fs "$HDFS_URI" -rm "${HDFS_DIR}"${WHICH_BINARY}.jar
hadoop fs -fs "$HDFS_URI" -mkdir "${HDFS_DIR}"
hadoop fs -fs "$HDFS_URI" -put ${WHICH_BINARY}.jar "${HDFS_DIR}"

#!/bin/bash

HDFS_DIR="/user/bigdata/SSCI/"
# HDFS_URI="hdfs://xd-namenode.xdata.data-tactics-corp.com:8020/"
HDFS_URI="hdfs://10.1.93.51:8020/"

# print script usage
usage() {
    cat <<EOF
usage: $0 options

    VMware automation functions

    OPTIONS:
    -h      Show this message
    -b      WHICH_BINARY=$WHICH_BINARY
    -d      HDFS_DIR=$HDFS_DIR
    -u      HDFS_URI=$HDFS_URI
EOF
exit
}

#Process the arguments
while getopts hb:d:u: opt
do
    case "$opt" in
        h) usage;;
        b) WHICH_BINARY=$OPTARG;;
	d) HDFS_DIR=$OPTARG;;
        u) HDFS_URI=$OPTARG;;
    esac
done

# determine if VPN exists
get_vpn_status() {
    this_dir="$(dirname $0)"
    rel_dir="$this_dir/../python_utils/"
    echo "$(python ${rel_dir}/xnet_utils.py assert_vpn_is_connected)"
}

# make sure you can get to XNET
assert_vpn_status() {
    vpn_status=$(get_vpn_status)
    if [[ ! -z $(get_vpn_status) ]]; then
        echo "!!!!!!!"
        echo "Can't detect VPN connection"
        echo "Connect to VPN with: sudo vpnc-connect"
        echo "EXITING without sending!!!"
        echo "!!!!!!!"
        exit
    fi
}

# make sure you know what to call the jar file
if [[ -z $WHICH_BINARY ]]; then
    echo "USAGE: bash build_and_push.sh -b <WHICH_BINARY>"
    echo "WHICH_BINARY is a required argument!!!"
    echo "EXITING without sending!!!"
    exit
fi

# setup
this_dir="$(dirname $(readlink -f $0))"
CODE_REL_DIR="$this_dir/../.."
export PYTHONPATH=$CODE_REL_DIR:$PYTHONPATH

# create binary
cd $CODE_REL_DIR/tabular_predDB/binary_creation
rm -rf build
python setup.py build >build.out 2>build.err
# FIXME: find a better way to do this; works on 20130307 VM to use on XDATA cluster
LARGEST_LAPACK_LITE=$(locate lapack_lite | xargs ls -al | sort -k 4 | head -n 1 | awk '{print $NF}')
if [[ ! -z $LARGEST_LAPACK_LITE ]]; then
    TARGET_LAPACK_LITE=build/exe.linux-x86_64-2.7/numpy.linalg.lapack_lite.so
    cp $LARGEST_LAPACK_LITE $TARGET_LAPACK_LITE
fi
(cd build/exe.linux-x86_64-2.7 && jar cvf ../../${WHICH_BINARY}.jar *)

# prep HDFS
hadoop fs -fs "$HDFS_URI" -rm "${HDFS_DIR}"${WHICH_BINARY}.jar
hadoop fs -fs "$HDFS_URI" -mkdir "${HDFS_DIR}"
hadoop fs -fs "$HDFS_URI" -put ${WHICH_BINARY}.jar "${HDFS_DIR}"


src: add race.bash

src: add race.bash

Add race.bash so anyone with suitable hardware can run a race detector build. race.bash can be called from the dashboard builder by passing -cmd="race.bash".

Original source for race.bash is here, http://code.google.com/p/go-wiki/wiki/DashboardBuilders

TODO: add race.bat for windows/amd64

R=dvyukov, minux.ma, adg, rsc
CC=fullung, golang-dev
https://golang.org/cl/7179052

#!/usr/bin/env bash
# Copyright 2013 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# race.bash tests the standard library under the race detector.
# http://golang.org/doc/articles/race_detector.html

set -e

function usage {
	echo 'race detector is only supported on linux/amd64 and darwin/amd64' 1>&2
	exit 1
}

case $(uname) in
"Darwin")
	# why Apple? why?
	if sysctl machdep.cpu.extfeatures | grep -qv EM64T; then
		usage
	fi
	;;
"Linux")
	if [ $(uname -m) != "x86_64" ]; then
		usage
	fi
	;;
*)
	usage
	;;
esac

if [ ! -f make.bash ]; then
	echo 'race.bash must be run from $GOROOT/src' 1>&2
	exit 1
fi
. ./make.bash --no-banner
go install -race std
go test -race -short std
go test -race -run=nothingplease -bench=.* -benchtime=.1s -cpu=4 std

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


chore: ncu update

chore: ncu update

#!/usr/bin/env sh

# this sh is to upgrade all package dependencies from NPM
# you need to install before: npm i -g npm-check-updates

rm package-lock.json

npm cache verify

npm outdated --depth=0

ncu -u

npm i

npm i --only=dev

npm install

npm test

npm run build

#!/usr/bin/env sh

# this sh is to upgrade all package dependencies from NPM
# you need to install before: npm i -g npm-check-updates

rm package-lock.json

npm cache verify

npm outdated --depth=0

ncu -u -m

npm install

npm test

npm run build


add initial npm config for saving global deps

#!/usr/bin/env bash

npm install -g create-react-app
npm install -g create-react-native-app
npm install -g depcheck
npm install -g flow-bin
npm install -g webpack

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


Support rvm

Support rvm

if [[ -s $HOME/.rvm/scripts/rvm ]]; then
    source "$HOME/.rvm/scripts/rvm"
    export PATH="$PATH:$HOME/.rvm/bin"

    if [[ -e $HOME/.rvm/bin/rvm-prompt ]]; then
        export RPROMPT="\$($HOME/.rvm/bin/rvm-prompt)"
    fi

fi

error: pathspec 'lib/zsh.d/rvm.zsh' did not match any file(s) known to git