For compiling a set of applications for multiple platforms, there are certain build exports which need to be set.
The sample command is as under:
source exports_file.sh <plaforms> <feature1> <feature2> <feature3>
Here the positional parameter <platform>
is mandatory whereas the other parameters such as <feature1>, <feature2>, <feature3>
are optional. These have to be enabled only if the corresponding feature is needed in the build.
The set of valid command line options are:
source exports_file.sh <plaforms> <feature1> <feature2> <feature3>
source exports_file.sh <plaforms> <feature1> <feature2>
source exports_file.sh <plaforms> <feature1>
source exports_file.sh <plaforms>
Important thing to note is that the script should return an error if:
1) <platform>
input param is not provided by the user.
2) Value of <platform>
input param is not present in the list i.e. it is other than 1234, 1235 or 1236.
3) Any other feature apart from <feature1>, <feature2>, <feature3>
are provided as input.
I have written a script which works fine but I'm not sure if its checking the validity of all the input parameters correctly.
$> cat exports_file.sh
if [ $# -gt 0 ]; then
platform=$1
# Common exports
unset PLATFORM
unset ENABLE_FEATURE_1
unset ENABLE_FEATURE_2
unset ENABLE_FEATURE_3
echo "INFO: Setting common exports for $platform"
if [ $platform == "1234" ]
then
export PLATFORM=91234
elif [ $platform == "1235" ]
then
export PLATFORM=91235
elif [ $platform == "1236" ]
then
export PLATFORM=91236
else
echo "ERROR: Exports are not defined for $platform."
exit 1
fi
# Check for feature based exports <feature1> <feature2> <feature3>
for var in "$@"
do
if [ $var == "arg2" ]
then
export ENABLE_FEATURE_1=Y
elif [ $var == "arg3" ]
then
export ENABLE_FEATURE_2=Y
elif [ $var == "arg4" ]
then
export ENABLE_FEATURE_3=Y
else
echo "ERROR: unrecognised argument '$var'";
exit 1
fi
done
else
echo "ERROR: No inputs parameters provided to the scripts."
echo "Usage: source exports_file.sh <plaforms> <feature1> <feature2> <feature3>"
fi`
Is there a better way to write this script. Most important thing is to ensure the validity of all the input parameters.