Fixing grepping for service names

Fixing grepping for service names

#!/bin/bash
set -e

# It takes ages on Docker to run the app without this
export MAVEN_OPTS="${MAVEN_OPTS} -Djava.security.egd=file:///dev/urandom"

function logInToCf() {
    local redownloadInfra="${1}"
    local cfUsername="${2}"
    local cfPassword="${3}"
    local cfOrg="${4}"
    local cfSpace="${5}"
    local apiUrl="${6:-api.run.pivotal.io}"
    CF_INSTALLED="$( cf --version || echo "false" )"
    CF_DOWNLOADED="$( test -r cf && echo "true" || echo "false" )"
    echo "CF Installed? [${CF_INSTALLED}], CF Downloaded? [${CF_DOWNLOADED}]"
    if [[ ${CF_INSTALLED} == "false" && (${CF_DOWNLOADED} == "false" || ${CF_DOWNLOADED} == "true" && ${redownloadInfra} == "true") ]]; then
        echo "Downloading Cloud Foundry"
        curl -L "https://cli.run.pivotal.io/stable?release=linux64-binary&source=github" --fail | tar -zx
        CF_DOWNLOADED="true"
    else
        echo "CF is already installed or was already downloaded but the flag to redownload was disabled"
    fi

    if [[ ${CF_DOWNLOADED} == "true" ]]; then
        echo "Adding CF to PATH"
        PATH=${PATH}:`pwd`
        chmod +x cf
    fi

    echo "Cloud foundry version"
    cf --version

    echo "Logging in to CF to org [${cfOrg}], space [${cfSpace}]"
    cf api --skip-ssl-validation "${apiUrl}"
    cf login -u "${cfUsername}" -p "${cfPassword}" -o "${cfOrg}" -s "${cfSpace}"
}

function deployRabbitMqToCf() {
    local serviceName="${1:-rabbitmq-github}"
    echo "Waiting for RabbitMQ to start"
    APP_NAME="${serviceName}"
    (cf s | awk -v "app=${APP_NAME}" '$1 == app {print($0)}'  && echo "found ${APP_NAME}") ||
        (cf cs cloudamqp lemur "${APP_NAME}" && echo "Started RabbitMQ") ||
        (cf cs p-rabbitmq standard "${APP_NAME}" && echo "Started RabbitMQ for PCF Dev")
}

function deleteMySql() {
    local serviceName="${1:-mysql-github}"
    APP_NAME="${serviceName}"
    cf delete-service -f ${APP_NAME}
}

function deployMySqlToCf() {
    local serviceName="${1:-mysql-github}"
    echo "Waiting for MySQL to start"
    APP_NAME="${serviceName}"
    (cf s | awk -v "app=${APP_NAME}" '$1 == app {print($0)}'  && echo "found ${APP_NAME}") ||
        (cf cs p-mysql 100mb "${APP_NAME}" && echo "Started MySQL") ||
        (cf cs p-mysql 512mb "${APP_NAME}" && echo "Started MySQL for PCF Dev")
}

function deployAndRestartAppWithName() {
    local appName="${1}"
    local jarName="${2}"
    local env="${3}"
    echo "Deploying and restarting app with name [${appName}] and jar name [${jarName}]"
    deployAppWithName "${appName}" "${jarName}" "${env}" 'true'
    restartApp "${appName}"
}

function deployAndRestartAppWithNameForSmokeTests() {
    local appName="${1}"
    local jarName="${2}"
    local rabbitName="${3}"
    local eurekaName="${4}"
    local mysqlName="${5}"
    local profiles="${6:-cloud,smoke}"
    local env="${7:-test}"
    local lowerCaseAppName=$( echo "${appName}" | tr '[:upper:]' '[:lower:]' )
    deleteApp "${appName}"
    echo "Deploying and restarting app with name [${appName}] and jar name [${jarName}] and env [${env}]"
    deployAppWithName "${appName}" "${jarName}" "${env}" 'false'
    bindService "${rabbitName}" "${appName}"
    if [[ "${eurekaName}" != "" ]]; then
        bindService "${eurekaName}" "${appName}"
    fi
    bindService "${mysqlName}" "${appName}"
    setEnvVar "${lowerCaseAppName}" 'spring.profiles.active' "${profiles}"
    restartApp "${appName}"
}

function appHost() {
    local appName="${1}"
    local lowerCase="$( echo "${appName}" | tr '[:upper:]' '[:lower:]' )"
    APP_HOST=`cf apps | awk -v "app=${lowerCase}" '$1 == app {print($0)}' | tr -s ' ' | cut -d' ' -f 6 | cut -d, -f1`
    echo "${APP_HOST}" | tail -1
}

function deployAppWithName() {
    local appName="${1}"
    local jarName="${2}"
    local env="${3}"
    local useManifest="${4:-false}"
    local manifestOption=$( if [[ "${useManifest}" == "false" ]] ; then echo "--no-manifest"; else echo "" ; fi )
    local lowerCaseAppName=$( echo "${appName}" | tr '[:upper:]' '[:lower:]' )
    local hostname="${lowerCaseAppName}"
    if [[ ${CF_HOSTNAME_UUID} != "" ]]; then
        hostname="${hostname}-${CF_HOSTNAME_UUID}"
    fi
    if [[ ${env} != "prod" ]]; then
        hostname="${hostname}-${env}"
    fi
    echo "Deploying app with name [${lowerCaseAppName}], env [${env}] with manifest [${useManifest}] and host [${hostname}]"
    if [[ ! -z "${manifestOption}" ]]; then
        cf push "${lowerCaseAppName}" -m 256m -i 1 -p "${OUTPUT_FOLDER}/${jarName}.jar" -n "${hostname}" --no-start -b https://github.com/cloudfoundry/java-buildpack.git#v3.8.1 ${manifestOption}
    else
        cf push "${lowerCaseAppName}" -p "${OUTPUT_FOLDER}/${jarName}.jar" -n "${hostname}" --no-start -b https://github.com/cloudfoundry/java-buildpack.git#v3.8.1
    fi
    APPLICATION_DOMAIN="$( appHost ${lowerCaseAppName} )"
    echo "Determined that application_domain for [${lowerCaseAppName}] is [${APPLICATION_DOMAIN}]"
    setEnvVar "${lowerCaseAppName}" 'APPLICATION_DOMAIN' "${APPLICATION_DOMAIN}"
    setEnvVar "${lowerCaseAppName}" 'JAVA_OPTS' '-Djava.security.egd=file:///dev/urandom'
}

function deleteApp() {
    local serviceName="${1}"
    local lowerCaseAppName=$( echo "${serviceName}" | tr '[:upper:]' '[:lower:]' )
    APP_NAME="${lowerCaseAppName}"
    echo "Deleting application [${APP_NAME}]"
    cf delete -f ${APP_NAME} || echo "Failed to delete the app. Continuing with the script"
}

function setEnvVarIfMissing() {
    local appName="${1}"
    local key="${2}"
    local value="${3}"
    echo "Setting env var [${key}] -> [${value}] for app [${appName}] if missing"
    cf env "${appName}" | grep "${key}" || setEnvVar appName key value
}

function setEnvVar() {
    local appName="${1}"
    local key="${2}"
    local value="${3}"
    echo "Setting env var [${key}] -> [${value}] for app [${appName}]"
    cf set-env "${appName}" "${key}" "${value}"
}

function restartApp() {
    local appName="${1}"
    echo "Restarting app with name [${appName}]"
    cf restart "${appName}"
}

function deployEureka() {
    local redeploy="${1}"
    local jarName="${2}"
    local appName="${3}"
    local env="${4}"
    echo "Deploying Eureka. Options - redeploy [${redeploy}], jar name [${jarName}], app name [${appName}], env [${env}]"
    local fileExists="true"
    local fileName="`pwd`/${OUTPUT_FOLDER}/${jarName}.jar"
    if [[ ! -f "${fileName}" ]]; then
        fileExists="false"
    fi
    if [[ ${fileExists} == "false" || ( ${fileExists} == "true" && ${redeploy} == "true" ) ]]; then
        deployAppWithName "${appName}" "${jarName}" "${env}"
        restartApp "${appName}"
        createServiceWithName "${appName}"
    else
        echo "Current folder is [`pwd`]; The [${fileName}] exists [${fileExists}]; redeploy flag was set [${redeploy}]. Skipping deployment"
    fi
}

function deployStubRunnerBoot() {
    local redeploy="${1}"
    local jarName="${2}"
    local repoWithJars="${3}"
    local rabbitName="${4}"
    local eurekaName="${5}"
    local env="${6:-test}"
    local stubRunnerName="${7:-stubrunner}"
    local fileExists="true"
    local fileName="`pwd`/${OUTPUT_FOLDER}/${jarName}.jar"
    if [[ ! -f "${fileName}" ]]; then
        fileExists="false"
    fi
    echo "Deploying Stub Runner. Options - redeploy [${redeploy}], jar name [${jarName}], app name [${stubRunnerName}]"
    if [[ ${fileExists} == "false" || ( ${fileExists} == "true" && ${redeploy} == "true" ) ]]; then
        deployAppWithName "${stubRunnerName}" "${jarName}" "${env}" "false"
        local prop="$( retrieveStubRunnerIds )"
        echo "Found following stub runner ids [${prop}]"
        setEnvVar "${stubRunnerName}" "stubrunner.ids" "${prop}"
        setEnvVar "${stubRunnerName}" "stubrunner.repositoryRoot" "${repoWithJars}"
        bindService "${rabbitName}" "${stubRunnerName}"
        if [[ "${eurekaName}" != "" ]]; then
            bindService "${eurekaName}" "${stubRunnerName}"
        fi
        restartApp "${stubRunnerName}"
    else
        echo "Current folder is [`pwd`]; The [${fileName}] exists [${fileExists}]; redeploy flag was set [${redeploy}]. Skipping deployment"
    fi
}

