[FAB-5195] byfn.sh help text is incorrect

The descriptions for "down" and "restart" are the same as "up".
This patch set changes the descriptions.

Change-Id: I0ee03e5d81faa4ad6a3c43354e8a44648288df90
Signed-off-by: Nao Nishijima <ba12c351dbe96870a968dc0b0668a4a809432a94@hal.hitachi.com>

#!/bin/bash

# This script will orchestrate a sample end-to-end execution of the Hyperledger
# Fabric network.
#
# The end-to-end verification provisions a sample Fabric network consisting of
# two organizations, each maintaining two peers, and a “solo” ordering service.
#
# This verification makes use of two fundamental tools, which are necessary to
# create a functioning transactional network with digital signature validation
# and access control:
#
# * cryptogen - generates the x509 certificates used to identify and
#   authenticate the various components in the network.
# * configtxgen - generates the requisite configuration artifacts for orderer
#   bootstrap and channel creation.
#
# Each tool consumes a configuration yaml file, within which we specify the topology
# of our network (cryptogen) and the location of our certificates for various
# configuration operations (configtxgen).  Once the tools have been successfully run,
# we are able to launch our network.  More detail on the tools and the structure of
# the network will be provided later in this document.  For now, let's get going...

# prepending $PWD/../bin to PATH to ensure we are picking up the correct binaries
# this may be commented out to resolve installed version of tools if desired
export PATH=${PWD}/../bin:${PWD}:$PATH
export FABRIC_CFG_PATH=${PWD}

# Print the usage message
function printHelp () {
  echo "Usage: "
  echo "  byfn.sh -m up|down|restart|generate [-c <channel name>] [-t <timeout>]"
  echo "  byfn.sh -h|--help (print this message)"
  echo "    -m <mode> - one of 'up', 'down', 'restart' or 'generate'"
  echo "      - 'up' - bring up the network with docker-compose up"
  echo "      - 'down' - clear the network with docker-compose down"
  echo "      - 'restart' - restart the network"
  echo "      - 'generate' - generate required certificates and genesis block"
  echo "    -c <channel name> - channel name to use (defaults to \"mychannel\")"
  echo "    -t <timeout> - CLI timeout duration in microseconds (defaults to 10000)"
  echo
  echo "Typically, one would first generate the required certificates and "
  echo "genesis block, then bring up the network. e.g.:"
  echo
  echo "	byfn.sh -m generate -c <channelname>"
  echo "	byfn.sh -m up -c <channelname>"
  echo "	byfn.sh -m down -c <channelname>"
  echo
  echo "Taking all defaults:"
  echo "	byfn.sh -m generate"
  echo "	byfn.sh -m up"
  echo "	byfn.sh -m down"
}

# Ask user for confirmation to proceed
function askProceed () {
  read -p "Continue (y/n)? " ans
  case "$ans" in
    y|Y )
      echo "proceeding ..."
    ;;
    n|N )
      echo "exiting..."
      exit 1
    ;;
    * )
      echo "invalid response"
      askProceed
    ;;
  esac
}

# Obtain CONTAINER_IDS and remove them
# TODO Might want to make this optional - could clear other containers
function clearContainers () {
  CONTAINER_IDS=$(docker ps -aq)
  if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
    echo "---- No containers available for deletion ----"
  else
    docker rm -f $CONTAINER_IDS
  fi
}

# Delete any images that were generated as a part of this setup
# specifically the following images are often left behind:
# TODO list generated image naming patterns
function removeUnwantedImages() {
  DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}')
  if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
    echo "---- No images available for deletion ----"
  else
    docker rmi -f $DOCKER_IMAGE_IDS
  fi
}

# Generate the needed certificates, the genesis block and start the network.
function networkUp () {
  # generate artifacts if they don't exist
  if [ ! -d "crypto-config" ]; then
    generateCerts
    replacePrivateKey
    generateChannelArtifacts
  fi
  CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1
  if [ $? -ne 0 ]; then
    echo "ERROR !!!! Unable to start network"
    docker logs -f cli
    exit 1
  fi
  docker logs -f cli
}

# Tear down running network
function networkDown () {
  docker-compose -f $COMPOSE_FILE down
  # Don't remove containers, images, etc if restarting
  if [ "$MODE" != "restart" ]; then
    #Cleanup the chaincode containers
    clearContainers
    #Cleanup images
    removeUnwantedImages
    # remove orderer block and other channel configuration transactions and certs
    rm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config
    # remove the docker-compose yaml file that was customized to the example
    rm -f docker-compose-e2e.yaml
  fi
}

# Using docker-compose-e2e-template.yaml, replace constants with private key file names
# generated by the cryptogen tool and output a docker-compose.yaml specific to this
# configuration
function replacePrivateKey () {
  # sed on MacOSX does not support -i flag with a null extension. We will use
  # 't' for our back-up's extension and depete it at the end of the function
  ARCH=`uname -s | grep Darwin`
  if [ "$ARCH" == "Darwin" ]; then
    OPTS="-it"
  else
    OPTS="-i"
  fi

  # Copy the template to the file that will be modified to add the private key
  cp docker-compose-e2e-template.yaml docker-compose-e2e.yaml

  # The next steps will replace the template's contents with the
  # actual values of the private key file names for the two CAs.
  CURRENT_DIR=$PWD
  cd crypto-config/peerOrganizations/org1.example.com/ca/
  PRIV_KEY=$(ls *_sk)
  cd $CURRENT_DIR
  sed $OPTS "s/CA1_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml
  cd crypto-config/peerOrganizations/org2.example.com/ca/
  PRIV_KEY=$(ls *_sk)
  cd $CURRENT_DIR
  sed $OPTS "s/CA2_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml
  # If MacOSX, remove the temporary backup of the docker-compose file
  if [ "$ARCH" == "Darwin" ]; then
    rm docker-compose-e2e.yamlt
  fi
}

# We will use the cryptogen tool to generate the cryptographic material (x509 certs)
# for our various network entities.  The certificates are based on a standard PKI
# implementation where validation is achieved by reaching a common trust anchor.
#
# Cryptogen consumes a file - ``crypto-config.yaml`` - that contains the network
# topology and allows us to generate a library of certificates for both the
# Organizations and the components that belong to those Organizations.  Each
# Organization is provisioned a unique root certificate (``ca-cert``), that binds
# specific components (peers and orderers) to that Org.  Transactions and communications
# within Fabric are signed by an entity's private key (``keystore``), and then verified
# by means of a public key (``signcerts``).  You will notice a "count" variable within
# this file.  We use this to specify the number of peers per Organization; in our
# case it's two peers per Org.  The rest of this template is extremely
# self-explanatory.
#
# After we run the tool, the certs will be parked in a folder titled ``crypto-config``.

# Generates Org certs using cryptogen tool
function generateCerts (){
  which cryptogen
  if [ "$?" -ne 0 ]; then
    echo "cryptogen tool not found. exiting"
    exit 1
  fi
  echo
  echo "##########################################################"
  echo "##### Generate certificates using cryptogen tool #########"
  echo "##########################################################"

  cryptogen generate --config=./crypto-config.yaml
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate certificates..."
    exit 1
  fi
  echo
}

# The `configtxgen tool is used to create four artifacts: orderer **bootstrap
# block**, fabric **channel configuration transaction**, and two **anchor
# peer transactions** - one for each Peer Org.
#
# The orderer block is the genesis block for the ordering service, and the
# channel transaction file is broadcast to the orderer at channel creation
# time.  The anchor peer transactions, as the name might suggest, specify each
# Org's anchor peer on this channel.
#
# Configtxgen consumes a file - ``configtx.yaml`` - that contains the definitions
# for the sample network. There are three members - one Orderer Org (``OrdererOrg``)
# and two Peer Orgs (``Org1`` & ``Org2``) each managing and maintaining two peer nodes.
# This file also specifies a consortium - ``SampleConsortium`` - consisting of our
# two Peer Orgs.  Pay specific attention to the "Profiles" section at the top of
# this file.  You will notice that we have two unique headers. One for the orderer genesis
# block - ``TwoOrgsOrdererGenesis`` - and one for our channel - ``TwoOrgsChannel``.
# These headers are important, as we will pass them in as arguments when we create
# our artifacts.  This file also contains two additional specifications that are worth
# noting.  Firstly, we specify the anchor peers for each Peer Org
# (``peer0.org1.example.com`` & ``peer0.org2.example.com``).  Secondly, we point to
# the location of the MSP directory for each member, in turn allowing us to store the
# root certificates for each Org in the orderer genesis block.  This is a critical
# concept. Now any network entity communicating with the ordering service can have
# its digital signature verified.
#
# This function will generate the crypto material and our four configuration
# artifacts, and subsequently output these files into the ``channel-artifacts``
# folder.
#
# If you receive the following warning, it can be safely ignored:
#
# [bccsp] GetDefault -> WARN 001 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
#
# You can ignore the logs regarding intermediate certs, we are not using them in
# this crypto implementation.

# Generate orderer genesis block, channel configuration transaction and
# anchor peer update transactions
function generateChannelArtifacts() {
  which configtxgen
  if [ "$?" -ne 0 ]; then
    echo "configtxgen tool not found. exiting"
    exit 1
  fi

  echo "##########################################################"
  echo "#########  Generating Orderer Genesis block ##############"
  echo "##########################################################"
  # Note: For some unknown reason (at least for now) the block file can't be
  # named orderer.genesis.block or the orderer will fail to launch!
  configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate orderer genesis block..."
    exit 1
  fi
  echo
  echo "#################################################################"
  echo "### Generating channel configuration transaction 'channel.tx' ###"
  echo "#################################################################"
  configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate channel configuration transaction..."
    exit 1
  fi

  echo
  echo "#################################################################"
  echo "#######    Generating anchor peer update for Org1MSP   ##########"
  echo "#################################################################"
  configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate anchor peer update for Org1MSP..."
    exit 1
  fi

  echo
  echo "#################################################################"
  echo "#######    Generating anchor peer update for Org2MSP   ##########"
  echo "#################################################################"
  configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate \
  ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate anchor peer update for Org2MSP..."
    exit 1
  fi
  echo
}

# Obtain the OS and Architecture string that will be used to select the correct
# native binaries for your platform
OS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
# timeout duration - the duration the CLI should wait for a response from
# another container before giving up
CLI_TIMEOUT=10000
# channel name defaults to "mychannel"
CHANNEL_NAME="mychannel"
# use this as the default docker-compose yaml definition
COMPOSE_FILE=docker-compose-cli.yaml

# Parse commandline args
while getopts "h?m:c:t:" opt; do
  case "$opt" in
    h|\?)
      printHelp
      exit 0
    ;;
    m)  MODE=$OPTARG
    ;;
    c)  CHANNEL_NAME=$OPTARG
    ;;
    t)  CLI_TIMEOUT=$OPTARG
    ;;
  esac
done

# Determine whether starting, stopping, restarting or generating for announce
if [ "$MODE" == "up" ]; then
  EXPMODE="Starting"
  elif [ "$MODE" == "down" ]; then
  EXPMODE="Stopping"
  elif [ "$MODE" == "restart" ]; then
  EXPMODE="Restarting"
  elif [ "$MODE" == "generate" ]; then
  EXPMODE="Generating certs and genesis block for"
else
  printHelp
  exit 1
fi

# Announce what was requested
echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}'"

# ask for confirmation to proceed
askProceed

#Create the network using docker compose
if [ "${MODE}" == "up" ]; then
  networkUp
  elif [ "${MODE}" == "down" ]; then ## Clear the network
  networkDown
