commit 2229e253e1316b38d69c4a394ab71965d9da6949 Author: Tobias Klaus Date: Thu Nov 9 00:11:56 2017 +0100 initial addition of gentoo-helpers diff --git a/buildCurrentSymlinkedKernel.sh b/buildCurrentSymlinkedKernel.sh new file mode 100755 index 0000000..e0d3cf3 --- /dev/null +++ b/buildCurrentSymlinkedKernel.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +if [ ! -f /usr/src/linux/.config ] && [ -f /proc/config.gz ] ; then + echo "**************** building kernel ***********" + + LWD="$PWD" + TIMESTAMP=$(date +%F-%H_%M_%S) + cd /usr/src/linux || exit 1 + + zcat /proc/config.gz > .config + + make olddefconfig + mount /boot + + (make -j5 CC="ccache gcc" && make install && make modules_install && make firmware_install) > "buildlog-$TIMESTAMP" || tail -n 20 "buildlog-$TIMESTAMP" + + GRUBMKONFIG="$(which grub2-mkconfig)" + if [[ -z "$GRUBMKONFIG" ]] ; then + GRUBMKONFIG="$(which grub-mkconfig)" + fi + + if [[ -f /boot/grub2/grub.cfg && -n "$GRUBMKONFIG" ]] ; then + "$GRUBMKONFIG" -o /boot/grub2/grub.cfg + elif [[ -f /boot/grub/grub.cfg && -n "$GRUBMKONFIG" ]] ; then + "$GRUBMKONFIG" -o /boot/grub/grub.cfg + else + echo "please update bootloader manually!" + fi + cd "${LWD}" || exit 1 +fi + diff --git a/buildUpgradePackages.sh b/buildUpgradePackages.sh new file mode 100755 index 0000000..e6dd437 --- /dev/null +++ b/buildUpgradePackages.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +PKGDIR="/usr/portage/packages" + +for atom in $(emerge -uDN --pretend --quiet world | grep ^'\[ebuild' | sed -e 's/.* \b\([a-z0-9\-]\+\/[\_A-Za-z\.0-9\-]\+\)\b.*/\1/g'); +do + if [[ ! -f "$PKGDIR/$atom.tbz2" ]] + then + #build one by one. This takes more time, however it builds all possible packages. + echo "building $atom " + emerge --quiet --keep-going -B "=${atom}" >> /dev/null + if [[ $? ]] + then + SUCCESS="$atom $SUCCESS" + else + FAILURE="$atom $FAILURE" + fi + fi +done + +if [[ -n "${SUCCESS}" ]] +then + echo "Successfully build: ${SUCCESS}" +fi + +if [[ -n "${FAILURE}" ]] +then + echo "Build Failures: ${FAILURE}" +fi diff --git a/gentooup.sh b/gentooup.sh new file mode 100755 index 0000000..a0399d2 --- /dev/null +++ b/gentooup.sh @@ -0,0 +1,94 @@ +#!/bin/bash + + +PORTAGE_OPTIONS=("--keep-going" "--autounmask-write" "--binpkg-respect-use=y" "--binpkg-changed-deps=y" "--verbose-conflicts") + +PORTAGE_UPGRADE_OPTIONS=("-vuNDk") + +PORTAGE_ASK="-a" + +SYNC_COMMAND="emaint sync -a" + +int_handler() { + exit 0 +} + +trap int_handler INT TERM EXIT + +STARTDATE="$(date -Iseconds)" + +if [[ -x /etc/cron.daily/porticron ]] ; then + echo "porticron" + PORTAGE_ASK="" +fi + +if [[ ${1} == "--no-sync" || ${2} == "--no-sync" ]] ; then + echo "not syncing" + SYNC_COMMAND="" +fi + +if [[ ${1} == "--full" || ${2} == "--full" ]] ; then + echo "Do a full upgrade including build dependencies" + PORTAGE_UPGRADE_OPTIONS+=("--with-bdeps=y") +fi + +#any parameter prevents syncing +if [[ ! -z ${SYNC_COMMAND} ]] ; then + ${SYNC_COMMAND} + eix-update >& /dev/null & +fi + +echo "emerge options: ${PORTAGE_OPTIONS[*]}" +emerge $PORTAGE_ASK "${PORTAGE_UPGRADE_OPTIONS[@]}" "${PORTAGE_OPTIONS[@]}" world +echo "emerge return value: $?" + +dispatch-conf +echo "dispatch-conf return value: $?" + +emerge "${PORTAGE_UPGRADE_OPTIONS[@]}" "${PORTAGE_OPTIONS[@]}" world +echo emerge return value: $? + +dispatch-conf +echo dispatch-conf return value: $? + +SETS=("@preserved-rebuild") + +if eix -eI smart-live-rebuild &> /dev/null ; then + SETS+=("@smart-live-rebuild") +fi + +echo "Started at $STARTDATE" +echo "***************** rebuild packages *******************" +echo "run emerge -v ${PORTAGE_OPTIONS[*]} ${SETS[*]}" +emerge -v "${PORTAGE_OPTIONS[@]}" "${SETS[@]}" + +if [[ -n "$(which webappup.sh 2> /dev/null)" ]] ; then + webappup.sh +elif [[ -x "${HOME}/bin/webappup.sh" ]] ; then + "${HOME}/bin/webappup.sh" +fi + +echo "**************** clean /etc/portage/ ***************" +portpeek -rq + +echo "**************** clean /usr/portage/distfiles ***********" +eclean-dist -d + +echo "**************** clean /usr/portage/packages ***********" +eclean-pkg + +if [[ -n "$(which buildCurrentSymlinkedKernel.sh 2> /dev/null)" ]] ; then + buildCurrentSymlinkedKernel.sh +elif [[ -x "${HOME}/bin/buildCurrentSymlinkedKernel.sh" ]] ; then + "${HOME}/bin/buildCurrentSymlinkedKernel.sh" +fi + +echo "***************** remove unneeded packages *******************" +echo Started at "$STARTDATE" +emerge -a "${PORTAGE_OPTIONS[@]}" --depclean + +if [[ -n "$(which restart_services)" ]] ; then + restart_services -l +fi +echo "Started at $STARTDATE" +echo " Ended at $(date -Iseconds)" diff --git a/globalflaggieLocalUse.sh b/globalflaggieLocalUse.sh new file mode 100755 index 0000000..260735a --- /dev/null +++ b/globalflaggieLocalUse.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e + + +for FLAG in "$@" ; do + FLAGMATCH=${FLAG/#+/} + FLAGMATCH=${FLAGMATCH/#-/} + FLAGMATCH=${FLAGMATCH/#%/} + for atom in $(eix -# --use "$FLAGMATCH") ; do + echo "$atom $FLAG" + flaggie "$atom" "$FLAG" + done +done + diff --git a/mountVirtualFS.sh b/mountVirtualFS.sh new file mode 100755 index 0000000..eeda972 --- /dev/null +++ b/mountVirtualFS.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +NEWBASE="$1" + +mount --rbind /dev "$NEWBASE/dev" +mount --rbind /sys "$NEWBASE/sys" +mount --bind /usr/portage "$NEWBASE/usr/portage/" +mount -t proc none "$NEWBASE/proc" + +cp /etc/resolv.conf "$NEWBASE/etc/" diff --git a/webappup.sh b/webappup.sh new file mode 100755 index 0000000..19405ae --- /dev/null +++ b/webappup.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +if [[ -n "$(which webapp-config)" ]] ; then + +echo "***************** upgrading webapps *******************" + + for webapp in $(ls /var/db/webapps/ ) ; do + #we assume a clean system where only ONE app is freshly available and this one app is newer than the currently installed + available_app=$(webapp-config --list-unused-installs | grep $webapp) + if [[ -z "$available_app" ]] ; then + continue + fi + new_version=$(echo $available_app|sed -e "s/^${webapp}-\(.*\)$/\1/") + echo updates for ${webapp}! + echo new version: $new_version + for install in $(webapp-config --list-installs $webapp) ; do + host=$(echo $install | cut -d / -f 4) + webdir=$(echo $install | cut -d / -f 6-) + + if [[ -z $webdir ]] ; then + webdir="" + dirflag="--dir /" + else + dirflag="--dir $webdir" + fi + + infostring=$(webapp-config --host $host $dirflag --show-installed) + echo $infostring + webapp_version=$(echo $infostring | cut -d\ -f2) + webapp_test=$(echo $infostring | cut -d\ -f1) + + if [[ -d /var/www/$host/htdocs/$webdir ]] ; then + COMMAND="webapp-config --secure --host $host $dirflag -U $webapp $new_version" + echo upgrade $webapp from $webapp_version to $new_version in $host/$webdir ? type yes to continue, anything else will abort + echo the command in question: + echo $COMMAND + read ANSWEAR + if [[ $ANSWEAR == "yes" ]] ; then + $COMMAND +## CONFIG_PROTECT="/var/www/$host/htdocs/$webdir/" dispatch-conf + fi + fi + done + done +fi diff --git a/wherefrom.sh b/wherefrom.sh new file mode 100755 index 0000000..3f8e8ea --- /dev/null +++ b/wherefrom.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +INSTALLED_SETS="$(cut -d\@ -f2 < /var/lib/portage/world_sets)" + +echo installed sets: $INSTALLED_SETS + +DEFAULT_LOCATION="/etc/portage/sets/" + +SET_LOCATIONS="$(grep location -rh /etc/portage/repos.conf | sed -e "s/location = \(.*\)$/\1\/sets/") $DEFAULT_LOCATION" +#echo all setlocations: $SET_LOCATIONS +for location in $SET_LOCATIONS ; do + if [[ ! -d $location ]] ; then continue ; fi + for setlocation in $location/* ; do +# echo testing $setlocation + setname=$(basename $setlocation) + if echo $INSTALLED_SETS | grep -qw $setname ; then + echo installed: $setlocation + INSTALLEDSETLOCATION="${INSTALLEDSETLOCATION} ${setlocation}" + fi + done +done + +INSTALLEDSETLOCATION="${INSTALLEDSETLOCATION} /var/lib/portage/world" + +echo installed setfiles: $INSTALLEDSETLOCATION +echo +echo +for SET in $INSTALLEDSETLOCATION ; do + #echo looking for $1 in $SET + grep -H $1 $SET | grep -v ":#" +done