-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-cli
executable file
·280 lines (209 loc) · 6.1 KB
/
test-cli
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
#default user
user=($USER)
#read static variables
inst_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
#inst_root=$(dirname $(readlink -f $0))
source $inst_root/a_env_conf
source $inst_root/allas-lib
#local variables
object_name=("")
print_help=(0)
os_project_name=("none")
input_def=("")
mode=("swift")
tmp_dir=("${tmp_root}/a_get_$$_tmp")
show_filelist=(0)
query=("")
object_with_bucket=(0)
testme () {
echo "foobar"
}
echo $user
make_temp_dir
echo return is $?
echo retval is $retval
echo tempme is $tempme
echo tmp_dir is $tmp_dir
echo deleting tmpdir
ls -la $tmp_dir
clean_temp_dir
ls -la $tmp_dir
echo end
tass=""
echo tass is $tass
tass=$(testme foobar)
echo tass is $tass
exit 0
# read customer defaults
if [[ -e $HOME/.a_tools_conf ]]; then
customized=1
source $HOME/.a_tools_conf
else
customized=0
fi
#Process command line
while [[ $# -ge 1 ]]
do
case "$1" in
'--object' | '-o' )
# query file
object_name=($2)
shift
shift
;;
'--project' | '-p' )
os_project_name=($2)
shift
shift
;;
'--bucket' | '-b' )
bucket=($2)
object_with_bucket=(2)
shift
shift
;;
'--help' | '-h' )
print_help=(1)
shift
;;
*)
if [[ $object_name != "" ]]; then
echo "unknown option: $1"
echo "Object name is: $object"
exit 1
fi
object_name=("$1")
shift # No more switches
;;
esac
done
if [ $print_help -eq 1 ]; then
cat <<EOF
This tool is used to show information about a data object that has been uploaded to Allas service using the a-put command.
The basic syntax of the command is:
a-info object_name
Options:
-p, --project <project_ID> Get information about objects form the buckets of the defined project instead of the currently configured project.
-b, --bucket Object name includes bucket name and the command does not try to use the default bucket names.
Related commands: a-put, a-get, a-delete, a-find
EOF
exit 0
fi
#source $HOME/.allas_default
project_label=$(echo ${os_project_name} | sed -e s/"project_"/""/g)
#Check if connection works
if [[ $mode == "swift" ]]; then
check_swift_connection
fi
if [[ $mode == "s3cmd" ]]; then
storage_server="s3allas"
fi
if [[ $object_name == "" ]] ; then
for buc in $(rclone lsd ${storage_server}: | awk '{print $NF}')
do
echo "-------------------------------"
echo "Bucket: $buc"
rclone size ${storage_server}:$buc
if [[ $(curl https://a3s.fi/${buc}/ 2>/dev/null | grep -c '</Name>') -gt 0 ]]
then
echo "Public URL: https://a3s.fi/$buc"
fi
echo ""
done
echo "-------------------------------"
echo ""
echo "Total summary of data in ${storage_server}"
rclone about ${storage_server}:
exit
fi
#source /appl/opt/allas_conf
#input=("$1")
if [[ $object_with_bucket == 2 ]]; then
object_name=("${bucket}/${object_name}")
object_with_bucket=(1)
fi
#echo "this checks if objectname contains bucket name"
check_os=$(rclone ls ${storage_server}:$object_name 2> /dev/null | wc -l)
if [ $check_os -gt 0 ]; then
object_with_bucket=(1)
#echo "this checks if we have just a bucket defined"
buc=$(remove_slash_from_ends $object_name)
if [[ $(echo $buc | tr -cd '/' | wc -c) -eq 0 ]];then
echo "-------------------------------"
echo "Bucket: $buc"
rclone size ${storage_server}:$buc
if [[ $(curl https://a3s.fi/${buc}/ 2>/dev/null | grep -c '</Name>') -gt 0 ]]
then
echo "Public URL: https://a3s.fi/$buc"
fi
echo ""
exit
fi
fi
# check if object name contains bucket (if not defined with bucket)
if [[ $object_with_bucket == 0 ]]; then
if [ $(echo $object_name | grep -c "${user}-${project_label}-MISC" ) -eq 1 ]
then
object_with_bucket=(1)
bucket=("${user}-${project_label}-MISC")
fi
if [ $(echo $object_name | grep -c "${user}-${project_label}-HOME" ) -eq 1 ]
then
object_with_bucket=(1)
bucket=("${user}-${project_label}-HOME")
fi
if [ $(echo $object_name | grep -c "${user}-${project_label}-SCRATCH" ) -eq 1 ]
then
object_with_bucket=(1)
bucket=("${user}-${project_label}-HOME")
fi
fi
# check all buckets if the bucket is not defined
if [ $object_with_bucket == 0 ]
then
buckets=("${user}-${project_label}-MISC ${user}-${project_label}-HOME ${user}-${project_label}-SCRATCH")
num_buckets=(0)
# go through the buckets
for bn in $buckets
do
bucket_found=$(rclone ls ${storage_server}:$bn/$object_name 2> /dev/null | wc -l)
if [ $bucket_found -eq 1 ]; then
echo "Bucket: $bn contains object:$object_name"
(( num_buckets = num_buckets + 1 ))
bucket=("$bn")
fi
done
if [[ $num_buckets -eq 0 ]]; then
echo ""
echo "Could not find object: $object_name "
exit 1
fi
if [[ $num_buckets -gt 1 ]]; then
echo ""
echo "Object $object_name was found in several buckets!"
echo "Please include the bucket name in the object name"
exit 1
fi
#add bucket to the object name
object_name=("$bucket/$object_name")
else
#check if object exists
bucket_found=$(rclone ls ${storage_server}:/$object_name 2> /dev/null | wc -l)
if [ $bucket_found -ne 1 ]; then
echo ""
echo "Object $object_name was not found"
echo ""
echo "You can list all the available objects with command:"
echo " a-find"
fi
fi
rclone lsl ${storage_server}:/${object_name}
rclone cat ${storage_server}:/${object_name}_ameta
#Use curl to check is the bucket is public
buc2=$(echo ${object_name} | awk -F "/" '{print $1}')
if [[ $(curl https://a3s.fi/$buc2 2>/dev/null | grep -c '</Name>') -gt 0 ]]
then
echo "Public URL: https://a3s.fi/${object_name}"
fi
exit