2012-06-22 04:46:59 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2012-06-22 05:47:51 +00:00
|
|
|
set -e +x
|
|
|
|
|
2012-06-22 04:46:59 +00:00
|
|
|
USAGE="Usage: $0 dep old new"
|
|
|
|
|
|
|
|
if [ $# -ne 3 ]; then
|
|
|
|
echo "$USAGE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-06-22 05:47:51 +00:00
|
|
|
DEP=$1
|
|
|
|
OLD=$(echo $2 | sed -e "s/*/\\\\*/g" -e "s/\./\\\\./g")
|
|
|
|
NEW=$3
|
|
|
|
|
|
|
|
CABALFILE=$(ls *.cabal)
|
2012-06-22 04:46:59 +00:00
|
|
|
|
2012-06-22 05:47:51 +00:00
|
|
|
if [ $(echo $CABALFILE | wc -w) -ne 1 ]; then
|
2012-06-22 04:46:59 +00:00
|
|
|
echo "There needs to be one .cabal file in the current dir!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-06-22 08:03:46 +00:00
|
|
|
BREAK=[^[:alnum:]-]
|
|
|
|
|
|
|
|
if ! grep -q "$BREAK$DEP$BREAK[^,]*$OLD" $CABALFILE; then
|
2012-06-22 05:47:51 +00:00
|
|
|
echo "$CABALFILE does not match: $DEP $OLD"
|
2012-06-22 04:46:59 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-06-22 06:21:43 +00:00
|
|
|
if [ ! -f $CABALFILE.orig ]; then
|
|
|
|
BACKUP=.orig
|
|
|
|
fi
|
|
|
|
|
2012-06-22 08:03:46 +00:00
|
|
|
sed -i$BACKUP -e "s/\($BREAK$DEP$BREAK[^,]*\)$OLD/\1$NEW/g" $CABALFILE
|