prepare_debian.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # Copies sources from SVN tree and prepare a Debian package.
  3. # JLBC, 2008-2011
  4. #set -o verbose # echo on
  5. set +o verbose # echo off
  6. APPEND_SVN_NUM=0
  7. IS_FOR_UBUNTU=0
  8. APPEND_LINUX_DISTRO=""
  9. while getopts "sud:" OPTION
  10. do
  11. case $OPTION in
  12. s)
  13. APPEND_SVN_NUM=1
  14. ;;
  15. u)
  16. IS_FOR_UBUNTU=1
  17. ;;
  18. d)
  19. APPEND_LINUX_DISTRO=$OPTARG
  20. ;;
  21. ?)
  22. echo "Unknown command line argument!"
  23. exit 1
  24. ;;
  25. esac
  26. done
  27. # Checks
  28. # --------------------------------
  29. if [ -f version ];
  30. then
  31. NANOFLANN_VERSION_STR=`cat version`
  32. NANOFLANN_VERSION_MAJOR=${NANOFLANN_VERSION_STR:0:1}
  33. NANOFLANN_VERSION_MINOR=${NANOFLANN_VERSION_STR:2:1}
  34. NANOFLANN_VERSION_PATCH=${NANOFLANN_VERSION_STR:4:1}
  35. NANOFLANN_VER_MM="${NANOFLANN_VERSION_MAJOR}.${NANOFLANN_VERSION_MINOR}"
  36. NANOFLANN_VER_MMP="${NANOFLANN_VERSION_MAJOR}.${NANOFLANN_VERSION_MINOR}.${NANOFLANN_VERSION_PATCH}"
  37. echo "nanoflann version: ${NANOFLANN_VER_MMP}"
  38. else
  39. echo "ERROR: Run this script from the nanoflann root directory."
  40. exit 1
  41. fi
  42. NANOFLANNSRC=`pwd`
  43. NANOFLANN_DEB_DIR="$HOME/nanoflann_debian"
  44. NANOFLANN_EXTERN_DEBIAN_DIR="$NANOFLANNSRC/packaging/debian/"
  45. if [ -f ${NANOFLANN_EXTERN_DEBIAN_DIR}/control ];
  46. then
  47. echo "Using debian dir: ${NANOFLANN_EXTERN_DEBIAN_DIR}"
  48. else
  49. echo "ERROR: Cannot find ${NANOFLANN_EXTERN_DEBIAN_DIR}"
  50. exit 1
  51. fi
  52. # Prepare a directory for building the debian package:
  53. #
  54. rm -fR $NANOFLANN_DEB_DIR
  55. mkdir $NANOFLANN_DEB_DIR
  56. # Are we in svn?
  57. NANOFLANN_SVN_VERSION=`svnversion -n`
  58. if [ $NANOFLANN_SVN_VERSION = "exported" ];
  59. then
  60. echo "Copying sources to $NANOFLANN_DEB_DIR/nanoflann-${NANOFLANN_VERSION_STR}"
  61. cp -R . $NANOFLANN_DEB_DIR/nanoflann-${NANOFLANN_VERSION_STR}
  62. else
  63. # Strip the last "M", if any:
  64. if [ ${NANOFLANN_SVN_VERSION:(-1)} = "M" ];
  65. then
  66. NANOFLANN_SVN_VERSION=${NANOFLANN_SVN_VERSION:0:${#NANOFLANN_SVN_VERSION}-1}
  67. fi
  68. if [ $APPEND_SVN_NUM == "1" ];
  69. then
  70. NANOFLANN_VERSION_STR="${NANOFLANN_VERSION_STR}svn${NANOFLANN_SVN_VERSION}${APPEND_LINUX_DISTRO}"
  71. else
  72. NANOFLANN_VERSION_STR="${NANOFLANN_VERSION_STR}${APPEND_LINUX_DISTRO}"
  73. fi
  74. echo "Exporting to $NANOFLANN_DEB_DIR/nanoflann-${NANOFLANN_VERSION_STR}"
  75. svn export . $NANOFLANN_DEB_DIR/nanoflann-${NANOFLANN_VERSION_STR}
  76. fi
  77. cd $NANOFLANN_DEB_DIR/nanoflann-${NANOFLANN_VERSION_STR}
  78. # Deletions:
  79. rm -fR bin 2>/dev/null
  80. rm -fR packaging
  81. # Orig tarball:
  82. cd ..
  83. echo "Creating orig tarball: nanoflann_${NANOFLANN_VERSION_STR}.orig.tar.gz"
  84. tar czf nanoflann_${NANOFLANN_VERSION_STR}.orig.tar.gz nanoflann-${NANOFLANN_VERSION_STR}
  85. # Copy debian directory:
  86. mkdir nanoflann-${NANOFLANN_VERSION_STR}/debian
  87. cp -r ${NANOFLANN_EXTERN_DEBIAN_DIR}/* nanoflann-${NANOFLANN_VERSION_STR}/debian
  88. cp ${NANOFLANN_EXTERN_DEBIAN_DIR}/copyright nanoflann-${NANOFLANN_VERSION_STR}/copyright
  89. # Strip my custom files...
  90. rm nanoflann-${NANOFLANN_VERSION_STR}/debian/*.new
  91. # debian/source file issues for old Ubuntu distros:
  92. if [ $IS_FOR_UBUNTU == "1" ];
  93. then
  94. rm -fr nanoflann-${NANOFLANN_VERSION_STR}/debian/source
  95. fi
  96. # Prepare install files:
  97. cd nanoflann-${NANOFLANN_VERSION_STR}
  98. # Figure out the next Debian version number:
  99. echo "Detecting next Debian version number..."
  100. CHANGELOG_UPSTREAM_VER=$( dpkg-parsechangelog | sed -n 's/Version:.*\([0-9]\.[0-9]*\.[0-9]*.*svn.*\)-.*/\1/p' )
  101. CHANGELOG_LAST_DEBIAN_VER=$( dpkg-parsechangelog | sed -n 's/Version:.*\([0-9]\.[0-9]*\.[0-9]*\).*-\([0-9]*\).*/\2/p' )
  102. echo " -> PREVIOUS UPSTREAM: $CHANGELOG_UPSTREAM_VER -> New: ${NANOFLANN_VERSION_STR}"
  103. echo " -> PREVIOUS DEBIAN VERSION: $CHANGELOG_LAST_DEBIAN_VER"
  104. # If we have the same upstream versions, increase the Debian version, otherwise create a new entry:
  105. if [ "$CHANGELOG_UPSTREAM_VER" = "$NANOFLANN_VERSION_STR" ];
  106. then
  107. NEW_DEBIAN_VER=$[$CHANGELOG_LAST_DEBIAN_VER + 1]
  108. echo "Changing to a new Debian version: ${NANOFLANN_VERSION_STR}-${NEW_DEBIAN_VER}"
  109. DEBCHANGE_CMD="--newversion ${NANOFLANN_VERSION_STR}-${NEW_DEBIAN_VER}"
  110. else
  111. DEBCHANGE_CMD="--newversion ${NANOFLANN_VERSION_STR}-1"
  112. fi
  113. echo "Adding a new entry to debian/changelog..."
  114. echo DEBEMAIL="Jose Luis Blanco (University of Malaga) <joseluisblancoc@gmail.com>" debchange $DEBCHANGE_CMD --distribution unstable --force-distribution New version of upstream sources.
  115. DEBEMAIL="Jose Luis Blanco (University of Malaga) <joseluisblancoc@gmail.com>" debchange $DEBCHANGE_CMD -b --distribution unstable --force-distribution New version of upstream sources.
  116. echo "Copying back the new changelog to a temporary file in: ${NANOFLANN_EXTERN_DEBIAN_DIR}changelog.new"
  117. cp debian/changelog ${NANOFLANN_EXTERN_DEBIAN_DIR}changelog.new
  118. set +o verbose # echo off
  119. echo "Now, you can build the source Deb package with 'debuild -S -sa'"
  120. cd ..
  121. ls -lh
  122. exit 0