elif [ "${MODE}" == "generate" ]; then ## Generate Artifacts
  generateCerts
  replacePrivateKey
  generateChannelArtifacts
  elif [ "${MODE}" == "restart" ]; then ## Restart the network
  networkDown
  networkUp
else
  printHelp
  exit 1
fi

#!/bin/bash

# This script will orchestrate a sample end-to-end execution of the Hyperledger
# Fabric network.
#
# The end-to-end verification provisions a sample Fabric network consisting of
# two organizations, each maintaining two peers, and a “solo” ordering service.
#
# This verification makes use of two fundamental tools, which are necessary to
# create a functioning transactional network with digital signature validation
# and access control:
#
# * cryptogen - generates the x509 certificates used to identify and
#   authenticate the various components in the network.
# * configtxgen - generates the requisite configuration artifacts for orderer
#   bootstrap and channel creation.
#
# Each tool consumes a configuration yaml file, within which we specify the topology
# of our network (cryptogen) and the location of our certificates for various
# configuration operations (configtxgen).  Once the tools have been successfully run,
# we are able to launch our network.  More detail on the tools and the structure of
# the network will be provided later in this document.  For now, let's get going...

# prepending $PWD/../bin to PATH to ensure we are picking up the correct binaries
# this may be commented out to resolve installed version of tools if desired
export PATH=${PWD}/../bin:${PWD}:$PATH
export FABRIC_CFG_PATH=${PWD}

# Print the usage message
function printHelp () {
  echo "Usage: "
  echo "  byfn.sh -m up|down|restart|generate [-c <channel name>] [-t <timeout>]"
  echo "  byfn.sh -h|--help (print this message)"
  echo "    -m <mode> - one of 'up', 'down', 'restart' or 'generate'"
  echo "      - 'up' - bring up the network with docker-compose up"
  echo "      - 'down' - bring up the network with docker-compose up"
  echo "      - 'restart' - bring up the network with docker-compose up"
  echo "      - 'generate' - generate required certificates and genesis block"
  echo "    -c <channel name> - channel name to use (defaults to \"mychannel\")"
  echo "    -t <timeout> - CLI timeout duration in microseconds (defaults to 10000)"
  echo
  echo "Typically, one would first generate the required certificates and "
  echo "genesis block, then bring up the network. e.g.:"
  echo
  echo "	byfn.sh -m generate -c <channelname>"
  echo "	byfn.sh -m up -c <channelname>"
  echo "	byfn.sh -m down -c <channelname>"
  echo
  echo "Taking all defaults:"
  echo "	byfn.sh -m generate"
  echo "	byfn.sh -m up"
  echo "	byfn.sh -m down"
}

# Ask user for confirmation to proceed
function askProceed () {
  read -p "Continue (y/n)? " ans
  case "$ans" in
    y|Y )
      echo "proceeding ..."
    ;;
    n|N )
      echo "exiting..."
      exit 1
    ;;
    * )
      echo "invalid response"
      askProceed
    ;;
  esac
}

# Obtain CONTAINER_IDS and remove them
# TODO Might want to make this optional - could clear other containers
function clearContainers () {
  CONTAINER_IDS=$(docker ps -aq)
  if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
    echo "---- No containers available for deletion ----"
  else
    docker rm -f $CONTAINER_IDS
  fi
}

# Delete any images that were generated as a part of this setup
# specifically the following images are often left behind:
# TODO list generated image naming patterns
function removeUnwantedImages() {
  DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}')
  if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
    echo "---- No images available for deletion ----"
  else
    docker rmi -f $DOCKER_IMAGE_IDS
  fi
}

# Generate the needed certificates, the genesis block and start the network.
function networkUp () {
  # generate artifacts if they don't exist
  if [ ! -d "crypto-config" ]; then
    generateCerts
    replacePrivateKey
    generateChannelArtifacts
  fi
  CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1
  if [ $? -ne 0 ]; then
    echo "ERROR !!!! Unable to start network"
    docker logs -f cli
    exit 1
  fi
  docker logs -f cli
}

# Tear down running network
function networkDown () {
  docker-compose -f $COMPOSE_FILE down
  # Don't remove containers, images, etc if restarting
  if [ "$MODE" != "restart" ]; then
    #Cleanup the chaincode containers
    clearContainers
    #Cleanup images
    removeUnwantedImages
    # remove orderer block and other channel configuration transactions and certs
    rm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config
    # remove the docker-compose yaml file that was customized to the example
    rm -f docker-compose-e2e.yaml
  fi
}

# Using docker-compose-e2e-template.yaml, replace constants with private key file names
# generated by the cryptogen tool and output a docker-compose.yaml specific to this
# configuration
function replacePrivateKey () {
  # sed on MacOSX does not support -i flag with a null extension. We will use
  # 't' for our back-up's extension and depete it at the end of the function
  ARCH=`uname -s | grep Darwin`
  if [ "$ARCH" == "Darwin" ]; then
    OPTS="-it"
  else
    OPTS="-i"
  fi

  # Copy the template to the file that will be modified to add the private key
  cp docker-compose-e2e-template.yaml docker-compose-e2e.yaml

  # The next steps will replace the template's contents with the
  # actual values of the private key file names for the two CAs.
  CURRENT_DIR=$PWD
  cd crypto-config/peerOrganizations/org1.example.com/ca/
  PRIV_KEY=$(ls *_sk)
  cd $CURRENT_DIR
  sed $OPTS "s/CA1_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml
  cd crypto-config/peerOrganizations/org2.example.com/ca/
  PRIV_KEY=$(ls *_sk)
  cd $CURRENT_DIR
  sed $OPTS "s/CA2_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml
  # If MacOSX, remove the temporary backup of the docker-compose file
  if [ "$ARCH" == "Darwin" ]; then
    rm docker-compose-e2e.yamlt
  fi
}

# We will use the cryptogen tool to generate the cryptographic material (x509 certs)
# for our various network entities.  The certificates are based on a standard PKI
# implementation where validation is achieved by reaching a common trust anchor.
#
# Cryptogen consumes a file - ``crypto-config.yaml`` - that contains the network
# topology and allows us to generate a library of certificates for both the
# Organizations and the components that belong to those Organizations.  Each
# Organization is provisioned a unique root certificate (``ca-cert``), that binds
# specific components (peers and orderers) to that Org.  Transactions and communications
# within Fabric are signed by an entity's private key (``keystore``), and then verified
# by means of a public key (``signcerts``).  You will notice a "count" variable within
# this file.  We use this to specify the number of peers per Organization; in our
# case it's two peers per Org.  The rest of this template is extremely
# self-explanatory.
#
# After we run the tool, the certs will be parked in a folder titled ``crypto-config``.

# Generates Org certs using cryptogen tool
function generateCerts (){
  which cryptogen
  if [ "$?" -ne 0 ]; then
    echo "cryptogen tool not found. exiting"
    exit 1
  fi
  echo
  echo "##########################################################"
  echo "##### Generate certificates using cryptogen tool #########"
  echo "##########################################################"

  cryptogen generate --config=./crypto-config.yaml
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate certificates..."
    exit 1
  fi
  echo
}

# The `configtxgen tool is used to create four artifacts: orderer **bootstrap
# block**, fabric **channel configuration transaction**, and two **anchor
# peer transactions** - one for each Peer Org.
#
# The orderer block is the genesis block for the ordering service, and the
# channel transaction file is broadcast to the orderer at channel creation
# time.  The anchor peer transactions, as the name might suggest, specify each
# Org's anchor peer on this channel.
#
# Configtxgen consumes a file - ``configtx.yaml`` - that contains the definitions
# for the sample network. There are three members - one Orderer Org (``OrdererOrg``)
# and two Peer Orgs (``Org1`` & ``Org2``) each managing and maintaining two peer nodes.
# This file also specifies a consortium - ``SampleConsortium`` - consisting of our
# two Peer Orgs.  Pay specific attention to the "Profiles" section at the top of
# this file.  You will notice that we have two unique headers. One for the orderer genesis
# block - ``TwoOrgsOrdererGenesis`` - and one for our channel - ``TwoOrgsChannel``.
# These headers are important, as we will pass them in as arguments when we create
# our artifacts.  This file also contains two additional specifications that are worth
# noting.  Firstly, we specify the anchor peers for each Peer Org
# (``peer0.org1.example.com`` & ``peer0.org2.example.com``).  Secondly, we point to
# the location of the MSP directory for each member, in turn allowing us to store the
# root certificates for each Org in the orderer genesis block.  This is a critical
# concept. Now any network entity communicating with the ordering service can have
# its digital signature verified.
#
# This function will generate the crypto material and our four configuration
# artifacts, and subsequently output these files into the ``channel-artifacts``
# folder.
#
# If you receive the following warning, it can be safely ignored:
#
# [bccsp] GetDefault -> WARN 001 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
#
# You can ignore the logs regarding intermediate certs, we are not using them in
# this crypto implementation.

# Generate orderer genesis block, channel configuration transaction and
# anchor peer update transactions
function generateChannelArtifacts() {
  which configtxgen
  if [ "$?" -ne 0 ]; then
    echo "configtxgen tool not found. exiting"
    exit 1
  fi

  echo "##########################################################"
  echo "#########  Generating Orderer Genesis block ##############"
  echo "##########################################################"
  # Note: For some unknown reason (at least for now) the block file can't be
  # named orderer.genesis.block or the orderer will fail to launch!
  configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate orderer genesis block..."
    exit 1
  fi
  echo
  echo "#################################################################"
  echo "### Generating channel configuration transaction 'channel.tx' ###"
  echo "#################################################################"
  configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate channel configuration transaction..."
    exit 1
  fi

  echo
  echo "#################################################################"
  echo "#######    Generating anchor peer update for Org1MSP   ##########"
  echo "#################################################################"
  configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate anchor peer update for Org1MSP..."
    exit 1
  fi

  echo
  echo "#################################################################"
  echo "#######    Generating anchor peer update for Org2MSP   ##########"
  echo "#################################################################"
  configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate \
  ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
  if [ "$?" -ne 0 ]; then
    echo "Failed to generate anchor peer update for Org2MSP..."
    exit 1
  fi
  echo
}

# Obtain the OS and Architecture string that will be used to select the correct
# native binaries for your platform
OS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
# timeout duration - the duration the CLI should wait for a response from
# another container before giving up
CLI_TIMEOUT=10000
# channel name defaults to "mychannel"
CHANNEL_NAME="mychannel"
# use this as the default docker-compose yaml definition
COMPOSE_FILE=docker-compose-cli.yaml

# Parse commandline args
while getopts "h?m:c:t:" opt; do
  case "$opt" in
    h|\?)
      printHelp
      exit 0
    ;;
    m)  MODE=$OPTARG
    ;;
    c)  CHANNEL_NAME=$OPTARG
    ;;
    t)  CLI_TIMEOUT=$OPTARG
    ;;
  esac
done

# Determine whether starting, stopping, restarting or generating for announce
if [ "$MODE" == "up" ]; then
  EXPMODE="Starting"
  elif [ "$MODE" == "down" ]; then
  EXPMODE="Stopping"
  elif [ "$MODE" == "restart" ]; then
  EXPMODE="Restarting"
  elif [ "$MODE" == "generate" ]; then
  EXPMODE="Generating certs and genesis block for"
else
  printHelp
  exit 1
fi

# Announce what was requested
echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}'"

# ask for confirmation to proceed
askProceed

#Create the network using docker compose
if [ "${MODE}" == "up" ]; then
  networkUp
  elif [ "${MODE}" == "down" ]; then ## Clear the network
  networkDown
elif [ "${MODE}" == "generate" ]; then ## Generate Artifacts
  generateCerts
  replacePrivateKey
  generateChannelArtifacts
  elif [ "${MODE}" == "restart" ]; then ## Restart the network
  networkDown
  networkUp
