-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-addon
executable file
·191 lines (168 loc) · 4.18 KB
/
get-addon
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# get-addon 1.2 for Omeka
# Copyright 2009-2011, John Flatness
# --------- #
# Constants #
# --------- #
scriptName="get-addon"
scriptVersion="1.2"
gitRoUrl='git://github.com/omeka'
gitRwUrl='git@github.com:omeka'
wwwUrl='http://omeka.org/files'
www=false
gitRw=false
pretend=false
# Utility paths. If you need to specify a specific version, or you do
# not have one installed in your $PATH, you can replace these with the
# actual path to the binary.
wgetBin="wget"
gitBin="git"
unzipBin="unzip"
# --------- #
# Functions #
# --------- #
# Print short usage information, and an error, if specified in $1
usage() {
if [[ -n "$1" ]]
then
echo -e "Error: $1\n"
fi
cat <<EOF
$scriptName $scriptVersion (for Omeka)
Usage: $scriptName [options] <addon name>
$scriptName -h for help and options
EOF
}
# Print long usage information/help.
# Includes the text of usage()
longHelp() {
usage
cat <<EOF
Retrieves an Omeka addon (a plugin or theme) from the Omeka addons
repository.
get-addon must be run from a plugins or themes directory inside an Omeka
installation. $scriptName will attempt to retrieve plugins when run from
within the plugins directory, and themes from within the themes directory.
With no additional options, $scriptName will checkout the addon with Git.
Options (specified below) allow other versions or formats to be selected.
Options:
-w
Read/write clone. Clones the addon from a URL that will allow push as
well as pull.
-v <version number>
Selects a specific zipped release by version number.
-p
Pretend. Outputs the commands that would be run, but performs no
operations.
-h
Displays this help text.
EOF
exit 0
}
# Throws an appropriate error when using exlusive options together.
exclusiveOptions() {
usage "The -w and -v options cannot be used together."
exit 1
}
# ----------- #
# Script body #
# ----------- #
# Parse options with getopts
while getopts ":hpwv:" opt
do
case "$opt" in
h)
longHelp
;;
w)
if [[ -z "$version" ]]
then
gitRw=true
else
exclusive_options
fi
;;
v)
version="$OPTARG"
www=true
;;
p)
pretend=true
;;
:)
usage "Option \"$OPTARG\" requires an argument."
exit 1
;;
*)
usage "Unknown option \"$OPTARG\"."
exit 1
;;
esac
done
shift $(($OPTIND-1))
# The only argument after the options should be the addon name
addon=$1
if [[ -z "$addon" ]]
then
usage "Addon not specified."
exit 1
fi
# Ensure we are running from an Omeka plugins or themes directory
if [ -f ../paths.php ]
then
case $(basename $PWD) in
'plugins')
type="plugin"
;;
'themes')
type="theme"
;;
*)
usage "$scriptName must be run from an Omeka plugins or themes directory."
exit 1
;;
esac
else
usage "$scriptName must be run from an Omeka plugins or themes directory."
exit 1
fi
if $www
then
# Set up for downloading and unzipping from omeka.org
url="$wwwUrl/{$type}s/$addon-$version.zip"
zipName=$(basename $url)
commands=( "$wgetBin -N $url" "$unzipBin $zipName" "rm $zipName" )
else
# Set up for git clone
if $gitRw
then
url="$gitRwUrl/$type-$addon.git"
else
url="$gitRoUrl/$type-$addon.git"
fi
commands=( "$gitBin clone $url $addon" )
fi
# Disallow getting a addon if a directory already exists for it
if [[ -e "$addon" ]] && ! $pretend
then
echo "Error: Addon \"$addon\" already exists."
exit 1
fi
# Actually get the addon (or print the commands for pretend)
for command in "${commands[@]}"
do
if [[ -n "$command" ]]
then
if $pretend
then
echo "$command"
else
if ! $command
then
echo "Error: Command \"$command\" failed."
exit 1;
fi
fi
fi
done
echo -e "\nAddon \"$addon\" downloaded successfully."