-
Notifications
You must be signed in to change notification settings - Fork 11
/
unraid_tools.sh
executable file
·216 lines (193 loc) · 5.34 KB
/
unraid_tools.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
CURDIR=$(pwd)
URTMP=${CURDIR}/tmp
BZROOT=${URTMP}/bzroot
TMPROOT=${CURDIR}/tmproot
vercomp () {
if [[ $1 == $2 ]]
then
echo "="
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
echo ">"
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
echo "<"
return 2
fi
done
echo "="
return 0
}
download () {
#URVER="6.11.5"
#URVER="6.12.0-rc2"
URVER="$1"
#CHANNEL="stable"
#CHANNEL="test"
#CHANNEL="next"
CHANNEL="$2"
URZIP="unRAIDServer-${URVER}-x86_64.zip"
read -p "Pack base on version ${URVER} in ${CHANNEL}"
# The link is found from https://unraid.net/download
# echo https://unraid-dl.sfo2.cdn.digitaloceanspaces.com/${CHANNEL}/${URZIP}
if ! wget -c https://unraid-dl.sfo2.cdn.digitaloceanspaces.com/${CHANNEL}/${URZIP} ; then
exit 1
fi
}
unpack_bzroot() {
BZROOT=$1;
if [ -z "${BZROOT}" ] || [ ! -e ${BZROOT} ];
then
echo "Path for bzroot not provided."
exit
fi
EXTDIR=$2
SKIPBLK=$(cpio -ivt -H newc < ${BZROOT} 2>&1 > /dev/null | awk '{print $1}')
echo "Skip ${SKIPBLK} to extract "${BZROOT};
mkdir ${TMPROOT}
# Extract ${EXTDIR}
dd if=${BZROOT} bs=512 skip=${SKIPBLK} | xzcat | (cd ${TMPROOT}; cpio -i -d -H newc --no-absolute-filenames ${EXTDIR} )
}
kernel_prepare() {
if ! download $@ ;then
echo error;
fi
unzip ${URZIP} -d ${URTMP}
# Extract usr/src
if [[ $(vercomp ${URVER} "6.11.99") == ">" ]];
then
EXTDIR="src"
mkdir -p ${TMPROOT}/usr
unsquashfs -d tmproot/usr -q ${URTMP}/bzfirmware -extract-file ${EXTDIR}
else
EXTDIR="usr/src/linux-*"
unpack_bzroot ${BZROOT} ${EXTDIR}
fi
KERNAME=$(ls ${TMPROOT}/usr/src/)
KERVER=$(echo ${KERNAME} | cut -d'-' -f2)
KERVERUR=$(echo ${KERNAME} | cut -d'-' -f2-)
KERVERM=$(echo ${KERVER} | cut -d'.' -f1)
# Download source from kernel.org
wget -c https://cdn.kernel.org/pub/linux/kernel/v${KERVERM}.x/linux-${KERVER}.tar.xz
tar xf linux-${KERVER}.tar.xz
cp -r ${TMPROOT}/usr/src/${KERNAME}/* linux-${KERVER}/
cp -r ${TMPROOT}/usr/src/${KERNAME}/.config linux-${KERVER}/
cd linux-${KERVER}
for patch in $(ls ./*.patch)
do
patch -p1 < ${patch}
done
cd ../
mv linux-${KERVER} ${KERNAME}
# Kernel prepare
cd ${KERNAME}
if [[ $(vercomp ${URVER} "6.12") == "<" ]] && [[ $(vercomp ${URVER} "6.10.99") == ">" ]];
then
patch -p0 < ${CURDIR}/config-5.19-enable-pxp.patch
fi
make oldconfig
make modules_prepare
cd ${CURDIR}
echo "Kernel source ${KERNAME} prepared."
}
# Compile kernel
#cp config-${KERVERUR} ${KERNAME}/.config
#cd ${KERNAME}
#make -j4
#make INSTALL_MOD_PATH=${CURDIR}/tmpmodules modules_install
#cd ${CURDIR}
##cp -r /lib/modules/${KERVERUR} tmpmodules
build_i915(){
kernel_prepare $@
# Build i915-sriov module
if [[ $(vercomp ${URVER} "6.11.99") == ">" ]];then
git clone -b 6.1 https://github.com/zhtengw/i915-sriov-dkms.git
elif [[ $(vercomp ${URVER} "6.10.99") == ">" ]];then
git clone -b 5.19 https://github.com/zhtengw/i915-sriov-dkms.git
else
git clone -b 5.15 https://github.com/zhtengw/i915-sriov-dkms.git
fi
cd i915-sriov-dkms
make -j4 -C ${CURDIR}/${KERNAME} M=${CURDIR}/i915-sriov-dkms KVER=${KERVER}
xz i915.ko
cd ${CURDIR}
mkdir -p tmpplugin/lib/modules/${KERVERUR}/kernel/drivers/gpu/drm/i915
cp i915-sriov-dkms/i915.ko.xz tmpplugin/lib/modules/${KERVERUR}/kernel/drivers/gpu/drm/i915
if [[ $(vercomp ${URVER} "6.11") == "<" ]];then
mkdir -p tmpplugin/lib/firmware/i915/
wget -c https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/i915/tgl_guc_70.bin -O tmpplugin/lib/firmware/i915/tgl_guc_70.bin
fi
# Make i915 package
PKGNAME="i915-sriov"
PKGARCH="x86_64"
PKGBUILD="2"
if [[ ! -e makepkg ]];
then
bash unraid_unpack_bzroot.sh ${BZROOT} sbin/makepkg
cp ${TMPROOT}/sbin/makepkg ${CURDIR}
fi
mkdir -p packages
cd tmpplugin
#${CURDIR}/makepkg --linkadd y --chown y ${CURDIR}/packages/${PKGNAME}-${KERVERUR}-${PKGARCH}-${PKGBUILD}.txz
${CURDIR}/makepkg --linkadd y --chown y ${CURDIR}/packages/${PKGNAME}-${KERVERUR}.txz
cd ${CURDIR}/packages
md5sum ${PKGNAME}-${KERVERUR}.txz > ${PKGNAME}-${KERVERUR}.txz.md5
cd ${CURDIR}
}
# Get new kernel image after building
#cp ${KERNAME}/arch/x86/boot/bzImage ./bzimage
#sha256sum bzimage > bzimage.sha256
#
# Extract bzmodules
#rdsquashfs -q -u / -p tmpmodules bzmodules # with squashfs-tools-ng
#unsquashfs -d tmpmodules -q bzmodules # with squashfs-tools
#
# Generate new bzmodules
##gensquashfs -q -D tmpmodules bzmodules # with squashfs-tools-ng
#mksquashfs tmpmodules bzmodules -quiet -comp xz # with squashfs-tools
#sha256sum bzmodules > bzmodules.sha256
clean() {
# Clean up
if [ -z ${CURDIR} ];then
exit 1;
fi
if [ -e ${CURDIR}/tmproot ];then
/bin/rm -r ${CURDIR}/tmproot
fi
if [ -e ${CURDIR}/tmpmodules ];then
/bin/rm -r ${CURDIR}/tmpmodules
fi
if [ -e ${CURDIR}/tmpplugin ];then
/bin/rm -r ${CURDIR}/tmpplugin
fi
if [ -e ${CURDIR}/tmp ];then
/bin/rm -r ${CURDIR}/tmp
fi
if [ -n "${KERNAME}" ] && [ -e ${CURDIR}/${KERNAME} ];then
/bin/rm -r ${CURDIR}/${KERNAME}
fi
if [ -e ${CURDIR}/i915-sriov-dkms ];then
/bin/rm -r ${CURDIR}/i915-sriov-dkms
fi
}
$@
clean