-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.sh
executable file
·130 lines (107 loc) · 3.49 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
#!/usr/bin/env bash
runfile="$1"
distro="$2"
topdir="$HOME/dkms-nvidia"
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-kmod-${version}-${arch}"
unpackDir="unpack"
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()
{
mkdir "${tarball}"
sh "${runfile}" --extract-only --target ${unpackDir}
mv "${unpackDir}/kernel" "${tarball}/"
rm -rf ${unpackDir}
tar --remove-files -cJf "${tarball}.tar.xz" "${tarball}"
}
build_dnf_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/dkms-nvidia.spec
cd - || err "Unable to cd into $OLDPWD"
}
build_yum_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/"
#
# NOTE: to build kmod-nvidia-branch-XXX and kmod-nvidia-latest packages
# see https://github.com/NVIDIA/yum-packaging-precompiled-kmod
flavor="latest-dkms"
is_latest=1
is_dkms=1
cd "$topdir" || err "Unable to cd into $topdir"
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/dkms-nvidia.spec
cd - || err "Unable to cd into $OLDPWD"
}
build_wrapper()
{
echo ":: Building $distro packages"
if [[ $distro == "rhel7" ]]; then
build_yum_rpm
else
build_dnf_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