-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconda.sh
232 lines (186 loc) · 5.17 KB
/
conda.sh
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
export SSB_CHANNEL_PUBLIC=http://ssb.stsci.edu/astroconda
export SSB_CHANNEL_DEV=http://ssb.stsci.edu/conda-dev
function ssb_emesg
{
echo "ERROR: $@"
}
function ssb_entry_checkpoint
{
if ! hash conda 2>/dev/null; then
ssb_emesg "'conda' was not found in your PATH"
return 1
fi
return 0
}
ssb_entry_checkpoint
retval=$?
if [[ $retval != 0 ]]; then
return $retval
fi
unset -f ssb_entry_checkpoint
function ssb_usage
{
echo "Usage: ssb {-i|-u} {-p|-d} [-an] [[package] ...]
General Arguments:
--help -h This usage message
--name [env] -n Update existing environment by name
--public -p Use astroconda
--dev -d Use conda-dev
--all -a Update all packages (supersedes [package] requests)
--yes -y Do not prompt (use with care)
Mode Arguments:
--install -i Perform an installation
--update -u Perform an update
--create -c Create an environment
Positional Arguments:
package Name of package(s) to update
"
return 0
}
function ssb
{
local cmd="conda "
local opts=""
local is_public=0
local is_dev=0
local is_all=0
local is_named=0
local is_create=0
local is_update=0
local is_install=0
if [[ $# < 1 ]]; then
ssb_emesg "Not enough arguments"
ssb_usage
return 1
fi
while [[ $# > 0 ]]
do
key=$1
case $key in
--help|-h)
ssb_usage
return 0
;;
--create|-c)
is_create=1
;;
--install|-i)
is_install=1
;;
--update|-u)
is_update=1
;;
--name|-n)
opts+="--name $2 "
is_named=1
shift
;;
--dev|-d)
opts+="--override-channels -c $SSB_CHANNEL_DEV -c defaults "
is_public=1
;;
--public|-p)
opts+="--override-channels -c $SSB_CHANNEL_PUBLIC -c defaults "
is_dev=1
;;
--all|-a)
opts+="--all "
is_all=1
;;
--yes|-y)
opts+="--yes "
;;
*)
opts+="$key "
;;
esac
shift
done
if [[ $is_public != 0 ]] && [[ $is_dev != 0 ]]; then
ssb_emesg "--public and --dev are mutually exclusive options"
ssb_usage
return 1
fi
if [[ $is_public == 0 ]] && [[ $is_dev == 0 ]]; then
ssb_emesg "--public or --dev must be specified"
ssb_usage
return 1
fi
if [[ $is_install == 0 ]] && [[ $is_update == 0 ]] && [[ $is_create == 0 ]]; then
ssb_emesg "--install, --update, or --create is required"
ssb_usage
return 1
fi
if [[ $is_all != 0 ]]; then
if [[ $is_public == 0 ]] && [[ $is_dev == 0 ]]; then
ssb_emesg "--all cannot be used without --public or --dev"
ssb_usage
return 1
fi
if [[ $is_install != 0 ]]; then
ssb_emesg "--all cannot be used with --install"
ssb_usage
return 1
fi
if [[ $is_create != 0 ]]; then
ssb_emesg "--all cannot be used with --create"
ssb_usage
return 1
fi
fi
if [[ $is_install != 0 ]]; then
if [[ $is_update != 0 ]]; then
ssb_emesg "--install and --update are mutually exclusive options"
ssb_usage
return 1
fi
if [[ $is_create != 0 ]]; then
ssb_emesg "--install and --create are mutually exclusive options"
ssb_usage
return 1
fi
fi
if [[ $is_update != 0 ]]; then
if [[ $is_install != 0 ]]; then
ssb_emesg "--update and --install are mutually exclusive options"
ssb_usage
return 1
fi
if [[ $is_create != 0 ]]; then
ssb_emesg "--update and --create are mutually exclusive options"
ssb_usage
return 1
fi
fi
if [[ $is_create != 0 ]]; then
if [[ $is_install != 0 ]]; then
ssb_emesg "--create and --install are mutually exclusive options"
ssb_usage
return 1
fi
if [[ $is_update != 0 ]]; then
ssb_emesg "--create and --update are mutually exclusive options"
ssb_usage
return 1
fi
fi
if [[ $is_install != 0 ]]; then
opts="install $opts"
fi
if [[ $is_update != 0 ]]; then
opts="update $opts"
fi
if [[ $is_create != 0 ]]; then
opts="create $opts"
fi
if [[ -z $CONDA_PREFIX ]] && [[ $is_named == 0 ]]; then
ssb_emesg "Refusing to corrupt base installation!"
ssb_emesg "You are not in an active conda environment!"
ssb_emesg "Use --name to interact with a specific environment!"
ssb_usage
return 1
fi
$cmd $opts
}
export -f ssb