aboutsummaryrefslogtreecommitdiff
path: root/node/slave-helpers
blob: b2a626d41c81edda36a92e835277d5493df43d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

###############################################################################
# Copyright (c) 2011 Linaro
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
###############################################################################


setup_ubuntu_s3_mirror () {
    sed -i.bk 's,^\(.*://[^.]*.ec2.archive.ubuntu.com\)/,\1.s3.amazonaws.com/,' /etc/apt/sources.list
    echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99no-pipelining
}

# Stubborn apt-get, retrying on errors
apt_get_retry () {
    local fatal="yes";
    if [ "$1" = "--non-fatal" ]; then
        fatal=""
        shift
    fi
    local delay=1;
    while [ $delay -lt 100 ]; do
        if apt-get "$@"; then
            return
        fi
        echo "apt-get failed, sleeping ${delay}s before retrying"
        sleep $delay
        delay=$((delay * 2))
    done
    if [ -n "$fatal" ]; then
        echo "apt-get failed after several attempts, aborting"
        exit 1
    fi
}