#!/bin/sh

source ~/sbostuff/sbostuff.sh
export SBOLINT=no

usage() {
  cat <<EOF
Usage:
orphanize <build> [<build> ...]
orphanize -m <maintainer>
EOF
}


orphanize_builds() {
  local b
  for b in "$@"; do
    cdsb "$b" && sbonewmaint nobody && git commit -a -m'Orphaned (unmaintained).'
  done
}

orphanize_maint() {
  local i
  cdsb
  for i in $( git grep "^MAINTAINER=\"$@\"" '*/*/*.info' | cut -d/ -f1,2 ); do
    orphanize_builds "$i"
  done
}

case "$1" in
  "-m") shift; orphanize_maint "$@" ;;
  ""|"-") usage ;;
  *) orphanize_builds "$@" ;;
esac
