build.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #!/bin/bash
  2. set -e -u
  3. iso_name=parabola-mate
  4. iso_label="PARA_$(date +%Y%m)"
  5. iso_version=$(date +%Y.%m.%d)
  6. install_dir=parabola
  7. work_dir=work
  8. out_dir=out
  9. data_dir=/usr/share/parabolaiso/data
  10. arch=$(uname -m)
  11. verbose=""
  12. pacman_conf=${work_dir}/pacman.conf
  13. script_path=$(readlink -f ${0%/*})
  14. initcpio_dir=${script_path}/../../parabolaiso/initcpio
  15. _usage ()
  16. {
  17. echo "usage ${0} [options]"
  18. echo
  19. echo " General options:"
  20. echo " -N <iso_name> Set an iso filename (prefix)"
  21. echo " Default: ${iso_name}"
  22. echo " -V <iso_version> Set an iso version (in filename)"
  23. echo " Default: ${iso_version}"
  24. echo " -L <iso_label> Set an iso label (disk label)"
  25. echo " Default: ${iso_label}"
  26. echo " -D <install_dir> Set an install_dir (directory inside iso)"
  27. echo " Default: ${install_dir}"
  28. echo " -w <work_dir> Set the working directory"
  29. echo " Default: ${work_dir}"
  30. echo " -o <out_dir> Set the output directory"
  31. echo " Default: ${out_dir}"
  32. echo " -v Enable verbose output"
  33. echo " -h This help message"
  34. exit ${1}
  35. }
  36. # Helper function to run make_*() only one time per architecture.
  37. run_once() {
  38. if [[ ! -e ${work_dir}/build.${1}_${arch} ]]; then
  39. $1
  40. touch ${work_dir}/build.${1}_${arch}
  41. fi
  42. }
  43. # Setup custom pacman.conf with current cache directories.
  44. make_pacman_conf() {
  45. local _cache_dirs
  46. _cache_dirs=($(pacman -v 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
  47. sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${_cache_dirs[@]})|g" ${script_path}/pacman.conf > ${pacman_conf}
  48. }
  49. # Base installation, plus needed packages (root-image)
  50. make_basefs() {
  51. setarch ${arch} mkparabolaiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" init
  52. setarch ${arch} mkparabolaiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -p "memtest86+ mkinitcpio-nfs-utils nbd" install
  53. }
  54. # Additional packages (root-image)
  55. make_packages() {
  56. setarch ${arch} mkparabolaiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -p "$(grep -h -v ^# ${script_path}/packages.{both,${arch}})" install
  57. }
  58. # Copy mkinitcpio parabolaiso hooks and build initramfs (root-image)
  59. make_setup_mkinitcpio() {
  60. local _hook
  61. for _hook in parabolaiso parabolaiso_shutdown parabolaiso_pxe_common parabolaiso_pxe_nbd parabolaiso_pxe_http parabolaiso_pxe_nfs parabolaiso_loop_mnt; do
  62. cp ${initcpio_dir}/hooks/${_hook} ${work_dir}/${arch}/root-image/usr/lib/initcpio/hooks
  63. cp ${initcpio_dir}/install/${_hook} ${work_dir}/${arch}/root-image/usr/lib/initcpio/install
  64. done
  65. cp ${initcpio_dir}/install/parabolaiso_kms ${work_dir}/${arch}/root-image/usr/lib/initcpio/install
  66. cp ${initcpio_dir}/hooks/parabolaiso_shutdown ${work_dir}/${arch}/root-image/usr/lib/initcpio
  67. cp ${script_path}/mkinitcpio.conf ${work_dir}/${arch}/root-image/etc/mkinitcpio-parabolaiso.conf
  68. setarch ${arch} mkparabolaiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -r 'mkinitcpio -c /etc/mkinitcpio-parabolaiso.conf -k /boot/vmlinuz-linux-libre -g /boot/parabolaiso.img' run
  69. }
  70. # Customize installation (root-image)
  71. make_customize_root_image() {
  72. cp -af ${script_path}/root-image ${work_dir}/${arch}
  73. iso_version="${iso_version}" setarch ${arch} mkparabolaiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -r '/root/customize_root_image.sh' run
  74. rm ${work_dir}/${arch}/root-image/root/customize_root_image.sh
  75. }
  76. # Prepare kernel/initramfs ${install_dir}/boot/
  77. make_boot() {
  78. mkdir -p ${work_dir}/iso/${install_dir}/boot/${arch}
  79. cp ${work_dir}/${arch}/root-image/boot/parabolaiso.img ${work_dir}/iso/${install_dir}/boot/${arch}/parabolaiso.img
  80. cp ${work_dir}/${arch}/root-image/boot/vmlinuz-linux-libre ${work_dir}/iso/${install_dir}/boot/${arch}/vmlinuz
  81. }
  82. # Add other aditional/extra files to ${install_dir}/boot/
  83. make_boot_extra() {
  84. cp ${work_dir}/${arch}/root-image/boot/memtest86+/memtest.bin ${work_dir}/iso/${install_dir}/boot/memtest
  85. cp ${work_dir}/${arch}/root-image/usr/share/licenses/common/GPL2/license.txt ${work_dir}/iso/${install_dir}/boot/memtest.COPYING
  86. }
  87. # Prepare /${install_dir}/boot/syslinux
  88. make_syslinux() {
  89. mkdir -p ${work_dir}/iso/${install_dir}/boot/syslinux
  90. for _cfg in ${script_path}/syslinux/*.cfg; do
  91. sed "s|%PARABOLAISO_LABEL%|${iso_label}|g;
  92. s|%INSTALL_DIR%|${install_dir}|g" ${_cfg} > ${work_dir}/iso/${install_dir}/boot/syslinux/${_cfg##*/}
  93. done
  94. cp ${script_path}/syslinux/splash.png ${work_dir}/iso/${install_dir}/boot/syslinux
  95. cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/*.c32 ${work_dir}/iso/${install_dir}/boot/syslinux
  96. cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/lpxelinux.0 ${work_dir}/iso/${install_dir}/boot/syslinux
  97. cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/memdisk ${work_dir}/iso/${install_dir}/boot/syslinux
  98. mkdir -p ${work_dir}/iso/${install_dir}/boot/syslinux/hdt
  99. gzip -c -9 ${work_dir}/${arch}/root-image/usr/share/hwdata/pci.ids > ${work_dir}/iso/${install_dir}/boot/syslinux/hdt/pciids.gz
  100. gzip -c -9 ${work_dir}/${arch}/root-image/usr/lib/modules/*-gnu-*/modules.alias > ${work_dir}/iso/${install_dir}/boot/syslinux/hdt/modalias.gz
  101. }
  102. # Prepare /isolinux
  103. make_isolinux() {
  104. mkdir -p ${work_dir}/iso/isolinux
  105. sed "s|%INSTALL_DIR%|${install_dir}|g" ${script_path}/isolinux/isolinux.cfg > ${work_dir}/iso/isolinux/isolinux.cfg
  106. cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/isolinux.bin ${work_dir}/iso/isolinux/
  107. cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/isohdpfx.bin ${work_dir}/iso/isolinux/
  108. cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/ldlinux.c32 ${work_dir}/iso/isolinux/
  109. }
  110. # Prepare /EFI
  111. make_efi() {
  112. mkdir -p ${work_dir}/iso/EFI/boot
  113. cp ${work_dir}/x86_64/root-image/usr/lib/systemd/boot/efi/systemd-bootx64.efi ${work_dir}/iso/EFI/boot/bootx64.efi
  114. mkdir -p ${work_dir}/iso/loader/entries
  115. cp ${script_path}/efiboot/loader/loader.conf ${work_dir}/iso/loader/
  116. cp ${script_path}/efiboot/loader/entries/uefi-shell-v2-x86_64.conf ${work_dir}/iso/loader/entries/
  117. cp ${script_path}/efiboot/loader/entries/uefi-shell-v1-x86_64.conf ${work_dir}/iso/loader/entries/
  118. sed "s|%PARABOLAISO_LABEL%|${iso_label}|g;
  119. s|%INSTALL_DIR%|${install_dir}|g" \
  120. ${script_path}/efiboot/loader/entries/parabolaiso-x86_64-usb.conf > ${work_dir}/iso/loader/entries/parabolaiso-x86_64.conf
  121. # EFI Shell 2.0 for UEFI 2.3+ ( http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=UEFI_Shell )
  122. cp ${data_dir}/Shell.efi ${work_dir}/iso/EFI/shellx64_v2.efi
  123. # EFI Shell 1.0 for non UEFI 2.3+ ( http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Efi-shell )
  124. cp ${data_dir}/Shell_Full.efi ${work_dir}/iso/EFI/shellx64_v1.efi
  125. }
  126. # Prepare efiboot.img::/EFI for "El Torito" EFI boot mode
  127. make_efiboot() {
  128. mkdir -p ${work_dir}/iso/EFI/parabolaiso
  129. truncate -s 38M ${work_dir}/iso/EFI/parabolaiso/efiboot.img
  130. mkfs.vfat -n PARABOLAISO_EFI ${work_dir}/iso/EFI/parabolaiso/efiboot.img
  131. mkdir -p ${work_dir}/efiboot
  132. mount ${work_dir}/iso/EFI/parabolaiso/efiboot.img ${work_dir}/efiboot
  133. mkdir -p ${work_dir}/efiboot/EFI/parabolaiso
  134. cp ${work_dir}/iso/${install_dir}/boot/x86_64/vmlinuz ${work_dir}/efiboot/EFI/parabolaiso/vmlinuz.efi
  135. cp ${work_dir}/iso/${install_dir}/boot/x86_64/parabolaiso.img ${work_dir}/efiboot/EFI/parabolaiso/parabolaiso.img
  136. mkdir -p ${work_dir}/efiboot/EFI/boot
  137. cp ${work_dir}/x86_64/root-image/usr/lib/systemd/boot/efi/systemd-bootx64.efi ${work_dir}/efiboot/EFI/boot/bootx64.efi
  138. mkdir -p ${work_dir}/efiboot/loader/entries
  139. cp ${script_path}/efiboot/loader/loader.conf ${work_dir}/efiboot/loader/
  140. cp ${script_path}/efiboot/loader/entries/uefi-shell-v2-x86_64.conf ${work_dir}/efiboot/loader/entries/
  141. cp ${script_path}/efiboot/loader/entries/uefi-shell-v1-x86_64.conf ${work_dir}/efiboot/loader/entries/
  142. sed "s|%PARABOLAISO_LABEL%|${iso_label}|g;
  143. s|%INSTALL_DIR%|${install_dir}|g" \
  144. ${script_path}/efiboot/loader/entries/parabolaiso-x86_64-cd.conf > ${work_dir}/efiboot/loader/entries/parabolaiso-x86_64.conf
  145. cp ${work_dir}/iso/EFI/shellx64_v2.efi ${work_dir}/efiboot/EFI/
  146. cp ${work_dir}/iso/EFI/shellx64_v1.efi ${work_dir}/efiboot/EFI/
  147. umount ${work_dir}/efiboot
  148. }
  149. # Copy aitab
  150. make_aitab() {
  151. mkdir -p ${work_dir}/iso/${install_dir}
  152. cp ${script_path}/aitab ${work_dir}/iso/${install_dir}/aitab
  153. }
  154. # Build all filesystem images specified in aitab (.fs.sfs .sfs)
  155. make_prepare() {
  156. cp -a -l -f ${work_dir}/${arch}/root-image ${work_dir}
  157. setarch ${arch} mkparabolaiso ${verbose} -w "${work_dir}" -D "${install_dir}" pkglist
  158. setarch ${arch} mkparabolaiso ${verbose} -w "${work_dir}" -D "${install_dir}" prepare
  159. rm -rf ${work_dir}/root-image
  160. # rm -rf ${work_dir}/${arch}/root-image (if low space, this helps)
  161. }
  162. # Build ISO
  163. make_iso() {
  164. mkparabolaiso ${verbose} -w "${work_dir}" -D "${install_dir}" checksum
  165. mkparabolaiso ${verbose} -w "${work_dir}" -D "${install_dir}" -L "${iso_label}" -o "${out_dir}" iso "${iso_name}-${iso_version}-dual.iso"
  166. }
  167. if [[ ${EUID} -ne 0 ]]; then
  168. echo "This script must be run as root."
  169. _usage 1
  170. fi
  171. if [[ ${arch} != x86_64 ]]; then
  172. echo "This script needs to be run on x86_64"
  173. _usage 1
  174. fi
  175. while getopts 'N:V:L:D:w:o:vh' arg; do
  176. case "${arg}" in
  177. N) iso_name="${OPTARG}" ;;
  178. V) iso_version="${OPTARG}" ;;
  179. L) iso_label="${OPTARG}" ;;
  180. D) install_dir="${OPTARG}" ;;
  181. w) work_dir="${OPTARG}" ;;
  182. o) out_dir="${OPTARG}" ;;
  183. v) verbose="-v" ;;
  184. h) _usage 0 ;;
  185. *)
  186. echo "Invalid argument '${arg}'"
  187. _usage 1
  188. ;;
  189. esac
  190. done
  191. mkdir -p ${work_dir}
  192. run_once make_pacman_conf
  193. # Do all stuff for each root-image
  194. for arch in i686 x86_64; do
  195. run_once make_basefs
  196. run_once make_packages
  197. run_once make_setup_mkinitcpio
  198. run_once make_customize_root_image
  199. done
  200. for arch in i686 x86_64; do
  201. run_once make_boot
  202. done
  203. # Do all stuff for "iso"
  204. run_once make_boot_extra
  205. run_once make_syslinux
  206. run_once make_isolinux
  207. run_once make_efi
  208. run_once make_efiboot
  209. run_once make_aitab
  210. for arch in i686 x86_64; do
  211. run_once make_prepare
  212. done
  213. run_once make_iso