Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 336 lines (304 sloc) 16.616 kb
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
#!/bin/bash

# This is a buildscript to build lglive (http://live.linux-gamers.net)
# To understand what is going on here, you should read the Arch Linux wiki
# article on "Archiso". Basically, this script prepares 2 editions of lglive:
# A 'big' edition and a 'lite' edition which both double as a CD/USB image.
# This file will need to be called as root because of nature of device files
# and my lazyness to handle this properly. As you know, this is dangerous and
# I do not advise the inexperienced user to attempt this. However, I'm trying
# my best to make the script work as well as possible.
# I know it is ugly.
#
# This script and the rest of the lglive distribution is licensed under
# GPLv3.
#
# If you have questions or feedback just shoot me a mail or ask on IRC.
#
# Sven-Hendrik 'Svenstaro' Haase (sh@lutzhaase.com)
#

#### Change these settings to modify how this ISO is built.
# The directory that we use for working files.
WORKDIR="work"
# Directory on the iso where our stuff is installed.
INSTALL_DIR=lglive
# Output directory for built images.
OUTDIR="out"
# Directory where packages are cached.
PKGCACHE="pkgcache"
# The name of our ISO. Does not specify the architecture!
NAME="lglive"
# Version will be appended to the ISO.
VER="0.9.7"
# Kernel version. We'll need this.
KVER="$(grep ^ALL_kver /etc/mkinitcpio.d/kernel26.kver | cut -d= -f2 | sed s/\'//g)"
#KVER="2.6.38" # You shouldn't attempt to make this on a kernel you aren't running.
# Architecture will also be appended to the ISO name.
ARCH="i686"
#ARCH="`uname -m`" # we can't build x86_64 just yet! :(
# Bootloader for our livecd/liveusb to use. Valid values: "grub-gfx", "syslinux"
# However, "syslinux" is the only acceptable value at the moment because it is
# not possible to build hybrid images using grub as of this writing.
BOOTLOADER="syslinux"
# A list of packages to install, either space separated in a string or line separated in a file. Can include groups.

# hacky fix till dcron is out of base
BASE_PACKAGES=$(pacman -Sgq base | grep -v dcron)

PACKAGES="`cat packages.list` ${BOOTLOADER}"
# Directory we originate from.
BASEDIR="`pwd`"
# Resulting long name for iso/img.
FULLNAME="${BASEDIR}/${OUTDIR}/${NAME}-${VER}-${ARCH}-hybrid"
# Set quiet for now.
VERBOSE="n"
QUIET="n"
# Absolute path to makepkg.conf.
MAKEPKGCNF=`readlink -f makepkg.conf`
# Compress the squashfs with this compressor. Values: "xz", "gzip", "lzo"
COMPRESS="xz"

# usage: usage <exitvalue>
usage ()
{
  echo "usage `basename "${0}"` [-v | -q] <target> .. <target>"
  echo "options:"
  echo " -v Be verbose"
  echo " -q Be quiet"
  echo " -h Usage help"
  echo "targets:"
  echo " 'all': makes all available targets"
  echo " 'clean': clean workdir and outdir"
  echo " 'lglive-lite-iso': reduced games selection; produces isohybrid for 700MB CD or USB drive"
  echo " 'lglive-big-iso': full games selection; produces isohybrid for 4700MB DVD or USB drive"
  exit $1
}

