230 lines
5.5 KiB
Bash
Executable file
230 lines
5.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
LOCKFILE=/usr/portage/local/gentooup.lock
|
|
|
|
PORTAGE_OPTIONS=("--keep-going" "--autounmask-write" "--binpkg-respect-use=y" "--autounmask-continue")
|
|
|
|
PORTAGE_UPGRADE_OPTIONS=("-vuNDk")
|
|
|
|
PORTAGE_ASK="-a"
|
|
|
|
INTERACTIVE=1
|
|
|
|
CHROOTED=0
|
|
|
|
SYNC_COMMAND="emaint sync -a"
|
|
|
|
BACKTRACK_INTERACTIVE=30 # 10 is the default
|
|
BACKTRACK_BATCH=200
|
|
|
|
int_handler() {
|
|
exit 0
|
|
}
|
|
|
|
trap int_handler INT TERM EXIT
|
|
|
|
SOURCE_ONLY=("--getbinpkg=n" "--usepkg=n")
|
|
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
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--no-sync)
|
|
echo "not syncing"
|
|
SYNC_COMMAND=""
|
|
shift
|
|
;;
|
|
--no-lock)
|
|
echo "not locking"
|
|
NO_LOCK=1
|
|
shift
|
|
;;
|
|
--full)
|
|
echo "Do a full upgrade including build dependencies"
|
|
PORTAGE_UPGRADE_OPTIONS+=("--with-bdeps=y")
|
|
shift
|
|
;;
|
|
--sequentialized)
|
|
shift
|
|
SEQUENTIALIZED="$1"
|
|
shift
|
|
echo "execute sequentialized: $SEQUENTIALIZED"
|
|
;;
|
|
--binary-only)
|
|
shift
|
|
BINARY_ONLY="$1"
|
|
shift
|
|
echo "emerge binary only: $BINARY_ONLY"
|
|
;;
|
|
--exclude)
|
|
shift
|
|
echo "excluding: $1"
|
|
PORTAGE_OPTIONS+=("--exclude" "$1")
|
|
shift
|
|
;;
|
|
--batch)
|
|
echo "We do not ask questions"
|
|
PORTAGE_ASK=""
|
|
INTERACTIVE=0
|
|
shift
|
|
;;
|
|
--interactive)
|
|
echo "We do ask questions"
|
|
INTERACTIVE=1
|
|
PORTAGE_ASK="-a"
|
|
shift
|
|
;;
|
|
--*)
|
|
echo "Unknown option $1"
|
|
shift
|
|
;;
|
|
*)
|
|
echo "Positional arguments aren't supported"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ $INTERACTIVE == 1 ]] ; then
|
|
BACKTRACK="$BACKTRACK_INTERACTIVE"
|
|
else
|
|
BACKTRACK="$BACKTRACK_BATCH"
|
|
fi
|
|
|
|
PORTAGE_OPTIONS+=( "--backtrack=$BACKTRACK" )
|
|
|
|
if [[ $CHROOTED == 1 ]] ; then
|
|
SYNC_COMMAND=""
|
|
fi
|
|
|
|
myemerge() {
|
|
echo emerge "$@"
|
|
emerge "$@"
|
|
echo "emerge return value: $?"
|
|
}
|
|
|
|
if [[ -z "$NO_LOCK" ]] ; then
|
|
mkdir -p $(dirname "$LOCKFILE")
|
|
exec {FD_LOCK}<>"$LOCKFILE"
|
|
echo "Try to acquire lock for $LOCKFILE"
|
|
if ! flock -x -w 60 "$FD_LOCK" ; then
|
|
echo "Could not acquire lock for $LOCKFILE"
|
|
exit 1
|
|
fi
|
|
echo "Lock acquired"
|
|
fi
|
|
|
|
if [[ -n ${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
|
|
myemerge -v1 sys-apps/portage app-portage/gentoolkit
|
|
else
|
|
myemerge -v1 portage
|
|
fi
|
|
fi
|
|
|
|
for exclusion in "$SEQUENTIALIZED" "$BINARY_ONLY" ; do
|
|
EXCLUSION_OPTION=("--exclude" "$exclusion")
|
|
done
|
|
myemerge $PORTAGE_ASK "${PORTAGE_UPGRADE_OPTIONS[@]}" "${PORTAGE_OPTIONS[@]}" "${EXCLUSION_OPTION[@]}" world
|
|
if [[ $INTERACTIVE == 1 ]] ; then
|
|
dispatch-conf
|
|
echo "dispatch-conf return value: $?"
|
|
|
|
myemerge "${PORTAGE_UPGRADE_OPTIONS[@]}" "${PORTAGE_OPTIONS[@]}" "${SEQUENTIALIZED_OPTION[@]}" world
|
|
|
|
dispatch-conf
|
|
echo "dispatch-conf return value: $?"
|
|
fi
|
|
|
|
if [[ -n $SEQUENTIALIZED ]] ; then
|
|
myemerge "${PORTAGE_UPGRADE_OPTIONS[@]}" "${PORTAGE_OPTIONS[@]}" -j1 -1 --noreplace $SEQUENTIALIZED
|
|
fi
|
|
if [[ -n $BINARY_ONLY ]] ; then
|
|
myemerge "${PORTAGE_UPGRADE_OPTIONS[@]}" "${PORTAGE_OPTIONS[@]}" --getbinpkgonly=y -1 --noreplace $BINARY_ONLY
|
|
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 *******************"
|
|
|
|
myemerge -v "${PORTAGE_OPTIONS[@]}" "${SOURCE_ONLY[@]}" "${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"/}"
|
|
myemerge --noreplace gentoo-sources:"${CURRENTKERNELVERSION/"-gentoo"/}"
|
|
myemerge -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
|
|
myemerge "${PORTAGE_OPTIONS[@]}" --deselect gentoo-sources:"${CURRENTKERNELVERSION/"-gentoo"/}"
|
|
fi
|
|
|
|
if [[ -n "$(which updateEfiStubsAndBootManager.sh)" && $CHROOTED == "1" ]] ; then
|
|
updateEfiStubsAndBootManager.sh
|
|
fi
|
|
|
|
if [[ -n "$(which restart-services)" && $CHROOTED == "1" ]] ; then
|
|
restart-services -l
|
|
fi
|
|
|
|
echo "Started at $STARTDATE"
|
|
echo " Ended at $(date -Iseconds)"
|