You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updateBundledPlugins.sh 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # updateBundledPlugins.sh <jar>
  3. #
  4. # Reads the version of each bundled plugin in the specified jar, and writes
  5. # the names and versions to the jar's version.config file.
  6. # Find out where we are
  7. BASEDIR=${0%/*}
  8. if [ "${BASEDIR}" = "${0}" ]; then
  9. BASEDIR=`which $0`
  10. BASEDIR="${BASEDIR%/*}"
  11. fi
  12. CHECKBASEDIR=`echo "${BASEDIR}" | sed 's#^/##'`
  13. if [ "${CHECKBASEDIR}" = "${BASEDIR}" -a "${PWD}" != "${CHECKBASEDIR}" -a "${PWD}/." != "${CHECKBASEDIR}" ]; then
  14. BASEDIR="${PWD}/${BASEDIR}"
  15. fi;
  16. if [ -e "${BASEDIR}/build-functions.sh" ]; then
  17. . "${BASEDIR}/build-functions.sh"
  18. else
  19. echo "Unable to find build-functions.sh. '${BASEDIR}/build-functions.sh'"
  20. exit 1;
  21. fi;
  22. jar=$1
  23. dir=`safe_mktemp ${jar##*/}`
  24. config="$dir/com/dmdirc/version.config"
  25. CHECKJAR=`echo "${jar}" | sed 's#^/##'`
  26. if [ "${CHECKJAR}" = "$jar" ]; then
  27. jar="`pwd`/$jar"
  28. fi;
  29. cd $dir
  30. # Read the jar's version.config out
  31. jar -xf $jar
  32. # Check for previous data
  33. startOffset=`grep -n "Begin updateBundledPlugins.sh" $config | head -n 1 | cut -f 1 -d ':'`
  34. endOffset=`grep -n "End updateBundledPlugins.sh" $config | tail -n 1 | cut -f 1 -d ':'`
  35. if [ -n "$startOffset" -a -n "$endOffset" ]; then
  36. # Previous data found, let's get rid of it
  37. head -n $(($startOffset-2)) $config >> $config.tmp;
  38. tail -n +$(($endOffset+1)) $config >> $config.tmp;
  39. mv $config.tmp $config;
  40. fi;
  41. # Add our new sections
  42. echo "" >> $config;
  43. echo "# --- Begin updateBundledPlugins.sh (`date`) --- " >> $config
  44. echo "keysections:" >> $config;
  45. echo " bundledplugins_versions" >> $config;
  46. echo "" >> $config;
  47. echo "bundledplugins_versions:" >> $config;
  48. # For each plugin in the jar...
  49. for plugin in `ls plugins/* | cut -f 2 -d '/'`; do
  50. pluginName=${plugin%.jar}
  51. # Extract it to our temporary dir (can't extract zip files from stdin)
  52. jar -xf plugins/$plugin;
  53. # Read the plugin.config file and parse out the version number
  54. version=`cat META-INF/plugin.config | grep -1 version: | grep number= | cut -f 2 -d '='`;
  55. # And add the version to our version.config
  56. echo " $pluginName=$version" >> $config;
  57. done;
  58. echo "# --- End updateBundledPlugins.sh --- " >> $config;
  59. # Update the version in the jar
  60. jar uf $jar -C $dir com/dmdirc/version.config;
  61. # Remove the temporary directory
  62. cd ..
  63. rm -rf $dir;