From 5297a584020a758655f130b9eef7dc012e3635b5 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Sat, 19 Sep 2015 02:32:46 +0000 Subject: [PATCH] Add tools scripts to overlay --- scripts/make_kernel.sh | 40 ++++++++++++++++ scripts/update_box.sh | 26 +++++++++++ scripts/update_portage.sh | 97 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100755 scripts/make_kernel.sh create mode 100755 scripts/update_box.sh create mode 100755 scripts/update_portage.sh diff --git a/scripts/make_kernel.sh b/scripts/make_kernel.sh new file mode 100755 index 0000000..6a236b9 --- /dev/null +++ b/scripts/make_kernel.sh @@ -0,0 +1,40 @@ +#!/bin/sh +set -e + +cd /usr/src/linux + +# make clean +# make oldconfig +make menuconfig +make all ${MAKEOPTS} +make modules_install + +NEW=$(make kernelversion) +TARGET=/boot + +# If EFI store kernel under EFI +[ -d /sys/firmware/efi ] && [ -d /boot/EFI/Gentoo ] && TARGET=/boot/EFI/Gentoo + +dracut --xz -H --force --strip ${TARGET}/initrd-${NEW} ${NEW} + +export INSTALL_PATH=${TARGET} +make install + +if [ ! -d /sys/firmware/efi ]; then + grub2-mkconfig -o ${TARGET}/grub/grub.cfg + pushd ${TARGET} >/dev/null + ln -sf System.map-${NEW} System.map + popd > /dev/null +fi + +echo "Building tools from within kernel sources..." +echo " cpupower (requires pciutils):" +cd tools/power/cpupower && make ${MAKEOPTS} +cp -a cpupower /usr/local/bin +cp -a libcpupower.so* /usr/lib + +echo "After successful boot of new kernel run:" +echo " root # emerge @module-rebuild" +# eselect opengl set ati + +cp /usr/src/linux/.config /etc/kernel/kernel-config-${NEW} diff --git a/scripts/update_box.sh b/scripts/update_box.sh new file mode 100755 index 0000000..971407f --- /dev/null +++ b/scripts/update_box.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -e + +# parallel jobs to speed up configure runs etc. +# but only half as many if CPU cores > 4 +CPUS=$(nproc) +[ $CPUS -ge 4 ] && JOBS="--jobs $((CPUS/2))" +emerge --ask --update --deep --newuse --keep-going --accept-properties=-interactive --with-bdeps=y ${JOBS} world + +echo "Going to remove unneeded packages ..." +emerge --depclean + +if [ -x $(which localepurge) ]; then + echo "Removing unneeded locales..." + localepurge +fi + +echo "Fixing dependencies..." +revdep-rebuild -i + +echo "Updating eix cache..." +eix-update -q + +echo "Cleaning up archives.." +eclean -q -d packages +eclean -q -d distfiles diff --git a/scripts/update_portage.sh b/scripts/update_portage.sh new file mode 100755 index 0000000..5bde9c3 --- /dev/null +++ b/scripts/update_portage.sh @@ -0,0 +1,97 @@ +#!/bin/sh +# set -x + +PORTAGE="/usr/portage" +# By default store SquashFS backing file under /mnt/portage +SQFS_PORTAGE="/mnt/portage/portage.sqfs" +# Store temporary overlayFS within portage tmpdir +OVERLAY="$(portageq envvar PORTAGE_TMPDIR)/portage.overlayfs" +OVERLAY_NAME=portage_overlay + +usage () { + cat << EOF +Usage: $0 [-p portage_tree] [-s squashfs_file] +EOF + exit 0 +} + +# mount squashed portage incl. writeable overlay +mount_overlay () { + # Make sure backing tree is mounted, try to mount otherwise + mountpoint -q ${PORTAGE} || mount ${PORTAGE} && echo "Mounted ${PORTAGE}." + + # mount the overlay on top of existing live portage tree + mkdir -p ${OVERLAY} ${OVERLAY}.work + mount | grep -q ${OVERLAY_NAME} || mount -t overlay ${OVERLAY_NAME} \ + -olowerdir=${PORTAGE},upperdir=${OVERLAY},workdir=${OVERLAY}.work \ + ${PORTAGE} && echo "Mounted Overlay file system." +} + +# umount overlay and clean up temp dirs +umount_overlay () { + umount ${OVERLAY_NAME} && rm -rf ${OVERLAY} ${OVERLAY}.work + echo "Overlay file system unmounted." +} + +# umount current, replace and mount new +replace_squashfs () { + mountpoint -q ${PORTAGE} + if [ $? -eq 0 ]; then + umount ${PORTAGE} && echo "Unmounted ${PORTAGE}." + if [ $? -ne 0 ]; then + echo "Could not unmount ${PORTAGE} !" + echo "New portage snapshot is at ${SQFS_PORTAGE}.new" + exit 1 + fi + fi + + if [ -f ${SQFS_PORTAGE} ]; then + mv ${SQFS_PORTAGE} ${SQFS_PORTAGE}.previous + else + echo "No current squashFS backing file ${SQFS_PORTAGE} found,\ + assuming initial setup." + fi + mv ${SQFS_PORTAGE}.new ${SQFS_PORTAGE} && \ + mount ${PORTAGE} && echo "Updated tree mounted at ${PORTAGE}." +} + +# Create new squashfs image +create_squashfs () { + mksquashfs ${PORTAGE} ${SQFS_PORTAGE}.new -comp xz -noappend \ + -no-progress && echo "SquashFS snapshot created at ${SQFS_PORTAGE}.new" +} + +# Any custom changes to the portage tree +customize () { + echo "Applying local customizations ..." + + # Delete any package mask + [ -f ${PORTAGE}/profiles/hardened/linux/amd64/package.mask ] && \ + rm -f ${PORTAGE}/profiles/hardened/linux/amd64/package.mask + + # Reenable nvidia + perl -i -p -e 's/^(app-admin\/conky nvidia|x11-drivers\/nvidia|nvidia|video_cards_nvidia|vdpau|cuda|opencl)/# $1/;' \ + ${PORTAGE}/profiles/hardened/linux/use.mask \ + ${PORTAGE}/profiles/hardened/linux/amd64/use.mask \ + ${PORTAGE}/profiles/hardened/linux/amd64/package.use.mask +} + +while getopts "p:s:" OPTIONS; do + case $OPTIONS in + p) PORTAGE=$OPTARG;; + s) SQFS_PORTAGE=$OPTARG;; + ?) usage;; + esac +done + +[ -d ${PORTAGE} ] || { echo "${PORTAGE} is not a directory!"; usage; } + +mount_overlay +emaint sync -r gentoo + +# Optional +customize + +create_squashfs +umount_overlay +replace_squashfs