1
0
Fork 0

Add tools scripts to overlay

This commit is contained in:
Stefan Reimer 2015-09-19 02:32:46 +00:00
parent b751e35ffb
commit 5297a58402
3 changed files with 163 additions and 0 deletions

40
scripts/make_kernel.sh Executable file
View File

@ -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}

26
scripts/update_box.sh Executable file
View File

@ -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

97
scripts/update_portage.sh Executable file
View File

@ -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