function bindService() {
    local serviceName="${1}"
    local appName="${2}"
    echo "Binding service [${serviceName}] to app [${appName}]"
    cf bind-service "${appName}" "${serviceName}"
}

function createServiceWithName() {
    local name="${1}"
    echo "Creating service with name [${name}]"
    APPLICATION_DOMAIN=`cf apps | grep ${name} | tr -s ' ' | cut -d' ' -f 6 | cut -d, -f1`
    JSON='{"uri":"http://'${APPLICATION_DOMAIN}'"}'
    cf create-user-provided-service "${name}" -p "${JSON}" || echo "Service already created. Proceeding with the script"
}

# The function uses Maven Wrapper - if you're using Maven you have to have it on your classpath
# and change this function
function extractMavenProperty() {
    local prop="${1}"
    MAVEN_PROPERTY=$(./mvnw ${MAVEN_ARGS} -q \
                    -Dexec.executable="echo" \
                    -Dexec.args="\${${prop}}" \
                    --non-recursive \
                    org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
    # In some spring cloud projects there is info about deactivating some stuff
    MAVEN_PROPERTY=$( echo "${MAVEN_PROPERTY}" | tail -1 )
    # In Maven if there is no property it prints out ${propname}
    if [[ "${MAVEN_PROPERTY}" == "\${${prop}}" ]]; then
        echo ""
    else
        echo "${MAVEN_PROPERTY}"
    fi
}

# The values of group / artifact ids can be later retrieved from Maven
function downloadJar() {
    local redownloadInfra="${1}"
    local repoWithJars="${2}"
    local groupId="${3}"
    local artifactId="${4}"
    local version="${5}"
    local destination="`pwd`/${OUTPUT_FOLDER}/${artifactId}-${version}.jar"
    local changedGroupId="$( echo "${groupId}" | tr . / )"
    local pathToJar="${repoWithJars}/${changedGroupId}/${artifactId}/${version}/${artifactId}-${version}.jar"
    if [[ ! -e ${destination} || ( -e ${destination} && ${redownloadInfra} == "true" ) ]]; then
        mkdir -p "${OUTPUT_FOLDER}"
        echo "Current folder is [`pwd`]; Downloading [${pathToJar}] to [${destination}]"
        (curl "${pathToJar}" -o "${destination}" --fail && echo "File downloaded successfully!") || (echo "Failed to download file!" && return 1)
    else
        echo "File [${destination}] exists and redownload flag was set to false. Will not download it again"
    fi
}

function propagatePropertiesForTests() {
    local projectArtifactId="${1}"
    local stubRunnerHost="${2:-stubrunner-${projectArtifactId}}"
    local fileLocation="${3:-${OUTPUT_FOLDER}/test.properties}"
    echo "Propagating properties for tests. Project [${projectArtifactId}] stub runner host [${stubRunnerHost}] properties location [${fileLocation}]"
    # retrieve host of the app / stubrunner
    # we have to store them in a file that will be picked as properties
    rm -rf "${fileLocation}"
    local host=$( appHost "${projectArtifactId}" )
    APPLICATION_URL="${host}"
    echo "APPLICATION_URL=${host}" >> ${fileLocation}
    host=$( appHost "${stubRunnerHost}" )
    STUBRUNNER_URL="${host}"
    echo "STUBRUNNER_URL=${host}" >> ${fileLocation}
    echo "Resolved properties"
    cat ${fileLocation}
}

function readTestPropertiesFromFile() {
    local fileLocation="${1:-${OUTPUT_FOLDER}/test.properties}"
    if [ -f "${fileLocation}" ]
    then
      echo "${fileLocation} found."
      while IFS='=' read -r key value
      do
        key=$(echo ${key} | tr '.' '_')
        eval "${key}='${value}'"
      done < "${fileLocation}"
    else
      echo "${fileLocation} not found."
    fi
}

# Function that executes integration tests
function runSmokeTests() {
    local applicationHost="${1}"
    local stubrunnerHost="${2}"
    echo "Running smoke tests"

    if [[ "${PROJECT_TYPE}" == "MAVEN" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}" || ( echo "$( printTestResults )" && return 1)
            else
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( echo "$( printTestResults )" && return 1)
            fi
        else
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}"
            else
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
            fi
        fi
    elif [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            ./gradlew smoke -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( echo "$( printTestResults )" && return 1)
        else
            ./gradlew smoke -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
        fi
    else
        echo "Unsupported project build tool"
        return 1
    fi
}

# Function that executes end to end tests
function runE2eTests() {
    local applicationHost="${1}"
    local stubrunnerHost="${2}"
    echo "Running e2e tests"

    if [[ "${PROJECT_TYPE}" == "MAVEN" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}" || ( $( printTestResults ) && return 1)
            else
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( $( printTestResults ) && return 1)
            fi
        else
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}"
            else
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
            fi
        fi
    elif [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            ./gradlew e2e -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( $( printTestResults ) && return 1)
        else
            ./gradlew e2e -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
        fi
    else
        echo "Unsupported project build tool"
        return 1
    fi
}

function findLatestProdTag() {
    local LAST_PROD_TAG=$(git for-each-ref --sort=taggerdate --format '%(refname)' refs/tags/prod | head -n 1)
    LAST_PROD_TAG=${LAST_PROD_TAG#refs/tags/}
    echo "${LAST_PROD_TAG}"
}

function extractVersionFromProdTag() {
    local tag="${1}"
    LAST_PROD_VERSION=${tag#prod/}
    echo "${LAST_PROD_VERSION}"
}

function retrieveGroupId() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        local result=$( ./gradlew groupId -q )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    else
        local result=$( ruby -r rexml/document -e 'puts REXML::Document.new(File.new(ARGV.shift)).elements["/project/groupId"].text' pom.xml || ./mvnw ${MAVEN_ARGS} org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.groupId |grep -Ev '(^\[|Download\w+:)' )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    fi
}

function retrieveArtifactId() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        local result=$( ./gradlew artifactId -q )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    else
        local result=$( ruby -r rexml/document -e 'puts REXML::Document.new(File.new(ARGV.shift)).elements["/project/artifactId"].text' pom.xml || ./mvnw ${MAVEN_ARGS} org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.artifactId |grep -Ev '(^\[|Download\w+:)' )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    fi
}

# Jenkins passes these as a separate step, in Concourse we'll do it manually
function prepareForSmokeTests() {
    local redownloadInfra="${1}"
    local username="${2}"
    local password="${3}"
    local org="${4}"
    local space="${5}"
    local api="${6}"
    echo "Retrieving group and artifact id - it can take a while..."
    projectGroupId=$( retrieveGroupId )
    projectArtifactId=$( retrieveArtifactId )
    mkdir -p "${OUTPUT_FOLDER}"
    logInToCf "${redownloadInfra}" "${username}" "${password}" "${org}" "${space}" "${api}"
    propagatePropertiesForTests ${projectArtifactId}
    readTestPropertiesFromFile
}

# Jenkins passes these as a separate step, in Concourse we'll do it manually
function prepareForE2eTests() {
    local redownloadInfra="${1}"
    local username="${2}"
    local password="${3}"
    local org="${4}"
    local space="${5}"
    local api="${6}"
    echo "Retrieving group and artifact id - it can take a while..."
    projectGroupId=$( retrieveGroupId )
    projectArtifactId=$( retrieveArtifactId )
    echo "Project groupId is ${projectGroupId}"
    echo "Project artifactId is ${projectArtifactId}"
    mkdir -p "${OUTPUT_FOLDER}"
    logInToCf "${redownloadInfra}" "${username}" "${password}" "${org}" "${space}" "${api}"
    propagatePropertiesForTests ${projectArtifactId}
    readTestPropertiesFromFile
}

function isMavenProject() {
    [ -f "mvnw" ]
}

function isGradleProject() {
    [ -f "gradlew" ]
}

function projectType() {
    if isMavenProject; then
        echo "MAVEN"
    elif isGradleProject; then
        echo "GRADLE"
    else
        echo "UNKNOWN"
    fi
}

function outputFolder() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        echo "build/libs"
    else
        echo "target"
    fi
}

function testResultsFolder() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        echo "**/test-results/*.xml"
    else
        echo "**/surefire-reports/*"
    fi
}

function printTestResults() {
    echo -e "\n\nBuild failed!!! - will print all test results to the console (it's the easiest way to debug anything later)\n\n" && tail -n +1 "$( testResultsFolder )"
}

function retrieveStubRunnerIds() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        echo "$( ./gradlew stubIds -q | tail -1 )"
    else
        echo "$( extractMavenProperty 'stubrunner.ids' )"
    fi
}

function renameTheOldApplicationIfPresent() {
    local appName="${1}"
    local newName="${appName}-venerable"
    echo "Renaming the app from [${appName}] -> [${newName}]"
    local appPresent="no"
    cf app "${appName}" && appPresent="yes"
    if [[ "${appPresent}" == "yes" ]]; then
        cf rename "${appName}" "${newName}"
    else
        echo "Will not rename the application cause it's not there"
    fi
}

function deleteTheOldApplicationIfPresent() {
    local appName="${1}"
    local oldName="${appName}-venerable"
    echo "Deleting the app [${oldName}]"
    cf app "${oldName}" && appPresent="yes"
    if [[ "${appPresent}" == "yes" ]]; then
        cf delete "${oldName}" -r -f
    else
        echo "Will not remove the old application cause it's not there"
    fi
}

export PROJECT_TYPE=$( projectType )
export OUTPUT_FOLDER=$( outputFolder )
export TEST_REPORTS_FOLDER=$( testResultsFolder )

echo "Project type [${PROJECT_TYPE}]"
echo "Output folder [${OUTPUT_FOLDER}]"
echo "Test reports folder [${TEST_REPORTS_FOLDER}]"

#!/bin/bash
set -e

# It takes ages on Docker to run the app without this
export MAVEN_OPTS="${MAVEN_OPTS} -Djava.security.egd=file:///dev/urandom"

function logInToCf() {
    local redownloadInfra="${1}"
    local cfUsername="${2}"
    local cfPassword="${3}"
    local cfOrg="${4}"
    local cfSpace="${5}"
    local apiUrl="${6:-api.run.pivotal.io}"
    CF_INSTALLED="$( cf --version || echo "false" )"
    CF_DOWNLOADED="$( test -r cf && echo "true" || echo "false" )"
    echo "CF Installed? [${CF_INSTALLED}], CF Downloaded? [${CF_DOWNLOADED}]"
    if [[ ${CF_INSTALLED} == "false" && (${CF_DOWNLOADED} == "false" || ${CF_DOWNLOADED} == "true" && ${redownloadInfra} == "true") ]]; then
        echo "Downloading Cloud Foundry"
        curl -L "https://cli.run.pivotal.io/stable?release=linux64-binary&source=github" --fail | tar -zx
        CF_DOWNLOADED="true"
    else
        echo "CF is already installed or was already downloaded but the flag to redownload was disabled"
    fi

    if [[ ${CF_DOWNLOADED} == "true" ]]; then
        echo "Adding CF to PATH"
        PATH=${PATH}:`pwd`
        chmod +x cf
    fi

    echo "Cloud foundry version"
    cf --version

    echo "Logging in to CF to org [${cfOrg}], space [${cfSpace}]"
    cf api --skip-ssl-validation "${apiUrl}"
    cf login -u "${cfUsername}" -p "${cfPassword}" -o "${cfOrg}" -s "${cfSpace}"
}

function deployRabbitMqToCf() {
    local serviceName="${1:-rabbitmq-github}"
    echo "Waiting for RabbitMQ to start"
    APP_NAME="${serviceName}"
    (cf s | grep "${APP_NAME}" && echo "found ${APP_NAME}") ||
        (cf cs cloudamqp lemur "${APP_NAME}" && echo "Started RabbitMQ") ||
        (cf cs p-rabbitmq standard "${APP_NAME}" && echo "Started RabbitMQ for PCF Dev")
}

function deleteMySql() {
    local serviceName="${1:-mysql-github}"
    APP_NAME="${serviceName}"
    cf delete-service -f ${APP_NAME}
}

function deployMySqlToCf() {
    local serviceName="${1:-mysql-github}"
    echo "Waiting for MySQL to start"
    APP_NAME="${serviceName}"
    (cf s | grep "${APP_NAME}" && echo "found ${APP_NAME}") ||
        (cf cs p-mysql 100mb "${APP_NAME}" && echo "Started MySQL") ||
        (cf cs p-mysql 512mb "${APP_NAME}" && echo "Started MySQL for PCF Dev")
}

function deployAndRestartAppWithName() {
    local appName="${1}"
    local jarName="${2}"
    local env="${3}"
    echo "Deploying and restarting app with name [${appName}] and jar name [${jarName}]"
    deployAppWithName "${appName}" "${jarName}" "${env}" 'true'
    restartApp "${appName}"
}

function deployAndRestartAppWithNameForSmokeTests() {
    local appName="${1}"
    local jarName="${2}"
    local rabbitName="${3}"
    local eurekaName="${4}"
    local mysqlName="${5}"
    local profiles="${6:-cloud,smoke}"
    local env="${7:-test}"
    local lowerCaseAppName=$( echo "${appName}" | tr '[:upper:]' '[:lower:]' )
    deleteApp "${appName}"
    echo "Deploying and restarting app with name [${appName}] and jar name [${jarName}] and env [${env}]"
    deployAppWithName "${appName}" "${jarName}" "${env}" 'false'
    bindService "${rabbitName}" "${appName}"
    if [[ "${eurekaName}" != "" ]]; then
        bindService "${eurekaName}" "${appName}"
    fi
    bindService "${mysqlName}" "${appName}"
    setEnvVar "${lowerCaseAppName}" 'spring.profiles.active' "${profiles}"
    restartApp "${appName}"
}

function appHost() {
    local appName="${1}"
    local lowerCase="$( echo "${appName}" | tr '[:upper:]' '[:lower:]' )"
    APP_HOST=`cf apps | awk -v "app=${lowerCase}" '$1 == app {print($0)}' | tr -s ' ' | cut -d' ' -f 6 | cut -d, -f1`
    echo "${APP_HOST}" | tail -1
}

function deployAppWithName() {
    local appName="${1}"
    local jarName="${2}"
    local env="${3}"
    local useManifest="${4:-false}"
    local manifestOption=$( if [[ "${useManifest}" == "false" ]] ; then echo "--no-manifest"; else echo "" ; fi )
    local lowerCaseAppName=$( echo "${appName}" | tr '[:upper:]' '[:lower:]' )
    local hostname="${lowerCaseAppName}"
    if [[ ${CF_HOSTNAME_UUID} != "" ]]; then
        hostname="${hostname}-${CF_HOSTNAME_UUID}"
    fi
    if [[ ${env} != "prod" ]]; then
        hostname="${hostname}-${env}"
    fi
    echo "Deploying app with name [${lowerCaseAppName}], env [${env}] with manifest [${useManifest}] and host [${hostname}]"
    if [[ ! -z "${manifestOption}" ]]; then
        cf push "${lowerCaseAppName}" -m 256m -i 1 -p "${OUTPUT_FOLDER}/${jarName}.jar" -n "${hostname}" --no-start -b https://github.com/cloudfoundry/java-buildpack.git#v3.8.1 ${manifestOption}
    else
        cf push "${lowerCaseAppName}" -p "${OUTPUT_FOLDER}/${jarName}.jar" -n "${hostname}" --no-start -b https://github.com/cloudfoundry/java-buildpack.git#v3.8.1
    fi
    APPLICATION_DOMAIN="$( appHost ${lowerCaseAppName} )"
    echo "Determined that application_domain for [${lowerCaseAppName}] is [${APPLICATION_DOMAIN}]"
    setEnvVar "${lowerCaseAppName}" 'APPLICATION_DOMAIN' "${APPLICATION_DOMAIN}"
    setEnvVar "${lowerCaseAppName}" 'JAVA_OPTS' '-Djava.security.egd=file:///dev/urandom'
}

function deleteApp() {
    local serviceName="${1}"
    local lowerCaseAppName=$( echo "${serviceName}" | tr '[:upper:]' '[:lower:]' )
    APP_NAME="${lowerCaseAppName}"
    echo "Deleting application [${APP_NAME}]"
    cf delete -f ${APP_NAME} || echo "Failed to delete the app. Continuing with the script"
}

function setEnvVarIfMissing() {
    local appName="${1}"
    local key="${2}"
    local value="${3}"
    echo "Setting env var [${key}] -> [${value}] for app [${appName}] if missing"
    cf env "${appName}" | grep "${key}" || setEnvVar appName key value
}

function setEnvVar() {
    local appName="${1}"
    local key="${2}"
    local value="${3}"
    echo "Setting env var [${key}] -> [${value}] for app [${appName}]"
    cf set-env "${appName}" "${key}" "${value}"
}

function restartApp() {
    local appName="${1}"
    echo "Restarting app with name [${appName}]"
    cf restart "${appName}"
}

function deployEureka() {
    local redeploy="${1}"
    local jarName="${2}"
    local appName="${3}"
    local env="${4}"
    echo "Deploying Eureka. Options - redeploy [${redeploy}], jar name [${jarName}], app name [${appName}], env [${env}]"
    local fileExists="true"
    local fileName="`pwd`/${OUTPUT_FOLDER}/${jarName}.jar"
    if [[ ! -f "${fileName}" ]]; then
        fileExists="false"
    fi
    if [[ ${fileExists} == "false" || ( ${fileExists} == "true" && ${redeploy} == "true" ) ]]; then
        deployAppWithName "${appName}" "${jarName}" "${env}"
        restartApp "${appName}"
        createServiceWithName "${appName}"
    else
        echo "Current folder is [`pwd`]; The [${fileName}] exists [${fileExists}]; redeploy flag was set [${redeploy}]. Skipping deployment"
    fi
}

function deployStubRunnerBoot() {
    local redeploy="${1}"
    local jarName="${2}"
    local repoWithJars="${3}"
    local rabbitName="${4}"
    local eurekaName="${5}"
    local env="${6:-test}"
    local stubRunnerName="${7:-stubrunner}"
    local fileExists="true"
    local fileName="`pwd`/${OUTPUT_FOLDER}/${jarName}.jar"
    if [[ ! -f "${fileName}" ]]; then
        fileExists="false"
    fi
    echo "Deploying Stub Runner. Options - redeploy [${redeploy}], jar name [${jarName}], app name [${stubRunnerName}]"
    if [[ ${fileExists} == "false" || ( ${fileExists} == "true" && ${redeploy} == "true" ) ]]; then
        deployAppWithName "${stubRunnerName}" "${jarName}" "${env}" "false"
        local prop="$( retrieveStubRunnerIds )"
        echo "Found following stub runner ids [${prop}]"
        setEnvVar "${stubRunnerName}" "stubrunner.ids" "${prop}"
        setEnvVar "${stubRunnerName}" "stubrunner.repositoryRoot" "${repoWithJars}"
        bindService "${rabbitName}" "${stubRunnerName}"
        if [[ "${eurekaName}" != "" ]]; then
            bindService "${eurekaName}" "${stubRunnerName}"
        fi
        restartApp "${stubRunnerName}"
    else
        echo "Current folder is [`pwd`]; The [${fileName}] exists [${fileExists}]; redeploy flag was set [${redeploy}]. Skipping deployment"
    fi
}

function bindService() {
    local serviceName="${1}"
    local appName="${2}"
    echo "Binding service [${serviceName}] to app [${appName}]"
    cf bind-service "${appName}" "${serviceName}"
}

function createServiceWithName() {
    local name="${1}"
    echo "Creating service with name [${name}]"
    APPLICATION_DOMAIN=`cf apps | grep ${name} | tr -s ' ' | cut -d' ' -f 6 | cut -d, -f1`
    JSON='{"uri":"http://'${APPLICATION_DOMAIN}'"}'
    cf create-user-provided-service "${name}" -p "${JSON}" || echo "Service already created. Proceeding with the script"
}

