2020-07-04 23:47:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#############################################################################
|
2020-07-06 21:38:45 +02:00
|
|
|
# tools/checkrelease.sh
|
2020-07-04 23:47:02 +02:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership. The
|
|
|
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance with the
|
|
|
|
# License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
|
2020-07-15 19:20:00 +02:00
|
|
|
RETURN_CODE=0
|
2020-07-04 23:47:02 +02:00
|
|
|
|
2022-12-13 02:26:31 +01:00
|
|
|
BASE_URL="https://dist.apache.org/repos/dist/dev/nuttx"
|
2020-07-15 19:20:00 +02:00
|
|
|
TEMPDIR="/tmp/nuttx-checkrelease"
|
2020-07-18 09:55:38 +02:00
|
|
|
KEY="$BASE_URL/KEYS"
|
2020-07-15 19:20:00 +02:00
|
|
|
|
|
|
|
function validate_url() {
|
|
|
|
if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then echo "true"; fi
|
|
|
|
}
|
2020-07-04 23:47:02 +02:00
|
|
|
|
|
|
|
function download_release() {
|
2020-07-15 19:20:00 +02:00
|
|
|
rm -rf "$TEMPDIR"
|
|
|
|
mkdir "$TEMPDIR"
|
|
|
|
cd "$TEMPDIR"
|
|
|
|
|
|
|
|
if [[ -n "$URL" ]]; then
|
|
|
|
if [[ $(validate_url "$URL") ]]; then
|
|
|
|
echo "Downloading release files from $URL"
|
|
|
|
wget -q -r -nd -np "$URL"
|
|
|
|
else
|
|
|
|
echo "The $URL given doesn't return HTTP 200 OK return code— exiting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
cp -r "$DIRECTORY"/* .
|
|
|
|
fi
|
2020-07-04 23:47:02 +02:00
|
|
|
}
|
|
|
|
|
2020-07-18 09:55:38 +02:00
|
|
|
function import_key() {
|
|
|
|
if [[ $(validate_url "$KEY") ]]; then
|
|
|
|
export GNUPGHOME="$TEMPDIR/.gnupg"
|
|
|
|
wget -q -O- "$KEY" | gpg --import
|
|
|
|
echo " OK: $KEY is imported."
|
|
|
|
else
|
|
|
|
echo " - Error importing $KEY."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-07-04 23:47:02 +02:00
|
|
|
function check_sha512() {
|
|
|
|
RELEASE_FILE=$1
|
|
|
|
echo "Checking $RELEASE_FILE sha512..."
|
2020-07-15 19:20:00 +02:00
|
|
|
output="$(sha512sum -c $RELEASE_FILE.sha512)" 2>&1
|
|
|
|
return_value=$?
|
|
|
|
if [ $return_value -eq 0 ]; then
|
|
|
|
echo " OK: $RELEASE_FILE sha512 hash matches."
|
|
|
|
else
|
|
|
|
RETURN_CODE=1
|
|
|
|
echo "$output"
|
|
|
|
echo " - $RELEASE_FILE sha512 hash does not match."
|
|
|
|
fi
|
|
|
|
echo
|
2020-07-04 23:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_gpg() {
|
|
|
|
RELEASE_FILE=$1
|
|
|
|
echo "Checking $RELEASE_FILE GPG signature:"
|
2020-07-15 19:20:00 +02:00
|
|
|
gpg --verify $RELEASE_FILE.asc $RELEASE_FILE
|
|
|
|
return_value=$?
|
|
|
|
if [ $return_value -eq 0 ]; then
|
|
|
|
echo " OK: $RELEASE_FILE gpg signature matches."
|
|
|
|
else
|
|
|
|
RETURN_CODE=1
|
|
|
|
echo " - Error checking $RELEASE_FILE gpg signature."
|
|
|
|
fi
|
2020-07-04 23:47:02 +02:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_required_files() {
|
2020-07-15 19:20:00 +02:00
|
|
|
RELEASE_DIR=$1
|
|
|
|
MISSING_FILE=0
|
|
|
|
echo "Checking $RELEASE_FILE for required files:"
|
2020-07-04 23:47:02 +02:00
|
|
|
if [ ! -f "$RELEASE_DIR/LICENSE" ]; then
|
2020-07-15 19:20:00 +02:00
|
|
|
echo " - LICENSE file not present."
|
|
|
|
MISSING_FILE=1
|
2020-07-04 23:47:02 +02:00
|
|
|
fi
|
|
|
|
if [ ! -f "$RELEASE_DIR/NOTICE" ]; then
|
2020-07-15 19:20:00 +02:00
|
|
|
echo " - NOTICE file not present."
|
|
|
|
MISSING_FILE=1
|
2020-07-04 23:47:02 +02:00
|
|
|
fi
|
2020-11-26 09:44:29 +01:00
|
|
|
if [ ! -f "$RELEASE_DIR/README.md" ]; then
|
|
|
|
echo " - README.md file not present."
|
2020-07-15 19:20:00 +02:00
|
|
|
MISSING_FILE=1
|
2020-07-04 23:47:02 +02:00
|
|
|
fi
|
2020-07-15 19:20:00 +02:00
|
|
|
if [ 0 -eq $MISSING_FILE ]; then
|
|
|
|
echo " OK: all required files exist in $RELEASE_DIR."
|
|
|
|
else
|
|
|
|
RETURN_CODE=$MISSING_FILE
|
2020-07-04 23:47:02 +02:00
|
|
|
fi
|
2020-07-15 19:20:00 +02:00
|
|
|
echo
|
2020-07-04 23:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_nuttx() {
|
|
|
|
RELEASE_FILE="$(ls *.tar.gz|head -1)"
|
2020-07-15 19:20:00 +02:00
|
|
|
RELEASE_DIR="nuttx"
|
|
|
|
check_sha512 "$RELEASE_FILE"
|
2020-07-04 23:47:02 +02:00
|
|
|
check_gpg "$RELEASE_FILE"
|
2020-07-15 19:20:00 +02:00
|
|
|
tar xf "$RELEASE_FILE"
|
|
|
|
check_required_files "$RELEASE_DIR"
|
2020-07-04 23:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_nuttx_apps() {
|
|
|
|
RELEASE_FILE="$(ls *.tar.gz|head -2| tail -1)"
|
2020-07-15 19:20:00 +02:00
|
|
|
RELEASE_DIR="apps"
|
2020-07-04 23:47:02 +02:00
|
|
|
check_sha512 "$RELEASE_FILE"
|
|
|
|
check_gpg "$RELEASE_FILE"
|
2020-07-15 19:20:00 +02:00
|
|
|
tar xf "$RELEASE_FILE"
|
|
|
|
check_required_files "$RELEASE_DIR"
|
|
|
|
}
|
|
|
|
|
2021-11-22 20:00:54 +01:00
|
|
|
function check_sim_asan() {
|
2020-07-15 19:20:00 +02:00
|
|
|
RELEASE_DIR="nuttx"
|
|
|
|
cd "$RELEASE_DIR"
|
2021-11-22 20:00:54 +01:00
|
|
|
|
|
|
|
echo "Trying to build $RELEASE_DIR sim:asan..."
|
2021-11-22 19:49:13 +01:00
|
|
|
output=$(make distclean; ./tools/configure.sh sim:asan; make) 2>&1
|
2020-07-15 19:20:00 +02:00
|
|
|
return_value=$?
|
|
|
|
if [ $return_value -eq 0 ]; then
|
2021-11-22 19:49:13 +01:00
|
|
|
echo " OK: we were able to build sim:asan."
|
2020-07-15 19:20:00 +02:00
|
|
|
else
|
|
|
|
RETURN_CODE=1
|
|
|
|
echo "$output"
|
2021-11-22 19:49:13 +01:00
|
|
|
echo " - Error building sim:asan."
|
2020-07-15 19:20:00 +02:00
|
|
|
fi
|
|
|
|
echo
|
2021-11-22 20:00:54 +01:00
|
|
|
|
|
|
|
echo "Trying to run $RELEASE_DIR sim:asan..."
|
|
|
|
output=$(./nuttx) 2>&1
|
|
|
|
return_value=$?
|
|
|
|
if [ $return_value -eq 0 ]; then
|
|
|
|
echo " OK: ostest with ASAN pass."
|
|
|
|
else
|
|
|
|
RETURN_CODE=1
|
|
|
|
echo "$output"
|
|
|
|
echo " - Error running sim:asan."
|
|
|
|
fi
|
|
|
|
echo
|
2020-07-04 23:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
2020-07-15 19:20:00 +02:00
|
|
|
echo "Usage: $0 [--url <URL-of-release-dir>] [--release <name-of-release] [--dir <path-to-directory>] [--tempdir <path-to-directory>]"
|
|
|
|
echo " Given release full URL, release name, or a local directory, downloads or copies"
|
|
|
|
echo " all files in that directory (which for a release should include nuttx and nuttx-apps, sha512, "
|
|
|
|
echo " asc, and tar.gz files), checks the release SHA512 and GPG signatures, checks the unpacked "
|
2021-11-22 19:49:13 +01:00
|
|
|
echo " directories for required files, and tries to build NuttX for sim:asan."
|
2020-07-15 19:20:00 +02:00
|
|
|
echo
|
|
|
|
echo " If tempdir is specified, it will be removed and recreated; if it is not specified, /tmp/nuttx-checkrelease"
|
|
|
|
echo " is used."
|
2020-07-04 23:47:02 +02:00
|
|
|
echo
|
2020-07-06 21:36:40 +02:00
|
|
|
echo "Examples:"
|
|
|
|
echo
|
2020-07-15 19:20:00 +02:00
|
|
|
echo " $0 --release 9.1.0-RC1"
|
2022-12-13 02:26:31 +01:00
|
|
|
echo " $0 --url https://dist.apache.org/repos/dist/dev/nuttx/9.1.0-RC1"
|
2020-07-15 19:20:00 +02:00
|
|
|
echo " $0 --dir ./some-dir-that-has-nuttx-and-apps"
|
2020-07-06 21:36:40 +02:00
|
|
|
echo
|
2020-07-04 23:47:02 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 19:20:00 +02:00
|
|
|
URL=""
|
|
|
|
DIRECTORY=""
|
2020-07-04 23:47:02 +02:00
|
|
|
|
2020-07-15 19:20:00 +02:00
|
|
|
while [[ $# -gt 0 ]]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
-U|--url)
|
|
|
|
shift
|
|
|
|
URL="$1/"
|
2020-07-18 09:55:38 +02:00
|
|
|
KEY="$1/../KEYS"
|
2020-07-15 19:20:00 +02:00
|
|
|
;;
|
|
|
|
-R|--release)
|
|
|
|
shift
|
|
|
|
RELEASE="$1"
|
|
|
|
URL="$BASE_URL/$RELEASE/"
|
|
|
|
;;
|
|
|
|
-D|--dir)
|
|
|
|
shift
|
|
|
|
DIRECTORY="$(readlink -f $1)"
|
|
|
|
;;
|
|
|
|
-T|--tempdir)
|
|
|
|
shift
|
|
|
|
TEMPDIR="$(readlink -f $1)"
|
|
|
|
;;
|
|
|
|
-h|--help)
|
2020-07-04 23:47:02 +02:00
|
|
|
usage
|
|
|
|
exit 0
|
2020-07-15 19:20:00 +02:00
|
|
|
;;
|
|
|
|
*) # unknown option
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2020-07-04 23:47:02 +02:00
|
|
|
|
2020-07-15 19:20:00 +02:00
|
|
|
if [[ (-z "$URL") && (-z "$DIRECTORY") ]]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
2020-07-04 23:47:02 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
download_release
|
2020-07-18 09:55:38 +02:00
|
|
|
import_key
|
2020-07-15 19:20:00 +02:00
|
|
|
check_nuttx
|
|
|
|
check_nuttx_apps
|
2021-11-22 20:00:54 +01:00
|
|
|
check_sim_asan
|
2020-07-15 19:20:00 +02:00
|
|
|
|
|
|
|
exit $RETURN_CODE
|