diff --git a/update-spec-version.sh b/update-spec-version.sh index 340a8ea..e037227 100755 --- a/update-spec-version.sh +++ b/update-spec-version.sh @@ -1,30 +1,51 @@ #!/bin/bash +set -e -SPEC=rpm/$1.spec -CPP=src/main.cpp +# Parse the project file, target name, version and release +PRO=$(ls *.pro | head -1) +NAME=$(grep -e "TARGET *= *" $PRO | sed "s/TARGET *= *//g") +VER=$(grep -e "VER *= *" $PRO | sed "s/VER *= *//g") +REL=$(grep -e "REL *= *" $PRO | sed "s/REL *= *//g") -if [[ $(grep "^Version: $2$" $SPEC | wc -l) = 0 ]] -then - sed -i "/^Version: /c\Version: $2" $SPEC - touch $CPP -fi -if [[ $(grep "^Release: $3$" $SPEC | wc -l) = 0 ]] -then - sed -i "/^Release: /c\Release: $3" $SPEC - touch $CPP +SPEC=rpm/$NAME.spec +YAML=rpm/$NAME.yaml +CPP=src/$NAME.cpp + +if [ ! -f $CPP ]; then + CPP=src/main.cpp + if [ ! -f $CPP ]; then + echo "Main C++ file not found!" + exit 1 + fi fi +echo "$NAME $VER-$REL" -YAML=rpm/$1.yaml -if [[ $(grep "^Version: $2$" $YAML | wc -l) = 0 ]] -then - sed -i "/^Version: /c\Version: $2" $YAML - touch $CPP +if [[ -f $SPEC && ($(grep "^Version: $VER$" $SPEC | wc -l) == 0 || $(grep "^Release: $REL$" $SPEC | wc -l) == 0) ]]; then + sed -i "/^Version: /c\Version: $VER" $SPEC + sed -i "/^Release: /c\Release: $REL" $SPEC + echo " $SPEC updated" +elif [[ ! -f $SPEC ]]; then + echo " .spec file not found" +else + echo " $SPEC up to date" fi -if [[ $(grep "^Release: $3$" $YAML | wc -l) = 0 ]] -then - sed -i "/^Release: /c\Release: $3" $YAML - touch $CPP + +if [[ -f $YAML && ($(grep "^Version: $VER$" $YAML | wc -l) == 0 || $(grep "^Release: $REL$" $YAML | wc -l) == 0) ]]; then + sed -i "/^Version: /c\Version: $VER" $YAML + sed -i "/^Release: /c\Release: $REL" $YAML + echo " $YAML updated" +elif [[ ! -f $YAML ]]; then + echo " .yaml file not found" +else + echo " $YAML up to date" +fi + +if [[ -f $CPP ]]; then + touch $CPP + echo " $CPP touched" +else + echo " .cpp file not found" fi -echo true +exit 0