forked from steamos-community/stephensons-rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.sh
executable file
·425 lines (372 loc) · 12.4 KB
/
gen.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#!/bin/sh
#Basic variables
BUILD="./buildroot"
DISTNAME="brewmaster"
CACHEDIR="./cache"
ISOPATH="."
ISONAME="rocket.iso"
ISOVNAME="Stephensons Rocket 2.60plus1"
UPSTREAMURL="http://repo.steampowered.com"
STEAMINSTALLFILE="SteamOSDVD.iso"
MD5SUMFILE="MD5SUMS"
KNOWNINSTALLER="e476adef556895d511c4ba52d6c6880f"
REPODIR="./archive-mirror/mirror/repo.steampowered.com/steamos"
#Show how to use gen.sh
usage ( )
{
cat <<EOF
$0 [OPTION] [MOD1] [MOD2] [MOD3] ...
-h Print this message
-d Re-Download ${STEAMINSTALLFILE}
-n Set the name for the iso
EOF
}
#Check some basic dependencies this script needs to run
deps ( ) {
#Check dependencies
deps="apt-utils xorriso syslinux rsync wget lftp p7zip-full realpath"
for dep in ${deps}; do
if dpkg-query -s ${dep} >/dev/null 2>&1; then
:
else
echo "Missing dependency: ${dep}"
echo "Install with: sudo apt-get install ${dep}"
exit 1
fi
done
if test "`expr length \"$ISOVNAME\"`" -gt "32"; then
echo "Volume ID is more than 32 characters: ${ISOVNAME}"
exit 1
fi
#Check xorriso version is compatible, must be 1.2.4 or higher
xorrisover=`xorriso --version 2>&1 | egrep -e "^xorriso version" | awk '{print $4}'`
reqxorrisover=1.2.4
if dpkg --compare-versions ${xorrisover} ge ${reqxorrisover} >/dev/null 2>&1; then
echo "PASS: xorriso version ${xorrisover} supports required functions."
else
echo "ERROR: xorriso version ${xorrisover} is too to old. Please upgrade to xorriso version ${reqxorrisover} or higher."
exit 1
fi
}
#Remove the ${BUILD} directory to start from scratch
rebuild ( ) {
if [ -d "${BUILD}" ]; then
echo "Building ${BUILD} from scratch"
rm -fr "${BUILD}"
fi
}
#Report on obsolete packages
obsoletereport ( ) {
if [ ! -d ${REPODIR} ]; then
echo "No ${REPODIR} directory exists, run archive-mirror.sh if you want this script to report obsolete packages"
else
echo "Reporting on packages which are different in ${BUILD} than ${REPODIR}"
echo "\nPackagename\t\ttype\tarch\told version\tnew version\n"
REPODIR="`realpath ${REPODIR}`"
cd ${BUILD}/pool/
for i in */*/*/*.*deb
do PKGNAME=`basename $i | cut -f1 -d'_'`
ARCHNAME=`basename $i | cut -f3 -d'_' | cut -f1 -d'.'`
PKGPATH=`dirname $i`;PKGVER=`basename $i | cut -f2 -d'_'`
DEBTYPE=`basename $i | sed 's/.*\.//g'`
if [ `ls -1 ${REPODIR}/pool/${PKGPATH}/${PKGNAME}_*_${ARCHNAME}.${DEBTYPE} 2> /dev/null | wc -l` -gt 0 ]
then NEWPKGVER=$(basename `ls -1 ${REPODIR}/pool/${PKGPATH}/${PKGNAME}_*_${ARCHNAME}.${DEBTYPE} | sort -n | tail -1` | cut -f2 -d'_')
if [ "x${PKGVER}" != "x${NEWPKGVER}" ]
then echo "${PKGNAME}\t\t${DEBTYPE}\t${ARCHNAME}\t${PKGVER}\t${NEWPKGVER}"
fi
fi
done
cd -
fi
}
#Extract the upstream SteamOSDVD.iso from repo.steampowered.com
extract ( ) {
#Download SteamOSDVD.iso
steaminstallerurl="${UPSTREAMURL}/download/brewmaster/${STEAMINSTALLFILE}"
#Download if the iso doesn't exist or the -d flag was passed
if [ ! -f ${STEAMINSTALLFILE} ] || [ -n "${redownload}" ]; then
if [ -f ${STEAMINSTALLFILE} ];then
rm ${STEAMINSTALLFILE}
fi
echo "Downloading ${steaminstallerurl} ..."
if lftp -e "pget -n 8 ${steaminstallerurl}"; then
:
else
echo "Error downloading ${steaminstallerurl}!"
exit 1
fi
else
echo "Using existing ${STEAMINSTALLFILE}"
fi
#Extract SteamOSDVD.iso into BUILD
if 7z x ${STEAMINSTALLFILE} -o${BUILD}; then
:
else
echo "Error extracting ${STEAMINSTALLFILE} into ${BUILD}!"
exit 1
fi
rm -fr ${BUILD}/\[BOOT\]
}
verify ( ) {
#Does this installer look familiar?
upstreaminstallermd5sum=` wget --quiet -O- ${UPSTREAMURL}/download/brewmaster/${MD5SUMFILE} | grep SteamOSDVD.iso$ | cut -f1 -d' '`
localinstallermd5sum=`md5sum ${STEAMINSTALLFILE} | cut -f1 -d' '`
if test "${localinstallermd5sum}" = "${KNOWNINSTALLER}"; then
echo "Downloaded installer matches this version of gen.sh"
elif test "${upstreaminstallermd5sum}" = "${KNOWNINSTALLER}"; then
echo "Local installer is missing or obsolete"
echo "Upstream version matches expectations, forcing update"
redownload="1"
else
echo "ERROR! Local installer and remote installer both unknown" >&2
echo "ERROR! Please update gen.sh to support unknown ${STEAMINSTALLFILE}" >&2
exit 1
fi
}
#Configure Rocket installer by:
# Removing uneeded debs
# Copy over modified/updated debs
# Copy over Rocket files
# Re-generate pressed files
# Re-build the cdrom installer package repositories
# Generate md5sums
# Build ISO
createbuildroot ( ) {
#Delete 32-bit udebs and d-i, as SteamOS is 64-bit only
echo "Deleting 32-bit garbage from ${BUILD}..."
find ${BUILD} -name "*_i386.udeb" -type f -exec rm -rf {} \;
find ${BUILD} -name "*_i386.deb" | egrep -v "(\/steamos-modeswitch-inhibitor\/|\/glibc\/|\/elfutils\/|\/expat\/|\/fglrx-driver\/|\/gcc-4.9\/|\/libdrm\/|\/libffi\/|\/libpciaccess\/|\/libvdpau\/|\/libx11\/|\/libxau\/|\/libxcb\/|\/libxdamage\/|\/libxdmcp\/|\/libxext\/|\/libxfixes\/|\/libxxf86vm\/|\/libxrandr\/|\/llvm-toolchain-3.5\/|\/mesa\/|\/nvidia-graphics-drivers\/|\/s2tc\/|\/zlib\/|\/udev\/|\/libxshmfence\/|\/steam\/|\/intel-vaapi-driver\/|\/libva\/|\/systemd\/|\/libedit\/|\/ncurses\/|\/libxrender\/|\/libbsd\/)" | xargs rm -f
rm -fr "${BUILD}/install.386"
rm -fr "${BUILD}/dists/*/main/debian-installer/binary-i386/"
#Copy over updated and added debs
#First remove uneeded debs
debstoremove=""
for debremove in ${debstoremove}; do
if [ -f ${BUILD}/${debremove} ]; then
echo "Removing ${BUILD}/${debremove}..."
rm -fr "${BUILD}/${debremove}"
fi
done
#Delete all firmware from /firmware/
echo "Removing bundled firmware"
rm -f ${BUILD}/firmware/*
#Rsync over our local pool dir
pooldir="./pool"
echo "Copying ${pooldir} into ${BUILD}..."
if rsync -av ${pooldir} ${BUILD}; then
:
else
echo "Error copying ${pooldir} to ${BUILD}"
exit 1
fi
#Symlink all firmware
for firmware in `cat firmware.txt`; do
echo "Symlinking ${firmware} into /firmware/ folder"
ln -s ../${firmware} ${BUILD}/firmware/`basename ${firmware}`
done
#Copy over the rest of our modified files
rocketfiles="default.preseed post_install.sh boot isolinux"
for file in ${rocketfiles}; do
echo "Copying ${file} into ${BUILD}"
cp -pfr ${file} ${BUILD}
done
sed -i 's/fglrx-driver//' ${BUILD}/.disk/base_include
sed -i 's/fglrx-modules-dkms//' ${BUILD}/.disk/base_include
sed -i 's/libgl1-fglrx-glx//' ${BUILD}/.disk/base_include
sed -i 's/nvidia-driver//' ${BUILD}/.disk/base_include
echo "keyboard-configuration" >> ${BUILD}/.disk/base_include
}
# Removes old versions of packages before they end up on the iso
checkduplicates ( ) {
echo ""
echo "Removing duplicate packages:"
# Create a list with all packages
files=$(ls buildroot/pool/*/*/*/*|grep -v ":"|grep ".deb")
# Find package names which are listed twice
duplicates=$(echo $files|tr "\ " "\n"|cut -d"_" -f1|uniq -d)
for curdupname in ${duplicates}; do
curdupfiles=$(ls `echo "$files"|tr "\ " "\n"|grep "${curdupname}\_"|tr "\n" "\ "`)
# Seperate packages with different architectures
curdupamd64=$(echo $curdupfiles|tr "\ " "\n"|grep amd64)
curdupi386=$(echo $curdupfiles|tr "\ " "\n"|grep i386)
curdupall=$(echo $curdupfiles|tr "\ " "\n"|grep all)
# Check the amount of packages per architecture
nramd64=$(echo $curdupamd64|wc -w)
nri386=$(echo $curdupi386|wc -w)
nrall=$(echo $curdupall|wc -w)
# Remove the everything but the latest package, good thing ls sorts alphabethically
if [ ${nramd64} -gt 1 ]; then
toremove=$(echo $curdupamd64|cut -f1-$((nramd64-1)) -d" ")
echo "Removing: $toremove"
rm ${toremove}
tokeep=$(echo $curdupamd64|cut -f$((nramd64)) -d" ")
echo "Keeping: $tokeep"
fi
if [ ${nri386} -gt 1 ]; then
toremove=$(echo $curdupi386|cut -f1-$((nri386-1)) -d" ")
echo "Removing: $toremove"
rm ${toremove}
tokeep=$(echo $curdupi386|cut -f$((nri386)) -d" ")
echo "Keeping: $tokeep"
fi
if [ ${nrall} -gt 1 ]; then
toremove=$(echo $curdupall|cut -f1-$((nrall-1)) -d" ")
echo "Removing: $toremove"
rm ${toremove}
tokeep=$(echo $curdupall|cut -f$((nrall)) -d" ")
echo "Keeping: $tokeep"
fi
done
echo "Done"
}
addmod ( ) {
echo "Added mod ${1}..."
# check if the mod has been set and exists
if [ -z ${1} ];then
echo "No mod specified"
return
fi
if [ ! -d ./${1} ];then
echo "Mod directory ./${1} doesn't exist"
return
fi
# read install from config file
modinstall=$(grep '^install' ./${1}/config|cut -d"=" -f2-)
modremove=$(grep '^remove' ./${1}/config|cut -d"=" -f2-)
# remove unwanted packages
for rmpkg in ${modremove};do
rm ${BUILD}/pool/*/*/*/${rmpkg}*
done
# add install to default.preseed of the build
sed -i "/^d-i pkgsel\/include/ s/$/ ${modinstall}/" ${BUILD}/default.preseed
# select sources.list file to use for mod
if [ -f ./${1}/sources.list ];then
modsources="./${1}/sources.list"
else
modsources="./sources.list"
fi
# add packages to pool
cd ${1}
if rsync -av --exclude 'pool/your-packages-here' ${pooldir} ../${BUILD}; then
:
else
echo "Error copying ${1}/packages to ${BUILD}"
exit 1
fi
cd - > /dev/null
# use post_install script from mod, if available
if [ -f ${1}/post_install.sh ];then
cp -f ${1}/post_install.sh ${BUILD}
fi
}
createiso ( ) {
#Make sure ${CACHEDIR} exists
if [ ! -d ${CACHEDIR} ]; then
mkdir -p ${CACHEDIR}
fi
#Generate our new repos
echo "Generating Packages.."
mv ${BUILD}/pool ${BUILD}/poolbase
rm -rf ${BUILD}/dists
mkdir ${BUILD}/conf
/bin/echo -e "Origin: Valve Software LLC\nSuite: testing\nCodename: ${DISTNAME}\nComponents: main contrib non-free\nUDebComponents: main\nArchitectures: i386 amd64\nDescription: SteamOS distribution based on Debian 8.0 Jessie\nContents: udebs . .gz\nUDebIndices: Packages . .gz" > ${BUILD}/conf/distributions
reprepro -Vb ${BUILD} includedeb ${DISTNAME} ${BUILD}/poolbase/*/*/*/*.deb
reprepro -Vb ${BUILD} includeudeb ${DISTNAME} ${BUILD}/poolbase/*/*/*/*.udeb
rm -rf ${BUILD}/poolbase ${BUILD}/db ${BUILD}/conf
cd ${BUILD}
find . -type f -print0 | xargs -0 md5sum > md5sum.txt
cd -
#Remove old ISO
if [ -f ${ISOPATH}/${ISONAME} ]; then
echo "Removing old ISO ${ISOPATH}/${ISONAME}"
rm -f "${ISOPATH}/${ISONAME}"
fi
#Find isohdpfx.bin
if [ -f "/usr/lib/syslinux/mbr/isohdpfx.bin" ]; then
SYSLINUX="/usr/lib/syslinux/mbr/isohdpfx.bin"
fi
if [ -f "/usr/lib/syslinux/bios/isohdpfx.bin" ]; then
SYSLINUX="/usr/lib/syslinux/bios/isohdpfx.bin"
fi
if [ -f "/usr/lib/syslinux/isohdpfx.bin" ]; then
SYSLINUX="/usr/lib/syslinux/isohdpfx.bin"
fi
if [ -f "/usr/lib/ISOLINUX/isohdpfx.bin" ]; then
SYSLINUX="/usr/lib/ISOLINUX/isohdpfx.bin"
fi
if [ -f "isohdpfx.bin" ]; then
SYSLINUX="isohdpfx.bin"
fi
if [ -z $SYSLINUX ]; then
echo "Error: isohdpfx.bin not found! Try putting it in ${pwd}."
exit 1
fi
#Build the ISO
echo "Building ${ISOPATH}/${ISONAME} ..."
xorriso -as mkisofs -r -checksum_algorithm_iso md5,sha1,sha256,sha512 \
-V "${ISOVNAME}" -o ${ISOPATH}/${ISONAME} \
-J -isohybrid-mbr ${SYSLINUX} \
-joliet-long -b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -eltorito-alt-boot -e boot/grub/efi.img \
-no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus ${BUILD}
}
#Generate a file with the md5 checksum in it
mkchecksum ( ) {
echo "Generating checksum..."
md5sum ${ISONAME} > "${ISONAME}.md5"
if [ -f ${ISONAME}.md5 ]; then
echo "Checksum saved in ${ISONAME}.md5"
else
echo "Failed to save checksum"
fi
}
#Setup command line arguments
while getopts "hdn:" OPTION; do
case ${OPTION} in
h)
usage
exit 1
;;
d)
redownload="1"
;;
n)
ISOVNAME="${OPTARG}"
ISONAME=$(echo "${OPTARG}.iso"|tr '[:upper:]' '[:lower:]'|tr "\ " "-")
;;
*)
echo "${OPTION} - Unrecongnized option"
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
MODSTOADD="$@"
#Check dependencies
#deps
#Rebuild ${BUILD}
rebuild
#Make sure ${BUILD} exists
if [ ! -d ${BUILD} ]; then
mkdir -p ${BUILD}
fi
#Verify we have an expected installer
verify
#Download and extract the SteamOSInstaller.zip
extract
#Build buildroot for Rocket installer
createbuildroot
#Add mods to the iso
for MOD in ${MODSTOADD}; do
addmod ${MOD}
done
#Check if there are multiple versions of packages in the buildroot
checkduplicates
#Build ISO for Rocket installer
createiso
#Generate rocket.iso.md5 file
mkchecksum
#Report on packages where newer is in the archive
#obsoletereport