rebuild.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. ## rebuild.sh options ##
  3. #readonly PRESERVE_CACHE='false' # preserve package cache in 'wipe' mode
  4. readonly PRESERVE_CACHE='true' # preserve package cache in 'wipe' mode
  5. readonly MODE='wipe' # total wipe of work dir, optionally preserving package cache
  6. # readonly MODE='rebuild' # full update rebuild preserving work dir
  7. # readonly MODE='tweak' # apply chroot customization tweaks only
  8. ## build.sh options ##
  9. # readonly TARGET='dual' # dual-arch
  10. # readonly TARGET='i686' # i686 target only
  11. readonly TARGET='x86_64' # x86_64 target only (default)
  12. # readonly INIT='openrc' # OpenRC initsystem
  13. readonly INIT='systemd' # SystemD initsystem (default)
  14. readonly WMDE='cli' # CLI (default)
  15. # readonly WMDE='LXDE' # LXDE
  16. # readonly WMDE='mini' # minimal installer system
  17. readonly TALKING='' # speech and braille disabled (default)
  18. # readonly TALKING='-S' # speech and braille enabled
  19. readonly CACHE='' # net-install (default)
  20. # readonly CACHE='-O' # offline install
  21. readonly VERSION="$(date +%Y.%m)" # for ISO filename (default)
  22. # readonly VERSION="`date +%Y.%m.%d-%H.%M`-alpha"
  23. readonly OUT_DIR=./out/new/
  24. # prepare build command
  25. readonly CMD="./build.sh -v -A $TARGET -I $INIT -W $WMDE $TALKING $CACHE -V $VERSION -o $OUT_DIR $*"
  26. # sanity checks
  27. (( ! $(id -u) )) && echo "Preparing (${MODE} mode): ${CMD}" || \
  28. ! echo "This script must be run with root privileges." || exit 1
  29. # cleanup in case of previous aborted run
  30. while pids=$(pidof ./rebuild.sh || pidof sudo ./rebuild.sh) && pids=${pids/$PPID/} && [ "$pids" ]
  31. do for pid in ${pids/$PPID/} ; do sudo kill -9 $pid ; done ; sleep 1 ;
  32. done
  33. for work_dir in "$PWD/work/i686" "$PWD/work/x86_64"
  34. do declare -a mountpoints=()
  35. for mnt in dev/pts dev/shm dev proc run sys tmp; do
  36. mountpoint=$(findmnt --noheadings --output="TARGET" "${work_dir}/root-image/${mnt}" || true)
  37. if [[ "${mountpoint}" != "" ]] ; then mountpoints=( ${mountpoints[@]} "${mountpoint}" ) ; fi ;
  38. done
  39. for mountpoint in ${mountpoints[@]} ; do umount "${mountpoint}" ; done ;
  40. done
  41. # prepare environment
  42. if [ "$MODE" == 'wipe' ]
  43. then # stash package cache
  44. if [ "$PRESERVE_CACHE" == 'true' ]
  45. then for arch in i686 x86_64
  46. do isorepo=$(realpath ./work)/${arch}/root-image/isorepo
  47. cache_dir=$(realpath ./work)/isorepo-${arch}
  48. mkdir -p $cache_dir
  49. [ -d $isorepo ] && mv $isorepo/* $cache_dir/ 2> /dev/null
  50. done
  51. fi
  52. # delete work area
  53. rm -rf ./work/${arch} 2> /dev/null
  54. # restore package cache
  55. for arch in i686 x86_64
  56. do isorepo=$(realpath ./work)/${arch}/root-image/isorepo
  57. cache_dir=$(realpath ./work)/isorepo-${arch}
  58. if [ "$PRESERVE_CACHE" == 'true' ]
  59. then if [ "$TARGET" == 'dual' -o "$TARGET" == "${arch}" ]
  60. then mkdir -p $isorepo
  61. mv $cache_dir/* $isorepo/ 2> /dev/null
  62. rmdir $cache_dir
  63. fi
  64. else rmdir $cache_dir 2> /dev/null
  65. fi
  66. done
  67. elif [ "$MODE" == 'rebuild' ]
  68. then rm -v ./work/build.make_*
  69. elif [ "$MODE" == 'tweak' ]
  70. then rm work/build.make_customize_root_image_$TARGET \
  71. work/build.make_prepare_$TARGET \
  72. work/build.make_iso* 2> /dev/null
  73. fi
  74. # start build
  75. echo "Starting build: ${CMD}"
  76. if ${CMD}
  77. then echo "success" ; rm ./continue.sh 2> /dev/null
  78. else echo -e "failure executing:\n\t${CMD}\ncontinue with:\n\t./continue.sh [extra-args-to-build.sh]"
  79. echo -e "#!/bin/bash\n\n${CMD} \$*" > ./continue.sh
  80. chmod a+x ./continue.sh
  81. fi
  82. sudo chgrp -R wheel ./root-image/