xiaoxiang781216 commented on a change in pull request #1382:
URL: https://github.com/apache/incubator-nuttx/pull/1382#discussion_r452592161



##########
File path: tools/checkrelease.sh
##########
@@ -19,114 +19,218 @@
 #
 #############################################################################
 
-set -e
-
+VERBOSE=0
+RETURN_CODE=0
 BASE_URL="https://dist.apache.org/repos/dist/dev/incubator/nuttx";
-TEMPDIR="dist.apache.org"
+DIST_DIR="dist.apache.org"
+TMP="/tmp"
+TEMPDIR="$TMP/nuttx-checkrelease"
 ORIGINAL_DIR="$(pwd)"
 trap "{ cd $ORIGINAL_DIR; rm -rf $TEMPDIR; }" EXIT
 
 function download_release() {
-    wget -r -np -R "index.html*" -P . --cut-dirs 7 "$URL"
+  rm -rf "$TEMPDIR"
+  if [[ -n "$URL" ]]; then
+    mkdir "$TEMPDIR"
+    wget -r --no-parent -P "$TEMPDIR" --cut-dirs 8 "$URL"
     cd "$TEMPDIR"
+    mv $DIST_DIR/apache-nuttx-* .
+  else
+    if [[ -n "$DIRECTORY" ]]; then
+      cp -r "$DIRECTORY" "$TEMPDIR"
+      cd "$TEMPDIR"
+    else
+      echo "One of --dir or --url is required!"
+      exit 1
+    fi
+  fi
 }
 
 function check_sha512() {
-    # check release sha512
     RELEASE_FILE=$1
     echo "Checking $RELEASE_FILE sha512..."
-    sha512sum -c "$RELEASE_FILE.sha512"
+    output="$(sha512sum -c $RELEASE_FILE.sha512)"
+    return_value=$?
+    if [ $return_value -eq 0 ]; then
+      echo " OK: $RELEASE_FILE sha512 hash matches."
+    else
+      RETURN_CODE=1
+      echo " - $RELEASE_FILE sha512 hash does not match:"
+      echo "$output"
+    fi
+    echo
 }
 
 function check_gpg() {
-    # check nuttx sha512 and gpg
     RELEASE_FILE=$1
     echo "Checking $RELEASE_FILE GPG signature:"
-    gpg --verify "$RELEASE_FILE.asc" "$RELEASE_FILE"
+    output="$(gpg --quiet --verify $RELEASE_FILE.asc $RELEASE_FILE 2>&1)"
+    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:"
+      echo "$output"
+      echo
+    fi
     echo
 }
 
 function check_required_files() {
-    # check nuttx for required files
-    RELEASE_FILE=$1
-    RELEASE_DIR=$2 
-    rm -rf "$RELEASE_DIR"
-    tar xf "$RELEASE_FILE"
+    RELEASE_DIR=$1
+    echo "Checking $RELEASE_FILE for required files:"
     ERROR=0
     if [ ! -f "$RELEASE_DIR/LICENSE" ]; then
-        echo "LICENSE file not present."
-        ERROR=1
+      echo " - LICENSE file not present."
+      ERROR=1
     fi
     if [ ! -f "$RELEASE_DIR/NOTICE" ]; then
-        echo "NOTICE file not present."
-        ERROR=1
+      echo " - NOTICE file not present."
+      ERROR=1
     fi
     if [ ! -f "$RELEASE_DIR/README.txt" ]; then
-        echo "README.txt file not present."
-        ERROR=1
+      echo " - README.txt file not present."
+      ERROR=1
     fi
     if [ ! -f "$RELEASE_DIR/DISCLAIMER-WIP" ]; then
-        echo "DISCLAIMER-WIP file not present."
-        ERROR=1
+      echo " - DISCLAIMER-WIP file not present."
+      ERROR=1
     fi
     if [ 0 -eq $ERROR ]; then
-        echo "OK: All required files exist."
+      echo " OK: all required files exist in $RELEASE_DIR."
+    else
+      RETURN_CODE=1
     fi
+    echo
 }
 
 function check_nuttx() {
-    # check nuttx sha512 and gpg
     RELEASE_FILE="$(ls *.tar.gz|head -1)"
-    check_sha512 "$RELEASE_FILE" 
+    RELEASE_DIR="nuttx"
+    check_sha512 "$RELEASE_FILE"
     check_gpg "$RELEASE_FILE"
-    check_required_files "$RELEASE_FILE" "nuttx"
-    mv "$RELEASE_FILE" ..
+    rm -rf "$RELEASE_DIR"
+    tar xf "$RELEASE_FILE"
+    check_required_files "$RELEASE_DIR"
+    mv "$RELEASE_FILE" "$TMP"
 }
 
 function check_nuttx_apps() {
-    # check nuttx-apps sha512 and gpg
     RELEASE_FILE="$(ls *.tar.gz|head -2| tail -1)"
+    RELEASE_DIR="apps"
     check_sha512 "$RELEASE_FILE"
     check_gpg "$RELEASE_FILE"
-    check_required_files "$RELEASE_FILE" "apps"
-    mv "$RELEASE_FILE" ..
+    rm -rf "$RELEASE_DIR"
+    tar xf "$RELEASE_FILE"
+    check_required_files "$RELEASE_DIR"
+    mv "$RELEASE_FILE" "$TMP"
 }
 
