This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.sh
executable file
·285 lines (252 loc) · 6.87 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
#!/bin/bash
###############
# Script Info #
###############
# Author: Wouter Wijsman aka sharkwouter
# Description:
# This script can be used to generate modified versions of the SteamOS ISO with different packages.
##########
# Script #
##########
# Make sure we're running in the correct directory
cd "$(dirname "$0")"
###################
# Basic variables #
###################
# Directories:
WORKDIR="${PWD}"
BUILD="${WORKDIR}/buildroot"
FIRMWAREFILE="${WORKDIR}/firmware.txt"
PACKAGES="${WORKDIR}/packages"
ADDITIONSPATH="${WORKDIR}/additions"
ISOPATH=${WORKDIR}
# Base ISO:
UPSTREAMURL="https://cdimage.debian.org/debian-cd/current/multi-arch/iso-cd/"
STEAMINSTALLFILE="debian-10.0.0-amd64-i386-netinst.iso"
MD5SUMFILE="MD5SUMS"
# ISO info:
DISTNAME="buster"
ISONAME="vaporos-buster.iso"
ISOVNAME="VaporOS"
ISODESCRIPTION="VaporOS distribution based on Debian 10.0 Buster"
# Other info:
DEPS="xorriso lftp 7z rsync reprepro wget"
#############
# Functions #
#############
#Show how to use gen.sh
usage ( )
{
cat <<EOF
$0 [OPTION]
-h Print this message
-d Only download the base ISO
-f Return filename of base ISO
-n Set the name for the ISO
EOF
}
#Check some basic dependencies this script needs to run
deps ( ) {
#Check dependencies
for dep in ${DEPS}; do
if which ${dep} >/dev/null 2>&1; then
:
else
echo "Missing dependency: ${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
#Make sure isohdpfx.bin exists
if [ -f "isohdpfx.bin" ]; then
SYSLINUX="isohdpfx.bin"
elif [ -f "/usr/lib/ISOLINUX/isohdpfx.bin" ]; then
SYSLINUX="/usr/lib/ISOLINUX/isohdpfx.bin"
else
echo "Error: isohdpfx.bin not found! Try putting it in ${WORKDIR}."
exit 1
fi
}
#Remove the ${BUILD} directory to start from scratch
scratch ( ) {
if [ -d "${BUILD}" ]; then
echo "Building ${BUILD} from scratch"
rm -fr "${BUILD}"
fi
#Create new directory
mkdir -p ${BUILD}
}
#Get the checksum of the current ISO
getchecksum ( ) {
#Get the checksum of the upstream version
echo "Upstream checksum:"
upstreaminstallermd5sum=$(wget --quiet -O- ${UPSTREAMURL}/${MD5SUMFILE} | grep ${STEAMINSTALLFILE}$ | cut -f1 -d' ')
echo ${upstreaminstallermd5sum}
#Get the checksum of our version
echo "local checksum:"
if [ ! -f ${ISOPATH}/${STEAMINSTALLFILE} ]; then
echo "No file found"
return
fi
localinstallermd5sum=$(md5sum ${ISOPATH}/${STEAMINSTALLFILE} | cut -f1 -d' ')
echo ${localinstallermd5sum}
#Return if they are the same
[ "${upstreaminstallermd5sum}" = "${localinstallermd5sum}" ]
}
#Download the iso, if needed
download ( ) {
steaminstallerurl="${UPSTREAMURL}/${STEAMINSTALLFILE}"
#Make we have the latest version
if getchecksum; then
echo "Using existing ${STEAMINSTALLFILE}"
else
if [ ! -f ${ISOPATH}/${STEAMINSTALLFILE} ]; then
echo "The downloaded version doesn't match the upstream version, deleting..."
rm ${ISOPATH}/${STEAMINSTALLFILE}
fi
fi
#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};exit"; then
if getchecksum; then
echo "Download succeeded"
else
echo "The downloaded version has been corrupted, deleting..."
rm ${ISOPATH}/${STEAMINSTALLFILE}
exit 1
fi
else
echo "Error downloading ${steaminstallerurl}!"
exit 1
fi
fi
}
#Extract the ISO into the ${BUILD}
extract ( ) {
#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\]
}
#Make changes to ${BUILD}
createbuildroot ( ) {
#Generate our new repos
echo "Generating pool.."
mv ${BUILD}/pool ${BUILD}/poolbase
rm -rf ${BUILD}/dists
mkdir ${BUILD}/conf
/bin/echo -e "Origin: ${ISOVNAME}\nLabel:${ISOVNAME}\nSuite: stable\nCodename: ${DISTNAME}\nComponents: main contrib non-free\nUDebComponents: main\nArchitectures: i386 amd64\nDescription: ${ISODESCRIPTION}\nContents: udebs . .gz\nUDebIndices: Packages . .gz" > ${BUILD}/conf/distributions
reprepro -Vb ${BUILD} includedeb ${DISTNAME} ${BUILD}/poolbase/*/*/*/*.deb > /dev/null
reprepro -Vb ${BUILD} includeudeb ${DISTNAME} ${BUILD}/poolbase/*/*/*/*.udeb > /dev/null
reprepro -Vb ${BUILD} includedeb ${DISTNAME} ${PACKAGES}/*.deb > /dev/null #This adds packages from the pool directory
rm -rf ${BUILD}/poolbase ${BUILD}/db ${BUILD}/conf
#Copy additions directory
echo "Copying configuration files"
rsync -av ${ADDITIONSPATH}/ ${BUILD}/
#Make symlinks based on the firmwares mentioned in the config
echo "Creating firmware symlinks..."
for f in `cat ${FIRMWAREFILE}`; do
package="$(find buildroot/pool/ -name ${f}_*_*.deb|head -1)"
if [ "${package}" ];then
ln -s $(find ${BUILD}/pool/ -name ${f}_*_*.deb|head -1) ${BUILD}/firmware
else
echo "Error: Couln't find ${f} firmware package"
exit 1
fi
done
#Generate new md5sum.txt for the iso
echo "Creating md5sum.txt file"
cd ${BUILD}
find . -type f -print0 | xargs -0 md5sum > md5sum.txt
cd -
}
#Generate the ISO from ${BUILD}
createiso ( ) {
#Remove old ISO
if [ -f ${ISOPATH}/${ISONAME} ]; then
echo "Removing old ISO ${ISOPATH}/${ISONAME}"
rm -f "${ISOPATH}/${ISONAME}"
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}
}
#Create md5sum of the created ISO
createmd5sum ( ) {
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
}
###########
# Getopts #
###########
#Setup command line arguments
while getopts "hdfn:" OPTION; do
case ${OPTION} in
h)
usage
exit 1
;;
d)
if which "lftp" >/dev/null 2>&1; then
:
else
echo "Missing dependency: lftp"
exit 1
fi
download
exit 0
;;
n)
ISOVNAME="${OPTARG}"
ISONAME=$(echo "${OPTARG}.iso"|tr '[:upper:]' '[:lower:]'|tr "\ " "-")
;;
f)
echo "${ISOPATH}/${STEAMINSTALLFILE}"
exit 0
;;
*)
echo "${OPTION} - Unrecongnized option"
usage
exit 1
;;
esac
done
#############
# Execution #
#############
#Check dependencies
deps
#Replace ${BUILD} with an empty directory
scratch
#Download the base ISO
download
#Extract the ISO into ${BUILD}
extract
#Make changes/additions to ${BUILD}
createbuildroot
#Build the actual ISO
createiso
#Generate a file with the md5sum of our newly created ISO
createmd5sum