# overlay: overlay <target>
overlay ()
{
  TARGET="$1"
  echo ${TARGET} | grep -q "lite" && gamelist=gamelist_lite || gamelist=gamelist_big
  [ ! ${QUIET} == "y" ] && echo "===== Making overlay ====="
  [ ! ${QUIET} == "y" ] && echo "overlay: Target is: ${TARGET}"

  [ ! ${QUIET} == "y" ] && echo "overlay: Updating drivers"
  cd "${BASEDIR}/overlay/opt/drivers"
  [ ! ${QUIET} == "y" ] && echo "overlay: Cleaning old drivers"
  rm *.tar.* &> /dev/null
  find . -type l|xargs rm &> /dev/null
  [ ! ${QUIET} == "y" ] && echo "overlay: Making NVIDIA driver packages"
  if [ ${VERBOSE} == "y" ]; then
pacman -Sywd --config ${BASEDIR}/pacman.conf --dbpath "${BASEDIR}"/"${WORKDIR}"/root-image/var/lib/pacman --cachedir `pwd` --noconfirm nvidia nvidia-utils nvidia-173xx nvidia-173xx-utils
  else
pacman -Sywd --config ${BASEDIR}/pacman.conf --dbpath "${BASEDIR}"/"${WORKDIR}"/root-image/var/lib/pacman --cachedir `pwd` --noconfirm nvidia nvidia-utils nvidia-173xx nvidia-173xx-utils &> /dev/null
  fi
  [ "$?" -ne 0 ] && echo -e "\e[01;31moverlay: Exiting due to error while getting NVIDIA driver packages\e[00m" && exit 1
  mv -f `ls nvidia-173xx*pkg.tar.*|grep -v utils` nvidia-legacy.tar.xz || return 1
  mv -f `ls nvidia-173xx*pkg.tar.*|grep utils` nvidia-utils-legacy.tar.xz || return 1
  mv -f `ls nvidia-*pkg.tar.*|grep -v utils|grep -v 173xx` nvidia-recent.tar.xz || return 1
  mv -f `ls nvidia-*pkg.tar.*|grep utils|grep -v 173xx` nvidia-utils-recent.tar.xz || return 1

  cd "${BASEDIR}"
  [ ! ${QUIET} == "y" ] && echo "overlay: Finished preparing driver packages"

  [ ! ${QUIET} == "y" ] && echo "overlay: Setting gamelist '$gamelist'"
  [ ! ${QUIET} == "y" ] && echo "overlay: Deleting old copied game data"
  cp -rp "${BASEDIR}"/overlay "${BASEDIR}"/"${WORKDIR}"/overlay/ || return 1
  if [ ${gamelist} == "gamelist_lite" ]; then
cp -f "${BASEDIR}"/gamelist_lite "${BASEDIR}"/"${WORKDIR}"/overlay/
  elif [ ${gamelist} == "gamelist_big" ]; then
cp -f "${BASEDIR}"/gamelist_{lite,big} "${BASEDIR}"/"${WORKDIR}"/overlay/
  fi

if [ ${VERBOSE} == "y" ]; then
pacman -Sy --config ${BASEDIR}/pacman.conf --dbpath "${BASEDIR}"/"${WORKDIR}"/root-image/var/lib/pacman || return 1
  else
pacman -Sy --config ${BASEDIR}/pacman.conf --dbpath "${BASEDIR}"/"${WORKDIR}"/root-image/var/lib/pacman &> /dev/null || return 1
  fi

mkdir -p "${BASEDIR}/${WORKDIR}/overlay/opt/games/" || return 1
  for game in $(cat ${BASEDIR}/${gamelist}); do
    [ ! ${QUIET} == "y" ] && echo "overlay: Installing ${game}"
    if [ ${VERBOSE} == "y" ]; then
echo "pacman -S --config ${BASEDIR}/pacman.conf --noconfirm --root \"${BASEDIR}/${WORKDIR}/overlay/\" --dbpath \"${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman\" ${game} || return 1"
      pacman -S --config ${BASEDIR}/pacman.conf --noconfirm --root "${BASEDIR}/${WORKDIR}/overlay/" --dbpath "${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman" ${game} || return 1
    else
pacman -S --config ${BASEDIR}/pacman.conf --noconfirm --root "${BASEDIR}/${WORKDIR}/overlay/" --dbpath "${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman" ${game} &> /dev/null || return 1
    fi
if [ -d "${BASEDIR}/games/${game}" ]; then
cp -rp "${BASEDIR}/games/${game}" "${BASEDIR}/${WORKDIR}/overlay/opt/games/" || return 1
    fi
done

cd "${BASEDIR}"
  #[ ! ${QUIET} == "y" ] && echo "overlay: Copying overlay to workdir"
  #cp -rpL overlay "${WORKDIR}/" || return 1
  [ "$?" -ne 0 ] && echo -e "\e[01;31moverlay: Exiting due to error while copying overlay\e[00m" && exit 1
  [ ! ${QUIET} == "y" ] && echo "===== Finished overlay ====="
  return 0
}

