/
nx-install
executable file
·77 lines (61 loc) · 1.54 KB
/
nx-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -e
. $BASEDIR/devhelper-common
r=${REPO-public}
PWD=`pwd`
if [ "$#" -eq 0 ]
then
cat >&2 <<EOF
USAGE: nx install (FILE|G:A[:V]) [$TARGET_DIR]
This will unpack the given Nexus plugin.
If a GAV is specified, the plugin bundle will be downloaded first.
If TARGET_DIR is not specified, it will try to use ./nexus/WEB-INF/plugin-repository or unpack into the current directory.
If TARGET_DIR is specified, it will try to use \$TARGET_DIR/nexus/WEB-INF/plugin-repository or unpack into the given directory.
EOF
exit
elif [ "$#" -eq 2 ]
then
PWD="$2"
fi
PREPO="$PWD/nexus/WEB-INF/plugin-repository"
if [ -f "$1" ]
then
tmp="$1"
else
tmp=`tmpfile`
gav=`echo $1 | sed -e "s/:/ /g"`
read g a v <<EOF
$gav
EOF
if [ -z "$v" ]
then
v=LATEST
fi
bundle_url="$NEXUS/service/local/artifact/maven/redirect?r=$r&g=$g&a=$a&c=bundle&e=zip&v=$v"
echo "Downloading plugin..."
if ! curl -# "$bundle_url" -f --netrc-optional -L -o "$tmp"
then
echo >&2 "Unable to download from $bundle_url"
exit 1
fi
fi
if [ -e "$PREPO" ]
then
if [ -z "$a" ]
then
# file was given - strip version from filename and remove old plugins
a=`basename ${tmp%%-[0-9]*}`
fi
if [ `ls -d "$PREPO/$a"* | wc -l` -gt 1 ]
then
echo >&2 "Not removing old plugin: multiple matches for prefix '$a':"
ls >&2 -d "$PREPO/$a"*
else
echo "Removing old plugin: $(basename `ls -d "$PREPO/$a"*`)"
rm -rf "$PREPO/$a"*
fi
echo "Extracting plugin..."
unzip -q -o "$tmp" -d "$PREPO"
else
unzip -q -o "$tmp"
fi