Guest User

Untitled

a guest
Oct 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Tool to maintain p2 composite repositories
  4.  
  5. USAGE="Usage:
  6. `basename "$0"` <repo-dir> [options] operation, operation ...
  7. Options:
  8. --name <repo name>
  9. the repository name
  10. --eclipse <eclipse install dir>
  11. the eclipse installation to use, can also be provided as \$ECLIPSE_DIR
  12. Operations:
  13. add <child>
  14. adds a child repository to the composite repository
  15. <child> can be a directory or a URL
  16. remove <child>
  17. removes a child repository to the composite repository
  18. <child> can be a directory or a URL
  19.  
  20. Examples:
  21. Create a composite repository with subfolder build-01 as first child:
  22. $0 /path/to/repo --name \"My repository\" add build-01
  23. Add childs build-05 and build-06, remove build-01:
  24. $0 /path/to/repo add build-05 add build-06 remove build-01
  25. "
  26.  
  27. fail() {
  28. echo Composite Repository Tool
  29. if [ $# -gt 0 ]; then
  30. echo -e "Error:\n $1"
  31. fi
  32. echo "$USAGE"
  33. exit 1
  34. }
  35.  
  36. if [ "$#" -lt 1 ]; then
  37. fail "Missing parameter <repo-dir>"
  38. fi
  39.  
  40. repoDir=`readlink -nm "$1"`
  41. shift
  42. if [ ! -d "$repoDir" ]; then
  43. fail "Directory does not exist: $repoDir"
  44. fi
  45.  
  46. repoName=
  47. addRepos=
  48. removeRepos=
  49.  
  50. while [ "$#" -gt 0 ]; do
  51. param="$1"
  52. shift
  53. test -z "$1" && fail "Missing parameter for '$param'"
  54. case "$param" in
  55. -n|--name)
  56. repoName="$1"
  57. shift
  58. ;;
  59. --eclipse)
  60. ECLIPSE_DIR="$1"
  61. shift
  62. ;;
  63. add)
  64. addRepos="$addRepos <repository location=\"$1\" />"
  65. shift
  66. ;;
  67. remove)
  68. removeRepos="$removeRepos <repository location=\"$1\" />"
  69. shift
  70. ;;
  71. *)
  72. fail "Illegal parameter: $param"
  73. ;;
  74. esac
  75. done
  76.  
  77. if [ -z "$addRepos" -a -z "$removeRepos" ]; then
  78. fail "At least one add or remove operation must be given"
  79. fi
  80.  
  81. # Check Eclipse dir
  82. if [ -z "$ECLIPSE_DIR" ]; then
  83. fail "Missing ECLIPSE_DIR, must point to an Eclipse installation"
  84. fi
  85.  
  86. if [ ! -d "$ECLIPSE_DIR/plugins" ]; then
  87. fail "Invalid ECLIPSE_DIR: $ECLIPSE_DIR, must point to an Eclipse installation"
  88. fi
  89.  
  90. # Find Equinox launcher
  91. launcher=$ECLIPSE_DIR/plugins/`ls -1 $ECLIPSE_DIR/plugins 2> /dev/null | grep launcher_ | tail -n 1`
  92. echo "Using Equinox launcher: $launcher"
  93.  
  94. tmpfile=`mktemp`
  95. cat > "$tmpfile" <<EOM
  96. <?xml version="1.0" encoding="UTF-8"?>
  97. <project name="p2 composite repository">
  98. <target name="default">
  99. <p2.composite.repository>
  100. <repository compressed="true" location="${repoDir}" name="${repoName}" />
  101. <add>
  102. ${addRepos}
  103. </add>
  104. <remove>
  105. ${removeRepos}
  106. </remove>
  107. </p2.composite.repository>
  108. </target>
  109. </project>
  110. EOM
  111.  
  112. java -cp $launcher org.eclipse.core.launcher.Main \
  113. -application org.eclipse.ant.core.antRunner \
  114. -buildfile "$tmpfile" \
  115. default
  116.  
  117. rm "$tmpfile"
  118.  
  119. cat > "$repoDir/p2.index" <<EOM
  120. version=1
  121. metadata.repository.factory.order=compositeContent.xml,\!
  122. artifact.repository.factory.order=compositeArtifacts.xml,\!
  123. EOM
Add Comment
Please, Sign In to add comment