|
2 | 2 | # setup/update system ready for building appliances |
3 | 3 |
|
4 | 4 | fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; } |
| 5 | +warning() { echo "WARNING [$(basename $0)]: $@"; } |
5 | 6 | info() { echo "INFO [$(basename $0)]: $@"; } |
6 | 7 |
|
| 8 | +[[ -z "$DEBUG" ]] || set -x |
| 9 | + |
| 10 | +GIT_DEPTH=1 |
| 11 | + |
7 | 12 | RELEASE="${RELEASE:-debian/$(lsb_release -s -c)}" |
8 | 13 | CODENAME="$(basename $RELEASE)" |
9 | 14 | ARCH="${ARCH:-$(dpkg --print-architecture)}" |
10 | 15 |
|
11 | | -GPGKEY="A16EB94D" |
12 | 16 | IMAGES="http://mirror.turnkeylinux.org/turnkeylinux/images" |
13 | 17 | FAB_PATH="/turnkey/fab" |
14 | 18 | BOOTSTRAP_NAME="bootstrap-${CODENAME}-${ARCH}" |
15 | 19 | BOOTSTRAP_PATH="$FAB_PATH/bootstraps/${CODENAME}" |
| 20 | +BT_PATH="/turnkey/buildtasks" |
| 21 | +BT_VERIFY="$BT_PATH/bin/signature-verify" |
16 | 22 |
|
17 | | -if [ ! -d $BOOTSTRAP_PATH ]; then |
18 | | - info "downloading $BOOTSTRAP_NAME" |
19 | | - mkdir -p $(dirname $BOOTSTRAP_PATH) |
20 | | - cd $(dirname $BOOTSTRAP_PATH) |
21 | | - wget -nc $IMAGES/bootstrap/$BOOTSTRAP_NAME.tar.gz |
22 | | - wget -nc $IMAGES/bootstrap/$BOOTSTRAP_NAME.tar.gz.hash |
23 | | - |
24 | | - info "verifying $BOOTSTRAP_NAME" |
25 | | - gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 0x$GPGKEY |
26 | | - gpg --verify $BOOTSTRAP_NAME.tar.gz.hash |
| 23 | +[[ $(id -u) -eq 0 ]] || fatal "Root user required. Please rerun with sudo." |
27 | 24 |
|
28 | | - info "unpacking $BOOTSTRAP_NAME" |
29 | | - mkdir $BOOTSTRAP_PATH |
30 | | - tar -zxf $BOOTSTRAP_NAME.tar.gz -C $BOOTSTRAP_PATH |
31 | | -fi |
32 | | - |
33 | | -g() { |
| 25 | +clone_or_update() { |
34 | 26 | src=https://github.com/$1 |
35 | 27 | dst=$2 |
36 | 28 | mkdir -p $(dirname $dst) |
37 | | - if [ -d $dst ]; then |
38 | | - info "updating $dst" |
39 | | - GIT_DIR=$dst/.git git pull |
| 29 | + if [[ -d "$dst" ]]; then |
| 30 | + info "$dst exists, attempting update." |
| 31 | + git_dir=$dst/.git |
| 32 | + if [[ -d "$git_dir" ]]; then |
| 33 | + GIT_DIR=$git_dir git pull || warning "Updating $dst failed, skipping." |
| 34 | + else |
| 35 | + warning "$dst exists, but is not a git repo - skipping." |
| 36 | + return |
| 37 | + fi |
40 | 38 | else |
41 | | - info "cloning $src" |
42 | | - git clone $src $dst |
| 39 | + info "Cloning $src into $dst." |
| 40 | + git clone --depth $GIT_DEPTH $src $dst || warning "Cloning $dst failed, skipping." |
43 | 41 | fi |
44 | 42 | } |
45 | 43 |
|
46 | | -g turnkeylinux/buildtasks /turnkey/buildtasks |
47 | | -g turnkeylinux/tklbam-profiles /turnkey/tklbam-profiles |
48 | | -g turnkeylinux/cdroots $FAB_PATH/cdroots |
49 | | -g turnkeylinux/common $FAB_PATH/common |
50 | | -g turnkeylinux-apps/core $FAB_PATH/products/core |
| 44 | +clone_or_update turnkeylinux/buildtasks $BT_PATH |
| 45 | +clone_or_update turnkeylinux/tklbam-profiles /turnkey/tklbam-profiles |
| 46 | +clone_or_update turnkeylinux/cdroots $FAB_PATH/cdroots |
| 47 | +clone_or_update turnkeylinux/common $FAB_PATH/common |
| 48 | +clone_or_update turnkeylinux-apps/core $FAB_PATH/products/core |
51 | 49 |
|
| 50 | +if [[ -f "$BT_PATH/config/common.cfg" ]]; then |
| 51 | + . $BT_PATH/config/common.cfg |
| 52 | +elif [[ -f "$BT_PATH/config.example/common.cfg" ]]; then |
| 53 | + . $BT_PATH/config.example/common.cfg |
| 54 | +else |
| 55 | + fatal "$BT_PATH config not found, unable to determine GPG key ID (BT_GPGKEY)." |
| 56 | +fi |
| 57 | + |
| 58 | +if [[ -d "$BOOTSTRAP_PATH" ]]; then |
| 59 | + info "$BOOTSTRAP_PATH exists, skipping download." |
| 60 | +else |
| 61 | + info "Downloading $BOOTSTRAP_NAME" |
| 62 | + mkdir -p $(dirname $BOOTSTRAP_PATH) |
| 63 | + cd $(dirname $BOOTSTRAP_PATH) |
| 64 | + bootstrap_file=$BOOTSTRAP_PATH |
| 65 | + wget -nc $IMAGES/bootstrap/$BOOTSTRAP_NAME.tar.gz \ |
| 66 | + || fatal "Downloading $BOOTSTRAP_NAME failed." |
| 67 | + wget -nc $IMAGES/bootstrap/$BOOTSTRAP_NAME.tar.gz.hash \ |
| 68 | + || fatal "Downloading $BOOTSTRAP_NAME hash file failed." |
| 69 | + |
| 70 | + if [[ -f "$BT_VERIFY" ]]; then |
| 71 | + bootstrap_file=$(dirname $BOOTSTRAP_PATH)/$BOOTSTRAP_NAME.tar.gz |
| 72 | + BT_DEBUG=$DEBUG $BT_VERIFY --force-gpg $bootstrap_file $bootstrap_file.hash |
| 73 | + else |
| 74 | + fatal "$BT_VERIFY script not found, unable to verfiy downloaded files." |
| 75 | + fi |
| 76 | + info "Unpacking $BOOTSTRAP_NAME" |
| 77 | + mkdir $BOOTSTRAP_PATH |
| 78 | + tar -zxf $BOOTSTRAP_NAME.tar.gz -C $BOOTSTRAP_PATH |
| 79 | +fi |
| 80 | +info "$(basename $0) complete." |
0 commit comments