-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patha-info
executable file
·288 lines (238 loc) · 7.47 KB
/
a-info
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
#default user
user=($USER)
#read static variables
inst_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
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)
# 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
;;
'--allas' | '-A' )
mode="swfit"
shift
;;
'--s3allas' )
mode="s3cmd"
shift
;;
'--lumi' | '-L' )
mode="lumi"
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
storage_server="allas"
check_swift_connection
fi
if [[ $mode == "s3cmd" ]]; then
storage_server="s3allas"
fi
if [[ $mode == "lumi" ]]; then
storage_server="lumi-o"
fi
if [[ $object_name == "" ]] ; then
rclone lsd "${storage_server}:" | awk '{$1=$2=$3=$4=""; print $0}'|sed 's/^ *//' | while read buc
do
echo "-------------------------------"
echo "Bucket: $buc"
rclone size "${storage_server}:$buc"
buc_encoded=$(python3 -c "import urllib.parse; print (urllib.parse.quote('''$buc'''))")
if [[ $(curl "https://a3s.fi/${buc_encoded}/" 2>/dev/null | grep -c '</Name>') -gt 0 ]]
then
echo "Public URL: https://a3s.fi/$buc_encoded"
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
#
#Here we print the actual output
#
# name and size
rclone lsl ${storage_server}:/${object_name}
#in case of swift protocol, we can print metadata if swift command is available
if [[ $mode == "swift" ]];then
if command -v swift >/dev/null 2>&1; then
echo "-----------------------------------------------------"
echo "Metadata for ${object_name}:"
bucket_name=$(echo $object_name | awk -F / '{print $1}')
#split bucket and object
if [[ $bucket_name != $object_name ]]; then
swift_object=$(echo $object_name | sed -e s/"${bucket_name}\/"/""/)
swift stat $bucket_name $swift_object
fi
else
echo "Detailed metadata can't be printed as swift command is not available"
fi
fi
#in case of S3 protocol, we can print metadata if s3cmd command is available
if [[ $mode == "s3cmd" ]] || [[ $mode == "lumi" ]] ;then
if command -v s3cmd >/dev/null 2>&1; then
echo "-----------------------------------------------------"
echo "Metadata for ${object_name}:"
s3cmd info "s3://${object_name}"
else
echo "Detailed metadata can't be printed as s3cmd command is not available"
fi
fi
#
echo ""
echo "--------------------------------------"
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