view util.sh @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
line wrap: on
line source

#!/bin/bash

extify() {
    local REQ_EXT=$1
    shift

    local OUTPUT=""
    local FILE
    for FILE in $*; do
        local BASENAME=$(basename ${FILE})
        local EXT=${BASENAME##*.}
        if [[ ${EXT} != ${REQ_EXT} ]]; then
            local LINK="${BASENAME%%.*}.${REQ_EXT}"
            if [[ ! -f ${LINK} ]]; then
                ln -s ${FILE} ${LINK}
            fi
            FILE="${LINK}"
        fi
        OUTPUT="${OUTPUT} ${FILE}"
    done

    echo ${OUTPUT}
}

# from http://www.linuxjournal.com/content/use-date-command-measure-elapsed-time
timer() {
    if [[ $# -eq 0 ]]; then
        echo $(date '+%s')
    else
        local  stime=$1
        etime=$(date '+%s')

        if [[ -z "$stime" ]]; then stime=$etime; fi

        dt=$((etime - stime))
        ds=$((dt % 60))
        dm=$(((dt / 60) % 60))
        dh=$((dt / 3600))
        printf '%d:%02d:%02d' $dh $dm $ds
    fi
}

on_exit() {
    echo "Elapsed time: $(timer ${START_TIME})"
}

set -eux

START_TIME=$(timer)
trap on_exit EXIT

# Custom to this tool; add the bin directory of the argo navis tool to path, and create an accessor for data
# in it
export ARGO_TOOL_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
export PATH=$ARGO_TOOL_DIR/bin:$PATH