Skip to content

Commit

Permalink
Bash cleanup and use set -e
Browse files Browse the repository at this point in the history
  • Loading branch information
onovy committed Aug 27, 2018
1 parent d110dc3 commit bb4e690
Show file tree
Hide file tree
Showing 36 changed files with 108 additions and 34 deletions.
13 changes: 6 additions & 7 deletions check-all
@@ -1,15 +1,16 @@
#!/bin/sh

set -e

if [ ! -e debian/control ] ; then
echo "$(basename ${PWD}): not a debian package"
echo "$(basename "$PWD"): not a debian package"
exit 0
fi

DIR=$(dirname "$(readlink -f "$0")")
PUSH=

git diff-index --quiet HEAD --
if [ $? -ne 0 ] ; then
if ! git diff-index --quiet HEAD -- ; then
echo "Local git tree has changes"
exit 1
fi
Expand All @@ -21,11 +22,9 @@ for CHECK in $DIR/checks/* ; do
echo "Not executable, skipping..."
continue
fi
OUT=$($CHECK)
STATUS=$?
if [ $STATUS -eq 0 ] ; then
if OUT=$($CHECK) ; then
if [ -n "$OUT" ] ; then
if $DIR/commit "$OUT" ; then
if "$DIR/commit" "$OUT" ; then
PUSH=1
fi
fi
Expand Down
2 changes: 2 additions & 0 deletions checks/0wrap-and-sort
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# OpenStack
if grep-dctrl -q -F Maintainer "openstack-devel@lists.alioth.debian.org" debian/control ||
grep-dctrl -q -F Maintainer "team+openstack@tracker.debian.org" debian/control
Expand Down
2 changes: 2 additions & 0 deletions checks/ancient-x-python-version-field
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

sed -i "/^X-Python-Version: *>= *2\\.[0-7].*$/d" debian/control
sed -i "/^X-Python-Version: *>> *2\\.[0-6].*$/d" debian/control
echo "d/control: Remove ancient X-Python-Version field"
2 changes: 2 additions & 0 deletions checks/ancient-x-python3-version-field
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

sed -i "/^X-Python3-Version: *>= *3\\.[0-4].*$/d" debian/control
sed -i "/^X-Python3-Version: *>> *3\\.[0-3].*$/d" debian/control
echo "d/control: Remove ancient X-Python3-Version field"
2 changes: 2 additions & 0 deletions checks/ancient-xs-python-version-field
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

sed -i "/^XS-Python-Version: *>= *2\\.[0-7].*$/d" debian/control
sed -i "/^XS-Python-Version: *>> *2\\.[0-6].*$/d" debian/control
echo "d/control: Remove ancient XS-Python-Version field"
2 changes: 2 additions & 0 deletions checks/copyright-format
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

sed -i "s#\(^Format: *\)http:#\1https:#g" debian/copyright
MESSAGE="d/copyright: Use https protocol in Format field"

Expand Down
2 changes: 2 additions & 0 deletions checks/copyright-me
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

if [ ! -d .git ] ; then
echo "Not git!"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions checks/gbp.conf
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# OpenStack
if grep-dctrl -q -F Maintainer "openstack-devel@lists.alioth.debian.org" debian/control ||
grep-dctrl -q -F Maintainer "team+openstack@tracker.debian.org" debian/control
Expand Down
5 changes: 4 additions & 1 deletion checks/git-dpm2gbp
@@ -1,7 +1,10 @@
#!/bin/bash

set -e

if ! [ -a "debian/.git-dpm" ] ; then
exit
echo "Not git-dpm layout"
exit 0
fi

# Check upstream branch exists
Expand Down
2 changes: 2 additions & 0 deletions checks/maintainer
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Debian Multimedia Team
if grep-dctrl -q -F Maintainer "debian-multimedia@lists.debian.org" debian/control ; then
sed -i "s#\(^Maintainer:\).*#\1 Debian Multimedia Maintainers <debian-multimedia@lists.debian.org>#g" debian/control
Expand Down
2 changes: 2 additions & 0 deletions checks/min-version-tilde
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# OpenStack
if ! grep-dctrl -q -F Maintainer "openstack-devel@lists.alioth.debian.org" debian/control &&
! grep-dctrl -q -F Maintainer "team+openstack@tracker.debian.org" debian/control
Expand Down
1 change: 1 addition & 0 deletions checks/priority
@@ -1,5 +1,6 @@
#!/bin/bash

set -e

MESSAGE="d/control: Removing redundant Priority field in binary package"

Expand Down
2 changes: 2 additions & 0 deletions checks/pycompat
@@ -1,4 +1,6 @@
#!/bin/bash

set -e

rm -f debian/pycompat
echo "Remove debian/pycompat, it's not used by any modern Python helper"
2 changes: 2 additions & 0 deletions checks/testsuite-field
@@ -1,4 +1,6 @@
#!/bin/bash

set -e

sed -i "/^Testsuite: *autopkgtest *$/d" debian/control
echo "d/control: Remove Testsuite field, not needed anymore"
2 changes: 2 additions & 0 deletions checks/trailing-whitespace-changelog
@@ -1,4 +1,6 @@
#!/bin/bash

set -e

sed -i -e 's@[[:space:]]*$@@g' debian/changelog
echo "d/changelog: Remove trailing whitespaces"
2 changes: 2 additions & 0 deletions checks/trailing-whitespace-control
@@ -1,4 +1,6 @@
#!/bin/bash

set -e

sed -i -e 's@[[:space:]]*$@@g' debian/control
echo "d/control: Remove trailing whitespaces"
2 changes: 2 additions & 0 deletions checks/trailing-whitespace-rules
@@ -1,4 +1,6 @@
#!/bin/bash

set -e

sed -i -e 's@[ ]*$@@g' debian/rules
echo "d/rules: Remove trailing whitespaces"
2 changes: 2 additions & 0 deletions checks/vcs-salsa
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

if [ ! -d .git ] ; then
echo "Not git!"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions checks/xs-testsuite-field
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

if grep-dctrl -q -X -F XS-Testsuite 'autopkgtest' debian/control ; then
sed -i "/^XS-Testsuite: *autopkgtest *$/d" debian/control
echo "d/control: Remove XS-Testsuite field, not needed anymore"
Expand Down
9 changes: 6 additions & 3 deletions clone-check-all
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

if [ "$#" -ne 1 ]; then
echo "$0 <repository_name>"
exit 1
Expand All @@ -17,11 +19,12 @@ pushd "$TMP" >/dev/null

rm -rf repo
git clone "${URL}/${REPO}" repo >/dev/null 2>&1
cd repo

$DIR/check-all
(
cd repo || exit
"$DIR/check-all"
)

cd ..
popd >/dev/null

rm -rf "$TMP"
9 changes: 6 additions & 3 deletions commit
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

if [ "$#" -lt 1 ]; then
echo "$0 <message> [--test]"
exit 1
Expand All @@ -10,25 +12,26 @@ MESSAGE=$1
if [ -n "$(git diff)" ] || [ "$2" == "--test" ] ; then
CHANGELOG=$(dpkg-parsechangelog)

cat debian/changelog | grep '^ --' | wc -l | grep -q "^1$"
set +e
grep -c '^ --' debian/changelog | grep -q "^1$"
ONE_ENTRY=$?

echo "$CHANGELOG" | grep -q '^Distribution: UNRELEASED$'
UNRELEASED=$?

echo "$CHANGELOG" | grep '^ ' | sed 's/ \* //' | grep -F -q "$MESSAGE"
PRESENT=$?
set -e

if ! (
([ $UNRELEASED -eq 0 ] && [ $PRESENT -eq 0 ]) || \
([ $ONE_ENTRY -eq 0 ] && [ $UNRELEASED -eq 0 ])
); then

MAINTAINER=$(grep-dctrl -n -F Maintainer '' -s Maintainer debian/control)
MAINTAINER=$(grep-dctrl -n -F Maintainer '' -s Maintainer debian/control || true)
case $MAINTAINER in
*debian-multimedia@lists.debian.org*) ;;
*pkg-multimedia-maintainers@lists.alioth.debian.org*) ;;
*debian-multimedia@lists.debian.org*) ;;
*pkg-salt-team@lists.alioth.debian.org*) ;;
*)
dch --no-auto-nmu "$MESSAGE"
Expand Down
2 changes: 2 additions & 0 deletions parallel-clone-check-all
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

if [ "$#" -ne 1 ]; then
echo "$0 <list_filename>"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions tests/checks/copyright-me/pre.in
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Git
git init >/dev/null
git commit --author "$DEBFULLNAME <$DEBEMAIL>" -m "Dummy commit" --allow-empty >/dev/null
Expand Down
2 changes: 2 additions & 0 deletions tests/checks/copyright-me/pre.out
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Current year
CURRENT_YEAR=$(date +%Y)
sed -i "s/#CURRENT_YEAR#/$CURRENT_YEAR/g" debian/copyright
2 changes: 2 additions & 0 deletions tests/checks/git-dpm2gbp/pre.in
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Git
git init >/dev/null
git add . >/dev/null
Expand Down
2 changes: 2 additions & 0 deletions tests/checks/git-dpm2gbp/pre.out
@@ -1,3 +1,5 @@
#!/bin/bash

set -e

rm debian/.git-dpm
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Git
git init >/dev/null

Expand Down
2 changes: 2 additions & 0 deletions tests/checks/git-dpm2gbp/python-apps-team-with-patch/pre.in
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Git
git init >/dev/null
git add . >/dev/null
Expand Down
2 changes: 2 additions & 0 deletions tests/checks/git-dpm2gbp/python-apps-team-with-patch/pre.out
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Not git-dpm
rm debian/.git-dpm

Expand Down
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Git
git init >/dev/null

Expand Down
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Git
git init >/dev/null
git add . >/dev/null
Expand Down
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

# Not git-dpm
rm debian/.git-dpm

Expand Down
22 changes: 13 additions & 9 deletions tests/checks/run.sh
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

DIR=$(dirname "$(readlink -f "$0")")

export DEBFULLNAME="#DEBFULLNAME#"
Expand All @@ -23,7 +25,7 @@ for CHECK in $DIR/* ; do
continue
fi
pushd "$TEST" >/dev/null
echo -n $(basename "$TEST")": "
echo -n "$(basename "$TEST"): "
rm -rf test.in test.out
cp -r in test.in

Expand All @@ -46,34 +48,36 @@ for CHECK in $DIR/* ; do
fi
popd >/dev/null

MESSAGE=$(../../../../../checks/$CHECK_NAME)
set +e
MESSAGE="$("../../../../../checks/$CHECK_NAME")"
STATUS=$?
set -e
popd >/dev/null

EXP_MESSAGE=$(cat message 2>/dev/null)
DIFF=$(diff -Naur --exclude=.git test.in test.out)
EXP_MESSAGE=$(cat message 2>/dev/null || true)
DIFF=$(diff -Naur --exclude=.git test.in test.out || true)

if [ "$STATUS" -ne 0 ] ; then
if [ -e "fail" ] ; then
PASS=$(($PASS + 1))
PASS=$((PASS + 1))
echo "OK"
else
FAIL=$(($FAIL + 1))
FAIL=$((FAIL + 1))
echo "Exit status $STATUS"
fi
elif [ "$DIFF" != "" ] ; then
FAIL=$(($FAIL + 1))
FAIL=$((FAIL + 1))
echo "Diff"
echo "#############################"
echo "$DIFF"
echo "#############################"
elif [ "$EXP_MESSAGE" != "" ] && [ "$EXP_MESSAGE" != "$MESSAGE" ] ; then
FAIL=$(($FAIL + 1))
FAIL=$((FAIL + 1))
echo "Wrong message"
echo "Expected: $EXP_MESSAGE"
echo "Got: $MESSAGE"
else
PASS=$(($PASS + 1))
PASS=$((PASS + 1))
echo "OK"
fi

Expand Down
2 changes: 2 additions & 0 deletions tests/checks/vcs-salsa/pre.in
@@ -1,4 +1,6 @@
#!/bin/bash

set -e

git init >/dev/null
git remote add origin ssh://git@salsa.debian.org/debian/project.git

0 comments on commit bb4e690

Please sign in to comment.