else
  printHelp
  exit 1
fi


Optionally specify your name to appear on the blog

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/bashrc/freedombone.git/'


Include Docker install for Arch

Include Docker install for Arch

#!/usr/bin/env bash

# All must be run as root
[ $(/usr/bin/id -u) -ne 0 ] \
	&& echo 'Must be run as root!' \
	&& exit 1

# Install (--sync/-S) docker container suite
pacman -S --noconfirm docker

# Also the docker-compose orchestra
pacman -S --noconfirm docker-compose

# Allow services/socket/daemon to start on boot
systemctl enable docker
systemctl start docker

# NOTE! I had this issue until after a system restart:
# 	"docker.socket: Failed with result 'service-start-limit-hit'"

# Run a test image in a container
CMD="docker run hello-world"
echo -n "Running '$CMD'... "
eval $CMD &> /dev/null

# Display test OK/FAILED
[ $? = 0 ] \
	&& echo -e '\E[32m'"\033[1m[OK]\033[0m" \
	|| echo -e '\E[31m'"\033[1m[FAIL]\033[0m"

# Display some help for our future-self
echo
echo 'To allow users to run docker:'
echo '	sudo usermod -aG docker $USER'

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


[BL-28] Added create_val_record.sh

[BL-28] Added create_val_record.sh

#!/bin/bash

source activate bl-magi
export PYTHONPATH=$PYTHONPATH:`pwd`/../../tensorflow:`pwd`/../../slim
export MODEL_BASE_PATH='gs://bluelens-style-model/object_detection'

python create_tf_record.py \
    --label_map_path=/dataset/deepfashion/data/label_map.pbtxt \
    --data_dir=/dataset/deepfashion --folder=dataset --set=val \
    --output_path=/dataset/data/val.record

error: pathspec 'stylelens/object_detection/create_val_record.sh' did not match any file(s) known to git


Update 001_packages.sh

Update 001_packages.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/jeremycurny/notes.git/'


Add knex down and up all tool

Add knex down and up all tool

#!/bin/bash

source .env
knex migrate:rollback
knex migrate:latest
knex seed:run

error: pathspec 'tools/knex-down-up.sh' did not match any file(s) known to git


add albert installation script

add albert installation 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/mspl13/dotfiles.git/'


Map generation script added.

Map generation script added.

#!/bin/bash

echo "Running the map generator."

echo "Minecraft container: $1"
echo "Server container: $2"

#$MINECRAFT = $1
#$MAPSERVER = $2

docker run -volumes-from=$1 -volumes-from=$2 stephen/mcoverviewer /minecraft_data/level /www

error: pathspec 'map-generator/run_generator.sh' did not match any file(s) known to git


Add refcount test script

Add refcount test script

git-svn-id: 0c5512015aa96f7d3f5c3ad598bd98edc52008b1@12271 dc4e9af1-7f46-4ead-bba6-71afc04862de

#!/bin/bash
SCS=~/ExM/scicolsim.git/

export STC_FLAGS="-T no-engine -I $SCS/src"

export TURBINE_USER_LIB=$SCS

# FROM PACT'13 PAPER
#ARGS='--graph_file=movie_graph.txt \
#            --annealingcycles=25 \
#            --evoreruns=100 --reruns_per_task=1 \
#            --minrange=58 --maxrange=58 \
#            --n_epochs=1 --n_steps=1'

# CCGrid '13 draft
#ARGS="--graph_file=${SCS}/data/movie_graph.txt \
#            --annealingcycles=25 \
#            --evoreruns=100 --reruns_per_task=1 \
#            --minrange=58 --maxrange=108 --rangeinc=50 \
#            --n_epochs=1 --n_steps=1"

ARGS="--graph_file=${SCS}/data/movie_graph.txt \
            --annealingcycles=50 \
            --evoreruns=100 --reruns_per_task=1 \
            --minrange=58 --maxrange=108 --rangeinc=50 \
            --n_epochs=30 --n_steps=50"

export ARGS

../scripts/o-level-test.sh $SCS/src/annealing-exm.swift ./rc-o-levels.txt

error: pathspec 'bench/pact-suite/scicolsim/rc-level-test.sh' did not match any file(s) known to git


Create users-delete.sh

Create users-delete.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/kalise/Kubernetes-Lab-Tutorial.git/'


sources script

sources script

#!/bin/sh
wget http://scg.unibe.ch/download/jk/sources/smalltalk-src-all.zip
mkdir smalltalk-sources
unzip smalltalk-src-all.zip -d ./smalltalk-sources/

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


mpv no longer needs bundle option

mpv no longer needs bundle option

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


wifi debug

wifi debug


Remove load-path

Remove load-path


Ne pas ajouter les lignes en cas de variable NULL

Ne rien ajouter au fichier de config si une de ses variables est a null, plus passage compatibilité sous bash (pour exécuter directement en "./make_config.sh" ou "bash ./make_config.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/exalgebra/tour-de-controle.git/'


add archive_world.sh for viking

add archive_world.sh for viking

#!/usr/bin/env sh
# -*- Mode: sh -*-
# archive_world.sh --- archive a host's vital files
# Copyright (C) 2016  Dan Harms (dharms)
# Author: Dan Harms <danielrharms@gmail.com>
# Created: Tuesday, August  9, 2016
# Version: 1.0
# Modified Time-stamp: <2016-08-17 17:15:52 dharms>
# Modified by: Dan Harms
# Keywords: archive backup

target=${1:-~/backups}

_backup.sh ~/Dropbox/notes "$target"

# code ends here

error: pathspec 'host/viking/bin/archive_world.sh' did not match any file(s) known to git


utility from justarandomgeek

utility from justarandomgeek

#!/bin/bash
# Run this script after committing an updated info.json to automatically tag the update and prepare a zip of it.

# Get mod name and version from info.json
# https://stedolan.github.io/jq/
modname=`cat info.json|jq -r .name`
modver=`cat info.json|jq -r .version`

# Create git tag for this version
git tag "$modver"

# Prepare zip for Factorio native use and mod portal
git archive --prefix "${modname}_$modver/" -o "${modname}_$modver.zip" HEAD

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


Add BASH implementation of "is prime" math test

error: pathspec 'math/is_prime/bash/is_prime.sh' did not match any file(s) known to git


Added install script for cvc4

Added install script for cvc4

Closes: #6228

#!/bin/bash -e

# Copyright (c) The Libra Core Contributors
# SPDX-License-Identifier: Apache-2.0

curl -L0 https://cvc4.cs.stanford.edu/downloads/builds/macos/cvc4-25-09-20.zip -o cvc4-25-09-20.zip
unzip cvc4-25-09-20.zip
sudo cp 25-09-20/cvc4 /usr/local/bin/
rm -rf 25-09-20
rm -rf cvc4-25-09-20.zip

error: pathspec 'language/move-prover/scripts/install-cvc4.sh' did not match any file(s) known to git


run-test.sh: pass on gdb arguments

run-test.sh: pass on gdb arguments

#!/usr/bin/env bash
#

RED='\033[31m'
GREEN='\033[32m'
CYAN='\033[36m'
CCLR='\033[0m'

if [ -z "$1" ]; then
    echo "Usage: $0 [-p] <00xx-...test> [modes..]"
    echo ""
    echo "  Modes: bare valgrind helgrind drd gdb"
    echo "  Options:"
    echo "   -p    - run all tests in parallel"
    exit 1
fi

ARGS=
if [[ $1 == "-p" ]]; then
    ARGS="$ARGS $1"
    shift
fi

TEST=$1
if [ ! -z "$2" ]; then
    MODES=$2
else
    MODES="bare"
    # Enable valgrind:
    #MODES="bare valgrind"
fi

FAILED=0

# Enable valgrind suppressions for false positives
SUPP="--suppressions=librdkafka.suppressions"

# Uncomment to generate valgrind suppressions
#GEN_SUPP="--gen-suppressions=yes"

# Common valgrind arguments
VALGRIND_ARGS="--error-exitcode=3"

# Enable vgdb on valgrind errors.
#VALGRIND_ARGS="$VALGRIND_ARGS --vgdb-error=1"

echo -e "${CYAN}############## $TEST ################${CCLR}"

for mode in $MODES; do
    echo -e "${CYAN}### Running test $TEST in $mode mode ###${CCLR}"
    case "$mode" in
	valgrind)
	    valgrind $VALGRIND_ARGS --leak-check=full --show-leak-kinds=all \
		     --track-origins=yes \
		     $SUPP $GEN_SUPP \
		./$TEST $ARGS
	    RET=$?
	    ;;
	helgrind)
	    valgrind $VALGRIND_ARGS --tool=helgrind \
                     --sim-hints=no-nptl-pthread-stackcache \
                     $SUPP $GEN_SUPP \
		./$TEST	$ARGS
	    RET=$?
	    ;;
	drd)
	    valgrind $VALGRIND_ARGS --tool=drd $SUPP $GEN_SUPP \
		./$TEST	$ARGS
	    RET=$?
	    ;;
        gdb)
            gdb $* ./$TEST
            RET=$?
            ;;
	bare)
	    ./$TEST $ARGS
	    RET=$?
	    ;;
	*)
	    echo -e "${RED}### Unknown mode $mode for $TEST ###${CCLR}"
	    RET=1
	    ;;
    esac

    if [ $RET -gt 0 ]; then
	echo -e "${RED}###"
	echo -e "### Test $TEST in $mode mode FAILED! ###"
	echo -e "###${CCLR}"
	FAILED=1
    else
	echo -e "${GREEN}###"
	echo -e "### $Test $TEST in $mode mode PASSED! ###"
	echo -e "###${CCLR}"
    fi
done

exit $FAILED

#!/usr/bin/env bash
#

RED='\033[31m'
GREEN='\033[32m'
CYAN='\033[36m'
CCLR='\033[0m'

if [ -z "$1" ]; then
    echo "Usage: $0 [-p] <00xx-...test> [modes..]"
    echo ""
    echo "  Modes: bare valgrind helgrind drd gdb"
    echo "  Options:"
    echo "   -p    - run all tests in parallel"
    exit 1
fi

ARGS=
if [[ $1 == "-p" ]]; then
    ARGS="$ARGS $1"
    shift
fi

TEST=$1
if [ ! -z "$2" ]; then
    MODES=$2
else
    MODES="bare"
    # Enable valgrind:
    #MODES="bare valgrind"
fi

FAILED=0

# Enable valgrind suppressions for false positives
SUPP="--suppressions=librdkafka.suppressions"

# Uncomment to generate valgrind suppressions
#GEN_SUPP="--gen-suppressions=yes"

# Common valgrind arguments
VALGRIND_ARGS="--error-exitcode=3"

# Enable vgdb on valgrind errors.
#VALGRIND_ARGS="$VALGRIND_ARGS --vgdb-error=1"

echo -e "${CYAN}############## $TEST ################${CCLR}"

for mode in $MODES; do
    echo -e "${CYAN}### Running test $TEST in $mode mode ###${CCLR}"
    case "$mode" in
	valgrind)
	    valgrind $VALGRIND_ARGS --leak-check=full --show-leak-kinds=all \
		     --track-origins=yes \
		     $SUPP $GEN_SUPP \
		./$TEST $ARGS
	    RET=$?
	    ;;
	helgrind)
	    valgrind $VALGRIND_ARGS --tool=helgrind \
                     --sim-hints=no-nptl-pthread-stackcache \
                     $SUPP $GEN_SUPP \
		./$TEST	$ARGS
	    RET=$?
	    ;;
	drd)
	    valgrind $VALGRIND_ARGS --tool=drd $SUPP $GEN_SUPP \
		./$TEST	$ARGS
	    RET=$?
	    ;;
        gdb)
            gdb ./$TEST
            RET=$?
            ;;
	bare)
	    ./$TEST $ARGS
	    RET=$?
	    ;;
	*)
	    echo -e "${RED}### Unknown mode $mode for $TEST ###${CCLR}"
	    RET=1
	    ;;
    esac

    if [ $RET -gt 0 ]; then
	echo -e "${RED}###"
	echo -e "### Test $TEST in $mode mode FAILED! ###"
	echo -e "###${CCLR}"
	FAILED=1
    else
	echo -e "${GREEN}###"
	echo -e "### $Test $TEST in $mode mode PASSED! ###"
	echo -e "###${CCLR}"
    fi
done

exit $FAILED


Fix regression in adb_*_command_line commands caused by c481d677

The "cut" should run on the host rather than the client. Android M
preview includes "cut", so this slipped through :S.

BUG=493878

Review URL: https://codereview.chromium.org/1153343007

