dotfiles/bin/asf-check

116 lines
3.1 KiB
Plaintext
Raw Normal View History

2022-09-08 16:17:06 +00:00
#!/bin/sh
set -e
check() {
URL=$1
RELEASE=$(basename $URL)
WORKDIR=/tmp/apache-devlake-asf-check/$RELEASE
mkdir -p $WORKDIR
# Get files information
METAFILE=$WORKDIR/meta
if [ ! -f "$METAFILE" ]; then
curl -L $URL | grep -oP 'href="\K(apache.+?)(?=")' > "$METAFILE"
2022-09-08 16:17:06 +00:00
cat "$METAFILE"
fi
ARCHIVE=$(awk 'FNR == 1 {print}' $METAFILE)
GPG_SIGN=$ARCHIVE.asc
SHA_SUM=$ARCHIVE.sha512
echo ARCHIVE: "$ARCHIVE"
echo GPG_SIGN: "$GPG_SIGN"
echo SHA_SUM: "$SHA_SUM"
# Download files
for FILE in "$ARCHIVE" "$GPG_SIGN" "$SHA_SUM"; do
LOCAL_PATH=$WORKDIR/$FILE
if [ ! -f "$LOCAL_PATH" ]; then
FILE_URL=${URL%%/}/$FILE
echo "Downloading from $FILE_URL"
curl -o "$LOCAL_PATH" $FILE_URL
else
echo "$LOCAL_PATH exists"
fi
done
# Uncompress archive
ARCHIVE_PATH=$WORKDIR/$ARCHIVE
SRC=$WORKDIR/${ARCHIVE%%.tar.gz}
rm -rf $SRC
tar xvf "$ARCHIVE_PATH" -C "$WORKDIR"
echo SRC: "$SRC"
# Checksums and signatures
echo "** VERIFY CHECKSUM **"
(cd $WORKDIR && sha512sum -c "$SHA_SUM" 1>&2)
echo
echo "** VERIFY SINGUATURES **"
GPG_SIGN_PATH=$WORKDIR/$GPG_SIGN
gpg --verify $GPG_SIGN_PATH $ARCHIVE_PATH 1>&2
echo
# LICENSE/NOTICE/DISCLAIMER files exist
echo "** CHECK LICENSE NOTICE DISCLAIMER **"
DISCLAIMER=DISCLAIMER
test -s $SRC/LICENSE 1>&2 && echo LICENSE exists
test -s $SRC/NOTICE 1>&2 && echo NOTICE exists
if test -s $SRC/DISCLAIMER-WIP 1>&2 && echo DISCLAIMER-WIP exists; then
DISCLAIMER=DISCLAIMER-WIP
! test -s $SRC/DISCLAIMER
else
test -s $SRC/DISCLAIMER 1>&2 && echo DISCLAIMER exists
fi
echo
# check unexpected binary files
echo "** CHECK UNEXPRECTED BINARY FILES **"
2023-12-13 12:40:39 +00:00
UNEXPRECTED_BIN_FILES="$(find $SRC -type f ! -size 0 ! -name '*.jpg' ! -name '*.png' ! -name '*.ico' -exec grep -IL . '{}' \;)"
2022-09-08 16:17:06 +00:00
if [ -n "$UNEXPRECTED_BIN_FILES" ]; then
printf "Found unexpected binary files: \n%s\n" "$UNEXPRECTED_BIN_FILES"
else
echo "no unexpected files"
fi
echo
# check headers
echo "** CHECK ASF HEADER **"
2023-04-21 17:07:23 +00:00
HEADER="$(cat $SRC/backend/.golangci-goheader.template)"
2022-09-08 16:17:06 +00:00
test -n "$HEADER"
2023-12-13 12:40:39 +00:00
OIFS="$IFS"
IFS='
'
for FN in `find "$SRC" -name '*.go'`; do
echo "$FN"
if ! grep -qF "$HEADER" "$FN"; then
2022-09-08 16:17:06 +00:00
echo $FN has no ASF header
exit -1
fi
done
2023-12-13 12:40:39 +00:00
IFS="$OIFS"
for FN in $(find "$SRC" -name '*.js' -not -path './config-ui/node_modules/*'); do
2022-09-08 16:17:06 +00:00
if ! cut -c4- $FN | grep -qF "$HEADER"; then
echo $FN has no ASF header
exit -1
fi
done
echo "All *.go *.js contains ASF headers"
echo "
2023-12-13 12:40:39 +00:00
+1 (binding)
2022-09-08 16:17:06 +00:00
I checked these items:
- Download links are valid.
- Checksums and signatures.
- LICENSE/NOTICE/$DISCLAIMER files exist
- No unexpected binary files
- All source files have ASF headers (**.go and **.js)
" | xsel -b
echo "All checks passed, the +1 mail body is copied to clipboard"
}
check $1