zipme.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #!/usr/bin/env bash
  2. # tools/zipme.sh
  3. #
  4. # Licensed to the Apache Software Foundation (ASF) under one or more
  5. # contributor license agreements. See the NOTICE file distributed with
  6. # this work for additional information regarding copyright ownership. The
  7. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance with the
  9. # License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. # License for the specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. #set -x
  20. WD=`pwd`
  21. TAR=tar
  22. GPG="gpg -sab"
  23. SHASUM=sha512sum
  24. verbose=0
  25. sign=0
  26. # A list of files and folders to exclude from the final tarball.
  27. EXCLPAT="
  28. .github
  29. .asf.yaml
  30. "
  31. # Get command line parameters
  32. USAGE="USAGE: $0 [-d|h|v|s] [-b <build]> [-e <exclude>] [-k <key-id>] [<major.minor.patch>]"
  33. ADVICE="Try '$0 -h' for more information"
  34. unset VERSION
  35. unset VERSIONOPT
  36. unset BUILD
  37. unset DEBUG
  38. while [ ! -z "$1" ]; do
  39. case $1 in
  40. -b )
  41. shift
  42. BUILD="-b ${1}"
  43. ;;
  44. -d )
  45. set -x
  46. DEBUG=-d
  47. ;;
  48. -e )
  49. shift
  50. EXCLPAT+=${1}
  51. ;;
  52. -v )
  53. verbose=1
  54. ;;
  55. -s )
  56. sign=1
  57. ;;
  58. -k )
  59. shift
  60. GPG+=" --default-key $1"
  61. ;;
  62. -h )
  63. echo "$0 is a tool for generation of release versions of NuttX"
  64. echo ""
  65. echo $USAGE
  66. echo ""
  67. echo "Where:"
  68. echo " -b <build>"
  69. echo " Use this build identification string. Default: use GIT build ID"
  70. echo " NOTE: GIT build information may not be available in a snapshot"
  71. echo " -d"
  72. echo " Enable script debug"
  73. echo " -h"
  74. echo " show this help message and exit"
  75. echo " -e"
  76. echo " Exclude a list of files or folders"
  77. echo " NOTE: The list must be quoted, example -e \"*.out tmp\""
  78. echo " -v"
  79. echo " Be verbose. The output could be more than you care to see."
  80. echo " -s"
  81. echo " PGP sign the final tarballs and create digests."
  82. echo " -k"
  83. echo " PGP key ID. If not provided the default ID will be used."
  84. echo " <major.minor.patch>"
  85. echo " The NuttX version number expressed as a major, minor and patch number separated"
  86. echo " by a period"
  87. exit 0
  88. ;;
  89. * )
  90. break
  91. ;;
  92. esac
  93. shift
  94. done
  95. # The last thing on the command line is the version number
  96. VERSION=$1
  97. if [ -n ${VERSION} ] ; then
  98. VERSIONOPT="-v ${VERSION}"
  99. fi
  100. # Full tar options
  101. for pat in ${EXCLPAT} ; do
  102. TAR+=" --exclude=${pat}"
  103. done
  104. TAR+=" --exclude-vcs"
  105. if [ $verbose != 0 ] ; then
  106. TAR+=" -czvf"
  107. else
  108. TAR+=" -czf"
  109. fi
  110. # Find the directory we were executed from and were we expect to
  111. # see the directories to tar up
  112. MYNAME=`basename $0`
  113. if [ -x ${WD}/${MYNAME} ] ; then
  114. TRUNKDIR="${WD}/../.."
  115. else
  116. if [ -x ${WD}/tools/${MYNAME} ] ; then
  117. TRUNKDIR="${WD}/.."
  118. else
  119. if [ -x ${WD}/nuttx/tools/${MYNAME} ] ; then
  120. TRUNKDIR="${WD}"
  121. else
  122. echo "You must cd into the NUTTX directory to execute this script."
  123. exit 1
  124. fi
  125. fi
  126. fi
  127. # Get the NuttX directory names and the path to the parent directory
  128. NUTTXDIR=${TRUNKDIR}/nuttx
  129. APPSDIR=${TRUNKDIR}/apps
  130. # Make sure that the directories exists
  131. if [ ! -d ${TRUNKDIR} ]; then
  132. echo "Directory ${TRUNKDIR} does not exist"
  133. exit 1
  134. fi
  135. cd ${TRUNKDIR} || \
  136. { echo "Failed to cd to ${TRUNKDIR}" ; exit 1 ; }
  137. if [ ! -d ${NUTTXDIR} ] ; then
  138. echo "Directory ${TRUNKDIR}/${NUTTXDIR} does not exist!"
  139. exit 1
  140. fi
  141. if [ ! -d ${APPSDIR} ] ; then
  142. echo "Directory ${TRUNKDIR}/${APPSDIR} does not exist!"
  143. exit 1
  144. fi
  145. # Perform a full clean for the distribution
  146. echo "Cleaning the repositories"
  147. if [ $verbose != 0 ] ; then
  148. make -C ${NUTTXDIR} distclean
  149. else
  150. make -C ${NUTTXDIR} distclean 1>/dev/null
  151. fi
  152. # Prepare the nuttx directory
  153. # Write a version file into the NuttX directory. The syntax of file is such that it
  154. # may be sourced by a bash script or included by a Makefile.
  155. VERSIONSH=${NUTTXDIR}/tools/version.sh
  156. if [ ! -x "${VERSIONSH}" ]; then
  157. echo "No executable script was found at: ${VERSIONSH}"
  158. exit 1
  159. fi
  160. ${VERSIONSH} ${DEBUG} ${BUILD} ${VERSIONOPT} ${NUTTXDIR}/.version || \
  161. { echo "${VERSIONSH} failed"; cat ${NUTTXDIR}/.version; exit 1; }
  162. chmod 755 ${NUTTXDIR}/.version || \
  163. { echo "'chmod 755 ${NUTTXDIR}/.version' failed"; exit 1; }
  164. if [ -z ${VERSION} ] ; then
  165. source ${NUTTXDIR}/.version
  166. VERSION=${CONFIG_VERSION_STRING}
  167. VERSIONOPT="-v ${VERSION}"
  168. fi
  169. # Update the configuration variable documentation
  170. #
  171. # MKCONFIGVARS=${NUTTXDIR}/tools/mkconfigvars.sh
  172. # CONFIGVARHTML=${NUTTXDIR}/Documentation/NuttXConfigVariables.html
  173. #
  174. # if [ ! -x "${MKCONFIGVARS}" ]; then
  175. # echo "No executable script was found at: ${MKCONFIGVARS}"
  176. # exit 1
  177. # fi
  178. #
  179. # cd ${NUTTXDIR} || \
  180. # { echo "Failed to cd to ${NUTTXDIR}" ; exit 1 ; }
  181. #
  182. # ${MKCONFIGVARS} ${DEBUG} ${VERSIONOPT} || \
  183. # { echo "${MKCONFIGVARS} failed"; exit 1; }
  184. # chmod 644 ${CONFIGVARHTML} || \
  185. # { echo "'chmod 644 ${CONFIGVARHTML}' failed"; exit 1; }
  186. #
  187. # Create the versioned tarball names
  188. NUTTX_TARNAME=apache-nuttx-${VERSION}-incubating.tar
  189. APPS_TARNAME=apache-nuttx-apps-${VERSION}-incubating.tar
  190. NUTTX_ZIPNAME=${NUTTX_TARNAME}.gz
  191. APPS_ZIPNAME=${APPS_TARNAME}.gz
  192. NUTTX_ASCNAME=${NUTTX_ZIPNAME}.asc
  193. APPS_ASCNAME=${APPS_ZIPNAME}.asc
  194. NUTTX_SHANAME=${NUTTX_ZIPNAME}.sha512
  195. APPS_SHANAME=${APPS_ZIPNAME}.sha512
  196. # Remove any previous tarballs
  197. if [ -f ${NUTTX_TARNAME} ] ; then
  198. echo "Removing ${TRUNKDIR}/${NUTTX_TARNAME}"
  199. rm -f ${NUTTX_TARNAME} || \
  200. { echo "rm ${NUTTX_TARNAME} failed!" ; exit 1 ; }
  201. fi
  202. if [ -f ${NUTTX_ZIPNAME} ] ; then
  203. echo "Removing ${TRUNKDIR}/${NUTTX_ZIPNAME}"
  204. rm -f ${NUTTX_ZIPNAME} || \
  205. { echo "rm ${NUTTX_ZIPNAME} failed!" ; exit 1 ; }
  206. fi
  207. if [ -f ${APPS_TARNAME} ] ; then
  208. echo "Removing ${TRUNKDIR}/${APPS_TARNAME}"
  209. rm -f ${APPS_TARNAME} || \
  210. { echo "rm ${APPS_TARNAME} failed!" ; exit 1 ; }
  211. fi
  212. if [ -f ${APPS_ZIPNAME} ] ; then
  213. echo "Removing ${TRUNKDIR}/${APPS_ZIPNAME}"
  214. rm -f ${APPS_ZIPNAME} || \
  215. { echo "rm ${APPS_ZIPNAME} failed!" ; exit 1 ; }
  216. fi
  217. # Remove any previous signatures or digests
  218. if [ -f ${NUTTX_ASCNAME} ] ; then
  219. echo "Removing ${TRUNKDIR}/${NUTTX_ASCNAME}"
  220. rm -f ${NUTTX_ASCNAME} || \
  221. { echo "rm ${NUTTX_ASCNAME} failed!" ; exit 1; }
  222. fi
  223. if [ -f ${APPS_ASCNAME} ] ; then
  224. echo "Removing ${TRUNKDIR}/${APPS_ASCNAME}"
  225. rm -f ${APPS_ASCNAME} || \
  226. { echo "rm ${APPS_ASCNAME} failed!" ; exit 1; }
  227. fi
  228. if [ -f ${NUTTX_SHANAME} ] ; then
  229. echo "Removing ${TRUNKDIR}/${NUTTX_SHANAME}"
  230. rm -f ${NUTTX_SHANAME} || \
  231. { echo "rm ${NUTTX_SHANAME} failed!" ; exit 1; }
  232. fi
  233. if [ -f ${APPS_SHANAME} ] ; then
  234. echo "Removing ${TRUNKDIR}/${APPS_SHANAME}"
  235. rm -f ${APPS_SHANAME} || \
  236. { echo "rm ${APPS_SHANAME} failed!" ; exit 1; }
  237. fi
  238. # Then tar and zip-up the directories
  239. echo "Archiving and zipping nuttx/"
  240. ${TAR} ${NUTTX_ZIPNAME} `basename ${NUTTXDIR}` || \
  241. { echo "tar of ${NUTTX_ZIPNAME} failed!" ; exit 1 ; }
  242. echo "Archiving and zipping apps/"
  243. ${TAR} ${APPS_ZIPNAME} `basename ${APPSDIR}` || \
  244. { echo "tar of ${APPS_ZIPNAME} failed!" ; exit 1 ; }
  245. # Create the hashes for the two tarballs
  246. echo "Creating the hashes"
  247. ${SHASUM} ${NUTTX_ZIPNAME} > ${NUTTX_SHANAME} || \
  248. { echo "Digest of ${NUTTX_ZIPNAME} failed!" ; exit 1 ; }
  249. ${SHASUM} ${APPS_ZIPNAME} > ${APPS_SHANAME} || \
  250. { echo "Digest of ${APPS_ZIPNAME} failed!" ; exit 1 ; }
  251. # Finally sign the tarballs
  252. if [ $sign != 0 ] ; then
  253. echo "Signing the tarballs"
  254. ${GPG} ${NUTTX_ZIPNAME} || \
  255. { echo "Signing ${NUTTX_ZIPNAME} failed!" ; exit 1 ; }
  256. ${GPG} ${APPS_ZIPNAME} || \
  257. { echo "Signing ${APPS_ZIPNAME} failed!" ; exit 1 ; }
  258. fi
  259. cd ${NUTTXDIR}