-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·136 lines (111 loc) · 3.65 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
runfile="$1"
distro="$2"
topdir="$HOME/nvidia-driver"
epoch="3"
[[ -n $OUTPUT ]] ||
OUTPUT="$HOME/rpm-nvidia"
[[ -n $distro ]] ||
distro=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
[[ $distro == "main" ]] && distro="rhel8"
drvname=$(basename "$runfile")
arch=$(echo "$drvname" | awk -F "-" '{print $3}')
version=$(echo "$drvname" | sed -e "s|NVIDIA\-Linux\-${arch}\-||" -e 's|\.run$||' -e 's|\-grid$||')
drvbranch=$(echo "$version" | awk -F "." '{print $1}')
tarball="nvidia-driver-${version}-${arch}"
unpackDir="temp"
err() { echo; echo "ERROR: $*"; exit 1; }
kmd() { echo; echo ">>> $*" | fold -s; eval "$*" || err "at line \`$*\`"; }
dep() { type -p "$1" >/dev/null || err "missing dependency $1"; }
generate_tarballs()
{
rm -rf ${unpackDir}
generateTarballs=$(echo -n "nvidia-generate-tarballs-${arch}.sh" | sed 's|\-x86_64\.|\.|')
kmd RUN_FILE="$runfile" VERSION="$version" ./"$generateTarballs"
}
build_rpm()
{
mkdir -p "$topdir"
(cd "$topdir" && mkdir -p BUILD BUILDROOT RPMS SRPMS SOURCES SPECS)
cp -v -- *conf* "$topdir/SOURCES/"
cp -v -- *.tar* "$topdir/SOURCES/"
cp -v -- *.spec "$topdir/SPECS/"
cd "$topdir" || err "Unable to cd into $topdir"
kmd rpmbuild \
--define "'%_topdir $(pwd)'" \
--define "'debug_package %{nil}'" \
--define "'version $version'" \
--define "'epoch $epoch'" \
--target "$arch" \
-v -bb SPECS/nvidia-driver.spec
cd - || err "Unable to cd into $OLDPWD"
}
build_triple_rpm()
{
mkdir -p "$topdir"
(cd "$topdir" && mkdir -p BUILD BUILDROOT RPMS SRPMS SOURCES SPECS)
cp -v -- *rules* "$topdir/SOURCES/"
cp -v -- *conf* "$topdir/SOURCES/"
cp -v -- *.tar* "$topdir/SOURCES/"
cp -v -- *.spec "$topdir/SPECS/"
for flavor in latest-dkms latest branch-${drvbranch}; do
cd "$topdir" || err "Unable to cd into $topdir"
is_latest=0
is_dkms=0
if [[ $flavor =~ latest ]]; then
is_latest=1
fi
if [[ $flavor =~ dkms ]]; then
is_dkms=1
fi
echo -e "\n:: flavor $flavor [$is_latest] [$is_dkms]"
kmd rpmbuild \
--define "'%_topdir $(pwd)'" \
--define "'debug_package %{nil}'" \
--define "'version $version'" \
--define "'driver_branch $flavor'" \
--define "'is_dkms $is_dkms'" \
--define "'is_latest $is_latest'" \
--define "'epoch $epoch'" \
--target "$arch" \
-v -bb SPECS/nvidia-driver.spec
cd - || err "Unable to cd into $OLDPWD"
echo "====================="
done
}
build_wrapper()
{
echo ":: Building $distro packages"
if [[ $distro == "rhel7" ]]; then
build_triple_rpm
else
build_rpm
fi
}
# Create tarball from runfile contents
if [[ -f ${tarball}.tar.xz ]]; then
echo "[SKIP] generate_tarballs()"
else
echo "==> generate_tarballs()"
[[ -f $runfile ]] || err "Usage: $0 /path/to/NVIDIA-Linux-*.run"
generate_tarballs
fi
# Sanity check
[[ -n $version ]] || err "version could not be determined"
# Build RPMs
empty=$(find "$topdir/RPMS" -maxdepth 0 -type d -empty 2>/dev/null)
found=$(find "$topdir/RPMS" -mindepth 2 -maxdepth 2 -type f -name "*${version}*" 2>/dev/null)
if [[ ! -d "$topdir/RPMS" ]] || [[ $empty ]] || [[ ! $found ]]; then
echo "==> build_rpm(${version})"
dep rpmbuild
build_wrapper
else
echo "[SKIP] build_rpm(${version})"
fi
echo "---"
found=$(find "$topdir/RPMS" -mindepth 2 -maxdepth 2 -type f -name "*${version}*" 2>/dev/null)
for rpm in $found; do
echo "-> $(basename "$rpm")"
mkdir -p "$OUTPUT"
rsync -a "$rpm" "$OUTPUT"
done