2012-12-03 07:00:06 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# TODO:
|
2013-01-22 03:22:28 +00:00
|
|
|
# support setting flag when no upstream default
|
2012-12-03 07:00:06 +00:00
|
|
|
|
|
|
|
set -e +x
|
|
|
|
|
2013-01-22 03:22:28 +00:00
|
|
|
USAGE="Usage: $0 FLAG [True|False]"
|
2012-12-03 07:00:06 +00:00
|
|
|
|
2013-01-22 03:22:28 +00:00
|
|
|
if [ $# -ne 2 ]; then
|
2012-12-03 07:00:06 +00:00
|
|
|
echo "$USAGE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
FLAG=$1
|
|
|
|
|
2013-01-22 03:22:28 +00:00
|
|
|
NEW=$2
|
|
|
|
case $NEW in
|
|
|
|
True) OLD=False ;;
|
|
|
|
False) OLD=True ;;
|
|
|
|
*) echo "Flag value can only be set to True or False" ; exit 1 ;;
|
|
|
|
esac
|
2012-12-03 07:00:06 +00:00
|
|
|
|
|
|
|
CABALFILE=$(ls *.cabal)
|
|
|
|
|
|
|
|
if [ $(echo $CABALFILE | wc -w) -ne 1 ]; then
|
|
|
|
echo "There needs to be one .cabal file in the current dir!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -q -i "^flag *$FLAG" $CABALFILE; then
|
|
|
|
echo "$CABALFILE does have flag $FLAG"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -A3 -i "^flag *$FLAG" $CABALFILE | grep -q -i "default:"; then
|
|
|
|
echo "$CABALFILE: $FLAG flag might not have a default"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -A3 -i "^flag *$FLAG" $CABALFILE | grep -q -i "default: *$OLD"; then
|
|
|
|
echo "$CABALFILE: $FLAG flag already defaults to $NEW"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $CABALFILE.orig ]; then
|
|
|
|
BACKUP=.orig
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -i$BACKUP -e "/[Ff]lag *$FLAG/,/[Dd]efault: *$OLD/ s/\([Dd]efault: *\)$OLD/\1$NEW/" $CABALFILE
|