Cr-Commit-Position: 972c6d2dc6dd5efdad1377c0d224e03eb8f276f7@{#332544}

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

# Variables must be set before calling:
# CMD_LINE_FILE - Path on device to flags file.
# REQUIRES_SU - Set to 1 if path requires root.
function set_command_line() {
  SU_CMD=""
  if [[ "$REQUIRES_SU" = 1 ]]; then
    # Older androids accept "su -c", while newer use "su uid".
    SDK_LEVEL=$(adb shell getprop ro.build.version.sdk | tr -d '\r')
    # E.g. if no device connected.
    if [[ -z "$SDK_LEVEL" ]]; then
      exit 1
    fi
    SU_CMD="su -c"
    if (( $SDK_LEVEL >= 21 )); then
      SU_CMD="su 0"
    fi
  fi

  if [ $# -eq 0 ] ; then
    # If nothing specified, print the command line (stripping off "chrome ")
    adb shell "cat $CMD_LINE_FILE 2>/dev/null" | cut -d ' ' -s -f2-
  elif [ $# -eq 1 ] && [ "$1" = '' ] ; then
    # If given an empty string, delete the command line.
    set -x
    adb shell $SU_CMD rm $CMD_LINE_FILE >/dev/null
  else
    # Else set it.
    set -x
    adb shell "echo 'chrome $*' | $SU_CMD dd of=$CMD_LINE_FILE"
    # Prevent other apps from modifying flags (this can create security issues).
    adb shell $SU_CMD chmod 0664 $CMD_LINE_FILE
  fi
}

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

# Variables must be set before calling:
# CMD_LINE_FILE - Path on device to flags file.
# REQUIRES_SU - Set to 1 if path requires root.
function set_command_line() {
  SU_CMD=""
  if [[ "$REQUIRES_SU" = 1 ]]; then
    # Older androids accept "su -c", while newer use "su uid".
    SDK_LEVEL=$(adb shell getprop ro.build.version.sdk | tr -d '\r')
    # E.g. if no device connected.
    if [[ -z "$SDK_LEVEL" ]]; then
      exit 1
    fi
    SU_CMD="su -c"
    if (( $SDK_LEVEL >= 21 )); then
      SU_CMD="su 0"
    fi
  fi

  if [ $# -eq 0 ] ; then
    # If nothing specified, print the command line (stripping off "chrome ")
    adb shell "cat $CMD_LINE_FILE 2>/dev/null | cut -d ' ' -s -f2-"
  elif [ $# -eq 1 ] && [ "$1" = '' ] ; then
    # If given an empty string, delete the command line.
    set -x
    adb shell $SU_CMD rm $CMD_LINE_FILE >/dev/null
  else
    # Else set it.
    set -x
    adb shell "echo 'chrome $*' | $SU_CMD dd of=$CMD_LINE_FILE"
    # Prevent other apps from modifying flags (this can create security issues).
    adb shell $SU_CMD chmod 0664 $CMD_LINE_FILE
  fi
}


added script for microbenchmark

added script for microbenchmark

#!/bin/bash
workload=microAllReduce

# Absolue path to this script
SCRIPT_DIR=$(dirname "$(realpath $0)")

# Absolute paths to useful directories
PROJECT_DIR="${SCRIPT_DIR:?}"/../../..
INPUT_DIR=${PROJECT_DIR}/inputs
COMPILE_SCRIPT="${SCRIPT_DIR:?}"/../build.sh
BINARY="${SCRIPT_DIR:?}"/../build/AnalyticalAstra/bin/AnalyticalAstra
NETWORK=${INPUT_DIR}/network/analytical/sample_Ring_AllToAll_Switch.json
SYSTEM=${INPUT_DIR}/system/sample_3dim_sys
WORKLOAD=${INPUT_DIR}/workload/"$workload"
STATS="${SCRIPT_DIR:?}"/../result/ring-alltoall-switch-${1:-result}

# create result directory
rm -rf "${STATS}"
mkdir -p "${STATS}"

# compile binary
echo "[SCRIPT] Compiling AnalyticalAstra"
"${COMPILE_SCRIPT}" -c

nodes=(2 4 8 16 32 64 128)
commScale=(1)

current_row=-1
tot_stat_row=$((${#nodes[@]} * ${#commScale[@]}))

# run test
for i in "${!nodes[@]}"; do
  for inj in "${commScale[@]}"; do
    current_row=$(($current_row + 1))
    totalNPUs=$((${nodes[$i]} * 16))
    filename="workload-$workload-npus-$totalNPUs-commScale-$inj"

    echo "[SCRIPT] Initiate ${filename}"

    nohup "${BINARY}" \
      --network-configuration="${NETWORK}" \
      --system-configuration="${SYSTEM}" \
      --workload-configuration="${WORKLOAD}" \
      --path="${STATS}/" \
      --units-count 2 8 "${nodes[$i]}" \
      --num-passes 2 \
      --num-queues-per-dim 1 \
      --comm-scale $inj \
      --compute-scale 1 \
      --injection-scale 1 \
      --rendezvous-protocol false \
      --total-stat-rows "$tot_stat_row" \
      --stat-row "$current_row" \
      --run-name $filename >> "${STATS}/$filename.txt" &

      sleep 1
  done
done

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


shellcheck fixes

shellcheck fixes

#!/bin/bash

cd /opt/scripts || exit -1
source ./config.sh $1

# create common state tree
mkdir -p $PillarLocal

svn export --force $SvnTrunk/salt/common/srv/salt $SaltLocal
chmod u+x /srv/salt/files/basics/cloudflare.sh

# put svn trunk url in pillar for subsequent checkouts via salt
if [ ! -e $PillarLocal/basics.sls ]; then
	printf "svn: %s\n" "$SvnTrunk" | tee $PillarLocal/basics.sls
fi

# determine my hostname, domain and public ip
if ! grep -q hostname: $PillarLocal/basics.sls ; then
	VARNAME=$1_publicIpInterface
	HOSTNAME=$(domainname -f)
	printf "hostname: %s\n" "$HOSTNAME" | tee -a $PillarLocal/basics.sls
	IP=$(ip addr show "${!VARNAME}"|grep "inet "|cut -d"/" -f1|cut -d" " -f6)
	printf "ip: %s\n" "$IP" | tee -a $PillarLocal/basics.sls
	SSLDOMAIN=$(printf "%s" "$domain")
	printf "ssldomain: %s\n" "$SSLDOMAIN" | tee -a $PillarLocal/basics.sls
fi

# determine my private IP
if ! grep -q privip: $PillarLocal/basics.sls ; then
	printf "privip: %s\n" "$(getprivip "$1")" | tee -a $PillarLocal/basics.sls
fi

# specify the service I am providing
if ! grep -q service: $PillarLocal/basics.sls ; then
	printf "service: %s\n" "$1" | tee -a $PillarLocal/basics.sls
fi

# cluster sizes need to be rewritten on every run
APPCLUSTERSIZE=$(host -t srv _app._tcp.$domain.|wc -l)
DBCLUSTERSIZE=$(host -t srv _db._tcp.$domain.|wc -l)
printf "appclustersize: %s\ndbclustersize: %s\n" "$APPCLUSTERSIZE" "$DBCLUSTERSIZE" | tee $PillarLocal/cluster.sls

# ask for Cloudflare API key
if ! grep -q CFKEY: $PillarLocal/basics.sls ; then
	read -rs -p 'Cloudflare API Key: ' CFKEY
	printf "CFKEY: %s\n" "$CFKEY" >> $PillarLocal/basics.sls
	printf "\n"
fi

# ask for Cloudflare email (username of Cloudflare account)
if ! grep -q CFEMAIL: $PillarLocal/basics.sls ; then
	read -rs -p 'Cloudflare Email: ' CFEMAIL
	printf "CFEMAIL: %s\n" "$CFEMAIL" >> $PillarLocal/basics.sls
	printf "\n"
fi

# determine zone id of domain
if ! grep -q CFZONEID: $PillarLocal/basics.sls ; then
	CFZONEID=$(/srv/salt/files/basics/cloudflare.sh get-zoneid "$CFAPI" "$CFEMAIL" "$CFKEY")
	printf "CFZONEID: %s\n" "$CFZONEID" | tee -a $PillarLocal/basics.sls
	printf "CFAPI: %s\n" "$CFAPI" | tee -a $PillarLocal/basics.sls
fi

if [ -e /opt/bootstrap.sh ]; then
	mv /opt/bootstrap.sh /opt/scripts
fi

#!/bin/bash

cd /opt/scripts || exit -1
source ./config.sh $1

# create common state tree
mkdir -p $PillarLocal

svn export --force $SvnTrunk/salt/common/srv/salt $SaltLocal
chmod u+x /srv/salt/files/basics/cloudflare.sh

# put svn trunk url in pillar for subsequent checkouts via salt
if [ ! -e $PillarLocal/basics.sls ]; then
	printf "svn: %s\n" "$SvnTrunk" | tee $PillarLocal/basics.sls
fi

# determine my hostname, domain and public ip
if ! grep -q hostname: $PillarLocal/basics.sls ; then
	VARNAME=$1_publicIpInterface
	HOSTNAME=$(domainname -f)
	printf "hostname: %s\n" "$HOSTNAME" | tee -a $PillarLocal/basics.sls
	IP=$(ip addr show "${!VARNAME}"|grep "inet "|cut -d"/" -f1|cut -d" " -f6)
	printf "ip: %s\n" "$IP" | tee -a $PillarLocal/basics.sls
	SSLDOMAIN=$(printf "%s" "$domain")
	printf "ssldomain: %s\n" "$SSLDOMAIN" | tee -a $PillarLocal/basics.sls
fi

# determine my private IP
if ! grep -q privip: $PillarLocal/basics.sls ; then
	printf "privip: %s\n" "$(getprivip "$1")" | tee -a $PillarLocal/basics.sls
fi

# specify the service I am providing
if ! grep -q service: $PillarLocal/basics.sls ; then
	printf "service: %s\n" "$1" | tee -a $PillarLocal/basics.sls
fi

# cluster sizes need to be rewritten on every run
APPCLUSTERSIZE=$(host -t srv _app._tcp.$domain.|wc -l)
DBCLUSTERSIZE=$(host -t srv _db._tcp.$domain.|wc -l)
printf "appclustersize: %s\ndbclustersize: %s\n" "$APPCLUSTERSIZE" "$DBCLUSTERSIZE" | tee $PillarLocal/cluster.sls

# ask for Cloudflare API key
if ! grep -q CFKEY: $PillarLocal/basics.sls ; then
	read -rs -p 'Cloudflare API Key: ' CFKEY
	printf "CFKEY: %a\n" "$CFKEY" >> $PillarLocal/basics.sls
	printf "\n"
fi

# ask for Cloudflare email (username of Cloudflare account)
if ! grep -q CFEMAIL: $PillarLocal/basics.sls ; then
	read -rs -p 'Cloudflare Email: ' CFEMAIL
	printf "CFEMAIL: %s\n" "$CFEMAIL" >> $PillarLocal/basics.sls
	printf "\n"
fi

# determine zone id of domain
if ! grep -q CFZONEID: $PillarLocal/basics.sls ; then
	CFZONEID=$(/srv/salt/files/basics/cloudflare.sh get-zoneid "$CFAPI" "$CFEMAIL" "$CFKEY")
	printf "CFZONEID: %s\n" "$CFZONEID" | tee -a $PillarLocal/basics.sls
	printf "CFAPI: %s\n" "$CFAPI" | tee -a $PillarLocal/basics.sls
fi

if [ -e /opt/bootstrap.sh ]; then
	mv /opt/bootstrap.sh /opt/scripts
fi


Update CI script

Update CI script

#!/usr/bin/env bash
# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of fiware-cygnus (FI-WARE project).
#
# fiware-cygnus is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# fiware-cygnus 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 Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with fiware-cygnus. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# iot_support at tid dot es

# Bash lib to know the RPM version and revision from a GitHub repository
# Call method get_rpm_version_string to obtain them for rpmbuild
#

if [[ $(ps -hp  $$ | grep bash) ]]; then
  shopt -s extglob
elif [[ $(ps -hp  $$ | grep zsh) ]]; then
  setopt kshglob
fi

get_branch()
{
    git rev-parse --abbrev-ref HEAD
}

## Specific functions according the TID workflow
get_branch_type()
{
    local branch="$(get_branch)"
    case $branch in
        release/*) echo "release";;
        develop) echo "develop";;
        master) echo "stable";;
        *) echo "other";;
    esac
}

get_version_string()
{
    local branch branch_name describe_tags version ancestor release
    case $(get_branch_type) in
        stable)
           # If we are on stable branch get last tag as the version, but transform to x.x.x-x-SHA1
           describe_tags="$(git describe --tags --long  --match "[[:digit:]]*.[[:digit:]]*.[[:digit:]]*" 2>/dev/null)"
           version="${describe_tags%-*-*}"
           echo "${version%.*}-${version#*.*.*.}-$(git log --pretty=format:'%h' -1)"
        ;;
        develop)
          ## If we are in develop use the total count of commits of the repo
          total_commit_number=$(git rev-list --all --count)
          short_hash=$(git rev-parse --short HEAD)
          version="$(git describe --tags --long  --match "[[:digit:]]*.[[:digit:]]*.[[:digit:]]*" 2>/dev/null)"
          version="${version%-*-*}"
          version="${version%KO}"
          echo "${version}-${total_commit_number}-${short_hash}"
        ;;
        release)
          ## in release branches the version is a tag named
          branch_name="$(get_branch)"
          branch_name="${branch_name#*/}"
          describe_tags="$(git describe --tags --long  --match ${branch_name} 2>/dev/null)"
          version="${describe_tags%-*-*}"
          version="${version%KO}"
          release=${describe_tags#*.*.*-}
          echo "${version}-${release}"
        ;;
        other)
            ## We are in detached mode, use the last x-y-z tag
            version="$(git describe --tags --long  --match "[[:digit:]]*.[[:digit:]]*.[[:digit:]]*" 2>/dev/null)"
            version="${version%-*-*}"
            version="${version%KO}"
            echo "${version}"
        ;;
        *)
           # RMs don't stablish any standard here, we use branch name as version
           version=$(get_branch)
           # Using always develop as parent branch does not describe correctly the number of revision
           # for branches not starting there, but works as an incremental rev
           ancestor="$(git merge-base $version develop)"
           version=${version#*/}
           local res="$(git log --oneline ${ancestor}.. --pretty='format:%h')"
           ## wc alone does not get the last line when there's no new line
           [[ -z $res ]] && rel=0 || rel=$(echo "$res" | wc -l | tr -d ' ')
           echo "${version}-${rel}-g$(git log --pretty=format:'%h' -1)"
    esac
}

get_rpm_version_string() {
    local version_string ver rel
    version_string="$(get_version_string)"
    ver="${version_string%-*-*}"
    rel="${version_string:$((${#ver}+1))}"
    echo "${ver//[[:space:]-\/#]}" "${rel//[-]/.}"
}

#cd $1
#get_version_string| cut -d "-" -f $2

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


Add dmtx element pipeline testing "tool"

#!/bin/sh
gst-launch --gst-plugin-path=`pwd`/src/.libs v4l2src ! video/x-raw-rgb,width=320, height=240 ! dmtx ! ffmpegcolorspace ! xvimagesink

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


Added script that allows me to traverse the redox codebase looking for new contributors.

#!/bin/sh

#
# Small hacky utility to get new contributors in a project-wise fashion.
# So we know when somebody is really new to Redox across all the sub-repos.
#
# I usually run it like:
# ./path/to-redox-website/new_contribs.sh 2017-02-01
#
# From the Redox main repo.
#
# Adapted from the Rust one.

# Create the temp files
touch names_old.txt
touch names_all.txt

#
# Gets the list of commiters for a give git repo. Only runs if the dir is a git repo.
# $1 holds the initial date from where we are gonna start counting.
#
get_new_commiters() {
    if git rev-parse --git-dir > /dev/null 2>&1; then
        INITIAL_COMMIT=`git log --reverse --pretty=format:%H|head -n1`
        START_COMMIT=`git log --before="$1" --pretty=format:%H|head -n1`
        ALL_NAMES=`git log $INITIAL_COMMIT.. --pretty=format:%an|sort|uniq`
        OLD_NAMES=`git log $INITIAL_COMMIT..$START_COMMIT --pretty=format:%an|sort|uniq`
        echo "$OLD_NAMES">>names_old.txt
        echo "$ALL_NAMES">>names_all.txt
    fi
}

export -f get_new_commiters

# Running the function recursively (defaulting to 1 level deep)
find . -maxdepth 1 -type d -exec bash -c "get_new_commiters $1" {} \;

# Subtracting the names from the initial commit to the start date - all names.
names=`diff names_old.txt names_all.txt`
names=`echo "$names" |grep \> | sed 's/^>//'|sort|uniq`
echo "$names"

# Clean files
rm names_old.txt names_all.txt

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


Add a script for fixing virtualenvs when moved.

#!/bin/bash
#
# fix_virtualenv_location.sh
#
# Author: Gary M. Josack <gary@byoteki.com>
# Repository: https://github.com/gmjosack/shell_scripts
# License: MIT
#
# This is a simple script to clean up links and references in a
# python virtualenv that has been relocated.

function wrap_color(){
    local red="\e[31m"
    local blue="\e[34m"
    local reset="\e[0m"

    local color="$1"; shift
    local data="$*"
    local output=""

    case "$color" in
        red)  output="${red}${data}${reset}" ;;
        blue) output="${blue}${data}${reset}" ;;
        *)    output="${data}" ;;
    esac

    echo "$output"
}

function log(){
    local name="$1"
    local line="$2"
    local stream="${3:-stdout}"
    local color="$4"

    local msg="[$name] $line"
    [[ -n "$color" ]] && msg=$(wrap_color "$color" "$msg")

    if [[ "$stream" == "stderr" ]]; then
        echo -e $msg 1>&2
    else
        echo -e $msg
    fi
}

function info(){
    log "info" "$*" "stdout" "blue"
}

function err(){
    log "error" "$*" "stderr" "red"
}

function die(){
    err "$*"
    exit 1
}

function abspath(){
    echo $(cd "$1"; pwd)
}

function add_trailing_slash(){
    [[ "${1:(-1)}" == "/" ]] && echo "$1" || echo "$1/"
}

function rm_trailing_slash(){
    [[ "${1:(-1)}" == "/" ]] && echo "${1:0:-1}" || echo "$1"
}

function usage(){
    local preamble="$1"
    local prog=$(basename $0)

    [[ -n "$preamble" ]] && err "${preamble}\n"
    echo "Usage: ${PROG} <old_name> <new_venv>"
    echo "  <old_name> - The name of the old path where the virtualenv existed. This"
    echo "               location does not need to exist."
    echo "  <new_venv> - The path of the virtualenv where links should be repaired."

    exit 1
}

function fix_bad_symlinks(){
    local search_path="$1"
    local old_name="$2"

    info "Fixing symlinks..."
    for symlink in $(find "$search_path" -type l); do
        local value=$(readlink "${symlink}")
        if [[ "$value" == *"$old_name"* ]]; then
            info "Found $symlink pointing $value. Correcting..."
            ln -sTf "${value/$old_name/$search_path}" "$symlink"
        fi

    done
}

function purge_pycs(){
    local search_path="$1"

    info "Purging the following *.pyc files..."
    find "$search_path" -type f -name "*.pyc" -printf "\t%p\n" -exec rm -f {} \;
}

function rename_refs(){
    local old_name=$(rm_trailing_slash "$1")
    local search_path=$(rm_trailing_slash "$2")

    local old_pattern="${old_name}(/|\"|$|')"
    local new_pattern="${search_path}(/|\"|$|')"

    info "Replacing references of ${old_name} with ${search_path}..."

    for file in $(find -P "${search_path}" \! -type l -type f | xargs grep -El "$old_pattern" | xargs grep -lv "$new_pattern"); do
        [[ -L "$file" ]] && continue  # Ignore symlinks.
        info "Updating ${file}"
        sed -i -e "s:${old_name}:${search_path}:g" "$file"
    done
}

function main(){
    [[ "$#" -eq 2 ]] || usage "Invalid number of parameters."

    local old_name="$1"
    local new_venv="$2"

    new_venv=$(abspath "$new_venv")

    old_name=$(add_trailing_slash "$old_name")
    new_venv=$(add_trailing_slash "$new_venv")

    # Simple sanity checks that the path exists and
    # appears to be a virtual env.
    [[ -d "$new_venv" ]] || usage "No such directory: ${new_venv}"
    [[ -f "$new_venv/bin/activate" ]] || usage "Doesn't appear to be a virtualenv: ${new_venv}"

    fix_bad_symlinks "$new_venv" "$old_name"
    purge_pycs "$new_venv"
    rename_refs "$old_name" "$new_venv"

}
main "$@"

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


First Draft

First Draft

#!/bin/bash
# Author: Swe Aung sirswa[at]gmail[at]com
# Date: 01/05/2013

function progress () {
        i=$1
	for (( c=1; c<=i; c++ ))
	do
       	   sleep 1
           echo -e "+ \c"
	done
}

echo -e "\nKill all dnsmasq             \c"
progress 2
/usr/bin/killall dnsmasq

echo -e "\nRestarting libvirt-bin       \c"
progress 5
/sbin/restart libvirt-bin

echo -e "\nRestarting nova-api-metadata \c"
progress 5
/sbin/restart nova-api-metadata

echo -e "\nRestarting nova-network      \c"
progress 5
/sbin/restart nova-network

echo -e "\nRestarting nova-compute      \c"
progress 5
/sbin/restart nova-compute

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


Script to install on a python virtualenv for development (#9685)

#!/usr/bin/env bash

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

######################################################################
# This script installs MXNet for Python in a virtualenv on OSX and ubuntu
######################################################################
set -e
#set -x

BUILDIR=build
VENV=mxnet_py3

setup_virtualenv() {
    if [ ! -d $VENV ];then
        virtualenv -p `which python3` $VENV
    fi
    source $VENV/bin/activate
}

gpu_count() {
    nvidia-smi -L | wc -l
}

detect_platform() {
	unameOut="$(uname -s)"
	case "${unameOut}" in
		Linux*)
			distro=$(awk -F= '/^NAME/{gsub(/"/, "", $2); print $2}' /etc/os-release)
			machine="Linux/$distro"
		;;
		Darwin*)    machine=Mac;;
		CYGWIN*)    machine=Cygwin;;
		MINGW*)     machine=MinGw;;
		*)          machine="UNKNOWN:${unameOut}"
	esac
	echo ${machine}
}

