123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #!/bin/bash
- ## rebuild.sh options ##
- #readonly PRESERVE_CACHE='false' # preserve package cache in 'wipe' mode
- readonly PRESERVE_CACHE='true' # preserve package cache in 'wipe' mode
- readonly MODE='wipe' # total wipe of work dir, optionally preserving package cache
- # readonly MODE='rebuild' # full update rebuild preserving work dir
- # readonly MODE='tweak' # apply chroot customization tweaks only
- ## build.sh options ##
- # readonly TARGET='dual' # dual-arch
- # readonly TARGET='i686' # i686 target only
- readonly TARGET='x86_64' # x86_64 target only (default)
- # readonly INIT='openrc' # OpenRC initsystem
- readonly INIT='systemd' # SystemD initsystem (default)
- readonly WMDE='cli' # CLI (default)
- # readonly WMDE='LXDE' # LXDE
- # readonly WMDE='mini' # minimal installer system
- readonly TALKING='' # speech and braille disabled (default)
- # readonly TALKING='-S' # speech and braille enabled
- readonly CACHE='' # net-install (default)
- # readonly CACHE='-O' # offline install
- readonly VERSION="$(date +%Y.%m)" # for ISO filename (default)
- # readonly VERSION="`date +%Y.%m.%d-%H.%M`-alpha"
- readonly OUT_DIR=./out/new/
- # prepare build command
- readonly CMD="./build.sh -v -A $TARGET -I $INIT -W $WMDE $TALKING $CACHE -V $VERSION -o $OUT_DIR $*"
- # sanity checks
- (( ! $(id -u) )) && echo "Preparing (${MODE} mode): ${CMD}" || \
- ! echo "This script must be run with root privileges." || exit 1
- # cleanup in case of previous aborted run
- while pids=$(pidof ./rebuild.sh || pidof sudo ./rebuild.sh) && pids=${pids/$PPID/} && [ "$pids" ]
- do for pid in ${pids/$PPID/} ; do sudo kill -9 $pid ; done ; sleep 1 ;
- done
- for work_dir in "$PWD/work/i686" "$PWD/work/x86_64"
- do declare -a mountpoints=()
- for mnt in dev/pts dev/shm dev proc run sys tmp; do
- mountpoint=$(findmnt --noheadings --output="TARGET" "${work_dir}/root-image/${mnt}" || true)
- if [[ "${mountpoint}" != "" ]] ; then mountpoints=( ${mountpoints[@]} "${mountpoint}" ) ; fi ;
- done
- for mountpoint in ${mountpoints[@]} ; do umount "${mountpoint}" ; done ;
- done
- # prepare environment
- if [ "$MODE" == 'wipe' ]
- then # stash package cache
- if [ "$PRESERVE_CACHE" == 'true' ]
- then for arch in i686 x86_64
- do isorepo=$(realpath ./work)/${arch}/root-image/isorepo
- cache_dir=$(realpath ./work)/isorepo-${arch}
- mkdir -p $cache_dir
- [ -d $isorepo ] && mv $isorepo/* $cache_dir/ 2> /dev/null
- done
- fi
- # delete work area
- rm -rf ./work/${arch} 2> /dev/null
- # restore package cache
- for arch in i686 x86_64
- do isorepo=$(realpath ./work)/${arch}/root-image/isorepo
- cache_dir=$(realpath ./work)/isorepo-${arch}
- if [ "$PRESERVE_CACHE" == 'true' ]
- then if [ "$TARGET" == 'dual' -o "$TARGET" == "${arch}" ]
- then mkdir -p $isorepo
- mv $cache_dir/* $isorepo/ 2> /dev/null
- rmdir $cache_dir
- fi
- else rmdir $cache_dir 2> /dev/null
- fi
- done
- elif [ "$MODE" == 'rebuild' ]
- then rm -v ./work/build.make_*
- elif [ "$MODE" == 'tweak' ]
- then rm work/build.make_customize_root_image_$TARGET \
- work/build.make_prepare_$TARGET \
- work/build.make_iso* 2> /dev/null
- fi
- # start build
- echo "Starting build: ${CMD}"
- if ${CMD}
- then echo "success" ; rm ./continue.sh 2> /dev/null
- else echo -e "failure executing:\n\t${CMD}\ncontinue with:\n\t./continue.sh [extra-args-to-build.sh]"
- echo -e "#!/bin/bash\n\n${CMD} \$*" > ./continue.sh
- chmod a+x ./continue.sh
- fi
- sudo chgrp -R wheel ./root-image/
|