-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.sh
executable file
·110 lines (95 loc) · 2.54 KB
/
build.sh
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
#
# Build NVIDIA drivers for a given CoreOS version
#
KEEP_CONTAINER=false
EMERGE_SOURCES=""
while :; do
case $1 in
--keep)
KEEP_CONTAINER=true
;;
--emerge-sources)
EMERGE_SOURCES=$1
;;
-?*)
echo Unknown flag $1
exit 1
;;
*)
break
esac
shift
done
echo "Keeping container around after build: ${KEEP_CONTAINER}"
echo "Additional flags: ${EMERGE_SOURCES}"
DRIVER_VERSION=${1:-367.57}
COREOS_TRACK=${2:-beta}
COREOS_VERSION=${3:-1185.5.0}
DRIVER_ARCHIVE=NVIDIA-Linux-x86_64-${DRIVER_VERSION}
DRIVER_ARCHIVE_PATH=${PWD}/nvidia_installers/${DRIVER_ARCHIVE}.run
DEV_CONTAINER=coreos_developer_container.bin.${COREOS_VERSION}
WORK_DIR=pkg/run_files/${COREOS_VERSION}
ORIGINAL_DIR=${PWD}
function onerr {
echo Caught error
finish
}
function onexit {
finish
}
function finish {
if [ "${KEEP_CONTAINER}" != "true" ]
then
cd ${ORIGINAL_DIR}
echo Cleaning up
sudo rm -Rf ${DEV_CONTAINER} ${WORK_DIR}/${DRIVER_ARCHIVE} tmp
fi
exit
}
set -e
trap onerr ERR
trap onexit exit
if [ ! -f ${DEV_CONTAINER} ]
then
echo Downloading CoreOS ${COREOS_TRACK} developer image ${COREOS_VERSION}
SITE=${COREOS_TRACK}.release.core-os.net/amd64-usr
curl -s -L https://${SITE}/${COREOS_VERSION}/coreos_developer_container.bin.bz2 \
-z ${DEV_CONTAINER}.bz2 \
-o ${DEV_CONTAINER}.bz2
echo Decompressing
bunzip2 -k ${DEV_CONTAINER}.bz2
fi
if [ ! -f ${DRIVER_ARCHIVE_PATH} ]
then
echo Downloading NVIDIA Linux drivers version ${DRIVER_VERSION}
mkdir -p nvidia_installers
SITE=us.download.nvidia.com/XFree86/Linux-x86_64
SITE2=us.download.nvidia.com/tesla
curl -s -L http://${SITE}/${DRIVER_VERSION}/${DRIVER_ARCHIVE}.run \
-z ${DRIVER_ARCHIVE_PATH} \
-o ${DRIVER_ARCHIVE_PATH} -f ||
curl -s -L http://${SITE2}/${DRIVER_VERSION}/${DRIVER_ARCHIVE}.run \
-z ${DRIVER_ARCHIVE_PATH} \
-o ${DRIVER_ARCHIVE_PATH} -f
fi
rm -Rf ${PWD}/tmp
mkdir -p ${PWD}/tmp ${WORK_DIR}
cp -ulf ${DRIVER_ARCHIVE_PATH} ${WORK_DIR}
cd ${WORK_DIR}
chmod +x ${DRIVER_ARCHIVE}.run
sudo rm -Rf ./${DRIVER_ARCHIVE}
./${DRIVER_ARCHIVE}.run -x -s
cd ${ORIGINAL_DIR}
# Ignore errors just for nspawn
set +e
trap ":" ERR
sudo systemd-nspawn -i ${DEV_CONTAINER} \
--bind=${PWD}/_container_build.sh:/build.sh \
--bind=${PWD}/${WORK_DIR}:/nvidia_installers \
/bin/bash -x /build.sh ${EMERGE_SOURCES} ${DRIVER_VERSION}
trap onerr ERR
set -e
sudo chown -R ${UID}:${GROUPS[0]} ${PWD}/${WORK_DIR}
bash -x _export.sh ${WORK_DIR}/*-${DRIVER_VERSION} \
${DRIVER_VERSION} ${COREOS_VERSION}-${DRIVER_VERSION}