#!/bin/sh
# rm
# Wrapper to strip GNU rm switches.

RM=/bin/rm

help() {
   echo "rm shim for BusyBox tar"
}

if [ -z "${1}" ]; then
   exec ${RM}
fi

# We're using busybox, right?
if ! ${RM} -h 2>&1 | grep -q "^BusyBox" ; then
   help;
   echo "ERR:  This only works with BusyBox"
   exit 1
fi

# Switch parser
while [ -n "${1}" ]; do
   case ${1} in
   --*)
      # Long options.  Whatever.  Let BB deal with it.
      USESWITCH="${USESWITCH} ${1}"
      shift 1
      ;;
   # Filter lonely switches.
   -v)
      shift 1
      ;;
   # Filter combined switches.
   -*)
      for SWITCH in $(echo ${1} | sed 's/./& /g'); do
         case ${SWITCH} in
         -)
            USESWITCH="${USESWITCH} -"
            ;;
         v)
            ;;
         *)
            USESWITCH="${USESWITCH}${SWITCH}"
            ;;
         esac
      done
      shift 1
      ;;
   *)
      # Not a switch, bye.
      break
      ;;
   esac
done

${RM} ${USESWITCH} "$@"
