ghc-rpm-macros/cabal-tweak-dep-ver
Petr Šabata 7b45c3d854 RHEL 9.0.0 Alpha bootstrap
The content of this branch was automatically imported from Fedora ELN
with the following as its source:
https://src.fedoraproject.org/rpms/ghc-rpm-macros#78bda0dce526795284ef1644e7d0dd6e0b3511dc
2020-10-15 01:21:28 +02:00

37 lines
615 B
Bash
Executable File

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