ghc-rpm-macros/cabal-tweak-drop-dep

33 lines
538 B
Bash
Executable File

#!/bin/sh
set -e +x
function fail {
echo "$0: $1" >&2
exit 1
}
USAGE="Usage: $0 dep"
if [ $# -ne 1 ]; then
fail "$USAGE"
fi
DEP=$1
CABALFILE=$(ls *.cabal)
if [ $(echo $CABALFILE | wc -w) -ne 1 ]; then
fail "There needs to be one .cabal file in the current dir!"
fi
if [ ! -f $CABALFILE.orig ]; then
BACKUP=.orig
fi
if grep "$DEP" $CABALFILE | sed -e "s/$DEP//" | grep -q -e "[A-Za-z]"; then
fail "$0: deleting whole $DEP lines not safe - try more precise pattern"
fi
sed -i$BACKUP -e "/$DEP/d" $CABALFILE