-
Notifications
You must be signed in to change notification settings - Fork 19
/
crouton
87 lines (79 loc) · 3.57 KB
/
crouton
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh -e
# Copyright (c) 2015 The crouton Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file of the source repository, which has been replicated
# below for convenience of distribution:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This is an indirect script. The actual installer will be downloaded, cached,
# and run with any parameters provided. Cached installer will be retained for
# 30 minutes unless this downloader is newer than the timestamp of the cache.
# Set CROUTON_BRANCH to change the branch downloaded.
set -e
CROUTON_BRANCH="${CROUTON_BRANCH#master}"
INSTALLER="crouton${CROUTON_BRANCH:+-}${CROUTON_BRANCH:-}"
URL="https://github.com/dnschneid/crouton/raw/releases/$INSTALLER"
CACHEDIR="/tmp/${0##*/}-installer-cache"
CACHEFILE="$CACHEDIR/$INSTALLER"
MAXAGE="$((30*60))"
# Process arguments
while getopts ':a:f:k:m:M:n:p:P:r:s:t:T:' f; do
if [ "$f" = 'P' ]; then
export http_proxy="$OPTARG" https_proxy="$OPTARG" ftp_proxy="$OPTARG"
fi
done
# Check dates and update the cache
(umask 000; mkdir -p "$CACHEDIR")
if [ ! -s "$CACHEFILE" -o ! "$CACHEFILE" -nt "$0" ] || \
[ "`date -r "$CACHEFILE" '+%s'`" -lt "$((`date '+%s'`-$MAXAGE))" ]; then
if [ ! -f "$CACHEFILE" -o -w "$CACHEFILE" ]; then
echo "Downloading latest $INSTALLER installer..." 1>&2
trap "rm -f '$CACHEFILE'; exit 1" INT HUP TERM 0
if ! (umask 022; \
curl -# -L --connect-timeout 60 --max-time 300 --retry 2 \
"$URL" -o "$CACHEFILE"); then
echo "Failed to download $INSTALLER installer.
Check your internet connection or proxy settings (-P) and try again." 1>&2
exit 1
fi
trap - INT HUP TERM 0
else
echo "Insufficient permissions to refresh $INSTALLER installer." 1>&2
fi
fi
# If this script was called with '-x' or '-v', pass that along.
SETOPTIONS="-e"
if set -o | grep -q '^xtrace.*on$'; then
SETOPTIONS="$SETOPTIONS -x"
fi
if set -o | grep -q '^verbose.*on$'; then
SETOPTIONS="$SETOPTIONS -v"
fi
# Launch the real script
exec sh $SETOPTIONS "$CACHEFILE" "$@"
# Some junk to fix the MIME type
: '