# The function uses Maven Wrapper - if you're using Maven you have to have it on your classpath
# and change this function
function extractMavenProperty() {
    local prop="${1}"
    MAVEN_PROPERTY=$(./mvnw ${MAVEN_ARGS} -q \
                    -Dexec.executable="echo" \
                    -Dexec.args="\${${prop}}" \
                    --non-recursive \
                    org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
    # In some spring cloud projects there is info about deactivating some stuff
    MAVEN_PROPERTY=$( echo "${MAVEN_PROPERTY}" | tail -1 )
    # In Maven if there is no property it prints out ${propname}
    if [[ "${MAVEN_PROPERTY}" == "\${${prop}}" ]]; then
        echo ""
    else
        echo "${MAVEN_PROPERTY}"
    fi
}

# The values of group / artifact ids can be later retrieved from Maven
function downloadJar() {
    local redownloadInfra="${1}"
    local repoWithJars="${2}"
    local groupId="${3}"
    local artifactId="${4}"
    local version="${5}"
    local destination="`pwd`/${OUTPUT_FOLDER}/${artifactId}-${version}.jar"
    local changedGroupId="$( echo "${groupId}" | tr . / )"
    local pathToJar="${repoWithJars}/${changedGroupId}/${artifactId}/${version}/${artifactId}-${version}.jar"
    if [[ ! -e ${destination} || ( -e ${destination} && ${redownloadInfra} == "true" ) ]]; then
        mkdir -p "${OUTPUT_FOLDER}"
        echo "Current folder is [`pwd`]; Downloading [${pathToJar}] to [${destination}]"
        (curl "${pathToJar}" -o "${destination}" --fail && echo "File downloaded successfully!") || (echo "Failed to download file!" && return 1)
    else
        echo "File [${destination}] exists and redownload flag was set to false. Will not download it again"
    fi
}

function propagatePropertiesForTests() {
    local projectArtifactId="${1}"
    local stubRunnerHost="${2:-stubrunner-${projectArtifactId}}"
    local fileLocation="${3:-${OUTPUT_FOLDER}/test.properties}"
    echo "Propagating properties for tests. Project [${projectArtifactId}] stub runner host [${stubRunnerHost}] properties location [${fileLocation}]"
    # retrieve host of the app / stubrunner
    # we have to store them in a file that will be picked as properties
    rm -rf "${fileLocation}"
    local host=$( appHost "${projectArtifactId}" )
    APPLICATION_URL="${host}"
    echo "APPLICATION_URL=${host}" >> ${fileLocation}
    host=$( appHost "${stubRunnerHost}" )
    STUBRUNNER_URL="${host}"
    echo "STUBRUNNER_URL=${host}" >> ${fileLocation}
    echo "Resolved properties"
    cat ${fileLocation}
}

function readTestPropertiesFromFile() {
    local fileLocation="${1:-${OUTPUT_FOLDER}/test.properties}"
    if [ -f "${fileLocation}" ]
    then
      echo "${fileLocation} found."
      while IFS='=' read -r key value
      do
        key=$(echo ${key} | tr '.' '_')
        eval "${key}='${value}'"
      done < "${fileLocation}"
    else
      echo "${fileLocation} not found."
    fi
}

# Function that executes integration tests
function runSmokeTests() {
    local applicationHost="${1}"
    local stubrunnerHost="${2}"
    echo "Running smoke tests"

    if [[ "${PROJECT_TYPE}" == "MAVEN" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}" || ( echo "$( printTestResults )" && return 1)
            else
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( echo "$( printTestResults )" && return 1)
            fi
        else
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}"
            else
                ./mvnw clean install -Psmoke -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
            fi
        fi
    elif [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            ./gradlew smoke -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( echo "$( printTestResults )" && return 1)
        else
            ./gradlew smoke -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
        fi
    else
        echo "Unsupported project build tool"
        return 1
    fi
}

# Function that executes end to end tests
function runE2eTests() {
    local applicationHost="${1}"
    local stubrunnerHost="${2}"
    echo "Running e2e tests"

    if [[ "${PROJECT_TYPE}" == "MAVEN" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}" || ( $( printTestResults ) && return 1)
            else
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( $( printTestResults ) && return 1)
            fi
        else
            if [[ ! -z ${MAVEN_ARGS} ]]; then
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" "${MAVEN_ARGS}"
            else
                ./mvnw clean install -Pe2e -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
            fi
        fi
    elif [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        if [[ "${CI}" == "CONCOURSE" ]]; then
            ./gradlew e2e -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}" || ( $( printTestResults ) && return 1)
        else
            ./gradlew e2e -PnewVersion=${PIPELINE_VERSION} -Dapplication.url="${applicationHost}" -Dstubrunner.url="${stubrunnerHost}"
        fi
    else
        echo "Unsupported project build tool"
        return 1
    fi
}

function findLatestProdTag() {
    local LAST_PROD_TAG=$(git for-each-ref --sort=taggerdate --format '%(refname)' refs/tags/prod | head -n 1)
    LAST_PROD_TAG=${LAST_PROD_TAG#refs/tags/}
    echo "${LAST_PROD_TAG}"
}

function extractVersionFromProdTag() {
    local tag="${1}"
    LAST_PROD_VERSION=${tag#prod/}
    echo "${LAST_PROD_VERSION}"
}

function retrieveGroupId() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        local result=$( ./gradlew groupId -q )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    else
        local result=$( ruby -r rexml/document -e 'puts REXML::Document.new(File.new(ARGV.shift)).elements["/project/groupId"].text' pom.xml || ./mvnw ${MAVEN_ARGS} org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.groupId |grep -Ev '(^\[|Download\w+:)' )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    fi
}

function retrieveArtifactId() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        local result=$( ./gradlew artifactId -q )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    else
        local result=$( ruby -r rexml/document -e 'puts REXML::Document.new(File.new(ARGV.shift)).elements["/project/artifactId"].text' pom.xml || ./mvnw ${MAVEN_ARGS} org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.artifactId |grep -Ev '(^\[|Download\w+:)' )
        result=$( echo "${result}" | tail -1 )
        echo "${result}"
    fi
}

# Jenkins passes these as a separate step, in Concourse we'll do it manually
function prepareForSmokeTests() {
    local redownloadInfra="${1}"
    local username="${2}"
    local password="${3}"
    local org="${4}"
    local space="${5}"
    local api="${6}"
    echo "Retrieving group and artifact id - it can take a while..."
    projectGroupId=$( retrieveGroupId )
    projectArtifactId=$( retrieveArtifactId )
    mkdir -p "${OUTPUT_FOLDER}"
    logInToCf "${redownloadInfra}" "${username}" "${password}" "${org}" "${space}" "${api}"
    propagatePropertiesForTests ${projectArtifactId}
    readTestPropertiesFromFile
}

# Jenkins passes these as a separate step, in Concourse we'll do it manually
function prepareForE2eTests() {
    local redownloadInfra="${1}"
    local username="${2}"
    local password="${3}"
    local org="${4}"
    local space="${5}"
    local api="${6}"
    echo "Retrieving group and artifact id - it can take a while..."
    projectGroupId=$( retrieveGroupId )
    projectArtifactId=$( retrieveArtifactId )
    echo "Project groupId is ${projectGroupId}"
    echo "Project artifactId is ${projectArtifactId}"
    mkdir -p "${OUTPUT_FOLDER}"
    logInToCf "${redownloadInfra}" "${username}" "${password}" "${org}" "${space}" "${api}"
    propagatePropertiesForTests ${projectArtifactId}
    readTestPropertiesFromFile
}

function isMavenProject() {
    [ -f "mvnw" ]
}

function isGradleProject() {
    [ -f "gradlew" ]
}

function projectType() {
    if isMavenProject; then
        echo "MAVEN"
    elif isGradleProject; then
        echo "GRADLE"
    else
        echo "UNKNOWN"
    fi
}

function outputFolder() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        echo "build/libs"
    else
        echo "target"
    fi
}

function testResultsFolder() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        echo "**/test-results/*.xml"
    else
        echo "**/surefire-reports/*"
    fi
}

function printTestResults() {
    echo -e "\n\nBuild failed!!! - will print all test results to the console (it's the easiest way to debug anything later)\n\n" && tail -n +1 "$( testResultsFolder )"
}

function retrieveStubRunnerIds() {
    if [[ "${PROJECT_TYPE}" == "GRADLE" ]]; then
        echo "$( ./gradlew stubIds -q | tail -1 )"
    else
        echo "$( extractMavenProperty 'stubrunner.ids' )"
    fi
}

function renameTheOldApplicationIfPresent() {
    local appName="${1}"
    local newName="${appName}-venerable"
    echo "Renaming the app from [${appName}] -> [${newName}]"
    local appPresent="no"
    cf app "${appName}" && appPresent="yes"
    if [[ "${appPresent}" == "yes" ]]; then
        cf rename "${appName}" "${newName}"
    else
        echo "Will not rename the application cause it's not there"
    fi
}

function deleteTheOldApplicationIfPresent() {
    local appName="${1}"
    local oldName="${appName}-venerable"
    echo "Deleting the app [${oldName}]"
    cf app "${oldName}" && appPresent="yes"
    if [[ "${appPresent}" == "yes" ]]; then
        cf delete "${oldName}" -r -f
    else
        echo "Will not remove the old application cause it's not there"
    fi
}

export PROJECT_TYPE=$( projectType )
export OUTPUT_FOLDER=$( outputFolder )
export TEST_REPORTS_FOLDER=$( testResultsFolder )

echo "Project type [${PROJECT_TYPE}]"
echo "Output folder [${OUTPUT_FOLDER}]"
echo "Test reports folder [${TEST_REPORTS_FOLDER}]"


Create check_ip.sh

Create check_ip.sh

#!/bin/sh
#
# Checks public IP via ident.me and triggers python script to email Raspberry Pi's IPs
#

IPFILE=~/ipaddress
CURRENT_IP=$(wget -q -O - http://ident.me)
if [ -f $IPFILE ]; then
KNOWN_IP=$(cat $IPFILE)
else
KNOWN_IP=
fi

if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
echo $CURRENT_IP > $IPFILE
python /home/pi/startup_mailer.py
fi

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


Adding shell script to check connectivity to a remote host and notify when it comes online.

#!/bin/bash

remote=192.168.0.125
port=22

while [[ 1 -eq 1 ]];
	do
		status=$(nc ${remote} ${port} > /dev/null 2>&1)
		if [[ $? -eq 0 ]]; then
			echo "[+] Computer '${remote} is now online."
			push -t "Online PC" -m "Computer '${remote}' is now online."
		else
			echo "[!] Computer '${remote}' is still offline."
			sleep 60
			exit
		fi

	done

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


Create pdevice.sh

Create pdevice.sh

pdevice stands for 'parted device'

references
http://www.linuxquestions.org/questions/linux-hardware-18/help-setting-up-gpt-partitions-with-gnu-parted-version-2-3-a-937469/
http://www.gnu.org/software/parted/manual/html_chapter/parted_toc.html

#!/bin/bash

#-------------------------------------------------------------------------------
# Created by Jerry Jianrui Xu: jerryjianruixu[at]gmail[dot]com
#-------------------------------------------------------------------------------

device=$1

gpttbl="mktable gpt"                          # create an empty GPT partition table on /dev/sda
p1="mkpart linux ---- 17.4KB 2MB"             # create a 2MB linux partition #1 {1st 17.4KB (34 x 512 =17408 sectors) used by parted for its data}
p1set="set 1 bios_grub on"                    # set partition #1 with the GRUB2 (core.img) stage2 bootcode (ef02)
p2="mkpart mkpart linux ext2 2MB 500MB"       # create a linux partition #2
p2set="set 2 boot on"                         # set partition #2 with the boot flag (ef00)
p3="mkpart linux ext2 500MB 200GB"            # create a linux partition #3
p4="mkpart swap linux-swap 200GB 208GB"       # create a linux partition #4
p5="mkpart linux ext2 208GB 220GB"            # create a linux partition #5
p6="mkpart linux ext2 220GB 100%"             # partition remaining disk space as linux partition #6

sudo parted --align optimal --script $device ${gpttbl} ${p1} ${p1set} ${p2} ${p2set} ${p3} ${p4} ${p5} ${p6}

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


Initial script for basic snapshot management (ES1.0+)

#!/bin/bash
#
# elasticsearch-snapshot-index.sh
#
# Script to back up your cluster (or individual indices) easily, using the new Snapshot Restore API.
# Note: REQUIRES ES 1.0+
#
# --- CREATE INDEX:
# $ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
#     "type": "fs",
#     "settings": {
#         "compress" : true,
#         "location": "/mnt2/elasticsearch/backup"
#     }
# }'
#
# --- SHOW INDEX:
# $ curl -XGET 'http://localhost:9200/_snapshot/my_backup?pretty'
#
# --- CREATE FULL SNAPSHOT:
# $ curl -XPUT 'http://localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=false'
#
# --- CREATE SELECTIVE SNAPSHOT:
# $ curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_1" -d '{
#     "indices": "kibana-int",
#     "ignore_unavailable": "true",
#     "include_global_state": false
# }'
#
# --- LIST ALL SNAPSHOTS:
# $ curl -XGET 'http://localhost:9200/_snapshot/my_backup/_all'
#
# --- RESTORE SNAPSHOT:
# $ curl -XPOST 'http://localhost:9200/_snapshot/my_backup/snapshot_1/_restore'
#
#
#   http://logstash.net
#   http://www.elasticsearch.org
#
# Must run on an elasticsearch node, and expects to find the index on this node.

usage()
{
cat << EOF

elasticsearch-snapshot-index.sh

Create a restorable backup of an elasticsearch index (assumes Logstash format
indexes), and upload it to an existing S3 bucket. The default backs up an
index from yesterday. Note that this script itself does not restart
elasticsearch - the restore script that is generated for each backup will
restart elasticsearch after restoring an archived index.

USAGE: ./elasticsearch-snapshot-index.sh -b SNAP_REPOSITORY -n SNAP_NAME [OPTIONS]

OPTIONS:
  -h    Show this message
  -b    Snapshot Repository (Required)
  -n    Snapshot Name (Required unless -l)
  -i    Snapshot Indexes (default: all)
  -t    Cluster directory for archiving (default: /tmp)
  -l    Show snapshot details only (read-only mode)
  -r    Restore snapshot (*MUST* match -n parameter for safety)
  -e    Elasticsearch URL (default: http://localhost:9200)

EXAMPLES:

  ./elasticsearch-snapshot-index.sh -l -b "my_backup" -n "snapshot_1"
    This uses http://localhost:9200 to connect to elasticsearch, fetches the snapshot
    details in the specified repository (default without -n is all snapshots in repo)

  ./elasticsearch-snapshot-index.sh -b "my_backup" -n "snapshot_1"

    This uses http://localhost:9200 to connect to elasticsearch, creates a snapshot
    repository if needed, and a full cluster snapshot under remote server's /tmp

  ./elasticsearch-snapshot-index.sh -b "my_backup" -i -n "snapshot_1" -i "kibana-int,logstash" -t "/mnt/es/bk" -e "http://127.0.0.1:9200"

    This uses http://localhost:9200 to connect to elasticsearch, creates a snapshot
    repository if needed, and a snapshot of the selected indexes (incremental) stored
    under "/mnt/es/bk" on the remote cluster server its being executed on.

  ./elasticsearch-snapshot-index.sh -b "my_backup" -n "snapshot_1" -r "snapshot_1"

    This uses http://localhost:9200 to connect to elasticsearch and restores snapshot
    "snapshot_1" from repository "my_backup" located on the cluster. Can accept the
    same options as the creation for specifying specific indexes to restore.

EOF
}

if [ "$USER" != 'root' ] && [ "$LOGNAME" != 'root' ]; then
  # I don't want to troubleshoot the permissions of others
  echo "This script must be run as root."
  exit 1
fi

# Defaults
TMP_DIR="/tmp"
ELASTICSEARCH="http://localhost:9200"
WAIT="yes"

# Validate shard/replica values
RE_D="^[0-9]+$"

while getopts ":b:i:n:t:e:w:ps:h:r:l" flag
do
  case "$flag" in
    h)
      usage
      exit 0
      ;;
    b)
      S_REPO=$OPTARG
      ;;
    i)
      INDEXES=$OPTARG
      ;;
    n)
      S_NAME=$OPTARG
      ;;
    t)
      TMP_DIR=$OPTARG
      ;;
    e)
      ELASTICSEARCH=$OPTARG
      ;;
    w)
      WAIT=$OPTARG
      ;;
    l)
      LIST=1
      ;;
    r)
      RESTORE=$OPTARG
      ;;
    ?)
      usage
      exit 1
      ;;
  esac
