Commit 00b3ce20 authored by Lucas Sulzbach's avatar Lucas Sulzbach
Browse files

SCRUM#498: Improve argument parsing and help

parent 0acc12fa
...@@ -20,30 +20,50 @@ ...@@ -20,30 +20,50 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA. # USA.
_HELP=false
_DIST="nodistro"
_ARCH="amd64"
if [ "$(id -u)" != "0" ]; then while true; do
echo You must have more power to run this script case "$1" in
exit -1 -h | --help ) _HELP=true; shift ;;
-d | --distro ) _DIST=$2; shift; shift ;;
-a | --arch ) _ARCH=$2; shift; shift ;;
-* ) echo "Unrecognized option. Try with --help."; exit 1 ;;
* ) break ;;
esac
done
if [ ${_HELP} = true ]; then
echo "Usage: sudo $0 [OPTION] [ARGUMENT]..."
echo ""
echo "Examples:"
echo " sudo $0 --distro le6/testing # Generate default arch (amd64) le6 iso image"
echo " sudo $0 -d le6/testing -a i386 # Generate i386 architecture le6 iso image"
echo ""
echo "Options:"
echo " -h, --help Show this help list"
echo " -d, --distro [DIST] Select iso image's distro"
echo " -a, --arch [amd64 | i386] Select iso image's architecture"
exit 2
fi fi
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo "Usage: $0 [dist] [arch]" if [ ${_DIST} = "nodistro" ]; then
echo "Argument [arch] is optional. Default architecture: amd64" echo "No distro. Try with --help."
exit 1 exit 1
fi fi
if [ "$1" == '--help' ]; then
echo "Usage: $0 [dist] [arch]"
echo "Argument [arch] is optional. Default architecture: amd64"
exit 2
fi
_DIST=$1 if [ ${_ARCH} != "amd64" -a ${_ARCH} != "i386" ]; then
echo "Unrecognized architecture. Try with --help."
exit 1
fi
if [ $# -ne 2 ]; then if [ "$(id -u)" != "0" ]; then
_ARCH="amd64" echo "You must have more power to run this script. Are you root?"
else exit -1
_ARCH=$2
fi fi
export PREFIX=$(pwd) export PREFIX=$(pwd)
source ${PREFIX}/conf/$_DIST/create-iso.conf \ source ${PREFIX}/conf/$_DIST/create-iso.conf \
|| log ERROR "configuration file not found for dist: \"${_DIST}\"" || log ERROR "configuration file not found for dist: \"${_DIST}\""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment