From a28652bb4a5baf7307f8d2f29bb765e18705cfb8 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Thu, 12 Oct 2017 17:19:55 +0100 Subject: day 3 : split even more --- src/backend/commands_jail.sh | 10 ++++ src/backend/functions_generic.sh | 48 +++++++++++++++ src/backend/functions_makeiso.sh | 0 src/backend/functions_makepkg.sh | 66 +++++++++++++++++++++ src/backend/functions_modeswitch.sh | 0 src/backend/jailcmds.sh | 10 ---- src/backend/jailfuncs.sh | 113 ------------------------------------ src/backend/jailvars.sh | 36 ------------ src/backend/libvasile.sh | 36 +++++++++--- src/backend/variables_jail.sh | 36 ++++++++++++ 10 files changed, 187 insertions(+), 168 deletions(-) create mode 100644 src/backend/commands_jail.sh create mode 100644 src/backend/functions_generic.sh create mode 100644 src/backend/functions_makeiso.sh create mode 100644 src/backend/functions_makepkg.sh create mode 100644 src/backend/functions_modeswitch.sh delete mode 100644 src/backend/jailcmds.sh delete mode 100644 src/backend/jailfuncs.sh delete mode 100644 src/backend/jailvars.sh create mode 100644 src/backend/variables_jail.sh (limited to 'src') diff --git a/src/backend/commands_jail.sh b/src/backend/commands_jail.sh new file mode 100644 index 0000000..fe5e82b --- /dev/null +++ b/src/backend/commands_jail.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +export local jailbinmodecmd="vasile --binmode" +export local jailsrcmodecmd="vasile --srcmode" +export local jaildkmscmd="vasile --dkms" +export local jailportagecmd="emerge -kav "$jailtarget"" +export local jaildracutcmd="dracut -N -a dmsquash-live -a pollcdrom --force --kver="$kernver" /boot/"$jailramfsname"" +export local jailmkchainloadercmd="grub2-mkimage -d /usr/lib64/grub/i386-pc -o core.img -O i386-pc biosdisk part_msdos fat -p /boot/grub" +export local jailmkx64eficmd="grub2-mkimage -d /usr/lib64/grub/x86_64-efi -o bootx64.efi -O x86_64-efi ext2 fat udf btrfs ntfs reiserfs xfs hfsplus lvm ata part_msdos part_gpt part_apple bsd search_fs_uuid normal chain iso9660 configfile help loadenv reboot cat search memdisk tar boot linux chain -p /boot/grub" +export local jailmkia32eficmd="grub2-mkimage -d /usr/lib64/grub/i386-efi -o bootia32.efi -O i386-efi ext2 fat udf btrfs ntfs reiserfs xfs hfsplus lvm ata part_msdos part_gpt part_apple bsd search_fs_uuid normal chain iso9660 configfile help loadenv reboot cat search memdisk tar boot linux chain -p /boot/grub" diff --git a/src/backend/functions_generic.sh b/src/backend/functions_generic.sh new file mode 100644 index 0000000..d692c46 --- /dev/null +++ b/src/backend/functions_generic.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +checkifroot () { + if [[ "$(whoami)" != root ]] ; then + eerror "I won't do that, unless you're root!" + exit 1 + fi +} + +checkkerncfg () { + if [[ $(zgrep 'CONFIG_OVERLAY_FS=' /proc/config.gz) && $(zgrep "CONFIG_SQUASHFS=" /proc/config.gz) && $(zgrep "CONFIG_BLK_DEV_LOOP=" /proc/config.gz) ]] ; then + einfo "Kernel config OK, moving on" + else + eerror "I won't do that with the current kernel" + eerror "I want a kernel with OVERLAYFS && SQUASHFS && LOOP DEVICES enabled" + exit 1 + fi +} + +checkiflive () { + if [[ -L /dev/mapper/live-base ]] ; then + eerror "I won't do that on a live system" + exit 1 + fi +} + +checkjailsum () { + if [[ -f "$jailx64" && -f "$jailx64sum" ]] ; then + if [[ "$(md5sum -c "$jailx64sum")" ]] ; then + einfo "Jail integrity OK, moving on" + else + eerror "I won't do that with a corrupted jail" + exit 1 + fi + else + eerror "I won't do that with a missing jail" + exit 1 + fi +} + +jaildkmsbuild () { + checkifroot + if [[ -x /usr/sbin/dkms ]] ; then + for i in $(dkms status | cut -d " " -f1,2 | sed -e 's/,//g' | sed -e 's/ /\//g' | sed -e 's/://g') ; do + dkms install $i + done + fi +} diff --git a/src/backend/functions_makeiso.sh b/src/backend/functions_makeiso.sh new file mode 100644 index 0000000..e69de29 diff --git a/src/backend/functions_makepkg.sh b/src/backend/functions_makepkg.sh new file mode 100644 index 0000000..5f60046 --- /dev/null +++ b/src/backend/functions_makepkg.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +jailpkgprep () { + while : true ; do + if [[ ! -d "$ropath" && ! -d "$rwpath" && ! -d "$workpath" && ! -d "$overlaypath" ]] ; then + for i in "$ropath" "$rwpath" "$workpath" "$overlaypath" ; do + mkdir "$i" + done + jailpkgmnt + break + elif [[ -d "$ropath" && -d "$rwdpath" && -d "$workpath" && -d "$overlaypath" ]] ; then + jailpkgdmnt + for i in "$ropath" "$rwpath" "$workpath" "$overlaypath" ; do + rm -rf "$i" + done + continue + fi + done +} + +jailpkgmnt () { + mount -t squashfs "$jailx64" "$ropath" + mount -t overlay -o lowerdir="$ropath",upperdir="$rwpath",workdir="$workpath" overlay "$overlaypath" + mount -o bind packages "$overlaypath"/var/cache/packages + mount -o bind distfiles "$overlaypath"/var/cache/distfiles + mount -t proc proc "$overlaypath"/proc + mount -t sysfs sysfs "$overlaypath"/sys + mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$overlaypath"/dev + mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$overlaypath"/dev/pts + mount -t tmpfs -o nosuid,nodev none "$overlaypath"/dev/shm +} + +jailpkgdmnt () { + umount -l "$overlaypath"/proc > /dev/null 2>&1 + umount -l "$overlaypath"/sys > /dev/null 2>&1 + umount -l "$overlaypath"/dev/pts > /dev/null 2>&1 + umount -l "$overlaypath"/dev/shm > /dev/null 2>&1 + umount -l "$overlaypath"/dev > /dev/null 2>&1 + umount -l "$overlaypath"/var/cache/packages > /dev/null 2>&1 + umount -l "$overlaypath"/var/cache/distfiles > /dev/null 2>&1 + umount -l "$overlaypath" > /dev/null 2>&1 + umount -l "$ropath" > /dev/null 2>&1 +} + +jailpkgsrcmode () { + chroot "$overlaypath" su - "$jailuser" -c "$jailsrcmodecmd" +} + +jailpkgbuild () { + chroot "$overlaypath" su - "$jailuser" -c "$jailportagecmd" +} + +jailpkgstart () { + einfo "Oh no, I'm in jail!" + chroot "$overlaypath" su - "$jailuser" +} + +jailmakepkg () { + checkifroot + checkjailsum + jailpkgprep + jailpkgsrcmode + jailpkgbuild + jailpkgstart + jailpkgdmnt +} diff --git a/src/backend/functions_modeswitch.sh b/src/backend/functions_modeswitch.sh new file mode 100644 index 0000000..e69de29 diff --git a/src/backend/jailcmds.sh b/src/backend/jailcmds.sh deleted file mode 100644 index fe5e82b..0000000 --- a/src/backend/jailcmds.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -export local jailbinmodecmd="vasile --binmode" -export local jailsrcmodecmd="vasile --srcmode" -export local jaildkmscmd="vasile --dkms" -export local jailportagecmd="emerge -kav "$jailtarget"" -export local jaildracutcmd="dracut -N -a dmsquash-live -a pollcdrom --force --kver="$kernver" /boot/"$jailramfsname"" -export local jailmkchainloadercmd="grub2-mkimage -d /usr/lib64/grub/i386-pc -o core.img -O i386-pc biosdisk part_msdos fat -p /boot/grub" -export local jailmkx64eficmd="grub2-mkimage -d /usr/lib64/grub/x86_64-efi -o bootx64.efi -O x86_64-efi ext2 fat udf btrfs ntfs reiserfs xfs hfsplus lvm ata part_msdos part_gpt part_apple bsd search_fs_uuid normal chain iso9660 configfile help loadenv reboot cat search memdisk tar boot linux chain -p /boot/grub" -export local jailmkia32eficmd="grub2-mkimage -d /usr/lib64/grub/i386-efi -o bootia32.efi -O i386-efi ext2 fat udf btrfs ntfs reiserfs xfs hfsplus lvm ata part_msdos part_gpt part_apple bsd search_fs_uuid normal chain iso9660 configfile help loadenv reboot cat search memdisk tar boot linux chain -p /boot/grub" diff --git a/src/backend/jailfuncs.sh b/src/backend/jailfuncs.sh deleted file mode 100644 index 37b382b..0000000 --- a/src/backend/jailfuncs.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash - -checkifroot () { - if [[ "$(whoami)" != root ]] ; then - eerror "I won't do that, unless you're root!" - exit 1 - fi -} - -checkkerncfg () { - if [[ $(zgrep 'CONFIG_OVERLAY_FS=' /proc/config.gz) && $(zgrep "CONFIG_SQUASHFS=" /proc/config.gz) && $(zgrep "CONFIG_BLK_DEV_LOOP=" /proc/config.gz) ]] ; then - einfo "Kernel config OK, moving on" - else - eerror "I won't do that with the current kernel" - eerror "I want a kernel with OVERLAYFS && SQUASHFS && LOOP DEVICES enabled" - exit 1 - fi -} - -checkiflive () { - if [[ -L /dev/mapper/live-base ]] ; then - eerror "I won't do that on a live system" - exit 1 - fi -} - -checkjailsum () { - if [[ -f "$jailx64" && -f "$jailx64sum" ]] ; then - if [[ "$(md5sum -c "$jailx64sum")" ]] ; then - einfo "Jail integrity OK, moving on" - else - eerror "I won't do that with a corrupted jail" - exit 1 - fi - else - eerror "I won't do that with a missing jail" - exit 1 - fi -} - -jaildkmsbuild () { - checkifroot - if [[ -x /usr/sbin/dkms ]] ; then - for i in $(dkms status | cut -d " " -f1,2 | sed -e 's/,//g' | sed -e 's/ /\//g' | sed -e 's/://g') ; do - dkms install $i - done - fi -} - -jailpkgprep () { - while : true ; do - if [[ ! -d "$ropath" && ! -d "$rwpath" && ! -d "$workpath" && ! -d "$overlaypath" ]] ; then - for i in "$ropath" "$rwpath" "$workpath" "$overlaypath" ; do - mkdir "$i" - done - jailpkgmnt - break - elif [[ -d "$ropath" && -d "$rwdpath" && -d "$workpath" && -d "$overlaypath" ]] ; then - jailpkgdmnt - for i in "$ropath" "$rwpath" "$workpath" "$overlaypath" ; do - rm -rf "$i" - done - continue - fi - done -} - -jailpkgmnt () { - mount -t squashfs "$jailx64" "$ropath" - mount -t overlay -o lowerdir="$ropath",upperdir="$rwpath",workdir="$workpath" overlay "$overlaypath" - mount -o bind packages "$overlaypath"/var/cache/packages - mount -o bind distfiles "$overlaypath"/var/cache/distfiles - mount -t proc proc "$overlaypath"/proc - mount -t sysfs sysfs "$overlaypath"/sys - mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$overlaypath"/dev - mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$overlaypath"/dev/pts - mount -t tmpfs -o nosuid,nodev none "$overlaypath"/dev/shm -} - -jailpkgdmnt () { - umount -l "$overlaypath"/proc > /dev/null 2>&1 - umount -l "$overlaypath"/sys > /dev/null 2>&1 - umount -l "$overlaypath"/dev/pts > /dev/null 2>&1 - umount -l "$overlaypath"/dev/shm > /dev/null 2>&1 - umount -l "$overlaypath"/dev > /dev/null 2>&1 - umount -l "$overlaypath"/var/cache/packages > /dev/null 2>&1 - umount -l "$overlaypath"/var/cache/distfiles > /dev/null 2>&1 - umount -l "$overlaypath" > /dev/null 2>&1 - umount -l "$ropath" > /dev/null 2>&1 -} - -jailpkgsrcmode () { - chroot "$overlaypath" su - "$jailuser" -c "$jailsrcmodecmd" -} - -jailpkgbuild () { - chroot "$overlaypath" su - "$jailuser" -c "$jailportagecmd" -} - -jailpkgstart () { - einfo "Oh no, I'm in jail!" - chroot "$overlaypath" su - "$jailuser" -} - -jailmakepkg () { - checkifroot - checkjailsum - jailpkgprep - jailpkgsrcmode - jailpkgbuild - jailpkgstart - jailpkgdmnt -} diff --git a/src/backend/jailvars.sh b/src/backend/jailvars.sh deleted file mode 100644 index 4a08a26..0000000 --- a/src/backend/jailvars.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash - -export local distupstream="gentoo" -export local distname="redcore" -export local disttarget="desktop" -export local distver="1" -export local kernver="4.9.53-"$distname"-lts" - -export local jailx64=""$distname"_"$distver"_core_x64.squashfs" -export local jailx64sum=""$jailx64".md5sum" - -export local ropath="rodir" -export local rwpath="rwdir" -export local workpath="workdir" -export local overlaypath="overlaydir" - -export local jailuser="root" -export local jailarch="x86_64" -export local jailtarget="${@:2}" -export local jailkernname="kernel-genkernel-"$jailarch"-"$kernver"" -export local jailramfsname="initramfs-genkernel-"$jailarch"-"$kernver"" -export local jailrootpath="$distname"-"$disttarget"-"$distver"-"$jailarch" -export local jailsynctarget=""$jailrootpath"/rootfs" -export local jailsyncsource="/tmp/"$jailrootpath"" -export local jailbootldrpath=""$jailrootpath"/boot/grub" -export local jailefildrpath=""$jailrootpath"/efi/boot" -export local jaildvdpath=""$jailrootpath"/CDroot" -export local jailsquashfspath=""$jailrootpath"/LiveOS" -export local jailrealfspath=""$jaildvdpath"/LiveOS" -export local jailbootldrdlpath="/tmp/bootcore" -export local jailbootldrcfgpath=""$jailbootldrdlpath"/cdroot/boot" -export local jailmainportpath="/usr/ports/"$distupstream"" -export local jailaddonportpath="/usr/ports/"$distname"" -export local jailportcfgtarget="/etc/portage" -export local jailportcfgsource="/opt/"$distname"-build/conf/intel/portage" -export local jailportvcspath="/opt/"$distname"-build" diff --git a/src/backend/libvasile.sh b/src/backend/libvasile.sh index ee2e357..79a46ab 100644 --- a/src/backend/libvasile.sh +++ b/src/backend/libvasile.sh @@ -7,20 +7,38 @@ else exit 1 fi -if [[ -f /usr/lib/vasile/jailvars.sh ]] ; then - source /usr/lib/vasile/jailvars.sh +if [[ -f /usr/lib/vasile/variables_jail.sh ]] ; then + source /usr/lib/vasile/variables_jail.sh else - source jailvars.sh + source variables_jail.sh fi -if [[ -f /usr/lib/vasile/jailcmds.sh ]] ; then - source /usr/lib/vasile/jailcmds.sh +if [[ -f /usr/lib/vasile/commands_jail.sh ]] ; then + source /usr/lib/vasile/commands_jail.sh else - source jailvars.sh + source commands_jail.sh fi -if [[ -f /usr/lib/vasile/jailfuncs.sh ]] ; then - source /usr/lib/vasile/jailfuncs.sh +if [[ -f /usr/lib/vasile/gfunctions_generic.sh ]] ; then + source /usr/lib/vasile/functions_generic.sh else - source jailfuncs.sh + source functions_generic.sh +fi + +if [[ -f /usr/lib/vasile/functions_makepkg.sh ]] ; then + source /usr/lib/vasile/functions_makepkg.sh +else + source functions_makepkg.sh +fi + +if [[ -f /usr/lib/vasile/functions_makeiso.sh ]] ; then + source /usr/lib/vasile/functions_makeiso.sh +else + source functions_makeiso.sh +fi + +if [[ -f /usr/lib/vasile/functions_modeswitch.sh ]] ; then + source /usr/lib/vasile/functions_modeswitch.sh +else + source functions_modeswitch.sh fi diff --git a/src/backend/variables_jail.sh b/src/backend/variables_jail.sh new file mode 100644 index 0000000..4a08a26 --- /dev/null +++ b/src/backend/variables_jail.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +export local distupstream="gentoo" +export local distname="redcore" +export local disttarget="desktop" +export local distver="1" +export local kernver="4.9.53-"$distname"-lts" + +export local jailx64=""$distname"_"$distver"_core_x64.squashfs" +export local jailx64sum=""$jailx64".md5sum" + +export local ropath="rodir" +export local rwpath="rwdir" +export local workpath="workdir" +export local overlaypath="overlaydir" + +export local jailuser="root" +export local jailarch="x86_64" +export local jailtarget="${@:2}" +export local jailkernname="kernel-genkernel-"$jailarch"-"$kernver"" +export local jailramfsname="initramfs-genkernel-"$jailarch"-"$kernver"" +export local jailrootpath="$distname"-"$disttarget"-"$distver"-"$jailarch" +export local jailsynctarget=""$jailrootpath"/rootfs" +export local jailsyncsource="/tmp/"$jailrootpath"" +export local jailbootldrpath=""$jailrootpath"/boot/grub" +export local jailefildrpath=""$jailrootpath"/efi/boot" +export local jaildvdpath=""$jailrootpath"/CDroot" +export local jailsquashfspath=""$jailrootpath"/LiveOS" +export local jailrealfspath=""$jaildvdpath"/LiveOS" +export local jailbootldrdlpath="/tmp/bootcore" +export local jailbootldrcfgpath=""$jailbootldrdlpath"/cdroot/boot" +export local jailmainportpath="/usr/ports/"$distupstream"" +export local jailaddonportpath="/usr/ports/"$distname"" +export local jailportcfgtarget="/etc/portage" +export local jailportcfgsource="/opt/"$distname"-build/conf/intel/portage" +export local jailportvcspath="/opt/"$distname"-build" -- cgit v1.2.3