-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·142 lines (115 loc) · 3.77 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
137
138
139
140
141
142
#!/usr/bin/env bash
runfile="$1"
distro="$2"
topdir="$HOME/nvidia-modprobe"
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$||' -e 's|\.tar\..*||' -e 's|nvidia\-modprobe\-||')
drvbranch=$(echo "$version" | awk -F "." '{print $1}')
tarball="nvidia-modprobe-${version}"
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"; }
fetch_input() {
inputfile="${tarball}.tar.bz2"
# Download runfile
if [[ ! -f "$inputfile" ]]; then
dep wget
kmd wget "https://download.nvidia.com/XFree86/nvidia-modprobe/${tarball}.tar.bz2" -O "$inputfile"
fi
}
build_rpm()
{
mkdir -p "$topdir"
(cd "$topdir" && mkdir -p BUILD BUILDROOT RPMS SRPMS SOURCES SPECS)
cp -v -- *.patch* "$topdir/SOURCES/"
cp -v -- *modprobe*.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'" \
-v -bb SPECS/nvidia-modprobe.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 -- *.patch* "$topdir/SOURCES/"
cp -v -- *modprobe*.tar* "$topdir/SOURCES/"
cp -v -- *.spec "$topdir/SPECS/"
if [[ -f "nvidia-modprobe-${version}.tar.gz" ]]; then
extension="gz"
elif [[ -f "nvidia-modprobe-${version}.tar.bz2" ]]; then
extension="bz2"
fi
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 "'extension $extension'" \
--define "'epoch $epoch'" \
-v -bb SPECS/nvidia-modprobe.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
}
# Download tarball
if [[ -f ${tarball}.tar.bz2 ]]; then
echo "[SKIP] fetch_input($version)"
else
echo "==> fetch_input($version)"
fetch_input
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 m4
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