if [ $(gpu_count) -ge 1 ];then
    USE_CUDA=ON
else
    USE_CUDA=OFF
fi

PLATFORM=$(detect_platform)
echo "Detected platform '$PLATFORM'"

if [ $PLATFORM = "Mac" ];then
    USE_OPENMP=OFF
else
    USE_OPENMP=ON
fi

if [ $PLATFORM = "Linux/Ubuntu" ];then
    install_dependencies_ubuntu() {
        sudo apt-get update
        sudo apt-get install -y build-essential libatlas-base-dev libopencv-dev graphviz virtualenv cmake\
            ninja-build libopenblas-dev liblapack-dev python3 python3-dev
    }
    echo "Installing build dependencies in Ubuntu!"
    install_dependencies_ubuntu
fi

echo "Preparing a Python virtualenv in ${VENV}"
setup_virtualenv

echo "Building MXNet core. This can take a few minutes..."
build_mxnet() {
    pushd .
    set -x
    mkdir -p $BUILDIR && cd $BUILDIR
    cmake -DUSE_CUDA=$USE_CUDA -DUSE_OPENCV=ON -DUSE_OPENMP=$USE_OPENMP -DUSE_SIGNAL_HANDLER=ON -DCMAKE_BUILD_TYPE=Release -GNinja ..
    ninja
    set +x
    popd
}

build_mxnet

echo "Installing mxnet under virtualenv ${VENV}"
install_mxnet() {
    pushd .
    cd python
    pip3 install -e .
    pip3 install opencv-python matplotlib graphviz jupyter ipython
    popd
}

install_mxnet

echo "

========================================================================================
Done! MXNet for Python installation is complete. Go ahead and explore MXNet with Python.
========================================================================================

Use the following command to enter the virtualenv:
$ source ${VENV}/bin/activate
$ iptyhon

You can then start using mxnet

import mxnet as mx
x = mx.nd.ones((5,5))
"

error: pathspec 'setup-utils/install-mxnet-virtualenv.sh' did not match any file(s) known to git


add script to update version easily

add script to update version easily

#
# Usage:
#   ./update_version.sh 0.3.0
#

git flow release start v$1
sed -i -e "s/__version__ = '.*'/__version__ = '$1'/g" frontend_notification/__init__.py

#rm -rf docs/html
#python setup.py develop
#make docs
#git commit docs nvd3/__init__.py -m "Update to version v$1"
git commit -a -m "Update to version v$1"
git flow release finish v$1
python setup.py sdist upload -r pypi

git push origin develop; git push origin master; git push --tags

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


ci: Install stack from git when necessary

verlte() {
    [  "$1" = "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -n1)" ]
}

mkdir -p "$build_dir/bin"

if command -v stack; then
	stack_ver=$(stack --numeric-version)
else
	stack_ver=0
fi

ghc_ver=$(ghc --numeric-version)

# we need at least 1.9.4 for `stack ide packages --cabal-files --stdout`
if verlte "$stack_ver" 1.9.3 &&
   verlte 8.2.2 "$ghc_ver"
then
	PATH="$build_dir/bin:$PATH"
	export PATH

	cabal v2-install \
	      --symlink-bindir="$build_dir/bin" \
	      --constraint "network < 3" \
	      --package-env=/dev/null \
	      hpack || exit 1

	stack_dir="$(mktemp --tmpdir -d "cabal-helper.stacksrcXXXXXXXXX")"

	git clone \
	    --depth=1 \
	    --branch=stable \
	    https://github.com/commercialhaskell/stack "$stack_dir"  || exit 1

	(
		cd "$stack_dir"
		hpack
		cabal v2-install \
		      --symlink-bindir="$build_dir/bin" \
		      --constraint "Cabal == 2.4.0.1" \
		      --constraint "network < 3" . \
		      --package-env=/dev/null || exit 1
        ) || exit 1
fi

error: pathspec 'scripts/ci/steps/25-deps.sh' did not match any file(s) known to git


git-pull-develop.sh

git-pull-develop.sh

#!/usr/bin/env bash
stash() {
  # check if we have un-committed changes to stash
  git status --porcelain | grep "^." >/dev/null;
  if [[ $? -eq 0 ]]
  then
    if git stash save -u "git-update on `date`";
    then
      stash=1;
    fi
  fi
}
unstash() {
  # check if we have un-committed change to restore from the stash
  if [[ ${stash} -eq 1 ]]
  then
    git stash pop;
  fi
}
echo "Pruning remote branches no longer on remote"
git -c diff.mnemonicprefix=false -c core.quotepath=false fetch --prune origin
stash=0;
stash;
branch=`git branch | grep "\*" | cut -d " " -f 2-9`;
if [[ "$branch" == "develop" ]]
then
  git pull origin develop;
else
  git checkout develop;
  git pull origin develop;
  #git checkout "$branch";  // If you want to switch back and merge changes
  #git rebase develop;
fi
sleep 3
unstash;
echo "Deleting local branches that have been merged to develop already"
git branch --merged | egrep -v "(^\*|master|dev)" | xargs -r git branch -d
#sleep 10

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


Create nodejs_uninstall.sh

Create nodejs_uninstall.sh

#! /bin/bash
# run it by: ./uninstall-node.sh
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules/
sudo rm -rf /usr/local/include/node/
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/bin/_node/

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


multi thread support

multi thread support

#!/bin/bash
# Job pooling for bash shell scripts
# This script provides a job pooling functionality where you can keep up to n
# processes/functions running in parallel so that you don't saturate a system
# with concurrent processes.
#
# Got inspiration from http://stackoverflow.com/questions/6441509/how-to-write-a-process-pool-bash-shell
#
# Copyright (c) 2012 Vince Tse
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# end-of-jobs marker
job_pool_end_of_jobs="JOBPOOL_END_OF_JOBS"

# job queue used to send jobs to the workers
job_pool_job_queue=/tmp/job_pool_job_queue_$$

# where to run results to
job_pool_result_log=/tmp/job_pool_result_log_$$

# toggle command echoing
job_pool_echo_command=0

# number of parallel jobs allowed. also used to determine if job_pool_init
# has been called when jobs are queued.
job_pool_pool_size=-1

# \brief variable to check for number of non-zero exits
job_pool_nerrors=0

################################################################################
# private functions
################################################################################

# \brief debug output
function _job_pool_echo()
{
    if [[ "${job_pool_echo_command}" == "1" ]]; then
echo $@
    fi
}

# \brief cleans up
function _job_pool_cleanup()
{
    rm -f ${job_pool_job_queue} ${job_pool_result_log}
}

# \brief signal handler
function _job_pool_exit_handler()
{
    _job_pool_stop_workers
    _job_pool_cleanup
}

# \brief print the exit codes for each command
# \param[in] result_log the file where the exit codes are written to
function _job_pool_print_result_log()
{
    job_pool_nerrors=$(grep ^ERROR "${job_pool_result_log}" | wc -l)
    cat "${job_pool_result_log}" | sed -e 's/^ERROR//'
}

# \brief the worker function that is called when we fork off worker processes
# \param[in] id the worker ID
# \param[in] job_queue the fifo to read jobs from
# \param[in] result_log the temporary log file to write exit codes to
function _job_pool_worker()
{
    local id=$1
    local job_queue=$2
    local result_log=$3
    local line=

    exec 7<> ${job_queue}
    while [[ "${line}" != "${job_pool_end_of_jobs}" && -e "${job_queue}" ]]; do
        # workers block on the exclusive lock to read the job queue
        flock --exclusive 7
        read line <${job_queue}
        flock --unlock 7
        # the worker should exit if it sees the end-of-job marker or run the
        # job otherwise and save its exit code to the result log.
        if [[ "${line}" == "${job_pool_end_of_jobs}" ]]; then
            # write it one more time for the next sibling so that everyone
            # will know we are exiting.
            echo "${line}" >&7
        else
_job_pool_echo "### _job_pool_worker-${id}: ${line}"
            # run the job
            { eval ${line} ; }
            # now check the exit code and prepend "ERROR" to the result log entry
            # which we will use to count errors and then strip out later.
            local result=$?
            local status=
            if [[ "${result}" != "0" ]]; then
status=ERROR
            fi
            # now write the error to the log, making sure multiple processes
            # don't trample over each other.
            exec 8<> ${result_log}
            flock --exclusive 8
#             echo "${status}job_pool: exited ${result}: ${line}" >> ${result_log}
            flock --unlock 8
            exec 8>&-
            _job_pool_echo "### _job_pool_worker-${id}: exited ${result}: ${line}"
        fi
done
exec 7>&-
}

# \brief sends message to worker processes to stop
function _job_pool_stop_workers()
{
    # send message to workers to exit, and wait for them to stop before
    # doing cleanup.
    echo ${job_pool_end_of_jobs} >> ${job_pool_job_queue}
    wait
}

# \brief fork off the workers
# \param[in] job_queue the fifo used to send jobs to the workers
# \param[in] result_log the temporary log file to write exit codes to
function _job_pool_start_workers()
{
    local job_queue=$1
    local result_log=$2
    for ((i=0; i<${job_pool_pool_size}; i++)); do
_job_pool_worker ${i} ${job_queue} ${result_log} &
    done
}

################################################################################
# public functions
################################################################################

# \brief initializes the job pool
# \param[in] pool_size number of parallel jobs allowed
# \param[in] echo_command 1 to turn on echo, 0 to turn off
function job_pool_init()
{
    local pool_size=$1
    local echo_command=$2

    # set the global attibutes
    job_pool_pool_size=${pool_size:=1}
    job_pool_echo_command=${echo_command:=0}

    # create the fifo job queue and create the exit code log
    rm -rf ${job_pool_job_queue} ${job_pool_result_log}
    mkfifo ${job_pool_job_queue}
    touch ${job_pool_result_log}

    # fork off the workers
    _job_pool_start_workers ${job_pool_job_queue} ${job_pool_result_log}
}

# \brief waits for all queued up jobs to complete and shuts down the job pool
function job_pool_shutdown()
{
    _job_pool_stop_workers
    _job_pool_print_result_log
    _job_pool_cleanup
}

# \brief run a job in the job pool
function job_pool_run()
{
    if [[ "${job_pool_pool_size}" == "-1" ]]; then
job_pool_init
    fi
echo $@ >> ${job_pool_job_queue}
}

# \brief waits for all queued up jobs to complete before starting new jobs
# This function actually fakes a wait by telling the workers to exit
# when done with the jobs and then restarting them.
function job_pool_wait()
{
    _job_pool_stop_workers
    _job_pool_start_workers ${job_pool_job_queue} ${job_pool_result_log}
}

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


add vim-airline and syntastic

add vim-airline and syntastic

add vim-airline and syntastic pathogen bundles for install for current vimrc

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/csuttles/utils.git/'


Ajout script d'installation des polices

Ajout script d'installation des polices

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/bchartier/style-osm-geopicardie.git/'


Minor fix for the oem scrip

Minor fix for the oem scrip

error: pathspec 'Installer/debian' did not match any file(s) known to git
error: pathspec 'help/install-oem.sh' did not match any file(s) known to git


Setup script for getting dependencies