base-iso ()
{
  [ ! ${QUIET} == "y" ] && echo "===== Making base-iso ====="
  [ ! ${QUIET} == "y" ] && echo "base-iso: Copying boot-files"
  mkdir -p ${WORKDIR}/iso/${INSTALL_DIR}/boot/${ARCH}
  cp "${WORKDIR}/root-image/boot/System.map26" "${WORKDIR}/iso/${INSTALL_DIR}/boot/${ARCH}/"
  cp "${WORKDIR}/root-image/boot/vmlinuz26" "${WORKDIR}/iso/${INSTALL_DIR}/boot/${ARCH}/"
  cp "${WORKDIR}/root-image/boot/memtest86+/memtest.bin" "${WORKDIR}/iso/${INSTALL_DIR}/boot/memtest"
  [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting due to error while moving boot files\e[00m" && exit 1
  mkdir -p ${WORKDIR}/iso/syslinux
  cp boot-files/splash.png ${WORKDIR}/iso/${INSTALL_DIR}/boot/ || return 1
  cp boot-files/syslinux/* ${WORKDIR}/iso/syslinux/ || return 1
  [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting due to error while copying boot files\e[00m" && exit 1
  [ ! ${QUIET} == "y" ] && echo "base-iso: Preparing isomounts"
  cp isomounts "${WORKDIR}/iso/${INSTALL_DIR}/isomounts" || return 1
  [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting because no isomounts file was found\e[00m" && exit 1
  sed -i "s|@ARCH@|${ARCH}|g" "${WORKDIR}/iso/${INSTALL_DIR}/isomounts"
  [ ! ${QUIET} == "y" ] && echo "base-iso: Making initrd image"
  git clone git://projects.archlinux.org/archiso.git archiso-temp &>/dev/null || return 1
  cp -r archiso-temp/archiso/{hooks,install} ${BASEDIR}/${WORKDIR}/root-image/lib/initcpio/ || return 1
  rm -r archiso-temp
  cp ${BASEDIR}/mkinitcpio.conf ${BASEDIR}/${WORKDIR}/root-image/etc/mkinitcpio.conf || return 1
  if [ ${VERBOSE} == "y" ]; then
chroot ${BASEDIR}/${WORKDIR}/root-image mkinitcpio -c /etc/mkinitcpio.conf -k ${KVER} -g "/lglive.img" || return 1
  else
chroot ${BASEDIR}/${WORKDIR}/root-image mkinitcpio -c /etc/mkinitcpio.conf -k ${KVER} -g "/lglive.img" &>/dev/null || return 1
  fi
mv ${BASEDIR}/${WORKDIR}/root-image/lglive.img "${BASEDIR}/${WORKDIR}/iso/${INSTALL_DIR}/boot/${ARCH}/lglive.img" &>/dev/null || return 1
  sed -i "s/^CacheDir/\#CacheDir/" "${BASEDIR}/${WORKDIR}/root-image/etc/pacman.conf"
  sed -i "/localrepo/,+2d" "${BASEDIR}/${WORKDIR}/root-image/etc/pacman.conf"
  [ "$?" -ne 0 ] && echo -e "\e[01;31mbase-iso: Exiting due to error while running mkinitcpio\e[00m" && exit 1
  [ ! ${QUIET} == "y" ] && echo "===== Finished base-iso ====="
  return 0
}

root-image ()
{
  [ ! ${QUIET} == "y" ] && echo "===== Making root-image ====="
  [ ! -d "${BASEDIR}"/"${OUTDIR}" ] && mkdir "${BASEDIR}"/"${OUTDIR}"
  [ ! -d "${BASEDIR}"/"${WORKDIR}" ] && mkdir "${BASEDIR}"/"${WORKDIR}"
  [ ! -d "${BASEDIR}"/"${PKGCACHE}" ] && mkdir "${BASEDIR}"/"${PKGCACHE}"
  sed -i "s|^CacheDir.*$|CacheDir = ${BASEDIR}\/${PKGCACHE}|" pacman.conf
  sed -i "/localrepo/{n; s|.*|Server = file\:\/\/${BASEDIR}/localrepo\/|}" pacman.conf
  [ ! ${QUIET} == "y" ] && echo "root-image: Installing packages"
  if [ ${VERBOSE} == "y" ]; then
mkarchiso -D ${INSTALL_DIR} -C pacman.conf -p "${BASE_PACKAGES}" -v create "${WORKDIR}" || return 1
    mkarchiso -D ${INSTALL_DIR} -C pacman.conf -p "${PACKAGES}" -v create "${WORKDIR}" || return 1
  else
mkarchiso -D ${INSTALL_DIR} -C pacman.conf -p "${BASE_PACKAGES}" -v create "${WORKDIR}" &> /dev/null || return 1
    mkarchiso -D ${INSTALL_DIR} -C pacman.conf -p "${PACKAGES}" -v create "${WORKDIR}" &> /dev/null || return 1
  fi
rm -r "${BASEDIR}"/"${WORKDIR}"/root-image/home/* || true
grep -v localrepo "${BASEDIR}"/pacman.conf > "${BASEDIR}"/"${WORKDIR}"/root-image/etc/pacman.conf
  #rm -r "${BASEDIR}"/"${WORKDIR}"/root-image/root/* || true
  [ "$?" -ne 0 ] && echo -e "\e[01;31mroot-image: Exiting due to error with mkarchiso\e[00m" && exit 1
  [ ! ${QUIET} == "y" ] && echo "===== Finished root-image ====="
  return 0
}

bootloader ()
{
  [ ! ${QUIET} == "y" ] && echo "===== Making bootloader ====="
  if [ ${BOOTLOADER} == "grub-gfx" ]; then
    [ ! ${QUIET} == "y" ] && echo "bootloader: Copying files for 'grub-gfx'"
    cp -r "${WORKDIR}/root-image/usr/lib/grub/i386-pc/"* "${WORKDIR}/iso/boot/grub" || return 1
    [ "$?" -ne 0 ] && echo -e "\e[01;31mbootloader: Exiting due to error while copying bootloader\e[00m" && exit 1
  elif [ ${BOOTLOADER} == "syslinux" ]; then
    [ ! ${QUIET} == "y" ] && echo "bootloader: Copying files for 'syslinux'"
    cp "${WORKDIR}/root-image/usr/lib/syslinux/isolinux.bin" "${WORKDIR}/iso/syslinux/" || return 1
    cp "${WORKDIR}/root-image/usr/lib/syslinux/memdisk" "${WORKDIR}/iso/syslinux/" || return 1
    cp "${WORKDIR}/root-image/usr/lib/syslinux/pxelinux.0" "${WORKDIR}/iso/syslinux/" || return 1
    cp "${WORKDIR}/root-image/usr/lib/syslinux/gpxelinux.0" "${WORKDIR}/iso/syslinux/" || return 1
    cp "${WORKDIR}/root-image/usr/lib/syslinux/"*.c32 "${WORKDIR}/iso/syslinux/" || return 1
    cp "${WORKDIR}/root-image/usr/lib/syslinux/poweroff.com" "${WORKDIR}/iso/syslinux/" || return 1
    #sed "s|archisolabel=[^ ]*|archisolabel=${NAME}-${VER//./}|" -i ${WORKDIR}/iso/boot/pxelinux.cfg/default || return 1
    [ "$?" -ne 0 ] && echo -e "\e[01;31mbootloader Exiting due to error while copying bootloader\e[00m" && exit 1
  fi
  [ ! ${QUIET} == "y" ] && echo "===== Finished bootloader ====="
  return 0
}

# build: build <target>
build ()
{
  TARGET="$1"

  #TODO: Persistent storage
  #dd if=/dev/zero of="${BASEDIR}"/"${WORKDIR}"/iso/persistent.ext4 bs=1M count=4
  #mkfs.ext4 -m0 -F "${BASEDIR}"/"${WORKDIR}"/iso/persistent.ext4
  #mkdir "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
  #mount -o loop -t ext4 "${BASEDIR}"/"${WORKDIR}"/iso/persistent.ext4 "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
  #mkdir -p /tmp/archiso-mount-tmp/home/gamer/persistent
  #umount "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
  #rmdir "${BASEDIR}"/"${WORKDIR}"/archiso-mount-tmp
  #TODO

  [ ! ${QUIET} == "y" ] && echo "===== Building final image for target: ${TARGET} ====="
  [ ! ${QUIET} == "y" ] && echo "build: Removing ballast"
  rm -rf "${WORKDIR}"/root-image/usr/src/*
  rm -rf "${WORKDIR}"/root-image/usr/share/doc/*
  rm -rf "${WORKDIR}"/root-image/usr/share/man/*
  rm -rf "${WORKDIR}"/overlay/usr/share/doc/*
  rm -rf "${WORKDIR}"/overlay/usr/share/man/*
  #pacman -Rsn --root "${BASEDIR}/${WORKDIR}/root-image/" --dbpath "${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman" --config ${BASEDIR}/pacman.conf --noconfirm man-db man-pages || return 1
  #pacman -Q --root "${BASEDIR}/${WORKDIR}/root-image/" --dbpath "${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman" --config ${BASEDIR}/pacman.conf --noconfirm doxygen && pacman -Rsn --root "${BASEDIR}/${WORKDIR}/root-image/" --dbpath "${BASEDIR}/${WORKDIR}/root-image/var/lib/pacman" --config ${BASEDIR}/pacman.conf --noconfirm doxygen
  echo ${TARGET} | grep -q "lite" && edition="lite" || edition="big"
  [ ! ${QUIET} == "y" ] && echo "build: Setting edition to '${edition}'"
  [ ! ${QUIET} == "y" ] && echo "build: Saving to ${FULLNAME}-${edition}.iso"
  [ ! ${QUIET} == "y" ] && echo "build: Starting build, this will take some time"
  if [ ${VERBOSE} == "y" ]; then
mkarchiso -D ${INSTALL_DIR} -c ${COMPRESS} -f -v -L "${NAME}-${VER//./}" -P "Linux-Gamers <live.linux-gamers.net>" -A "live.linux-gamers" -p "${BOOTLOADER}" iso "${WORKDIR}" "${FULLNAME}-${edition}.iso"
  else
mkarchiso -D ${INSTALL_DIR} -c ${COMPRESS} -f -v -L "${NAME}-${VER//./}" -P "Linux-Gamers <live.linux-gamers.net>" -A "live.linux-gamers" -p "${BOOTLOADER}" iso "${WORKDIR}" "${FULLNAME}-${edition}.iso" &> /dev/null
  fi
  [ "$?" -ne 0 ] && echo -e "\e[01;31mbuild: Exiting due to error while running mkarchiso\e[00m" && exit 1
  [ ! ${QUIET} == "y" ] && echo "===== Finished building final image for target: ${TARGET} ====="
  return 0
}

clean ()
{
  [ ! ${QUIET} == "y" ] && echo "===== Cleaning ====="
  [ ! ${QUIET} == "y" ] && echo "clean: Deleting '${BASEDIR}/${WORKDIR}'"
  rm -rf "${BASEDIR}/${WORKDIR}"
  [ "$?" -ne 0 ] && echo -e "\e[01;31mclean: Exiting due to error while cleaning workdir\e[00m" && exit 1
  [ ! ${QUIET} == "y" ] && echo "===== Cleaning finished successfully ====="
  return 0
}

# Catch options here
while getopts "hvq" opt; do
case "${opt}" in
    v) VERBOSE="y" ;;
    q) QUIET="y" ;;
    h|?) usage 0 ;;
    *) echo "ERROR: Invalid argument '${opt}'"; usage 1 ;;
  esac
done

shift $(($OPTIND - 1))

if [ $# -lt 1 ]; then
echo "ERROR: No build targets"
  usage 1
fi

if [ "${USER}" != "root" ]; then
echo "ERROR: Need to be root"
  exit 1
fi

START_TIME=`date +%s`
START_DATE=`date`

LAUNCH_ARGS="$@"

if echo "$@" | grep -q "clean"; then
clean
  exit 0
fi

if echo "$@" | grep -q "all"; then
LAUNCH_ARGS="lglive-lite-iso lglive-big-iso"
fi

for arg in ${LAUNCH_ARGS}; do
if [[ ${arg} != "lglive-lite-iso" && ${arg} != "lglive-big-iso" ]]; then
echo "ERROR: Invalid target"
    usage 1
  fi
  [ ! ${QUIET} == "y" ] && echo -e "\e[01;33m===== Starting build for target: ${arg} =====\e[00m"
  clean || (echo -e "\e[01;31mclean: Exiting due to error while cleaning\e[00m"; exit 1)
  root-image || (echo -e "\e[01;31mroot-image: Exiting due to error while making root-image\e[00m"; exit 1)
  base-iso || (echo -e "\e[01;31mbase-iso: Exiting due to error while making base-iso\e[00m"; exit 1)
  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
  bootloader || (echo -e "\e[01;31mbootloader: Exiting due to error while making bootloader\e[00m"; exit 1)
  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
  [ ! ${QUIET} == "y" ] && echo -e "\e[01;33m===== Finished build for target: ${arg} =====\e[00m"
done

END_TIME=`date +%s`
ELAPSED=`expr ${END_TIME} - ${START_TIME}`
h=$(( ELAPSED / 3600 ))
m=$(( ( ELAPSED / 60 ) % 60 ))
s=$(( ELAPSED % 60 ))
echo -e "\e[01;34m===== FINISHED ALL BUILDS =====\e[00m"
echo "BUILDING STARTED at" ${START_DATE}
echo "BUILDING FINISHED at" `date`
printf "ELAPSED TIME: %02d:%02d:%02d\n" $h $m $s
du -h out/*

# vim:ts=2:sw=2:et

Something went wrong with that request. Please try again.