Skip to content
This repository
Newer
Older
100755 331 lines (304 sloc) 16.106 kb
4eafa41d »
2010-04-08 Initial commit
1 #!/bin/bash
2
3 # This is a buildscript to build lglive (http://live.linux-gamers.net)
4 # To understand what is going on here, you should read the Arch Linux wiki
5 # article on "Archiso". Basically, this script prepares 2 editions of lglive:
6 # A 'big' edition and a 'lite' edition which both double as a CD/USB image.
7 # This file will need to be called as root because of nature of device files
8 # and my lazyness to handle this properly. As you know, this is dangerous and
9 # I do not advise the inexperienced user to attempt this. However, I'm trying
10 # my best to make the script work as well as possible.
11 # I know it is ugly.
12 #
13 # This script and the rest of the lglive distribution is licensed under
14 # GPLv3.
15 #
16 # If you have questions or feedback just shoot me a mail or ask on IRC.
17 #
18 # Sven-Hendrik 'Svenstaro' Haase (sh@lutzhaase.com)
19 #
20
21 #### Change these settings to modify how this ISO is built.
22 # The directory that we use for working files.
23 WORKDIR="work"
24 # Output directory for built images.
25 OUTDIR="out"
26 # Directory where packages are cached.
27 PKGCACHE="pkgcache"
28 # The name of our ISO. Does not specify the architecture!
29 NAME="lglive"
30 # Version will be appended to the ISO.
31 VER="0.9.6"
32 # Kernel version. We'll need this.
33 KVER="2.6.31-ARCH"
34 # Architecture will also be appended to the ISO name.
35 ARCH="i686"
36 #ARCH="`uname -m`" # we can't build x86_64 just yet! :(
37 # Bootloader for our livecd/liveusb to use. Valid values: "grub-gfx", "syslinux"
38 # However, "syslinux" is the only acceptable value at the moment because it is
39 # not possible to build hybrid images using grub as of this writing.
40 BOOTLOADER="syslinux"
41 # A list of packages to install, either space separated in a string or line separated in a file. Can include groups.
42 PACKAGES="`cat packages.list` ${BOOTLOADER}"
43 # Directory we originate from.
44 BASEDIR="`pwd`"
45 # Resulting long name for iso/img.
46 FULLNAME="${BASEDIR}/${OUTDIR}/${NAME}-${VER}-${ARCH}-hybrid"
47 # Set quiet for now.
48 VERBOSE="n"
49 QUIET="n"
50 # Absolute path to makepkg.conf.
51 MAKEPKGCNF=`readlink -f makepkg.conf`
52
53 # usage: usage <exitvalue>
54 usage ()
55 {
56 echo "usage `basename "${0}"` [-v | -q] <target> .. <target>"
57 echo "options:"
58 echo " -v Be verbose"
59 echo " -q Be quiet"
60 echo " -h Usage help"
61 echo "targets:"
62 echo " 'all': makes all available targets"
63 echo " 'clean': clean workdir and outdir"
64 echo " 'lglive-lite-iso': reduced games selection; produces isohybrid for 700MB CD or USB drive"
65 echo " 'lglive-big-iso': full games selection; produces isohybrid for 4700MB DVD or USB drive"
66 exit $1
67 }
68
69 # overlay: overlay <target>
70 overlay ()
71 {
72 TARGET="$1"
73 echo ${TARGET} | grep -q "lite" && gamelist=gamelist_lite || gamelist=gamelist_big
74 [ ! ${QUIET} == "y" ] && echo "===== Making overlay ====="
75 [ ! ${QUIET} == "y" ] && echo "overlay: Target is: ${TARGET}"
76
77 [ ! ${QUIET} == "y" ] && echo "overlay: Updating drivers"
78 cd overlay/opt/drivers
79 [ ! ${QUIET} == "y" ] && echo "overlay: Cleaning old drivers"
80 rm *.tar.* &> /dev/null
81 find . -type l|xargs rm &> /dev/null
82 [ ! ${QUIET} == "y" ] && echo "overlay: Making NVIDIA driver packages"
83 if [ ${VERBOSE} == "y" ]; then
84 pacman -Syw --config ${BASEDIR}/pacman.conf --cachedir `pwd` --noconfirm nvidia nvidia-utils nvidia-173xx nvidia-173xx-utils nvidia-96xx nvidia-96xx-utils
85 else
86 pacman -Syw --config ${BASEDIR}/pacman.conf --cachedir `pwd` --noconfirm nvidia nvidia-utils nvidia-173xx nvidia-173xx-utils nvidia-96xx nvidia-96xx-utils &> /dev/null
87 fi
88 [ "$?" -ne 0 ] && echo -e "\e[01;31moverlay: Exiting due to error while getting NVIDIA driver packages\e[00m" && exit 1
89 mv -f `ls nvidia-173xx*.tar.*|grep -v utils` nvidia-legacy
90 mv -f `ls nvidia-173xx*.tar.*|grep utils` nvidia-legacy-utils
91 mv -f `ls nvidia-96xx*.tar.*|grep -v utils` nvidia-prelegacy
92 mv -f `ls nvidia-96xx*.tar.*|grep utils` nvidia-prelegacy-utils
93 mv -f `ls nvidia-*.tar.*|grep -v utils|grep -v 173xx|grep -v 96xx` nvidia-recent
94 mv -f `ls nvidia-*.tar.*|grep utils|grep -v 173xx|grep -v 96xx` nvidia-utils-recent
95 rm *.tar.* &> /dev/null
96
97 [ ! ${QUIET} == "y" ] && echo "overlay: Making ATI driver package"
98 #cp -r /usr/src/linux-${KVER} ${BASEDIR}/${WORKDIR}/root-image/usr/src/
99 cd ${BASEDIR}/${WORKDIR}/root-image/tmp/
100 wget -q http://aur.archlinux.org/packages/catalyst/catalyst.tar.*
101 tar xzf catalyst.tar.* && rm catalyst.tar.*
102 cd catalyst && [ ${VERBOSE} == "y" ] && makepkg --asroot --nobuild || makepkg --asroot --nobuild &> /dev/null
103 cd ../../../../
104 echo 'cd /tmp/
105 [ "$?" -ne 0 ] && echo -e "\e[01;31moverlay: Exiting due to error while getting ATI driver packages\e[00m" && exit 1
106 cd catalyst && makepkg -dfc --asroot > /dev/null
107 [ "$?" -ne 0 ] && echo -e "\e[01;31moverlay: Exiting due to error while making ATI driver packages\e[00m" && exit 1
108 pacman -Rsnu --noconfirm base-devel &>/dev/null' >> ${BASEDIR}/${WORKDIR}/root-image/atiscript.sh
109 if [ ${VERBOSE} == "y" ]; then
110 chroot ${BASEDIR}/${WORKDIR}/root-image bash atiscript.sh || return 1
111 else
112 chroot ${BASEDIR}/${WORKDIR}/root-image bash atiscript.sh &> /dev/null || return 1
113 fi
114 mv ${BASEDIR}/${WORKDIR}/root-image/tmp/catalyst/catalyst-*.tar.* . && rm -r ${BASEDIR}/${WORKDIR}/root-image/tmp/catalyst && rm ${BASEDIR}/${WORKDIR}/root-image/atiscript.sh
115
116 #rm -r ${BASEDIR}/${WORKDIR}/root-image/usr/src/linux-${KVER}
117 [ "$?" -ne 0 ] && echo -e "\e[01;31moverlay: Exiting due to error while making ATI driver packages\e[00m" && exit 1
118 mv -f `ls catalyst-*.tar.*|grep -v utils` catalyst-recent && mv catalyst-recent overlay/opt/drivers
119
120 [ ! ${QUIET} == "y" ] && echo "overlay: Finished preparing driver packages"
121
122 [ ! ${QUIET} == "y" ] && echo "overlay: Setting gamelist '$gamelist'"
123 [ ! ${QUIET} == "y" ] && echo "overlay: Deleting old copied game data"
124 cp -rp "${BASEDIR}"/overlay "${BASEDIR}"/"${WORKDIR}"/overlay/ || return 1
125 if [ ${gamelist} == "gamelist_lite" ]; then
126 cp -f "${BASEDIR}"/gamelist_lite "${BASEDIR}"/"${WORKDIR}"/overlay/
127 elif [ ${gamelist} == "gamelist_big" ]; then
128 cp -f "${BASEDIR}"/gamelist_{lite,big} "${BASEDIR}"/"${WORKDIR}"/overlay/
129 fi
130 if [ ${VERBOSE} == "y" ]; then
131 pacman -Sy --config pacman.conf --dbpath "${BASEDIR}"/"${WORKDIR}"/root-image/var/lib/pacman || return 1
132 else
133 pacman -Sy --config pacman.conf --dbpath "${BASEDIR}"/"${WORKDIR}"/root-image/var/lib/pacman &> /dev/null || return 1
134 fi
135 while read game; do
136 [ ! ${QUIET} == "y" ] && echo "overlay: Installing ${game}"
137 if [ ${VERBOSE} == "y" ]; then
138 pacman -S --config pacman.conf --noconfirm --root "${BASEDIR}/${WORKDIR}/overlay/" --dbpath "${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman" ${game} || return 1
139 else
140 pacman -S --config pacman.conf --noconfirm --root "${BASEDIR}/${WORKDIR}/overlay/" --dbpath "${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman" ${game} &> /dev/null || return 1
141 fi
142 cp -rp "${BASEDIR}/games/${game}" "${BASEDIR}/${WORKDIR}/overlay/opt/games/" || return 1
143 done < "${BASEDIR}/${gamelist}"
144 cd "${BASEDIR}"
145 #[ ! ${QUIET} == "y" ] && echo "overlay: Copying overlay to workdir"
146 #cp -rpL overlay "${WORKDIR}/" || return 1
147 [ "$?" -ne 0 ] && echo -e "\e[01;31moverlay: Exiting due to error while copying overlay\e[00m" && exit 1
148 [ ! ${QUIET} == "y" ] && echo "===== Finished overlay ====="
149 return 0
150 }
151
152 base-iso ()
153 {
154 [ ! ${QUIET} == "y" ] && echo "===== Making base-iso ====="
155 [ ! ${QUIET} == "y" ] && echo "base-iso: Copying boot-files"
156 mv "${WORKDIR}/root-image/boot" "${WORKDIR}/iso/" || true
157 [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting due to error while moving boot files\e[00m" && exit 1
158 cp -r boot-files/* "${WORKDIR}/iso/boot/" || return 1
159 [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting due to error while copying boot files\e[00m" && exit 1
160 [ ! ${QUIET} == "y" ] && echo "base-iso: Preparing isomounts"
161 cp isomounts "${WORKDIR}" || return 1
162 [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting because no isomounts file was found\e[00m" && exit 1
163 sed -i "s|@ARCH@|${ARCH}|g" "${WORKDIR}/isomounts"
164 [ ! ${QUIET} == "y" ] && echo "base-iso: Making initrd image"
165 git clone git://projects.archlinux.org/archiso.git archiso-temp &>/dev/null
166 cp -r archiso-temp/archiso/{hooks,install} ${BASEDIR}/${WORKDIR}/root-image/lib/initcpio/
167 # TODO: Hacky workaround until klibc-utils fstype supports udf
168 sed '/if mount -r -t "${_FSTYPE}" \/dev\/archiso \/bootmnt >\/dev\/null 2>&1; then/c\if mount -r -t udf \/dev\/archiso \/bootmnt >\/dev\/null 2>&1; then' -i ${BASEDIR}/${WORKDIR}/root-image/lib/initcpio/hooks/archiso || return 1
169 rm -r archiso-temp
170 cp ${BASEDIR}/mkinitcpio.conf ${BASEDIR}/${WORKDIR}/root-image/etc/mkinitcpio.conf
171 cp ${BASEDIR}/mkinitcpio-lanboot.conf ${BASEDIR}/${WORKDIR}/root-image/etc/mkinitcpio-lanboot.conf
172 chroot ${BASEDIR}/${WORKDIR}/root-image mkinitcpio -c /etc/mkinitcpio.conf -k ${KVER} -g "/lglive.img" &>/dev/null
173 mv ${BASEDIR}/${WORKDIR}/root-image/lglive.img "${BASEDIR}/${WORKDIR}/iso/boot/lglive.img" &>/dev/null
174 chroot ${BASEDIR}/${WORKDIR}/root-image mkinitcpio -c /etc/mkinitcpio-lanboot.conf -k ${KVER} -g "/lglivelanboot.img" &>/dev/null
175 mv ${BASEDIR}/${WORKDIR}/root-image/lglivelanboot.img "${BASEDIR}/${WORKDIR}/iso/boot/lglivelanboot.img" &>/dev/null
176 sed -i "s/^CacheDir/\#CacheDir/" "${BASEDIR}/${WORKDIR}/root-image/etc/pacman.conf"
177 sed -i "/localrepo/,+2d" "${BASEDIR}/${WORKDIR}/root-image/etc/pacman.conf"
178 [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting due to error while running mkinitcpio\e[00m" && exit 1
179 [ ! ${QUIET} == "y" ] && echo "===== Finished base-iso ====="
180 return 0
181 }
182
183 root-image ()
184 {
185 [ ! ${QUIET} == "y" ] && echo "===== Making root-image ====="
186 [ ! -d "${BASEDIR}"/"${OUTDIR}" ] && mkdir "${BASEDIR}"/"${OUTDIR}"
187 [ ! -d "${BASEDIR}"/"${WORKDIR}" ] && mkdir "${BASEDIR}"/"${WORKDIR}"
188 [ ! -d "${BASEDIR}"/"${PKGCACHE}" ] && mkdir "${BASEDIR}"/"${PKGCACHE}"
189 sed -i "s|^CacheDir.*$|CacheDir = ${BASEDIR}\/${PKGCACHE}|" pacman.conf
190 sed -i "/localrepo/{n; s|.*|Server = file\:\/\/${BASEDIR}/localrepo\/|}" pacman.conf
191 [ ! ${QUIET} == "y" ] && echo "root-image: Installing packages"
192 if [ ${VERBOSE} == "y" ]; then
193 mkarchiso -C pacman.conf -p "${PACKAGES}" -v create "${WORKDIR}"
194 else
195 mkarchiso -C pacman.conf -p "${PACKAGES}" -v create "${WORKDIR}" &> /dev/null
196 fi
197 [ "$?" -ne 0 ] && echo -e "\e[01;31mroot-image: Exiting due to error with mkarchiso\e[00m" && exit 1
198 [ ! ${QUIET} == "y" ] && echo "===== Finished root-image ====="
199 return 0
200 }
201
202 bootloader ()
203 {
204 [ ! ${QUIET} == "y" ] && echo "===== Making bootloader ====="
205 if [ ${BOOTLOADER} == "grub-gfx" ]; then
206 [ ! ${QUIET} == "y" ] && echo "bootloader: Copying files for 'grub-gfx'"
207 cp -r "${WORKDIR}/root-image/usr/lib/grub/i386-pc/"* "${WORKDIR}/iso/boot/grub" || return 1
208 [ "$?" -ne 0 ] && echo -e "\e[01;31mbootloader: Exiting due to error while copying bootloader\e[00m" && exit 1
209 elif [ ${BOOTLOADER} == "syslinux" ]; then
210 [ ! ${QUIET} == "y" ] && echo "bootloader: Copying files for 'syslinux'"
211 cp "${WORKDIR}/root-image/usr/lib/syslinux/isolinux.bin" "${WORKDIR}/iso/boot/isolinux" || return 1
212 cp "${WORKDIR}/root-image/usr/lib/syslinux/pxelinux.0" "${WORKDIR}/iso/boot/" || return 1
213 cp "${WORKDIR}/root-image/usr/lib/syslinux/"*.c32 "${WORKDIR}/iso/boot/isolinux/" || return 1
214 sed "s|archisolabel=[^ ]*|archisolabel=${NAME}-${VER//./}|" -i ${WORKDIR}/iso/boot/pxelinux.cfg/default || return 1
215 [ "$?" -ne 0 ] && echo -e "\e[01;31mbootloader Exiting due to error while copying bootloader\e[00m" && exit 1
216 fi
217 [ ! ${QUIET} == "y" ] && echo "===== Finished bootloader ====="
218 return 0
219 }
220
221 # build: build <target>
222 build ()
223 {
224 TARGET="$1"
225
226 #TODO: Persistent storage
227 #dd if=/dev/zero of="${BASEDIR}"/"${WORKDIR}"/iso/persistent.ext4 bs=1M count=4
228 #mkfs.ext4 -m0 -F "${BASEDIR}"/"${WORKDIR}"/iso/persistent.ext4
229 #mkdir "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
230 #mount -o loop -t ext4 "${BASEDIR}"/"${WORKDIR}"/iso/persistent.ext4 "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
231 #mkdir -p /tmp/archiso-mount-tmp/home/gamer/persistent
232 #umount "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
233 #rmdir "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
234 #TODO
235
236 [ ! ${QUIET} == "y" ] && echo "===== Building final image for target: ${TARGET} ====="
237 [ ! ${QUIET} == "y" ] && echo "build: Removing ballast"
238 rm -rf "${WORKDIR}"/root-image/usr/include/*
239 rm -rf "${WORKDIR}"/root-image/usr/src/
240 rm -rf "${WORKDIR}"/root-image/usr/man/*
241 rm -rf "${WORKDIR}"/root-image/usr/share/vim/*
242 echo ${TARGET} | grep -q "iso" && imagetype="iso" || imagetype="img"
243 [ ! ${QUIET} == "y" ] && echo "build: Setting imagetype to '${imagetype}'"
244 echo ${TARGET} | grep -q "lite" && edition="lite" || edition="big"
245 [ ! ${QUIET} == "y" ] && echo "build: Setting edition to '${edition}'"
246 [ ! ${QUIET} == "y" ] && echo "build: Saving to ${FULLNAME}-${edition}.${imagetype}"
247 [ ! ${QUIET} == "y" ] && echo "build: Starting build, this will take some time"
248 if [ ${VERBOSE} == "y" ]; then
249 mkarchiso -f -v -L "${NAME}-${VER//./}" -P "Linux-Gamers <live.linux-gamers.net>" -A "live.linux-gamers" -p "${BOOTLOADER}" "${imagetype}" "${WORKDIR}" "${FULLNAME}-${edition}.${imagetype}"
250 else
251 mkarchiso -f -v -L "${NAME}-${VER//./}" -P "Linux-Gamers <live.linux-gamers.net>" -A "live.linux-gamers" -p "${BOOTLOADER}" "${imagetype}" "${WORKDIR}" "${FULLNAME}-${edition}.${imagetype}" &> /dev/null
252 fi
253 [ ! ${QUIET} == "y" ] && [ ${BOOTLOADER} == "syslinux" ] && echo "build: Making isohybrid" && isohybrid -offset 1 "${FULLNAME}-${edition}.${imagetype}" && echo "build: Made isohybrid" || return 1
254 [ "$?" -ne 0 ] && echo -e "\e[01;31mbuild: Exiting due to error while running mkarchiso\e[00m" && exit 1
255 [ ! ${QUIET} == "y" ] && echo "===== Finished building final image for target: ${TARGET} ====="
256 return 0
257 }
258
259 clean ()
260 {
261 [ ! ${QUIET} == "y" ] && echo "===== Cleaning ====="
262 [ ! ${QUIET} == "y" ] && echo "clean: Deleting '${BASEDIR}/${WORKDIR}'"
263 rm -rf "${BASEDIR}/${WORKDIR}"
264 [ "$?" -ne 0 ] && echo -e "\e[01;31mclean: Exiting due to error while cleaning workdir\e[00m" && exit 1
265 [ ! ${QUIET} == "y" ] && echo "===== Cleaning finished successfully ====="
266 return 0
267 }
268
269 # Catch options here
270 while getopts "hvq" opt; do
271 case "${opt}" in
272 v) VERBOSE="y" ;;
273 q) QUIET="y" ;;
274 h|?) usage 0 ;;
275 *) echo "ERROR: Invalid argument '${opt}'"; usage 1 ;;
276 esac
277 done
278
279 shift $(($OPTIND - 1))
280
281 if [ $# -lt 1 ]; then
282 echo "ERROR: No build targets"
283 usage 1
284 fi
285
286 if [ "${USER}" != "root" ]; then
287 echo "ERROR: Need to be root"
288 exit 1
289 fi
290
291 START_TIME=`date +%s`
292 START_DATE=`date`
293
294 LAUNCH_ARGS="$@"
295
296 if echo "$@" | grep -q "clean"; then
297 clean
298 exit 0
299 fi
300
301 if echo "$@" | grep -q "all"; then
302 LAUNCH_ARGS="lglive-lite-iso lglive-big-iso"
303 fi
304
305 for arg in ${LAUNCH_ARGS}; do
306 if [[ ${arg} != "lglive-lite-iso" && ${arg} != "lglive-big-iso" ]]; then
307 echo "ERROR: Invalid target"
308 usage 1
309 fi
310 [ ! ${QUIET} == "y" ] && echo -e "\e[01;33m===== Starting build for target: ${arg} =====\e[00m"
311 clean || (echo -e "\e[01;31mclean: Exiting due to error while cleaning\e[00m"; exit 1)
312 root-image || (echo -e "\e[01;31mroot-image: Exiting due to error while making root-image\e[00m"; exit 1)
313 base-iso || (echo -e "\e[01;31mbase-iso: Exiting due to error while making base-iso\e[00m"; exit 1)
314 overlay ${arg} || (echo -e "\e[01;31moverlay: Exiting due to error while making overlay\e[00m"; exit 1) # pass target info to get correct gameset
315 bootloader || (echo -e "\e[01;31mbootloader: Exiting due to error while making bootloader\e[00m"; exit 1)
316 build ${arg} || (echo -e "\e[01;31mbuild: Exiting due to error while building iso\e[00m"; exit 1) # pass target info to build correct image
317 [ ! ${QUIET} == "y" ] && echo -e "\e[01;33m===== Finished build for target: ${arg} =====\e[00m"
318 done
319
320 END_TIME=`date +%s`
321 ELAPSED=`expr ${END_TIME} - ${START_TIME}`
322 h=$(( ELAPSED / 3600 ))
323 m=$(( ( ELAPSED / 60 ) % 60 ))
324 s=$(( ELAPSED % 60 ))
325 echo -e "\e[01;34m===== FINISHED ALL BUILDS =====\e[00m"
326 echo "BUILDING STARTED at" ${START_DATE}
327 echo "BUILDING FINISHED at" `date`
328 printf "ELAPSED TIME: %02d:%02d:%02d\n" $h $m $s
329 du -h out/*
330
331 # vim:ts=2:sw=2
332
Something went wrong with that request. Please try again.