summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV3n3RiX <venerix@rogentos.ro>2016-11-06 08:50:58 +0000
committerV3n3RiX <venerix@rogentos.ro>2016-11-06 08:50:58 +0000
commit162b0a4c81305967aa35fabe40ded35a95fe9478 (patch)
tree4cec9a5c171ac80e757b8edaeda138ecd3f625f2
parent73ea227a9bc63bd4b091ab53c510ab3f369b1ece (diff)
parent7fdb4e5689cf6cc1c7e524962a5940e64097b6c0 (diff)
merge back into master
-rwxr-xr-xdevmodeset30
-rwxr-xr-xlibvasile221
-rwxr-xr-xmakeiso89
-rwxr-xr-xmakepkg36
-rwxr-xr-xmodereset31
-rwxr-xr-xusermodeset35
-rwxr-xr-xvasile53
7 files changed, 495 insertions, 0 deletions
diff --git a/devmodeset b/devmodeset
new file mode 100755
index 0000000..ac1ff3f
--- /dev/null
+++ b/devmodeset
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+export local portagedir="/usr/portage"
+export local confdir="/etc/portage"
+export local gitdir="/opt/kogaion-build/conf/intel/portage"
+
+fetch_devmode_portage_tree() {
+ if [[ ! -d "$portagedir"/.git ]] ; then
+ cd "$portagedir" && git init > /dev/null 2>&1
+ git remote add origin https://gitlab.com/kogaion/portage.git
+ git pull --depth=1 origin master
+ git branch -u origin/master master
+ rm -rf ""$portagedir"/profiles/updates"
+ fi
+}
+
+set_devmode_portage_tree() {
+ ln -sf "$gitdir" "$confdir"
+ ln -sf "$confdir"/make.conf.amd64-devel "$confdir"/make.conf
+ eselect profile set 1
+ env-update
+ . /etc/profile
+}
+
+main() {
+ fetch_devmode_portage_tree
+ set_devmode_portage_tree
+}
+
+main
diff --git a/libvasile b/libvasile
new file mode 100755
index 0000000..981f265
--- /dev/null
+++ b/libvasile
@@ -0,0 +1,221 @@
+#!/usr/bin/env bash
+
+# import gentoo functions
+source /lib/gentoo/functions.sh
+
+# generic variables
+
+export local releasename="kogaion"
+export local releasetarget="desktop"
+export local releaseversion="3"
+export local kernelver="4.8.5-"$releasename""
+export local chrootx64=""$releasename"_"$releaseversion"_core_x64.squashfs"
+export local chrootx64md5=""$chrootx64".md5"
+
+# build variables
+
+export local rodir="rodir"
+export local rwdir="rwdir"
+export local workdir="workdir" # only needed for overlayfs on kernel greather than 3.18
+export local overlaydir="overlaydir"
+export local chrootuser="root"
+export local chroottarget="${@:2}"
+export local chrootbuildtarget="emerge -kav "$chroottarget""
+export local chrootdevtree="/usr/share/kvasile/devmodeset"
+export local chrootmainoverlay="layman -f -a "$releasename"-"$releasetarget" -o https://gitlab.com/"$releasename"/"$releasename"-"$releasetarget"/raw/master/overlay.xml"
+export local chrootbuildgit="cd /opt && git clone https://gitlab.com/"$releasename"/"$releasename"-build.git"
+
+# iso variables
+
+export local bootcorepath="/tmp/bootcore"
+export local bootcorefiles="/tmp/bootcore/cdroot/boot"
+export local isouser="root"
+export local isousertree="/usr/share/kvasile/usermodeset"
+export local isomainoverlay="layman -f -a "$releasename"-"$releasetarget" -o https://gitlab.com/"$releasename"/"$releasename"-"$releasetarget"/raw/master/overlay.xml"
+export local isobuildgit="cd /opt && git clone https://gitlab.com/"$releasename"/"$releasename"-build.git"
+
+export local isodracutcmd="dracut -N -a dmsquash-live -a pollcdrom -o systemd -o systemd-initrd -o systemd-networkd -o dracut-systemd --force --kver "$kernelver""
+export local isodracutrd="initramfs-"$kernelver".img"
+export local isoeficmd="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"
+export local isochainloadcmd="grub2-mkimage -d /usr/lib64/grub/i386-pc -o core.img -O i386-pc biosdisk part_msdos fat"
+export local isomainarch="x86_64"
+export local isorootdir=""$releasename"-"$releasetarget"-"$releaseversion"-"$isomainarch""
+export local isokernelname="kernel-genkernel-"$isomainarch"-"$kernelver""
+export local isostagingdir="/tmp/"$isorootdir""
+export local isosupersquashdir=""$isorootdir"/CDroot"
+export local isolivesqfsdir=""$isosupersquashdir"/LiveOS"
+export local isoliveosdir=""$isorootdir"/LiveOS"
+export local isosyncdir=""$isorootdir"/rootfs"
+export local isobootdir=""$isorootdir"/boot/grub"
+export local isoefibootdir=""$isorootdir"/efi/boot"
+
+# generic 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
+ einfo "Kernel configuration seems OK, moving on"
+ sleep 1
+ else
+ eerror "Vasile needs OVERLAYFS && SQUASHFS && LOOP DEVICES to work"
+ eerror "Please rebuild the kernel with those activated to use it"
+ exit 1
+ fi
+}
+
+checkroot () {
+ if [[ "$(whoami)" != root ]] ; then
+ eerror "You're not root?...No cookies for you, go away !!!"
+ exit 1
+ fi
+}
+
+checkiflive () {
+ if [[ -L /dev/mapper/live-base ]] ; then
+ eerror "Running in Live mode is unsupported"
+ exit 1
+ fi
+}
+
+chrootchecksum () {
+ while : true ; do
+ if [[ -f "$chrootx64" && -f "$chrootx64md5" ]] ; then
+ einfo "Squashed chroot && Checksum file found"
+ if [[ "$(md5sum -c "$chrootx64md5")" ]] ; then
+ einfo "Squashed chroot checksum passed"
+ sleep 1
+ break
+ else
+ eerror "Squashed chroot checksum failed"
+ exit 1
+ fi
+ else
+ eerror "Squashed chroot || Checksum file not found"
+ exit 1
+ fi
+ done
+}
+
+# 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"/usr/portage/distfiles > /dev/null 2>&1
+ umount -l "$overlaydir" > /dev/null 2>&1
+ umount -l "$rodir" > /dev/null 2>&1
+}
+
+chrootstart () {
+ mount -t squashfs "$chrootx64" "$rodir"
+ mount -t overlay -o lowerdir="$rodir",upperdir="$rwdir",workdir="$workdir" overlay "$overlaydir"
+ mount -o bind packages "$overlaydir"/usr/portage/packages
+ mount -o bind distfiles "$overlaydir"/usr/portage/distfiles
+ 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
+}
+
+chrootdevtree () {
+ einfo "Injecting devmode portage tree"
+ sleep 1
+ chroot "$overlaydir" su - "$chrootuser" -c "$chrootdevtree"
+}
+
+chrootoverlays () {
+ einfo "Injecting "$releasename" "$releasetarget" overlay"
+ sleep 1
+ chroot "$overlaydir" su - "$chrootuser" -c "$chrootmainoverlay"
+}
+
+chrootbuildsystem () {
+ einfo "Injecting "$releasename" buildsystem"
+ sleep 1
+ chroot "$overlaydir" su - "$chrootuser" -c "$chrootbuildgit"
+}
+
+chrootbuild () {
+ einfo "All systems are go!"
+ sleep 1
+ chroot "$overlaydir" su - "$chrootuser" -c "$chrootbuildtarget"
+}
+
+chrootx64 () {
+ einfo "DROPPING YOU TO A ROOT SHELL INTO BUILD ENVIRONMENT"
+ einfo "FIX FAILURES && ADJUST PORTAGE CONFIGURATION FILES"
+ einfo "TEST USEFLAGS && KEYWORDS && MASKS IF REQUIRED"
+ einfo "IN THE END : DO NOT FORGET TO COMMIT YOUR CHANGES"
+ chroot "$overlaydir" su - "$chrootuser"
+}
+
+# iso functions
+
+isostart () {
+ mount -o bind packages "$isosyncdir"/usr/portage/packages
+ mount -t proc proc "$isosyncdir"/proc
+ mount -t sysfs sysfs "$isosyncdir"/sys
+ mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$isosyncdir"/dev
+ mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$isosyncdir"/dev/pts
+ mount -t tmpfs -o nosuid,nodev none "$isosyncdir"/dev/shm
+ mount -t tmpfs -o nosuid,nodev,noexec none "$isosyncdir"/tmp
+}
+
+isostop () {
+ umount -l "$isosyncdir"/proc > /dev/null 2>&1
+ umount -l "$isosyncdir"/sys > /dev/null 2>&1
+ umount -l "$isosyncdir"/dev/pts > /dev/null 2>&1
+ umount -l "$isosyncdir"/dev/shm > /dev/null 2>&1
+ umount -l "$isosyncdir"/dev > /dev/null 2>&1
+ umount -l "$isosyncdir"/tmp > /dev/null 2>&1
+ umount -l "$isosyncdir"/usr/portage/packages > /dev/null 2>&1
+}
+
+isousertree () {
+ einfo "Injecting usermode portage tree"
+ sleep 1
+ chroot "$isosyncdir" su - "$isouser" -c "$isousertree"
+}
+
+isooverlays () {
+ einfo "Injecting "$releasename" "$releasetarget" overlay"
+ sleep 1
+ chroot "$isosyncdir" su - "$isouser" -c "$isomainoverlay"
+}
+
+isobuildsystem () {
+ einfo "Injecting "$releasename" buildsystem"
+ sleep 1
+ chroot "$isosyncdir" su - "$isouser" -c "$isobuildgit"
+}
+
+isoramfs () {
+ chroot "$isosyncdir" su - "$isouser" -c "$isodracutcmd"
+}
+
+isoefiimg () {
+ chroot "$isosyncdir" su - "$isouser" -c "$isoeficmd"
+}
+
+isochainload () {
+ chroot "$isosyncdir" su - "$isouser" -c "$isochainloadcmd"
+}
+
+isoservices () {
+ for service in avahi-daemon cups connman dkms dm-event kogaionlive lightdm lvm2-lvmetad lvm2-monitor NetworkManager ModemManager virtualbox-guest-additions ; do
+ chroot "$isosyncdir" su - "$isouser" -c "systemctl enable "$service""
+ done
+}
+
+isochroot () {
+ einfo "DROPPING YOU TO A ROOT SHELL INTO ISO ENVIRONMENT"
+ einfo "INSTALL APPS & TARGETS & DES YOU WANT INSIDE ISO"
+ einfo "EXIT WHEN YOU'RE DONE AND I'LL CREATE THE IMAGE"
+ chroot "$isosyncdir" su - "$isouser"
+}
diff --git a/makeiso b/makeiso
new file mode 100755
index 0000000..e6ef8dc
--- /dev/null
+++ b/makeiso
@@ -0,0 +1,89 @@
+#!/usr/bin/env bash
+
+prepareiso () {
+ # we really need this folder as quick as possible
+ mkdir -p "$isosyncdir"
+ # create an empty 20GB ext4 fs were our rootfs will stay
+ dd if=/dev/zero of=""$isosyncdir".img" bs=50M count=400
+ mkfs.ext4 ""$isosyncdir".img"
+ # create live iso layout
+ mkdir -p "$isostagingdir"
+ mkdir -p "$isobootdir"
+ mkdir -p "$isoefibootdir"
+ mkdir -p "$isoliveosdir"
+ mkdir -p "$isosupersquashdir"
+ mkdir -p "$isolivesqfsdir"
+ # mount && copy core stage 4 image
+ mount -t squashfs "$chrootx64" "$isostagingdir"
+ mount -t ext4 ""$isosyncdir".img" "$isosyncdir"
+ rsync -aHAXr --progress "$isostagingdir/" "$isosyncdir/"
+ # copy kernel into cdroot
+ cp -avx ""$isosyncdir"/boot/"$isokernelname"" ""$isorootdir"/boot/vmlinuz"
+ # generate live initramfs
+ isostart
+ isoramfs
+ isostop
+ # copy live initramfs into cdroot
+ mv ""$isosyncdir"/boot/"$isodracutrd"" ""$isorootdir"/boot/initrd"
+ # generate live efi image
+ isostart
+ isoefiimg
+ isostop
+ # copy efi image into cdroot
+ mv ""$isosyncdir"/root/bootx64.efi" "$isoefibootdir"
+ chmod 755 ""$isoefibootdir"/bootx64.efi"
+ # generate grub chainloader for syslinux
+ isostart
+ isochainload
+ isostop
+ # copy chainloader parts into cdroot
+ mv ""$isosyncdir"/root/core.img" "$isobootdir"
+ cp -avx ""$isosyncdir"/usr/lib64/grub/i386-pc/lnxboot.img" "$isobootdir"
+ # configure portage && give up control for package / desktop environment installation
+ isostart
+ isooverlays
+ isobuildsystem
+ isousertree
+ isochroot
+ isostop
+ # enable system services
+ isostart
+ isoservices
+ isostop
+ # unmount rootfs before compression
+ umount -l "$isosyncdir" > /dev/null 2>&1
+ # move rootfs in place
+ mv ""$isosyncdir".img" "$isolivesqfsdir"
+ # squash rootfs with best compression
+ mksquashfs "$isosupersquashdir" ""$isorootdir"/squashfs.img" -b 1048576 -comp xz -Xdict-size 100%
+ # move squashed rootfs in place
+ mv ""$isorootdir/"squashfs.img" "$isoliveosdir"
+}
+
+bootcoreiso () {
+ # configure live bootloader
+ git clone https://gitlab.com/"$releasename"/boot-core.git "$bootcorepath"
+ cp -avx "$bootcorefiles" "$isorootdir"
+}
+
+cleanupiso () {
+ umount "$isostagingdir"
+ rm -rf "$isosyncdir"
+ rm -rf "$isostagingdir"
+ rm -rf "$isosupersquashdir"
+ rm -rf "$bootcorepath"
+}
+
+makeiso () {
+ grub2-mkrescue -o ""$releasename"-"$releasetarget"-"$releaseversion"-"$isomainarch".iso" "$isorootdir"
+}
+
+main () {
+ chrootchecksum
+ prepareiso
+ bootcoreiso
+ cleanupiso
+ makeiso
+}
+
+main
diff --git a/makepkg b/makepkg
new file mode 100755
index 0000000..d8590b5
--- /dev/null
+++ b/makepkg
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+chrootprepare () {
+ # check our environment for sanity
+ # if safe, trigger start && break the loop to build packages
+ # else trigger stop && cleanup && check again
+ while : true ; do
+ if [[ ! -d "$rodir" && ! -d "$rwdir" && ! -d "$workdir" && ! -d "$overlaydir" ]] ; then
+ for i in "$rodir" "$rwdir" "$workdir" "$overlaydir" ; do
+ mkdir "$i"
+ done
+ chrootstart
+ break
+ elif [[ -d "$rodir" && -d "$rwdir" && -d "$workdir" && -d "$overlaydir" ]] ; then
+ chrootstop
+ for i in "$rodir" "$rwdir" "$workdir" "$overlaydir" ; do
+ rm -rf "$i"
+ done
+ continue
+ fi
+ done
+}
+
+main () {
+ chrootchecksum
+ chrootprepare
+ chrootoverlays
+ chrootbuildsystem
+ chrootdevtree
+ chrootbuild
+ chrootx64
+ chrootstop
+}
+
+main
+exit 0
diff --git a/modereset b/modereset
new file mode 100755
index 0000000..e961c6a
--- /dev/null
+++ b/modereset
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+export local portagedir="/usr/portage"
+export local confdir="/etc/portage"
+export local gitdir="/opt/kogaion-build"
+
+empty_portage_tree() {
+ if [ -d ""$portagedir"/.git" ] ; then
+ find "$portagedir" -mindepth 1 -name "packages" -prune -o -name "distfiles" -prune -o -exec rm -rf {} \; > /dev/null 2>&1
+ fi
+}
+
+reset_portage_config() {
+ rm ""$confdir"/make.conf"
+ rm ""$confdir"/make.profile"
+ rm "$confdir"
+ rm -rf "$gitdir"
+}
+
+fetch_portage_config() {
+ pushd /opt > /dev/null 2>&1
+ git clone https://gitlab.com/kogaion/kogaion-build.git > /dev/null 2>&1
+ popd > /dev/null 2>&1
+}
+
+main () {
+ empty_portage_tree
+ reset_portage_config
+ fetch_portage_config
+}
+main
diff --git a/usermodeset b/usermodeset
new file mode 100755
index 0000000..0edef40
--- /dev/null
+++ b/usermodeset
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+export local portagedir="/usr/portage"
+export local confdir="/etc/portage"
+export local gitdir="/opt/kogaion-build/conf/intel/portage"
+
+fetch_usermode_portage_tree() {
+ if [[ ! -d "$portagedir"/.git ]] ; then
+ cd "$portagedir" && git init > /dev/null 2>&1
+ git remote add origin https://gitlab.com/kogaion/portage.git
+ git config core.sparsecheckout true
+ echo "profiles/*" >> .git/info/sparse-checkout
+ echo "metadata/*" >> .git/info/sparse-checkout
+ echo "eclass/*" >> .git/info/sparse-checkout
+ echo ".gitignore" >> .git/info/sparse-checkout
+ git pull --depth=1 origin master
+ git branch -u origin/master master
+ rm -rf ""$portagedir"/profiles/updates"
+ fi
+}
+
+set_usermode_portage_tree() {
+ ln -sf "$gitdir" "$confdir"
+ ln -sf "$confdir"/make.conf.amd64-user "$confdir"/make.conf
+ eselect profile set 1
+ env-update
+ . /etc/profile
+}
+
+main() {
+ fetch_usermode_portage_tree
+ set_usermode_portage_tree
+}
+
+main
diff --git a/vasile b/vasile
new file mode 100755
index 0000000..4dd7669
--- /dev/null
+++ b/vasile
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+# Say Hello to Vasile, a modular script to build Redcore Linux packages && ISO images using a clean squashfs + overlayfs chroot
+# Main author : Ghiunhan Mamut (aka V3n3RiX)
+# Dependencies : kernel built with squashfs + overlayfs + loopback support && sys-fs/grub:2 && sys-fs/squashfs-tools && dev-libs/libisoburn && sys-fs/mtools
+#
+
+# Import our variables and functions
+
+source /usr/lib/vasile/libvasile
+
+# Vasile need root privileges and a proper kernel to run
+# Also, running it in live mode is a really bad idea
+
+checkroot
+checkiflive
+kernelconfig
+
+
+case $1 in
+ --makepkg)
+ source /usr/share/vasile/makepkg
+ ;;
+ --makeiso)
+ source /usr/share/vasile/makeiso
+ ;;
+ --resetmode)
+ source /usr/share/vasile/modereset
+ ;;
+ --usermode)
+ source /usr/share/vasile/modereset
+ source /usr/share/vasile/usermodeset
+ ;;
+ --devmode)
+ source /usr/share/vasile/modereset
+ source /usr/share/vasile/devmodeset
+ ;;
+ --help)
+ einfo "Usage: vasile [options]"
+ einfo ""
+ einfo "Options:"
+ einfo "--makepkg : build package/target in a clean squashed core"
+ einfo "--makeiso : build iso based on clean squashed core + targets"
+ einfo "--resetmode : reset INSTALLED Redcore Linux system state - You're on your own, you've been warned!"
+ einfo "--usermode : switch INSTALLED Redcore Linux system state to usermode - use binary packages from repositories"
+ einfo "--devmode : switch INSTALLED Redcore Linux system state to devmode (aka Gentoo mode) - use source packages from portage tree"
+ einfo "--help : display this help and exit"
+ ;;
+ *)
+ eerror "error: no operation specified, use --help for help"
+ ;;
+esac
+
+exit 0