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