done

# We need an S3 base path
if [ -z "$S_REPO" ]; then
  ERROR="${ERROR}Please provide a repository for your snapshot -b.\n"
fi

# We need an elasticsearch index directory
if [[ -z "S_NAME" && ! -z "$LIST" ]]; then
  ERROR="${ERROR}Please provide an name for your snapshot -n.\n"
fi

# If we have errors, show the errors with usage data and exit.
if [ -n "$ERROR" ]; then
  echo -e $ERROR
  usage
  exit 1
fi

# List mode?
if [ -n $LIST ]; then
	echo;
	# If no snapshot name specified, show all
	if [ -z "$S_NAME" ]; then
	   echo "Showing ALL snapshots in repository $S_REPO"
	   curl -XGET "$ELASTICSEARCH/_snapshot/$S_REPO/_all"
	else
	   echo "Showing $S_NAME snapshots in repository $S_REPO"
	   curl -XGET "$ELASTICSEARCH/_snapshot/$S_REPO/$S_NAME"
	fi
	echo
	echo
	exit 0;
fi

# Restore mode?
if [ -n $RESTORE ]; then
	# Let's play it safe here
	if [[ ! $RESTORE == $S_NAME ]]
	then
	  echo "Safe Lock: Snapshot NAME and RESTORE not matching!";
	  echo; exit 0;
	fi

	echo;
	echo "Fetching snapshot details..."
	echo
	REPO_TEST=`curl -s -XGET "$ELASTICSEARCH/_snapshot/$S_REPO/$S_NAME"`
	if [[ $REPO_TEST == *error* ]]
	then
	  echo "Repository $S_REPO not found!";
	  echo; exit 0;
	else echo $REPO_TEST
	fi

	read -p "Are you sure you want to restore this snapshot? (y/n)?" choice
	case "$choice" in
	  y|Y )
	   	echo "Restoring $S_NAME snapshots from repository $S_REPO ..."
		if [ -n $INDEXES ]; then
		  # selective restore
	  	  curl -XPUT "$ELASTICSEARCH/_snapshot/$S_REPO/$S_NAME/_restore" -d '{"indices": "$INDEXES","ignore_unavailable": "true","include_global_state": false}'
		else
		  # full restore
	   	  curl -XGET "$ELASTICSEARCH/_snapshot/$S_REPO/$S_NAME/_restore"
		fi
		;;
	  n|N )
		echo "Mission abandoned! Exiting..."
		;;
	  * )
		echo "Exiting..."
		;;
	esac

	echo
	echo
	exit 0;
fi

# Create Snapshot?
# Get snapshot repository details from Elasticsearch

REPO_TEST=`curl -s -XGET "$ELASTICSEARCH/_snapshot/$S_REPO"`
if [[ $REPO_TEST == *error* ]]
then
  echo "Repository $S_REPO not found! Creating one...";
  curl -XPUT '$ELASTICSEARCH/_snapshot/$S_REPO' -d '{"type": "fs","settings": {"compress" : true,"location": "$TMP_DIR"}}'