Setup script for getting dependencies

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/Aclark2089/Scapy_DDoS.git/'


build 2.7.3

build 2.7.3

#!/usr/bin/env bash
# Usage: $ build.sh <output-dir

SOURCE_TARBALL='http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2'
curl $SOURCE_TARBALL | tar zx
mv Python-2.7.3 src
cd src

./configure --prefix=$(pwd)/../python
make
make install

cd ..
tar cjf python-2.7.3.tar.bz2 python/

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


Change build.sh to exploit parallelism

Change build.sh to exploit parallelism

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/iasakura/CertSkel.git/'


build script added

build script added

cat \
src/flock.js \
src/utils.js \
src/core.js \
src/live.js \
src/event.js \
src/constants.js \
src/query.js \
> build/flock-latest.js

jsmin < build/flock-latest.js > build/flock-latest-min.js


Fixed the build break in savan/c

Fixed the build break in savan/c

git-svn-id: 938b416e21db2f01dc5c93b2a51c543066b9c9b8@2378 a5903396-d722-0410-b921-86c7d4935375

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/techhead/wsf_c.git/'


simple build script for testing

simple build script for testing

#!/bin/bash
python setup.py bdist_rpm
cd dist
rpm -ev tacc_stats-2.1.0-1
rpm -ivh tacc_stats-2.1.0-1.x86_64.rpm


Added build script

Added build script

#!/bin/bash

msg() {
    printf "\033[1;32m :: %s\n\033[0m" "$1"
}

msg "Building jar"
Rscript compile.r

msg "Documenting R code"
R -e 'devtools::document()'

msg "Updating R bindings"
R -e 'devtools::install()'


Add build script

Add build 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/jeremiahlee/page-translator.git/'


adding build script

adding build script

g++ -O3 -Wall *.cpp -o Release/RNNLMPara


created a build file.

created a build file.

#!/bin/bash

#------------------------------------------------
# Functions & other helpers
#------------------------------------------------

# Print the usage message
function usage {
    echo ""
    echo "usage: build.sh [options]"
    echo ""
    echo "Options:"
    echo " --no-tests       Skip the tests during mvn install."
    echo " -h,--help        Show this message."
    echo ""
}

# Check if Java in the right version is installed
function check_java {
    type java >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        echo >&2 "Java is required but it's not installed! Aborting."
        exit 100;
    fi
    local java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
    if [[ "$java_version" < "1.8" ]]; then
        echo >&2 "At least Java 8 is required! Aborting."
        exit 101;
    fi
}

# Check if Maven (in the right version) is installed
function check_maven {
    type mvn >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        echo >&2 "Maven is required, but it's not installed! Aborting."
        exit 110;
    fi
    local maven_version=$(mvn --version 2>&1 | awk -F ' ' '/Apache Maven/ {print $3}')
    if [[ "$maven_version" < "3.3" ]]; then
        echo >&2 "At least Maven version 3.3 is recommended!"
    fi
}

# Check if Node in the right version is installed
function check_node {
    type node >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        echo >&2 "Node.JS is required, but it's not installed! Aborting."
        exit 120;
    fi
    local node_version=$(node --version)
    if [[ "$node_version" < "v0.12" ]]; then
        echo >&2 "At least Node.JS version 0.12 is required! Aborting."
        exit 121;
    fi
}

# Check if Grunt CLI in the right version is installed
function check_grunt {
    type grunt >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        echo >&2 "Grunt is required, but it's not installed! Aborting."
        exit 130;
    fi
    local grunt_version=$(grunt --version | awk -F ' ' '{print $2}')
    if [[ "$grunt_version" < "v0.1.13" ]]; then
        echo >&2 "At least Grunt CLI version 0.1.13 is required! Aborting."
        exit 132;
    fi
}

# Check all tool requirements (Java, Node, ...)
function check_requirements {
    check_java
    check_maven
    check_node
    check_grunt
}

# Do the magic for the frontend
function run_npm_and_grunt {
    npm install
    grunt
}

# Run maven install (with or without tests)
function run_maven_install {
    if [[ "$skip_tests" = true ]]; then
        mvn install -Dmaven.test.skip=true
    else
        mvn install
    fi
}

#------------------------------------------------
# Main
#------------------------------------------------

# init. vars
skip_tests=false

# read command line arguments
while [ "$1" != "" ]; do
    case $1 in
        --no-tests )
            skip_tests=true
            ;;
        -h | --help )
            usage
            exit
            ;;
        * )
            echo "Unkown command line argument: $1!"
            usage
            exit 1
    esac
    shift
done

check_requirements

cd main/src/main/webapp
run_npm_and_grunt

cd ../../../..
run_maven_install

exit 0


Build change for go 1.5

Build change for go 1.5

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/AchievementNetwork/static.git/'


add install wrapper

add install wrapper

#!/bin/bash
# BGPanel installation wrapper
# http://bgpanel.net

#
# Currently Supported Operating Systems:
#
#   RHEL 6 - 7
#   CentOS 6 - 7
#   Debian 7, 8
#   Ubuntu 12.04 - 16.04
#

# Am I root?
if [ "x$(id -u)" != 'x0' ]; then
    echo 'Error: this script can only be executed by root'
    exit 1
fi

# Detect OS
case $(head -n1 /etc/issue | cut -f 1 -d ' ') in
    Debian)     type="debian" ;;
    Ubuntu)     type="ubuntu" ;;
    *)          type="rhel" ;;
esac

# Fallback to Ubuntu
if [ ! -e "/etc/redhat-release" ]; then
    type='ubuntu'
fi

# Check wget
if [ -e '/usr/bin/wget' ]; then
    wget https://raw.githubusercontent.com/BGPanel/BGPanel-v2/master/install/bg-install-$type.sh -O bg-install-$type.sh
    if [ "$?" -eq '0' ]; then
        bash bg-install-$type.sh $*
        exit
    else
        echo "Error: bg-install-$type.sh download failed."
        exit 1
    fi
fi

# Check curl
if [ -e '/usr/bin/curl' ]; then
    curl -O https://raw.githubusercontent.com/BGPanel/BGPanel-v2/master/install/bg-install-$type.sh
    if [ "$?" -eq '0' ]; then
        bash bg-install-$type.sh $*
        exit
    else
        echo "Error: bg-install-$type.sh download failed."
        exit 1
    fi
fi

exit

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


Script for release build

Script for release build

#!/bin/bash

tundra2 -v linux-gcc-release

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


use https instead of ssh auth on submodules

#!/bin/bash
#
# Copyright 2014-2015 Range Networks, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# See the COPYING file in the main directory for details.
#

source $(dirname $0)/common.source

for component in $REPOS
do
	if [ ! -d $component ]; then
		echo "# cloning $component"
		sayAndDo git clone https://github.com/RangeNetworks/$component.git
		cd $component
		for remote in `git branch -r | grep -v master `
		do
			sayAndDo git checkout --track $remote
		done
		sayAndDo git checkout master
		sayAndDo git submodule update --init --recursive --remote
		# sayAndDo doesn't like this string at all, can't seem to get the quoting right
		git submodule foreach 'git checkout `git config -f $toplevel/.gitmodules submodule.$name.branch`'
		cd ..
		echo
	fi
done

#!/bin/bash
#
# Copyright 2014 Range Networks, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# See the COPYING file in the main directory for details.
#

source $(dirname $0)/common.source

for component in $REPOS
do
	if [ ! -d $component ]; then
		echo "# cloning $component"
		sayAndDo git clone git@github.com:RangeNetworks/$component.git
		cd $component
		for remote in `git branch -r | grep -v master `
		do
			sayAndDo git checkout --track $remote
		done
		sayAndDo git checkout master
		sayAndDo git submodule update --init --recursive --remote
		# sayAndDo doesn't like this string at all, can't seem to get the quoting right
		git submodule foreach 'git checkout `git config -f $toplevel/.gitmodules submodule.$name.branch`'
		cd ..
		echo
	fi
done


Fix go example test to refer to remote repos

Another part of #976.

--
MOS_MIGRATED_REVID=115859513

#!/bin/bash
#
# Copyright 2015 The Bazel Authors. All arights reserved.
#
# 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.
#
# Tests the examples provided in Bazel
#

# Load test environment
source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
  || { echo "test-setup.sh not found!" >&2; exit 1; }

function setup_go() {
  copy_examples

  GO_REPO=$PWD/tools/build_rules/go/toolchain

  cat <<EOF > WORKSPACE
new_local_repository(
    name = "bazel_tools",
    path = __workspace_dir__,
    build_file = __workspace_dir__ + "/BUILD",
)
new_local_repository(
    name = "golang_linux_amd64",
    path = "$GO_REPO",
    build_file = "$GO_REPO/BUILD"
)
new_local_repository(
    name = "golang_darwin_amd64",
    path = "$GO_REPO",
    build_file = "$GO_REPO/BUILD"
)
EOF

  # avoid trying to download the SDK from within the test.
  rm -rf tools/build_rules/go/toolchain
  for p in golang_linux_amd64 golang_darwin_amd64 ; do
    d=$TEST_SRCDIR/external/${p}
    if [[ -d "${d}" ]]; then
      for f in $(cd ${d}; find -L . -type f -print ) ; do
        mkdir -p tools/build_rules/go/toolchain/$(dirname $f)
        ln -s ${d}/$f tools/build_rules/go/toolchain/$f
      done
    fi
  done
  cat <<'EOF' >tools/build_rules/go/toolchain/BUILD
package(
  default_visibility = [ "//visibility:public" ])

filegroup(
  name = "toolchain",
  srcs = glob(["go/bin/*", "go/pkg/**", ]),
)

filegroup(
  name = "go_tool",
  srcs = [ "go/bin/go" ],
)
EOF
  cat  <<EOF > BUILD
load("/tools/build_rules/go/def", "go_prefix")
go_prefix("prefix")
EOF

}

function test_basic() {
  setup_go
  mkdir -p ex/
  cat <<EOF > ex/m.go
package main
import (
  "fmt"

  "prefix/ex"
)
func main() {
  fmt.Println("F", ex.F())
}

EOF
  cat <<EOF > ex/l.go
package ex
func F() int { return 42 }
EOF

  cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_library(name = "go_default_library",
  srcs = [ "l.go"])
go_binary(name = "m",
  srcs = [ "m.go" ],
  deps = [ ":go_default_library" ])
EOF

  assert_build //ex:m
  test -x ./bazel-bin/ex/m || fail "binary not found"
  (./bazel-bin/ex/m > out) || fail "binary does not execute"
  grep "F 42" out || fail "binary output suspect"
}

function test_runfiles() {
  setup_go
  mkdir -p ex/

# Note this binary is also a test (for the correct handling of runfiles by
# Bazel's go_binary rule).
  cat <<EOF > ex/rf.go
package main
import (
  "fmt"
  "log"
  "io/ioutil"
)

func main() {
  rfcontent, err := ioutil.ReadFile("ex/runfile")
  if err != nil {
    log.Fatalf("Runfiles test binary: Error reading from runfile: %v", err)
  }

  fmt.Printf("Runfile: %s\n", rfcontent)
}

EOF

  cat <<EOF > ex/rf_test.go
package main
import (
  "fmt"
  "io/ioutil"
  "testing"
)

func TestRunfiles(t *testing.T) {
  rfcontent, err := ioutil.ReadFile("runfile")
  if err != nil {
    t.Errorf("TestRunfiles: Error reading from runfile: %v", err)
  }

  if string(rfcontent) != "12345\n" {
    t.Errorf("TestRunfiles: Read incorrect value from runfile: %s", rfcontent)
  }

  fmt.Printf("Runfile: %s\n", rfcontent)
}
EOF

  cat <<EOF > ex/runfile
12345
EOF

  cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_binary", "go_test")
go_binary(name = "runfiles_bin",
  srcs = [ "rf.go" ],
  data = [ "runfile" ])
go_test(name = "runfiles_test",
  srcs = [ "rf_test.go" ],
  data = [ "runfile" ])
EOF

  assert_build //ex:runfiles_bin
  test -x ./bazel-bin/ex/runfiles_bin || fail "binary not found"
  (./bazel-bin/ex/runfiles_bin > out) || fail "binary does not execute"
  grep "Runfile: 12345" out || fail "binary output suspect"

  assert_build //ex:runfiles_test
  test -x ./bazel-bin/ex/runfiles_test || fail "binary not found"
  (./bazel-bin/ex/runfiles_test > out) || fail "binary does not execute"
  grep "Runfile: 12345" out || fail "binary output suspect"
}

