aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2010-01-18 00:05:59 -0500
committerDave Reisner <d@falconindy.com>2010-01-18 00:05:59 -0500
commitdcff2ddd3f856648487adfe95b4778961c8a4f59 (patch)
tree52abeb732693653c35f6f2ddca9cf0986db45512
parent56a75a989d9da37cfc8edd29c05953b328cb97be (diff)
downloadsquashfu-dcff2ddd3f856648487adfe95b4778961c8a4f59.tar.gz
Reimplement options using getopts
-rwxr-xr-xsquashfu43
1 files changed, 34 insertions, 9 deletions
diff --git a/squashfu b/squashfu
index e6f376b..6c43084 100755
--- a/squashfu
+++ b/squashfu
@@ -358,7 +358,7 @@ usage () {
cat <<HELP
USAGE
- squashfu <operation>
+ squashfu <action>
ACTIONS
-B
@@ -383,13 +383,38 @@ HELP
exit 0
}
-case $1 in
- "-B") action=backup ;;
- "-C") action=resquash_now ;;
- "-Q") action=report ;;
- "-R") shift; action=rollback $1 ;;
- "-U") unmount_all ;;
- *) usage ;;
-esac
+[[ -z $1 ]] && ( usage; exit 1; )
+
+while getopts :BCQR:U opt; do
+ case $opt in
+ B)
+ action=backup
+ ;;
+ C)
+ action=resquash_now
+ ;;
+ Q)
+ action=report
+ ;;
+ R)
+ action="rollback $OPTARG"
+ ;;
+ U)
+ unmount_all
+ exit 0
+ ;;
+ c)
+ [[ -f $OPTARG ]] && source $OPTARG
+ ;;
+ \:)
+ echo "Argument missing from -$OPTARG"
+ usage ;;
+ \?)
+ echo "Unrecognized option -$OPTARG"
+ usage ;;
+ esac >&2
+done
+
+[[ -z $action ]] && ( usage; exit 1; )
action_$action