# generic arch independent functions (used for both build && iso creation) kernelconfig () { if [[ $(zgrep 'CONFIG_OVERLAY_FS=' /proc/config.gz) && $(zgrep "CONFIG_SQUASHFS=" /proc/config.gz) && $(zgrep "CONFIG_BLK_DEV_LOOP=" /proc/config.gz) ]] ; then echo "" echo "Kernel configuration seems OK, moving on" echo "" sleep 1 else echo "" echo "Vasile needs OVERLAYFS && SQUASHFS && LOOP DEVICES to work" echo "Please rebuild the kernel with those activated to use it" echo "" exit 1 fi } checkroot () { if [[ "$(whoami)" != root ]] ; then echo "" echo "You're not root?...No cookies for you, go away !!!" echo "" exit 1 fi } # generic x64 functions (used for both build && iso creation) chrootchecksumx64 () { while : true ; do if [[ -f "$chrootx64" && -f "$chrootx64md5" ]] ; then echo "good, x64 squashed chroot && checksum file found ... verifying integrity" echo "" if [[ "$(md5sum -c "$chrootx64md5")" ]] ; then echo "good, x64 squashed chroot checksum passed ... starting environment" echo "" sleep 1 break else echo "ooops, x64 squashed chroot checksum failed ... aborting" exit 1 fi else echo "ooops, x64 squashed chroot or checksum file not found ... aborting" exit 1 fi done } chrootchecksumx86 () { while : true ; do if [[ -f "$chrootx86" && -f "$chrootx86md5" ]] ; then echo "good, x86 squashed chroot && checksum file found ... verifying integrity" echo "" if [[ "$(md5sum -c "$chrootx86md5")" ]] ; then echo "good, x86 squashed chroot checksum found ... starting environment" echo "" sleep 1 break else echo "ooops, x86 squashed chroot checksum failed ... aborting" exit 1 fi else echo "ooops, x86 squashed chroot or checksum file not found ... aborting" exit 1 fi done } # arch independent build functions chrootstop () { umount -l "$overlaydir"/proc > /dev/null 2>&1 umount -l "$overlaydir"/sys > /dev/null 2>&1 umount -l "$overlaydir"/dev/pts > /dev/null 2>&1 umount -l "$overlaydir"/dev/shm > /dev/null 2>&1 umount -l "$overlaydir"/dev > /dev/null 2>&1 umount -l "$overlaydir"/tmp > /dev/null 2>&1 umount -l "$overlaydir"/usr/portage/packages > /dev/null 2>&1 umount -l "$overlaydir"/mnt > /dev/null 2>&1 umount -l "$overlaydir" > /dev/null 2>&1 umount -l "$rodir" > /dev/null 2>&1 } # x64 specific build functions chrootstartx64 () { mount -t squashfs "$chrootx64" "$rodir" if [[ "$(uname -r | cut -d . -f1,2)" = "3.14" ]] ; then mount -t overlayfs -o lowerdir="$rodir",upperdir="$rwdir" overlayfs "$overlaydir" else mount -t overlay -o lowerdir="$rodir",upperdir="$rwdir",workdir="$workdir" overlay "$overlaydir" fi while : true ; do if [[ ! -d packages ]] ; then mkdir packages mount -o bind packages "$overlaydir"/usr/portage/packages break elif [[ -d packages ]] ; then mount -o bind packages "$overlaydir"/usr/portage/packages break fi done while : true ; do if [[ ! -d distfiles ]] ; then mkdir distfiles mount -o bind distfiles "$overlaydir"/usr/portage/distfiles break elif [[ -d distfiles ]] ; then mount -o bind distfiles "$overlaydir"/usr/portage/distfiles break fi done mount -o bind targets "$overlaydir"/mnt mount -t proc proc "$overlaydir"/proc mount -t sysfs sysfs "$overlaydir"/sys mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$overlaydir"/dev mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$overlaydir"/dev/pts mount -t tmpfs -o nosuid,nodev none "$overlaydir"/dev/shm mount -t tmpfs -o nosuid,nodev,noexec none "$overlaydir"/tmp } chrootoverlaysx64 () { echo "injecting "$releasename" main overlay into x64 environment" sleep 1 chroot "$overlaydir" su - "$chrootuser" -c "$chrootmainoverlay" echo "injecting "$releasename" "$releasetarget" overlay into x64 environment" sleep 1 chroot "$overlaydir" su - "$chrootuser" -c "$chrootaddonoverlay" } chrootbuildsystemx64 () { echo "injecting "$releasename" x64 buildsystem && setting up portage" echo "" sleep 1 for cmd in "$chrootbuildgit" "$chrootportageconfig" "$chrootmakeconfx64" "$chrootprofile" "$chrootenvupdate" ; do chroot "$overlaydir" su - "$chrootuser" -c "$cmd" done } chrootbuildx64 () { echo "" echo "x64 Environment is up && running ... building targets" sleep 1 chroot "$overlaydir" su - "$chrootuser" -c "$chrootbuildtarget" } chrootx64 () { echo -e "" echo -e "#################################################################" echo -e "# ENTERING CHROOT ENV FOR YOU TO PUSH BUILT PACKAGES #" echo -e "# OR TO FIX EVENTUAL BUILD ERRORS #" echo -e "#################################################################" echo -e "# !!! WARNING !!! WARNING !!! WARNING !!! #" echo -e "#################################################################" echo -e "# NEXT RUN OF THIS SCRIPT WILL DESTROY ALL YOUR WORK #" echo -e "# DO NOT EXIT CHROOT UNTIL ALL PACKAGES ARE PUSHED TO REPOS #" echo -e "# OR, IN CASE OF BUILD FAILURES, UNTIL ALL FIXES ARE COMMITED #" echo -e "#################################################################" echo -e "# !!! WARNING !!! WARNING !!! WARNING !!! #" echo -e "#################################################################" echo -e "" echo -e "" chroot "$overlaydir" su - "$chrootuser" } # x86 specific build functions chrootstartx86 () { mount -t squashfs "$chrootx86" "$rodir" if [[ "$(uname -r | cut -d . -f1,2)" = "3.14" ]] ; then mount -t overlayfs -o lowerdir="$rodir",upperdir="$rwdir" overlayfs "$overlaydir" else mount -t overlay -o lowerdir="$rodir",upperdir="$rwdir",workdir="$workdir" overlay "$overlaydir" fi while : true ; do if [[ ! -d packages ]] ; then mkdir packages mount -o bind packages "$overlaydir"/usr/portage/packages break elif [[ -d packages ]] ; then mount -o bind packages "$overlaydir"/usr/portage/packages break fi done while : true ; do if [[ ! -d distfiles ]] ; then mkdir distfiles mount -o bind distfiles "$overlaydir"/usr/portage/distfiles break elif [[ -d distfiles ]] ; then mount -o bind distfiles "$overlaydir"/usr/portage/distfiles break fi done mount -o bind targets "$overlaydir"/mnt mount -t proc proc "$overlaydir"/proc mount -t sysfs sysfs "$overlaydir"/sys mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$overlaydir"/dev mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$overlaydir"/dev/pts mount -t tmpfs -o nosuid,nodev none "$overlaydir"/dev/shm mount -t tmpfs -o nosuid,nodev,noexec none "$overlaydir"/tmp } chrootoverlaysx86 () { echo "injecting "$releasename" main overlay into x86 environment" sleep 1 linux32 chroot "$overlaydir" su - "$chrootuser" -c "$chrootmainoverlay" echo "injecting "$releasename" "$releasetarget" overlay into x86 environment" sleep 1 linux32 chroot "$overlaydir" su - "$chrootuser" -c "$chrootaddonoverlay" } chrootbuildsystemx86 () { echo "injecting "$releasename" x86 buildsystem && setting up portage" echo "" sleep 1 for cmd in "$chrootbuildgit" "$chrootportageconfig" "$chrootmakeconfx86" "$chrootprofile" "$chrootenvupdate" ; do linux32 chroot "$overlaydir" su - "$chrootuser" -c "$cmd" done } chrootbuildx86 () { echo "" echo "x86 environment is up && running ... building targets" sleep 1 chroot "$overlaydir" su - "$chrootuser" -c "$chrootbuildtarget" } chrootx86 () { echo -e "" echo -e "#################################################################" echo -e "# ENTERING CHROOT ENV FOR YOU TO PUSH BUILT PACKAGES #" echo -e "# OR TO FIX EVENTUAL BUILD ERRORS #" echo -e "#################################################################" echo -e "# !!! WARNING !!! WARNING !!! WARNING !!! #" echo -e "#################################################################" echo -e "# NEXT RUN OF THIS SCRIPT WILL DESTROY ALL YOUR WORK #" echo -e "# DO NOT EXIT CHROOT UNTIL ALL PACKAGES ARE PUSHED TO REPOS #" echo -e "# OR, IN CASE OF BUILD FAILURES, UNTIL ALL FIXES ARE COMMITED #" echo -e "#################################################################" echo -e "# !!! WARNING !!! WARNING !!! WARNING !!! #" echo -e "#################################################################" echo -e "" echo -e "" linux32 chroot "$overlaydir" su - "$chrootuser" } # x64 specific iso functions isostartx64 () { mount -o bind packages "$livedirx64"/usr/portage/packages mount -o bind targets "$livedirx64"/mnt mount -t proc proc "$livedirx64"/proc mount -t sysfs sysfs "$livedirx64"/sys mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$livedirx64"/dev mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$livedirx64"/dev/pts mount -t tmpfs -o nosuid,nodev none "$livedirx64"/dev/shm mount -t tmpfs -o nosuid,nodev,noexec none "$livedirx64"/tmp } isooverlaysx64 () { echo "injecting "$releasename" main overlay into x64 environment" sleep 1 chroot "$livedirx64" su - "$isouser" -c "$isomainoverlay" echo "injecting "$releasename" "$releasetarget" overlay into x64 environment" sleep 1 chroot "$livedirx64" su - "$isouser" -c "$isoaddonoverlay" } isobuildsystemx64 () { echo "injecting "$releasename" x64 buildsystem && setting up portage" echo "" sleep 1 for cmd in "$isobuildgit" "$isoportageconfig" "$isomakeconfx64" "$isoprofile" "$isoenvupdate" ; do chroot "$livedirx64" su - "$isouser" -c "$cmd" done } isochrootx64 () { echo -e "" echo -e "DROPPING YOU TO A ROOT SHELL INTO ISO ENVIRONMENT" echo -e "INSTALL APPS & TARGETS & DES YOU WANT INSIDE ISO" echo -e "EXIT WHEN YOU'RE DONE AND I'LL CREATE THE IMAGE" echo -e "" chroot "$livedirx64" su - "$isouser" } # x86 specific iso functions isostartx86 () { mount -o bind packages "$livedirx86"/usr/portage/packages mount -o bind targets "$livedirx86"/mnt mount -t proc proc "$livedirx86"/proc mount -t sysfs sysfs "$livedirx86"/sys mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$livedirx86"/dev mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$livedirx86"/dev/pts mount -t tmpfs -o nosuid,nodev none "$livedirx86"/dev/shm mount -t tmpfs -o nosuid,nodev,noexec none "$livedirx86"/tmp } isooverlaysx86 () { echo "injecting "$releasename" main overlay into x86 environment" sleep 1 linux32 chroot "$livedirx86" su - "$isouser" -c "$isomainoverlay" echo "injecting "$releasename" "$releasetarget" overlay into x86 environment" sleep 1 linux32 chroot "$livedirx86" su - "$isouser" -c "$isoaddonoverlay" } isobuildsystemx86 () { echo "injecting "$releasename" x86 buildsystem && setting up portage" echo "" sleep 1 for cmd in "$isobuildgit" "$isoportageconfig" "$isomakeconfx86" "$isoprofile" "$isoenvupdate" ; do linux32 chroot "$livedirx86" su - "$isouser" -c "$cmd" done } isochrootx86 () { echo -e "" echo -e "DROPPING YOU TO A ROOT SHELL INTO ISO ENVIRONMENT" echo -e "INSTALL APPS & TARGETS & DES YOU WANT INSIDE ISO" echo -e "EXIT WHEN YOU'RE DONE AND I'LL CREATE THE IMAGE" echo -e "" linux32 chroot "$livedirx86" su - "$isouser" }