+function check_sim_nsh_build() {
+    RELEASE_DIR="nuttx"
+    echo "Trying to build $RELEASE_DIR sim:nsh..."
+    cd "$RELEASE_DIR"
+    if [[ $VERBOSE -eq 0 ]]; then
+      output=$(make distclean ; ./tools/configure.sh sim:nsh ; make) 2>&1
+    else
+      make distclean
+      ./tools/configure.sh sim:nsh
+      make
+    fi
+    return_value=$?
+    if [ $return_value -eq 0 ]; then
+      echo " OK: we were able to build sim:nsh"
+    else
+      RETURN_CODE=1
+      echo " - Error building sim:nsh:"
+      echo
+      echo $output
+    fi
+
+    echo
+}
 function usage() {
-    echo "Usage: $0 <URL-of-release-candidate-directory-or-release-name>"
-    echo "   Given release name or release full URL, downloads all files in"
-    echo "   in that directory (which should include nuttx and nuttx-apps"
-    echo "   sha512, asc, and tar.gz files), checks the release SHA512 and GPG 
"
-    echo "   signatures, and checks the unpacked directories for required "
-    echo "   files. Creates a temporary directory to do its work in."
+    echo "Usage: $0 [--verbose] [--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 "
+    echo "   directories for required files, and tries to build NuttX for 
sim:nsh."
+    echo
+    echo "   If tempdir is specified, it will be removed and recreated; if it 
is not specified, /tmp/nuttx-checkrelease"
+    echo "   is used."
     echo
-    echo "   nuttx and nuttx-apps tar.gz files are left in the current"
-    echo "   directory."
+    echo "   If --url or --release are given, nuttx and nuttx-apps tar.gz 
files are left in /tmp for the user to "
+    echo "   build for their platform."
     echo 
     echo "Examples:"
     echo
-    echo "  $0 9.1.0-RC1"
-    echo "  $0 
https://dist.apache.org/repos/dist/dev/incubator/nuttx/9.1.0-RC1/";
+    echo "  $0 --release 9.1.0-RC1"
+    echo "  $0 --url 
https://dist.apache.org/repos/dist/dev/incubator/nuttx/9.1.0-RC1/";
+    echo "  $0 --dir ./some-dir-that-has-nuttx-and-apps"
     echo
 }
 
-if [ "-h" == "$1" ]; then
-    usage
-    exit 0
-fi
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
 
-if [ -z "$1" ]; then
+URL=""
+DIRECTORY=""
+
+case $key in
+    -U|--url)
+    URL="$2"
+    shift # past argument
+    shift # past value
+    ;;
+    -R|--release)
+    RELEASE="$2"
+    URL="$BASE_URL/$RELEASE/"
+    shift # past argument
+    shift # past value
+    ;;
+    -D|--dir)
+    DIRECTORY="$(readlink -f $2)"
+    shift # past argument
+    shift # past value
+    ;;
+    -T|--tempdir)
+    TEMPDIR="$(readlink -f $2)"
+    shift # past argument
+    shift # past value
+    ;;
+    -h|--help)
+    shift # past argument
     usage
     exit 0
-fi
+    ;;
+    -V|--verbose)
+    VERBOSE=1
+    shift # past argument
+    shift # past value
+    ;;
+    *)    # unknown option
+    POSITIONAL+=("$1") # save it in an array for later
+    shift # past argument
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
 
-ARG=$1
-if [[ "$ARG" =~ ^"http".* ]]; then
-  URL="$1/"
-else
-  URL="$BASE_URL/$1/"
+if [[ (-z "$URL") && (-z "$DIRECTORY") ]]; then
+  usage
+  exit 1
 fi
 
 download_release
-check_nuttx 
-check_nuttx_apps 
+if [[ -n "$URL" ]]; then
+  check_nuttx
+  check_nuttx_apps
+else

Review comment:
       But check_nuttx/check_nuttx_apps should work with local directory too if 
my understanding is correct.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to