function test_runfiles_lib() {
  setup_go
  mkdir -p ex/
  cat <<EOF > ex/m.go
package main
import (
  "fmt"
  "io/ioutil"
  "log"

  "prefix/ex"
)
func main() {
  rfcontent, err := ioutil.ReadFile(ex.RunfilePath())
  if err != nil {
    log.Fatalf("Runfiles test binary: Error reading from runfile: %v", err)
  }

  fmt.Printf("Runfile: %s\n", rfcontent)
}

EOF

  cat <<EOF > ex/l.go
package ex
func RunfilePath() string { return "ex/runfile" }
EOF

  cat <<EOF > ex/runfile
12345
EOF

    cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_library(name = "go_default_library",
  data = [ "runfile" ],
  srcs = [ "l.go"])
go_binary(name = "m",
  srcs = [ "m.go" ],
  deps = [ ":go_default_library" ])
EOF

  assert_build //ex:m
  test -x ./bazel-bin/ex/m || fail "binary not found"
  (./bazel-bin/ex/m > out) || fail "binary does not execute"
  grep "Runfile: 12345" out || fail "binary output suspect"
}

function test_empty_prefix() {
  setup_go

 cat  <<EOF > BUILD
load("/tools/build_rules/go/def", "go_prefix")
go_prefix("")
EOF

  rm -rf ex
  mkdir -p ex/
  cat <<EOF > ex/m.go
package main
import (
  "fmt"

  "library"
)
func main() {
  fmt.Println(library.F())
}
EOF
   cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_binary(name = "m",
  srcs = [ "m.go" ],
  deps = [ "//library:go_default_library" ])
EOF

  mkdir -p library

  cat <<EOF > library/BUILD
package(default_visibility=["//visibility:public"])
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_library(name = "go_default_library",
  srcs = [ "l.go"])
EOF

   cat <<EOF > library/l.go
package library
func F() int { return 42 }
EOF

  assert_build //ex:m
  test -x ./bazel-bin/ex/m || fail "binary not found"
  (./bazel-bin/ex/m > out) || fail "binary does not execute"
  grep "42" out || fail "binary output suspect"
}

run_suite "go_examples"

#!/bin/bash
#
# Copyright 2015 The Bazel Authors. All arights reserved.
#
# 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.
#
# Tests the examples provided in Bazel
#

# Load test environment
source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
  || { echo "test-setup.sh not found!" >&2; exit 1; }

function setup_go() {
  copy_examples

  cat <<EOF > WORKSPACE

EOF

  # avoid trying to download the SDK from within the test.
  rm -rf tools/build_rules/go/toolchain
  for p in golang_linux_amd64 golang_darwin_amd64 ; do
    d=$TEST_SRCDIR/external/${p}
    if [[ -d "${d}" ]]; then
      for f in $(cd ${d}; find -L . -type f -print ) ; do
        mkdir -p tools/build_rules/go/toolchain/$(dirname $f)
        ln -s ${d}/$f tools/build_rules/go/toolchain/$f
      done
    fi
  done
  cat <<'EOF' >tools/build_rules/go/toolchain/BUILD
package(
  default_visibility = [ "//visibility:public" ])

filegroup(
  name = "toolchain",
  srcs = glob(["go/bin/*", "go/pkg/**", ]),
)

filegroup(
  name = "go_tool",
  srcs = [ "go/bin/go" ],
)
EOF
  cat  <<EOF > BUILD
load("/tools/build_rules/go/def", "go_prefix")
go_prefix("prefix")
EOF

}

function test_basic() {
  setup_go
  mkdir -p ex/
  cat <<EOF > ex/m.go
package main
import (
  "fmt"

  "prefix/ex"
)
func main() {
  fmt.Println("F", ex.F())
}

EOF
  cat <<EOF > ex/l.go
package ex
func F() int { return 42 }
EOF

  cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_library(name = "go_default_library",
  srcs = [ "l.go"])
go_binary(name = "m",
  srcs = [ "m.go" ],
  deps = [ ":go_default_library" ])
EOF

  assert_build //ex:m
  test -x ./bazel-bin/ex/m || fail "binary not found"
  (./bazel-bin/ex/m > out) || fail "binary does not execute"
  grep "F 42" out || fail "binary output suspect"
}

function test_runfiles() {
  setup_go
  mkdir -p ex/

# Note this binary is also a test (for the correct handling of runfiles by
# Bazel's go_binary rule).
  cat <<EOF > ex/rf.go
package main
import (
  "fmt"
  "log"
  "io/ioutil"
)

func main() {
  rfcontent, err := ioutil.ReadFile("ex/runfile")
  if err != nil {
    log.Fatalf("Runfiles test binary: Error reading from runfile: %v", err)
  }

  fmt.Printf("Runfile: %s\n", rfcontent)
}

EOF

  cat <<EOF > ex/rf_test.go
package main
import (
  "fmt"
  "io/ioutil"
  "testing"
)

func TestRunfiles(t *testing.T) {
  rfcontent, err := ioutil.ReadFile("runfile")
  if err != nil {
    t.Errorf("TestRunfiles: Error reading from runfile: %v", err)
  }

  if string(rfcontent) != "12345\n" {
    t.Errorf("TestRunfiles: Read incorrect value from runfile: %s", rfcontent)
  }

  fmt.Printf("Runfile: %s\n", rfcontent)
}
EOF

  cat <<EOF > ex/runfile
12345
EOF

  cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_binary", "go_test")
go_binary(name = "runfiles_bin",
  srcs = [ "rf.go" ],
  data = [ "runfile" ])
go_test(name = "runfiles_test",
  srcs = [ "rf_test.go" ],
  data = [ "runfile" ])
EOF

  assert_build //ex:runfiles_bin
  test -x ./bazel-bin/ex/runfiles_bin || fail "binary not found"
  (./bazel-bin/ex/runfiles_bin > out) || fail "binary does not execute"
  grep "Runfile: 12345" out || fail "binary output suspect"

  assert_build //ex:runfiles_test
  test -x ./bazel-bin/ex/runfiles_test || fail "binary not found"
  (./bazel-bin/ex/runfiles_test > out) || fail "binary does not execute"
  grep "Runfile: 12345" out || fail "binary output suspect"
}

function test_runfiles_lib() {
  setup_go
  mkdir -p ex/
  cat <<EOF > ex/m.go
package main
import (
  "fmt"
  "io/ioutil"
  "log"

  "prefix/ex"
)
func main() {
  rfcontent, err := ioutil.ReadFile(ex.RunfilePath())
  if err != nil {
    log.Fatalf("Runfiles test binary: Error reading from runfile: %v", err)
  }

  fmt.Printf("Runfile: %s\n", rfcontent)
}

EOF

  cat <<EOF > ex/l.go
package ex
func RunfilePath() string { return "ex/runfile" }
EOF

  cat <<EOF > ex/runfile
12345
EOF

    cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_library(name = "go_default_library",
  data = [ "runfile" ],
  srcs = [ "l.go"])
go_binary(name = "m",
  srcs = [ "m.go" ],
  deps = [ ":go_default_library" ])
EOF

  assert_build //ex:m
  test -x ./bazel-bin/ex/m || fail "binary not found"
  (./bazel-bin/ex/m > out) || fail "binary does not execute"
  grep "Runfile: 12345" out || fail "binary output suspect"
}

function test_empty_prefix() {
  setup_go

 cat  <<EOF > BUILD
load("/tools/build_rules/go/def", "go_prefix")
go_prefix("")
EOF

  rm -rf ex
  mkdir -p ex/
  cat <<EOF > ex/m.go
package main
import (
  "fmt"

  "library"
)
func main() {
  fmt.Println(library.F())
}
EOF
   cat <<EOF > ex/BUILD
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_binary(name = "m",
  srcs = [ "m.go" ],
  deps = [ "//library:go_default_library" ])
EOF

  mkdir -p library

  cat <<EOF > library/BUILD
package(default_visibility=["//visibility:public"])
load("/tools/build_rules/go/def", "go_library", "go_binary")
go_library(name = "go_default_library",
  srcs = [ "l.go"])
EOF

   cat <<EOF > library/l.go
package library
func F() int { return 42 }
EOF

  assert_build //ex:m
  test -x ./bazel-bin/ex/m || fail "binary not found"
  (./bazel-bin/ex/m > out) || fail "binary does not execute"
  grep "42" out || fail "binary output suspect"
}

run_suite "go_examples"


Update to monitorInputImagesDir.bash script to allow for non-instantaneous upload times

git-svn-id: 0d44558f3e9696571fe5d95dcd0b555bae93067b@10206 7c0444ca-5550-0410-9008-faecdbe78eb5

#!/usr/bin/env bash
#
# This script monitors the inputImages folder for files and prints the paths
# to the files as they are detected.
#
# It was written to be used on a remote machine while upload_to_aws.bash
# (in the demo-localsize.tgz archive) is running on a local machine;
# the output can then be piped to the PASCAL_Classification executable.
#
# The script watches for a file inputImages/.uploadedfile, and
# when such a file is noticed, it prints the contents of .uploadedfile
# and then deletes .uploadedfile.  It then watches for
# inputImages/.uploadedfile again, and repeats the process.
#
# If the file inputImages/.uploadfinished appears, the script breaks out
# of the .uploadedfile loop, deletes the .uploadfinished file, and exits.
#
# The assumption behind this script is that the local side would upload
# an image into the inputImages folder, and on completion, write the
# path to the uploaded file into inputImages/.uploadedfile.
# The local script would then watch for .uploadedfile to be deleted before
# uploading the next file.  When the last file had been uploaded and
# the corresponding .uploadedfile deleted, the local script would create
# the .uploadfinished file and then exit.
#
# The reason for the .uploadedfile file is so that monitorInputImagesDir.bash
# does not report the file until the file has finished uploading, so the
# local side should wait for uploading to finish before creating this file.
#
until test -f inputImages/.uploadfinished || test -f inputImages/.uploadedfile
do
    sleep 1
    if test -f inputImages/.uploadedfile
    then
        cat inputImages/.uploadedfile
        rm inputImages/.uploadedfile
    fi
done
rm inputImages/.uploadfinished

#!/usr/bin/env bash
ls inputImages/* | sort > olda
while true
do
    sleep 1
    ls inputImages/* | sort > newa
    diffs="$(diff -Nau olda newa | egrep '^[+][^+]' | cut -c2-)"
    test -n "$diffs" && echo "$diffs"
    mv newa olda
done


Template for scripts

Template for scripts

#! /bin/cat

# . ~/jab/src/bash/all_abored.sh

# aaaa may be defined in all_abored.sh

# x

alias a=ack
# _
# xx

alias aa=aack
# _x
# xxx

aaa () {
    aaack "$@"
}
# _xx
# xxxx
# _xxx
# xxxxx
# _xxxx
# xxxxxx
# _xxxxx

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