fi

# Check if FULL or SELECTIVE snapshot
if [ -n $INDEXES ]; then
	# selective
	curl -XPUT "$ELASTICSEARCH/_snapshot/$S_REPO/$S_NAME" -d '{"indices": "$INDEXES","ignore_unavailable": "true","include_global_state": false}'
else
	# full snap
	curl -XPUT "$ELASTICSEARCH/_snapshot/$S_REPO/$S_NAME?wait_for_completion=$WAIT"
fi

echo
exit 0

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


Add script of tunning number of instance cluster

Idx_dataSet="1 2 3 4 5 6 7 8 9 10"

for idx in $Idx_dataSet
do
	/usr/local/MATLAB/R2012a/bin/matlab -r "datasetId=$idx; Exp_ours_num_instance_cluster; exit;" &
done

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


Database and web version sync

Database and web version sync

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/danog/video-dl.git/'


single equals sign

single equals sign

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


additional tmux aliases

additional tmux aliases

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/cpcloud/oh-my-zsh.git/'


adjusted text color

adjusted text color

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/unforswearing/tobin.git/'


initial commit

initial commit

#!/usr/bin/env bash

# This file is sourced when running various Spark programs.
# Copy it as spark-env.sh and edit that to configure Spark for your site.

# Options read when launching programs locally with
# ./bin/run-example or ./bin/spark-submit
# - HADOOP_CONF_DIR, to point Spark towards Hadoop configuration files
# - SPARK_LOCAL_IP, to set the IP address Spark binds to on this node
# - SPARK_PUBLIC_DNS, to set the public dns name of the driver program
# - SPARK_CLASSPATH, default classpath entries to append

# Options read by executors and drivers running inside the cluster
# - SPARK_LOCAL_IP, to set the IP address Spark binds to on this node
# - SPARK_PUBLIC_DNS, to set the public DNS name of the driver program
# - SPARK_CLASSPATH, default classpath entries to append
# - SPARK_LOCAL_DIRS, storage directories to use on this node for shuffle and RDD data
# - MESOS_NATIVE_JAVA_LIBRARY, to point to your libmesos.so if you use Mesos

# Options read in YARN client mode
export JAVA_HOME=/etc/alternatives/java_sdk_openjdk
export HADOOP_CONF_DIR=/home/ec2-user/hadoopconf
# - SPARK_EXECUTOR_INSTANCES, Number of workers to start (Default: 2)
# - SPARK_EXECUTOR_CORES, Number of cores for the workers (Default: 1).
# - SPARK_EXECUTOR_MEMORY, Memory per Worker (e.g. 1000M, 2G) (Default: 1G)
# - SPARK_DRIVER_MEMORY, Memory for Master (e.g. 1000M, 2G) (Default: 1G)
# - SPARK_YARN_APP_NAME, The name of your application (Default: Spark)
# - SPARK_YARN_QUEUE, The hadoop queue to use for allocation requests (Default: ‘default’)
# - SPARK_YARN_DIST_FILES, Comma separated list of files to be distributed with the job.
# - SPARK_YARN_DIST_ARCHIVES, Comma separated list of archives to be distributed with the job.

# Options for the daemons used in the standalone deploy mode
# - SPARK_MASTER_IP, to bind the master to a different IP address or hostname
# - SPARK_MASTER_PORT / SPARK_MASTER_WEBUI_PORT, to use non-default ports for the master
# - SPARK_MASTER_OPTS, to set config properties only for the master (e.g. "-Dx=y")
# - SPARK_WORKER_CORES, to set the number of cores to use on this machine
# - SPARK_WORKER_MEMORY, to set how much total memory workers have to give executors (e.g. 1000m, 2g)
# - SPARK_WORKER_PORT / SPARK_WORKER_WEBUI_PORT, to use non-default ports for the worker
# - SPARK_WORKER_INSTANCES, to set the number of worker processes per node
# - SPARK_WORKER_DIR, to set the working directory of worker processes
# - SPARK_WORKER_OPTS, to set config properties only for the worker (e.g. "-Dx=y")
# - SPARK_DAEMON_MEMORY, to allocate to the master, worker and history server themselves (default: 1g).
# - SPARK_HISTORY_OPTS, to set config properties only for the history server (e.g. "-Dx=y")
# - SPARK_SHUFFLE_OPTS, to set config properties only for the external shuffle service (e.g. "-Dx=y")
# - SPARK_DAEMON_JAVA_OPTS, to set config properties for all daemons (e.g. "-Dx=y")
# - SPARK_PUBLIC_DNS, to set the public dns name of the master or workers

# Generic options for the daemons used in the standalone deploy mode
# - SPARK_CONF_DIR      Alternate conf dir. (Default: ${SPARK_HOME}/conf)
# - SPARK_LOG_DIR       Where log files are stored.  (Default: ${SPARK_HOME}/logs)
# - SPARK_PID_DIR       Where the pid file is stored. (Default: /tmp)
# - SPARK_IDENT_STRING  A string representing this instance of spark. (Default: $USER)
# - SPARK_NICENESS      The scheduling priority for daemons. (Default: 0)

error: pathspec 'aws-blog-zeppelin-yarn-on-ec2/conf/spark-env.sh' did not match any file(s) known to git


add script to install overviwer, rabbitmq, and minecraft client.

sudo echo "deb http://overviewer.org/debian ./" >> /etc/apt/sources.list
echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list
apt-get update
apt-get install minecraft-overviewer
apt-get install rabbitmq-server
VERSION=1.9
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.9/1.9.jar -P ~/.minecraft/versions/1.9/
sudo pip install -r requirements.txt

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


Update ubuntu14.04.sh

Update ubuntu14.04.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/imwithye/dotfiles.git/'


Add basic refresh and deploy script

Add basic refresh and deploy script

#!/bin/bash

BIN_DIR=$(dirname "$0")
ROOT_DIR="$BIN_DIR/.."
TMP_DIR="$ROOT_DIR/_tmp"
SITE_DIR="$ROOT_DIR/_site"
GITHUB_DIR="$TMP_DIR/github"
REPOS_DIR="$TMP_DIR/repos"
LANYRD_DIR="$TMP_DIR/lanyrd"
DEPLOY_REPO='ssh://3904f9a5cba346ddb8eb25fff0125185@arqpreview-alrubinger.rhcloud.com/~/git/arqpreview.git'

if [[ $# -ne 1 ]]; then
  DEPLOY_DIR="$ROOT_DIR/_deploy"
  if [[ ! -d "$DEPLOY_DIR/.git" ]]; then
    echo "Specify the path to the clone of $DEPLOY_REPO"
    exit 1
  fi
else
  DEPLOY_DIR="$1"
  if [[ ! -d "$DEPLOY_DIR/.git" ]]; then
    echo "Not a git repository: $DEPLOY_DIR"
    exit 1
  fi
fi

set -e

pushd $DEPLOY_DIR
if ! git remote -v | grep -qF "$DEPLOY_REPO"; then
  echo "Not a $DEPLOY_REPO clone: $DEPLOY_DIR"
  exit 1
fi
popd

cd $ROOT_DIR

pushd $REPOS_DIR
for repo in */; do
  pushd "$repo"
  git pull
  popd
done
popd

pushd $GITHUB_DIR
# TODO check if github repository has been updated since the contributions file was written, then nuke the contributions file
rm -f contributors-*.json
popd

pushd $LANYRD_DIR
rm -f search-*.html
popd

rm -rf $SITE_DIR
rm -rf $SASS_CACHE_DIR

awestruct -g

rsync -a --delete "$SITE_DIR/" "$DEPLOY_DIR/src/main/webapp/"

pushd $DEPLOY_DIR
git add .
git commit -m 'publish'
git push
popd

exit 0

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


Only set AUTO{MAKE,CONF}_VERSION on OpenBSD

OpenBSD requires the presence of AUTOMAKE_VERSION and AUTOCONF_VERSION for
bootstrapping purposes.  Setting these on any other system requires that
explicit version to be used, rather than what might already be installed.

Therefore, only do this when the platform is OpenBSD and ignore everything
else.

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/klaxalk/tmux.git/'


add autogen-sh

add autogen-sh

20070502150348-7fe3f-128c6e3685e505509d43372983aeaf79d5bfc2be.gz

#!/bin/sh
set -e

if test -z "$MAKE"
then
	MAKE=make
fi

autoreconf -i

run_configure=true
for arg in $*; do
    case $arg in
        --no-configure)
            run_configure=false
            ;;
        *)
            ;;
    esac
done

if test $run_configure = true; then
    ./configure "$@"
fi

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


Steal autogen.sh from LibWCL.

Steal autogen.sh from LibWCL.

#!/bin/sh

ACLOCAL=`which aclocal`
AUTOCONF=`which autoconf`
AUTOHEADER=`which autoheader`
AUTOMAKE=`which automake`

LIBTOOLIZE=`which libtoolize`
if [ "$?" -ne "0" ] ;
then
	echo "Libtoolize not on path! Trying glibtoolize (osx)"
	LIBTOOLIZE=`which glibtoolize`
	if [ "$?" -ne "0" ] ; then
		echo "Nope, couldn't find libtoolize, bailing."
		exit
	else
		echo "Yep, glibtoolize works"
	fi
fi

#
# LIBTOOLIZE
#
# We don't check the libtoolize verision as we don't know if we need to
$LIBTOOLIZE --force

#
#  ACLOCAL
#

ACLOCALMINVERSION="1.9.6"
acl_version=`${ACLOCAL:-aclocal} --version 2>/dev/null|head -n 1| sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//' -e 's/\(.*\)\(-p.*\)/\1/'`
if test -z "$acl_version"; then
  echo "buildconf: aclocal not found."
  echo "            You  aclocal version $ACLOCALMINVERSION or newer installed."
  exit 1
