#!/bin/bash
# Apply all Gibraltar patch packages
# Copyright Rene Mayrhofer 2003

if [ $# -gt 1 ] || [ $# -eq 1 -a "$1" != "skip-hooks" ]; then
  echo "Usage: $0 [skip-hooks]"
  exit 1
fi

apply_patches() {
  echo "Applying all patches from $1:"
  if [ -n "`ls $1`" ]; then
    for patch in $1/*; do
      patchme "$patch" $skip_hooks
      ret=$?
      case $ret in 
        10|100) # either for another Gibraltar version or invalid signature
          echo "Removing patch from directory"
          rm $patch
          ;;
      esac
    done
  fi
}

patchdir_cd=/system/patches
patchdir_etc=/etc/gibraltar/patches
skip_hooks=$1

apply_patches $patchdir_cd
apply_patches $patchdir_etc

exit 0
