#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: bin/sde-reschedule-package
|
|
# Copyright (C) 2008 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
#Description: Reschedule packages from the builds
|
|
#Alias: pkg
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
|
|
|
|
. "$SDEROOT/lib/libsde.in"
|
|
|
|
reschedule_usage() {
|
|
local progname=${0##*/}
|
|
cat <<EOT
|
|
Usage: ${progname//-/ } [<options>] <package_1> ...
|
|
|
|
Supported Options:
|
|
--all|-a every package
|
|
--new|-N every package updated since it was built
|
|
--deps|-D every package depending on the others
|
|
|
|
--cfg|-c <config> process a given config (multiple supported)
|
|
--any|-A process any available config
|
|
|
|
--dry-run|-n don't really reschedule
|
|
--soft|-s don't remove the packages when rescheduling
|
|
--force|-f try to remove them even if we can't validate the package
|
|
EOT
|
|
}
|
|
|
|
shortopts='aNDc:Ansf'
|
|
longopts='help,all,new,deps,cfg:,any,soft,dry-run,force'
|
|
options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
|
|
if [ $? -ne 0 ]; then
|
|
reschedule_usage
|
|
exit -1
|
|
fi
|
|
|
|
# load new arguments list
|
|
eval set -- "$options"
|
|
|
|
reschedule_all=
|
|
reschedule_new=
|
|
reschedule_dependers=
|
|
reschedule_any=
|
|
reschedule_soft=
|
|
reschedule_dry=
|
|
reschedule_force=
|
|
|
|
reschedule_configs=
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--help)
|
|
reschedule_usage
|
|
exit 0 ;;
|
|
|
|
--all|-a) reschedule_all=yes ;;
|
|
--new|-N) reschedule_new=yes ;;
|
|
--deps|-D) reschedule_dependers=yes ;;
|
|
--any|-A) reschedule_any=yes ;;
|
|
--soft|-s) reschedule_soft=yes ;;
|
|
--dry-run|-n) reschedule_dry=yes ;;
|
|
--force|-f) reschedule_force=yes ;;
|
|
|
|
--cfg|-c) reschedule_configs="$reschedule_configs $2"
|
|
shift ;;
|
|
|
|
--) shift; break ;;
|
|
*) echo_abort 1 "$1: Unknown argument, aborting."
|
|
esac
|
|
shift
|
|
done
|
|
|
|
. "$SDEROOT/lib/sde-config.in"
|
|
. "$SDEROOT/lib/sde-package.in"
|
|
|
|
reschedule_package()
|
|
{
|
|
local config="$1" pkg= sandbox=
|
|
local logs= log=
|
|
shift
|
|
|
|
[ $# -gt 0 ] || return
|
|
|
|
sandbox="$SDEROOT/build/$( config_id "$config" )"
|
|
for pkg; do
|
|
logs=$(ls -1 "$sandbox/var/adm/logs"/?-$pkg.{err,out,log} \
|
|
2> /dev/null)
|
|
|
|
[ -n "$logs" -o -s "$sandbox/var/adm/packages/$pkg" ] || continue
|
|
|
|
echo "$config: Removing $pkg..."
|
|
|
|
if [ "$reschedule_dry" != "yes" ]; then
|
|
if [ "$reschedule_soft" != "yes" ]; then
|
|
mine -rf -R "$sandbox" "$pkg"
|
|
fi
|
|
|
|
# in the case $SDEROOT includes spaces
|
|
echo "$logs" | while read log; do
|
|
rm -f "$log"
|
|
done
|
|
fi
|
|
done
|
|
}
|
|
|
|
# which configs?
|
|
#
|
|
if [ "$reschedule_any" = "yes" ]; then
|
|
reschedule_configs=$( config_list )
|
|
|
|
[ -n "$reschedule_configs" ] || echo_abort 1 "No config found."
|
|
elif [ -z "$reschedule_configs" ]; then
|
|
# try default
|
|
|
|
y="$( config_id default )"
|
|
|
|
if [ -z "$y" ]; then
|
|
echo_abort 1 "No config found."
|
|
elif [ -d "$SDEROOT/build/$y/" ]; then
|
|
reschedule_configs=default
|
|
else
|
|
exit 0
|
|
fi
|
|
else
|
|
z="$reschedule_configs"
|
|
reschedule_configs=
|
|
for x in $z; do
|
|
y=$( config_id "$x" )
|
|
if [ -z "$y" ]; then
|
|
echo_warning "$x: Invalid config."
|
|
elif [ -d "$SDEROOT/build/$y/" ]; then
|
|
reschedule_configs="$reschedule_configs $x"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# any config ?
|
|
[ -n "$reschedule_configs" ] || exit 0
|
|
|
|
if [ "$reschedule_all" = "yes" ]; then
|
|
# every single package
|
|
#
|
|
for x in $reschedule_configs; do
|
|
y="$SDEROOT/build/$( config_id $x )/var/adm/logs"
|
|
reschedule_package "$x" $( ls -1d "$y"/* 2> /dev/null |
|
|
sed -e 's|.*/.-\(.*\)\..*|\1|' )
|
|
done
|
|
exit $?
|
|
elif [ -n "$reschedule_new" ]; then
|
|
# every modified package
|
|
#
|
|
$SDEROOT/bin/sde-reschedule-new \
|
|
${reschedule_dry:+--dry-run} \
|
|
${reschedule_dependers:+--deps} \
|
|
${reschedule_soft:+--soft} \
|
|
$reschedule_configs
|
|
fi
|
|
|
|
reschedule_packages=
|
|
for x; do
|
|
if package_exists "$x"; then
|
|
# in db
|
|
reschedule_packages="$reschedule_packages $x"
|
|
elif [ "$reschedule_force" = yes ]; then
|
|
echo_warning "$x: Unknown package, but forcing..."
|
|
reschedule_packages="$reschedule_packages $x"
|
|
else
|
|
echo_warning "$x: Invalid package"
|
|
fi
|
|
done
|
|
|
|
[ $UID -eq 0 -o "$reschedule_dry" = "yes" ] ||
|
|
echo_abort 1 "You have to be superuser to proceed, sorry."
|
|
|
|
set -- $reschedule_packages
|
|
|
|
for x in $reschedule_configs; do
|
|
reschedule_package "$x" "$@"
|
|
if [ "$reschedule_dependers" = "yes" ]; then
|
|
$SDEROOT/bin/sde-reschedule-dependers \
|
|
${reschedule_dry:+--dry-run} \
|
|
${reschedule_soft:+--soft} \
|
|
-c "$x" "$@"
|
|
fi
|
|
done
|