fi
IFS=.; set $acl_version; IFS=' '
if test "$1" = "1" -a "$2" -lt "9" || test "$1" -lt "1"; then
  echo "buildconf: aclocal version $acl_version found."
  echo "            You need aclocal version $ACLOCALMINVERSION or newer installed."
  echo "            If you have a sufficient aclocal installed, but it"
  echo "            is not named 'aclocal', then try setting the"
  echo "            aclocal environment variable."
  exit 1
fi

$ACLOCAL  -I cfg

#
# AUTOCONF
#

AUTOCONFMINVERSION="2.59"
ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|head -n 1| sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//' -e 's/\(.*\)\(-p.*\)/\1/'`
if test -z "$ac_version"; then
  echo "buildconf: autoconf not found."
  echo "            You  autoconf version $AUTOCONFMINVERSION or newer installed."
  exit 1
fi
IFS=.; set $ac_version; IFS=' '
if test "$1" = "2" -a "$2" -lt "59" || test "$1" -lt "2"; then
  echo "buildconf: autoconf version $ac_version found."
  echo "            You need autoconf version $AUTOCONFMINVERSION or newer installed."
  echo "            If you have a sufficient autoconf installed, but it"
  echo "            is not named 'autoconf', then try setting the"
  echo "            AUTOCONF environment variable."
  exit 1
fi

$AUTOCONF

#
# AUTOHEADER
#
AUTOHEADERMINVERSION="2.59"

ah_version=`${AUTOHEADER:-autoheader} --version 2>/dev/null|head -n 1| sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//' -e 's/\(.*\)\(-p.*\)/\1/'`
if test -z "$ah_version"; then
  echo "buildconf: autoheader not found."
  echo "            You  autoheader version $AUTOHEADERMINVERSION or newer installed."
  exit 1
fi
IFS=.; set $ah_version; IFS=' '
if test "$1" = "2" -a "$2" -lt "59" || test "$1" -lt "2"; then
  echo "buildconf: autoheader version $ah_version found."
  echo "            You need autoheader version $AUTOHEADERMINVERSION or newer installed."
  echo "            If you have a sufficient autoheader installed, but it"
  echo "            is not named 'autoheader', then try setting the"
  echo "            AUTOHEADER environment variable."
  exit 1
fi

$AUTOHEADER

#
# AUTOMAKE
#
AUTOMAKEMINVERSION="1.9.6"
am_version=`${AUTOMAKE:-automake} --version 2>/dev/null|head -n 1| sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//' -e 's/\(.*\)\(-p.*\)/\1/'`
if test -z "$am_version"; then
  echo "buildconf: automake not found."
  echo "            You  automake version $AUTOMAKEMINVERSION or newer installed."
  exit 1
fi
IFS=.; set $am_version; IFS=' '
if test "$1" = "1" -a "$2" -lt "9" || test "$1" -lt "1"; then
  echo "buildconf: automake version $am_version found."
  echo "            You need automake version $AUTOMAKEMINVERSION or newer installed."
  echo "            If you have a sufficient automake installed, but it"
  echo "            is not named 'automake', then try setting the"
  echo "            AUTOMAKE environment variable."
  exit 1
fi

$AUTOMAKE -a


