helper/gentooup.sh
layman 0575ae669c gentooup.sh: update gentoolkit with portage if installed
Otherwise cirular dependecies prevent portage upgrade
2019-11-07 08:08:15 +01:00

142 lines
3.6 KiB
Bash
Executable file

#!/bin/bash
PORTAGE_OPTIONS=("--keep-going" "--autounmask-write" "--binpkg-respect-use=y" "--binpkg-changed-deps=y" "--verbose-conflicts" "--backtrack=100")
PORTAGE_UPGRADE_OPTIONS=("-vuNDk")
PORTAGE_ASK="-a"
INTERACTIVE=1
CHROOTED=0
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 detected! -> skipping --ask"
PORTAGE_ASK=""
fi
if [[ ! -t 1 ]] ; then
echo "No tty connected! -> skipping --ask"
echo "Waiting 10s for manual abortion..."
sleep 10
PORTAGE_ASK=""
INTERACTIVE=0
fi
if [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then
CHROOTED=1
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
if [[ $CHROOTED == 1 ]] ; then
SYNC_COMMAND="layman -S"
fi
#any parameter prevents syncing
if [[ ! -z ${SYNC_COMMAND} ]] ; then
${SYNC_COMMAND}
eix-update >& /dev/null
fi
if eix -u -# sys-apps/portage > /dev/null ; then
echo "portage update detected -> merging it"
if eix -u -# app-portage/gentoolkit > /dev/null ; then
emerge -v1 sys-apps/portage app-portage/gentoolkit
else
emerge -v1 portage
fi
fi
echo "emerge options: ${PORTAGE_OPTIONS[*]}"
emerge $PORTAGE_ASK "${PORTAGE_UPGRADE_OPTIONS[@]}" "${PORTAGE_OPTIONS[@]}" world
echo "emerge return value: $?"
if [[ $INTERACTIVE == 1 ]] ; then
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: $?"
fi
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 --getbinpkg=n --usepkg=n ${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
#Currently chroots are used to build and preserve packages!
if [[ $CHROOTED == 0 ]] ; then
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
fi
echo "***************** remove unneeded packages *******************"
echo Started at "$STARTDATE"
if [[ $(qlist -I gentoo-sources) != "" ]] ; then
#make sure that current kernel sources are kept:
CURRENTKERNELVERSION="$(uname -r)"
echo current running kernel:"${CURRENTKERNELVERSION/"-gentoo"/}"
emerge --noreplace gentoo-sources:"${CURRENTKERNELVERSION/"-gentoo"/}"
emerge -a "${PORTAGE_OPTIONS[@]}" --depclean
if [[ "$(grep -c gentoo-sources /var/lib/portage/world)" -gt 2 ]] ; then
echo too many kernelversion in world file!
grep gentoo-source /var/lib/portage/world
fi
emerge "${PORTAGE_OPTIONS[@]}" --deselect gentoo-sources:"${CURRENTKERNELVERSION/"-gentoo"/}"
fi
if [[ -n "$(which restart_services)" && $CHROOTED == "1" ]] ; then
restart_services -l
fi
echo "Started at $STARTDATE"
echo " Ended at $(date -Iseconds)"