2019-08-13 15:31:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e +x
|
|
|
|
|
2020-06-18 02:56:14 +00:00
|
|
|
function fail {
|
|
|
|
echo "$0: $1" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:31:29 +00:00
|
|
|
USAGE="Usage: $0 dep"
|
|
|
|
|
|
|
|
if [ $# -ne 1 ]; then
|
2020-06-18 02:56:14 +00:00
|
|
|
fail "$USAGE"
|
2019-08-13 15:31:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
DEP=$1
|
|
|
|
CABALFILE=$(ls *.cabal)
|
|
|
|
|
|
|
|
if [ $(echo $CABALFILE | wc -w) -ne 1 ]; then
|
2020-06-18 02:56:14 +00:00
|
|
|
fail "There needs to be one .cabal file in the current dir!"
|
2019-08-13 15:31:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
BREAK=[^[:alnum:]-]
|
|
|
|
|
|
|
|
if ! grep -q "$BREAK$DEP$BREAK[^,]*" $CABALFILE; then
|
2020-06-18 02:56:14 +00:00
|
|
|
fail "$CABALFILE does not match: $DEP"
|
2019-08-13 15:31:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $CABALFILE.orig ]; then
|
|
|
|
BACKUP=.orig
|
|
|
|
fi
|
|
|
|
|
|
|
|
if grep -q "$BREAK$DEP$BREAK[^,]*&&" $CABALFILE; then
|
|
|
|
sed -i$BACKUP -e "s/\($BREAK$DEP$BREAK[^&,]*[^ ]\+\) *&&[^,]*/\1/g" $CABALFILE
|
|
|
|
fi
|
|
|
|
|
|
|
|
if grep -q "$BREAK$DEP$BREAK[^,]*==" $CABALFILE; then
|
|
|
|
sed -i$BACKUP -e "s/\($BREAK$DEP$BREAK[^=,]*\)==\([^,*]*\)\.\*/\1>=\2/g" $CABALFILE
|
|
|
|
fi
|