[util-linux] run tools/oss-fuzz.sh if it exists (#4227)

to make it easier to use CIFuzz to make sure https://github.com/karelzak/util-linux/pull/1068
is more or less in good shape.

#!/bin/bash -eu
# Copyright 2020 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

set -x

if [[ -f "tools/oss-fuzz.sh" ]]; then
	./tools/oss-fuzz.sh
else
	./autogen.sh
	./configure --disable-all-programs --enable-libmount --enable-libblkid
	make -j$(nproc) V=1 libmount.la libblkid.la
	$CC $CFLAGS -Wall -Wextra -include config.h -I./include -I./libblkid/src -I./libmount/src -c $SRC/test_mount_fuzz.c -o test_mount_fuzz.o
	$CXX $CXXFLAGS $LIB_FUZZING_ENGINE test_mount_fuzz.o ./.libs/libblkid.a ./.libs/libmount.a .libs/libblkid.a -o $OUT/test_mount_fuzz
fi

#!/bin/bash -eu
# Copyright 2020 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

set -x

./autogen.sh
./configure --disable-all-programs --enable-libmount --enable-libblkid
make -j$(nproc) V=1 libmount.la libblkid.la
$CC $CFLAGS -Wall -Wextra -include config.h -I./include -I./libblkid/src -I./libmount/src -c $SRC/test_mount_fuzz.c -o test_mount_fuzz.o
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE test_mount_fuzz.o ./.libs/libblkid.a ./.libs/libmount.a .libs/libblkid.a -o $OUT/test_mount_fuzz


Added toggle_tpad. A script for toggling x touchpads. Mostly transferrable, but device name may change + script will need altering if so.

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/rhunt04/bitsnpieces.git/'


Run travis tests in checked mode.

Run travis tests in checked mode.

R=brianwilkerson@google.com

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

#!/bin/bash

# Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

# Fast fail the script on failures.
set -e

# Verify that the libraries are error free.
dartanalyzer --fatal-warnings \
  bin/linter.dart \
  lib/src/linter.dart \
  test/all.dart

# Run the tests.
dart -checked test/all.dart

# Install dart_coveralls; gather and send coverage data.
if [ "$COVERALLS_TOKEN" ]; then
  pub global activate dart_coveralls
  pub global run dart_coveralls report \
    --token $COVERALLS_TOKEN \
    --retry 2 \
    --exclude-test-files \
    test/all.dart
fi

#!/bin/bash

# Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

# Fast fail the script on failures.
set -e

# Verify that the libraries are error free.
dartanalyzer --fatal-warnings \
  bin/linter.dart \
  lib/src/linter.dart \
  test/all.dart

# Run the tests.
dart test/all.dart

# Install dart_coveralls; gather and send coverage data.
if [ "$COVERALLS_TOKEN" ]; then
  pub global activate dart_coveralls
  pub global run dart_coveralls report \
    --token $COVERALLS_TOKEN \
    --retry 2 \
    --exclude-test-files \
    test/all.dart
fi


Fix paths in travis.sh.

Fix paths in travis.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/DrMarcII/webdriver.dart.git/'


add tools/btest.sh

add tools/btest.sh

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


Add login.sh

Add login.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/fs714/proxy-setting.git/'


Added publish script so I can't keep forgetting how.

rsync -r _site/ root@ryanandsarah.co.za:/var/www/html/

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


Add a script to publish drafts with the current date

files=${@:-$(find _drafts -type f)}
for file in $files; do
  mv $file _posts/$(date +"%Y-%m-%d-")$(basename $file)
done


Initial commit

Initial commit

grunt build
git add --all
git commit -m "Just another commit"
git push heroku master


add pushall

add pushall

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/devlabmtl/base-app.git/'


Add wifi autoconnect script

Add wifi autoconnect 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/rybus/mogette-ui.git/'


Create server.sh

Create server.sh

#!/bin/bash
# web.sh -- http://localhost:8080/index.html
# chmod 755 server.sh
# then run: ./server.sh

RESP=/tmp/webresp
[ -p $RESP ] || mkfifo $RESP

while true ; do

( cat $RESP ) | nc -l -p 8080 | (
REQ=`while read L && [ " " "<" "$L" ] ; do echo "$L" ; done`
url="${REQ#GET }"
url="${url% HTTP/*}"
echo "[`date '+%Y-%m-%d %H:%M:%S'`] $REQ" | head -1 >> server.log 2>&1 | echo "[`date '+%Y-%m-%d %H:%M:%S'`] $url"

#split get into filename, arguments
url=(${url//\?/ })
filename="/home/george${url[0]}"

#if there is a file
if [ -f "$filename" ]; then
#if html, set conten type html, otherwise read from file(needed for Firefox)
if [[ "${url[0]}" == *.html ]] || [[ "${url[0]}" == *.htm ]] || [[ "${url[0]}" == *.php ]] || [[ "${url[0]}" == *.py ]] || [[ "${url[0]}" == *.cb ]]
        then
          ctype="text/html"
        else
          ctype=$(file --mime-type $filename)
          ctype=${ctype#* }
fi

#list arguments - to pass on to pyton or C
if [ "${#url[@]}" -gt 1 ]; then
        arg=${url[1]}
cont=""
getarg=(${url[1]//\&/ })
for x in ${getarg[@]}
do
    cont="$cont $x"
done

fi
#end argument list

#if PHP or Python script or binary, process it, show the result to the user, otherwise, just output the file
filedata=""
executefile=${url[0]#*/}
#execute C, Python and PHP scripts
if [[ "${url[0]}" == *.cb ]]; then
        filedata=$(./$executefile $cont)
elif [[ "${url[0]}" == *.php ]]; then
        filedata=$(php $filename $cont)
elif [[ "${url[0]}" == *.py ]]; then
        filedata=$(python $filename $cont)
else
        filedata=$(<$filename)
fi
# Content-Length: ${#filedata}
        TRES="HTTP/1.1 200 OK
Cache-Control: private
Server: bash/2.1
Content-Type: $ctype
Connection: Close
Content-Length: ${#filedata}

$filedata"
else
        TRES="HTTP/1.1 404 Not Found
Content-Type: text/html

404 Not Found

The requested resource was not found"
fi

cat >$RESP <<EOF
$TRES
EOF
)
done

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


Added script to create test streams from local agents.

#!/bin/bash
# ./streams-from-local.bash ./streams /usr/bin/jujud
set -eu

# GO (and Juju) compile by OS and arch. All Linux releases are the same!
RELEASES="precise trusty xenial centos7"
WIN_RELEASES="win2012hvr2"

STREAM_DIR=$1
JUJUD=$2
WIN_JUJUD=${3"-}

if [[ ! -d $STREAM_DIR ]]; then
    echo "Provide a path to a dir to hold the streams."
    exit 1
fi

if [[ ! -f $JUJUD ]]; then
    echo "Provide a path to a dir to hold the streams."
    exit 1
fi

full_version=$($JUJUD version)
version=$(echo $full_version | cut -d '-' -f 1)
arch=$(echo $full_version | cut -d '-' -f 3)

# Juju wont permit devel versions to be in released streams.
if [[ $version =~ (alpha|beta) ]]; then
    agent_dir="devel"
else
    agent_dir="released"
fi

mkdir -p $STREAM_DIR/tools/$agent_dir
mkdir -p $STREAM_DIR/tools/streams/v1

change_dir=$(dirname $JUJUD)
base_agent="agent.tgz"
tar cvfz $base_agent -C $change_dir jujud
for series in $RELEASES; do
    agent="juju-$version-$series-$arch.tgz"
    cp $base_agent $STREAM_DIR/tools/$agent_dir/$agent
done
rm $base_agent

if [[ -n $WIN_JUJUD ]]; then
    change_dir=$(dirname $WIN_JUJUD)
    base_agent="agent.tgz"
    tar cvfz $base_agent -C $change_dir jujud.exe
    for series in $WIN_RELEASES; do
        agent="juju-$version-$series-$arch.tgz"
        cp $base_agent $STREAM_DIR/tools/$agent_dir/$agent
    done
    rm $base_agent
fi

juju metadata generate-tools -d $STREAM_DIR --stream $agent_dir

echo "You can boostrap using these local streams like so:"
echo "juju bootstrap --metadata-source $STREAM_DIR"
echo ""

echo "or"
echo "Publish the $STREAM_DIR tree to a website or maybe your localhost."
echo "cd $STREAM_DIR"
echo "python -m SimpleHTTPServer"
echo "set agent-metadata-url: <HOST/path/tools>"

error: pathspec 'streams-from-local.bash' did not match any file(s) known to git


tests: try git apply from subdir of toplevel

Make sure git apply can apply patches with paths relative to the
toplevel of a work tree, a subdirectory, or within the repository
metadata directory.

Relative paths are broken for most commands when run from a
subdirectory of $GIT_DIR, "git apply" being no exception.  The other
tests are meant to keep the demonstration of that company.

Based on a test by Duy.

Cc: Nguyễn Thái Ngọc Duy <024f400cd820cb2ddbe54c7fecfd01e45f30bb96@gmail.com>
Signed-off-by: Jonathan Nieder <b57189c5f2fd5b3daf3350a77fde90def1080fa5@gmail.com>
Signed-off-by: Junio C Hamano <a6723cc3f76163bf7adb636a73ac3b0ceb3e6b9b@pobox.com>

#!/bin/sh

test_description='patching from inconvenient places'

. ./test-lib.sh

test_expect_success 'setup' '
	cat >patch <<-\EOF &&
	diff file.orig file
	--- a/file.orig
	+++ b/file
	@@ -1 +1,2 @@
	 1
	+2
	EOF
	patch="$(pwd)/patch" &&

	echo 1 >preimage &&
	printf "%s\n" 1 2 >postimage &&
	echo 3 >other &&

	test_tick &&
	git commit --allow-empty -m basis
'

test_expect_success 'setup: subdir' '
	reset_subdir() {
		git reset &&
		mkdir -p sub/dir/b &&
		mkdir -p objects &&
		cp "$1" file &&
		cp "$1" objects/file &&
		cp "$1" sub/dir/file &&
		cp "$1" sub/dir/b/file &&
		git add file sub/dir/file sub/dir/b/file objects/file &&
		cp "$2" file &&
		cp "$2" sub/dir/file &&
		cp "$2" sub/dir/b/file &&
		cp "$2" objects/file
	}
'

test_expect_success 'apply from subdir of toplevel' '
	cp postimage expected &&
	reset_subdir other preimage &&
	(
		cd sub/dir &&
		git apply "$patch"
	) &&
	test_cmp expected sub/dir/file
'

test_expect_success 'apply --cached from subdir of toplevel' '
	cp postimage expected &&
	cp other expected.working &&
	reset_subdir preimage other &&
	(
		cd sub/dir &&
		git apply --cached "$patch"
	) &&
	git show :sub/dir/file >actual &&
	test_cmp expected actual &&
	test_cmp expected.working sub/dir/file
'

test_expect_success 'apply --index from subdir of toplevel' '
	cp postimage expected &&
	reset_subdir preimage other &&
	(
		cd sub/dir &&
		test_must_fail git apply --index "$patch"
	) &&
	reset_subdir other preimage &&
	(
		cd sub/dir &&
		test_must_fail git apply --index "$patch"
	) &&
	reset_subdir preimage preimage &&
	(
		cd sub/dir &&
		git apply --index "$patch"
	) &&
	git show :sub/dir/file >actual &&
	test_cmp expected actual &&
	test_cmp expected sub/dir/file
'

test_expect_success 'apply from .git dir' '
	cp postimage expected &&
	cp preimage .git/file &&
	cp preimage .git/objects/file
	(
		cd .git &&
		git apply "$patch"
	) &&
	test_cmp expected .git/file
'

test_expect_failure 'apply from subdir of .git dir' '
	cp postimage expected &&
	cp preimage .git/file &&
	cp preimage .git/objects/file
	(
		cd .git/objects &&
		git apply "$patch"
	) &&
	test_cmp expected .git/objects/file
'

test_expect_success 'apply --cached from .git dir' '
	cp postimage expected &&
	cp other expected.working &&
	cp other .git/file &&
	reset_subdir preimage other &&
	(
		cd .git &&
		git apply --cached "$patch"
	) &&
	git show :file >actual &&
	test_cmp expected actual &&
	test_cmp expected.working file &&
	test_cmp expected.working .git/file
'

test_expect_success 'apply --cached from subdir of .git dir' '
	cp postimage expected &&
	cp preimage expected.subdir &&
	cp other .git/file &&
	cp other .git/objects/file &&
	reset_subdir preimage other &&
	(
		cd .git/objects &&
		git apply --cached "$patch"
	) &&
	git show :file >actual &&
	git show :objects/file >actual.subdir &&
	test_cmp expected actual &&
	test_cmp expected.subdir actual.subdir
'

test_done

error: pathspec 't/t4111-apply-subdir.sh' did not match any file(s) known to git


here it is

here it is

#!/bin/bash

# this script requires: zip, unzip, sort, awk, grep
# everything should come installed except maybe zip

# Provide a gtfs zip file which contains trips.txt and stop_times.txt
if [ -z "${1}" ]; then
    echo "Please provide a zip file"
    exit 1
fi

echo "Extracting the trips and stop_times files from $1"
unzip $1 trips.txt stop_times.txt
# don't need to remove ^M
#sed -e 's/'`echo "\015"`'//g' stop_times.txt

echo "Get all the unique trip ids and read into stop_times_trips.txt"
# take the file stop_times.txt and output to the unique file out.txt
sort -u -t, -k1,1 stop_times.txt | cut -d \, -f 1 > stop_times_trips.txt

# kill the last line which isn't numeric
#head -n -1 stop_times_trips.txt > temp.txt ; mv temp.txt stop_times_trips.txt

# just the trip id from trips.txt
echo "Get just the trip ids from trips.txt"
cat trips.txt | cut -d \, -f 3 > just_trips.txt

#strip the first line out
#tail -n +2 just_trips.txt > temp.txt ; mv temp.txt just_trips.txt

# these will need to be removed
echo "Build a list of stop_times that will need to be removed due to missing parent trip id"
grep -v -F -x -f just_trips.txt stop_times_trips.txt > missing_no_parents.txt

NUMOFLINES=$(wc -l < "missing_no_parents.txt")

# this will most likely be empty
grep -v -F -x -f stop_times_trips.txt just_trips.txt > missing_no_kids.txt

if [ "$NUMOFLINES" -gt 0 ]; then
  counter=1
  while read DELETEME
  do
      echo "Removing $DELETEME; number $counter of $NUMOFLINES"
      let counter++
      awk '!/'"$DELETEME"'/' stop_times.txt > temp && mv temp stop_times.txt
  done < missing_no_parents.txt

  # replace the stop_times file
  echo "Rebuild the zip file"
  zip -f $1 stop_times.txt
else
  echo "Nothing missing!"
fi

# cleanup
rm just_trips.txt
rm trips.txt
rm stop_times_trips.txt
rm stop_times.txt

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


Create build.sh

Create build.sh

#!/bin/sh

mkdir build
cd build

cmake ${CMAKE_ARGS} -GNinja .. \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS:BOOL=ON \
      -DBUILD_TESTING:BOOL=ON ..

cmake --build . --config Release
cmake --build . --config Release --target install
ctest --output-on-failure -C Release

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


script to update documentation in gh-pages

#!/bin/bash
ME=$(readlink -f "$0")
MYDIR=$(dirname "$ME")
cd $MYDIR &&
[ -e 'wrapperl' ] &&
pod2markdown wrapperl README.md &&
contents=$(kramdown README.md) &&
here=$(git reflog | perl -nale 'print$F[0];last') &&
git checkout gh-pages &&
echo "$contents" > index.html &&
(
   git commit index.html -m 'aligned documentation'
   git checkout "$here"
)

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


Added Firefox section

Added Firefox section

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/taylorfrey/Fedora-Post-Install.git/'


add cronjob script

add cronjob script

#!/bin/bash
. ../env/bin/activate
python manage.py update_from_feed --settings=unisubs-settings
python manage.py send_notification --settings=unisubs-settings

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


deploy script to sws.workhardplay.pw

deploy script to sws.workhardplay.pw

#!/bin/bash

echo "deploying to sws.workhardplay.pw" &&
    # lein clean &&
    lein with-profile dev filegen-ng &&
    lein scss :dev once &&
    LEIN_SNAPSHOTS_IN_RELEASE=true lein with-profile dev cljsbuild once &&
    scp -r ./resources/public/* deploy.do.myfutures.trade:/var/www/sws-workhardplay-pw &&
    echo "done"
    # ssh do.myfutures.trade "sudo service dev-myfutures-trade restart; sleep 10; sudo service dev-myfutures-trade status"

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