~smoser/+junk/modev-bin

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
#!/bin/bash

_APT_UPDATED=false
IPXE_GIT="http://git.ipxe.org/ipxe.git"
IPXE_REF="HEAD"

error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 2; }

rel="$(lsb_release -sc)"
DEPS=(
    build-essential
    liblzma-dev
    libiberty-dev
    zlib1g-dev
)

apt_get() {
    local ret=""
    if [ "$1" != "update" ] && ! $_APT_UPDATED; then
        error "updating apt"
        apt_get update >/dev/null || {
            ret=$?;
            error "failed to update apt [$ret]";
            return $ret;
        }
        _APT_UPDATED=true
    fi
    sudo DEBIAN_FRONTEND=noninteractive eatmydata apt-get --quiet \
        --assume-yes "$@" </dev/null
}

filter_installed_packages() {
    # write to stdout, a list of packages not installed locally
    local fmt='${Package} ${Version}\n'
    LC_ALL=C dpkg-query --show "--showformat=${fmt}" "$@" 2>&1 | awk '
        $0 ~ /[Nn]o packages/ {
            sub("[.]$","",$NF);
            pkgs[n]=$NF;
            n=n+1;
        }
        $2 == "" {
                pkgs[n]=$1;
                n=n+1;
        };
        END { for(p in pkgs) {printf("%s ",pkgs[p])}; printf("\n"); }' n=0
}

apt_install() {
    local needed
    needed=$(filter_installed_packages "$@")
    [ -z "$needed" ] && return 0
    error "installing: $needed"
    apt_get install "$@"
}

apt_install "${DEPS[@]}" || fail "failed install deps: ${DEPS[*]}"

if [ ! -d ipxe ]; then
    rm -Rf ipxe.working &&
        git clone "$IPXE_GIT" ipxe.working || fail "failed clone $IPXE_GIT"
    mv ipxe.working ipxe || fail "failed mv git to ipxe"
fi

start_d="$PWD"
cd ipxe
git checkout master && git branch -d buildbranch >/dev/null || :
git branch buildbranch "$IPXE_REF" &&
    git checkout buildbranch || fail "failed branch of $IPXE_REF"

cat > src/config/local/console.h <<EOF
#define CONSOLE_PCBIOS
#define CONSOLE_SERIAL
EOF
[ $? -eq 0 ] || fail "failed write console.h"
( cd src && make ) || fail "failed build"