diff --git a/sabayon-maint-helper b/sabayon-maint-helper new file mode 100755 index 0000000..4bfd979 --- /dev/null +++ b/sabayon-maint-helper @@ -0,0 +1,89 @@ +#!/bin/bash +set -e +. /sbin/sabayondevkit-functions.sh + +help_msg() { + + echo " + sabayon-maint-helper: + +Script for builder boxes maintenance. + +-h|--help This message. +--installed Upgrades all the packages installed in the box. +--obsolete Upgrades ONLY the packages that are listed obsolete in eix-test-obsolete. +--all Tries to upgrade all package without any euristics +--category Tries to upgrade/install all the packages in the specified category + e.g. sabayon-maint-helper "app-office" + +Some options could be set also as environment variables: +EMERGE_DEFAULT_ARGS Default emerge options + +NOTE: This script MUST be execute as root. +" +} + + +parse_args() { + + local short_opts="h" + local long_opts="help arch: host-arch: unprivileged stagingdir: image-descr: image:" + + $(set -- $(getopt -u -q -a -o "$short_opts" -l "$long_opts" -- "$@")) + + while [ $# -gt 0 ] ; do + case "$1" in + + -h|--help) + help_msg + exit 1 + ;; + --installed) + echo "Trying to upgrade all the installed packages" + rebuild_all + shift + ;; + --obsolete) + echo "Upgrading the packages that are marked as obsolete" + build_obsolete + shift + ;; + --all) + echo "Upgrading/Installing everything available to install" + build_all_availables + ;; + --category) + echo "Upgrading/Installing everything inside the '$2' category" + build_category_installed "$2" + ;; + --) + help_msg + exit 1 + ;; + *) + echo "Invalid parameter $1." + exit 1 + ;; + + esac + + shift + done + + return 0 +} + +main() { + + if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 + fi + + [ -z "$@" ] && help_msg && exit 1 + + parse_args "$@" + +} + +main "$@" diff --git a/sabayondevkit-functions.sh b/sabayondevkit-functions.sh index 2ca128e..9c38ed5 100644 --- a/sabayondevkit-functions.sh +++ b/sabayondevkit-functions.sh @@ -9,46 +9,9 @@ check_docker_requirements(){ die() { echo "$@" 1>&2 ; exit 1; } -build() { -local SEARCH=$1 -local EMERGE_DEFAULT_ARGS=${2:---accept-properties=-interactive --verbose --oneshot --nospinner --noreplace --quiet-build=y --quiet-fail --fail-clean=y --complete-graph --buildpkg} -for i in $(EIX_LIMIT=0 eix --only-names --pure-packages "$SEARCH/" | xargs echo | uniq); - do - echo "Building $i" - emerge $EMERGE_DEFAULT_ARGS -o $i && \ - emerge $EMERGE_DEFAULT_ARGS $i - done -} - -build_installed() { - local SEARCH=$1 - local EMERGE_DEFAULT_ARGS=${2:---accept-properties=-interactive --newuse --noreplace --changed-use --update --verbose --oneshot --nospinner --quiet-build=y --quiet-fail --fail-clean=y --complete-graph --buildpkg} - - for i in $(EIX_LIMIT=0 eix -I --only-names --pure-packages "$SEARCH/" | xargs echo | uniq); - do - echo "Building $i" - emerge $EMERGE_DEFAULT_ARGS $i - done -} - -build_all_availables() { -for i in $(cat /usr/portage/profiles/categories | xargs echo | uniq); - do - build "$i/" - done -} - -rebuild_all() { -for i in $(cat /usr/portage/profiles/categories | xargs echo | uniq); - do - build_installed "$i/" - done -} - build_sync() { - emerge-webrsync || exit 1 - emerge --sync layman -S + emerge --sync eix-update || exit 1 pushd /opt/sabayon-build/ git stash @@ -57,3 +20,65 @@ build_sync() { git reset --heard origin/master popd } + +build_category() { + local SEARCH=$1 + build_sync + for i in $(EIX_LIMIT=0 eix --only-names --pure-packages "$SEARCH/" | xargs echo | uniq); + do + echo "Building $i" + emerge ${EMERGE_DEFAULT_ARGS:---accept-properties=-interactive --verbose --oneshot --nospinner --noreplace --quiet-build=y --quiet-fail --fail-clean=y --complete-graph --buildpkg} $i + done +} + +build_obsolete() { + build_sync + for i in $(EIX_LIMIT=0 eix-test-obsolete | grep '\[U\]' | awk '{ print $2 }' | xargs echo | uniq); + do + echo "Build $i" + emerge ${EMERGE_DEFAULT_ARGS:---accept-properties=-interactive --verbose --oneshot --nospinner --quiet-build=y --quiet-fail --fail-clean=y --complete-graph --buildpkg --noreplace} $i + done +} + +build_category_installed() { + local SEARCH=$1 + build_sync + for i in $(EIX_LIMIT=0 eix -I --only-names --pure-packages "$SEARCH/" | xargs echo | uniq); + do + echo "Building $i" + emerge ${EMERGE_DEFAULT_ARGS:---accept-properties=-interactive --newuse --noreplace --changed-use --update --verbose --oneshot --nospinner --quiet-build=y --quiet-fail --fail-clean=y --complete-graph --buildpkg} $i + done +} + +build_all_availables() { + for i in $(cat /usr/portage/profiles/categories | xargs echo | uniq); + do + build_category "$i/" + done +} + +rebuild_all() { +for i in $(cat /usr/portage/profiles/categories | xargs echo | uniq); + do + build_category_installed "$i/" + done +} + +get_category() { + local CATEGORY=$1 + local PACKS + for i in $(EIX_LIMIT=0 eix --only-names --pure-packages "$CATEGORY/" | xargs echo | uniq); + do + PACKS+="$i " + done + echo $PACKS +} + +get_all_availables() { + local RES + for i in $(cat /usr/portage/profiles/categories | xargs echo | uniq); + do + RES+="$(get_category $i) " + done + echo $RES +}