security/nss/automation/taskcluster/scripts/tools.sh
author Kai Engert <kaie@kuix.de>
Wed, 11 Apr 2018 12:54:08 +0200
changeset 412831 0037f2516d1015029e8a3d0901d6e6d12a6aa140
parent 330549 052b90b5414fea4b6d6ed3a5ce714d76a029716a
child 438793 3a5aa4e939536f27d4f3be418dd5e3e7bbe9130a
permissions -rw-r--r--
Bug 1445731, land NSS 2eefd697d661 UPGRADE_NSS_RELEASE, r=me

#!/usr/bin/env bash

set -v -e -x

if [[ $(id -u) -eq 0 ]]; then
    # Stupid Docker. It works without sometimes... But not always.
    echo "127.0.0.1 localhost.localdomain" >> /etc/hosts

    # Drop privileges by re-running this script.
    # Note: this mangles arguments, better to avoid running scripts as root.
    exec su worker -c "$0 $*"
fi

export PATH="${PATH}:/home/worker/.cargo/bin/:/usr/lib/go-1.6/bin"

# Usage: hg_clone repo dir [revision=@]
hg_clone() {
    repo=$1
    dir=$2
    rev=${3:-@}
    if [ -d "$dir" ]; then
        hg pull -R "$dir" -ur "$rev" "$repo" && return
        rm -rf "$dir"
    fi
    for i in 0 2 5; do
        sleep $i
        hg clone -r "$rev" "$repo" "$dir" && return
        rm -rf "$dir"
    done
    exit 1
}

fetch_dist() {
    url=https://queue.taskcluster.net/v1/task/$TC_PARENT_TASK_ID/artifacts/public/dist.tar.bz2
    if [ ! -d "dist" ]; then
        for i in 0 2 5; do
            sleep $i
            curl --retry 3 -Lo dist.tar.bz2 $url && tar xvjf dist.tar.bz2 && return
            rm -fr dist.tar.bz2 dist
        done
        exit 1
    fi
}