Add gsutil to path
[releng.git] / utils / retention_script.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 The Linux Foundation and others
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #  http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 ##############################################################################
17
18 PATH=$PATH:/usr/local/bin/gsutil
19
20 #These are the only projects that generate artifacts
21 for x in armband ovsnfv fuel apex compass4nfv
22 do
23
24   echo "Looking at artifacts for project $x"
25
26   while IFS= read -r artifact; do
27
28     artifact_date="$(gsutil ls -L $artifact | grep "Creation time:" | awk '{print $4,$5,$6}')"
29     age=$(($(date +%s)-$(date -d"$artifact_date" +%s)))
30     daysold=$(($age/86400))
31
32     if [[ "$daysold" -gt "10" ]]; then
33       echo "$daysold Days old deleting: $(basename $artifact)"
34     else
35       echo "$daysold Days old retaining: $(basename $artifact)"
36     fi
37
38   done < <(gsutil ls gs://artifacts.opnfv.org/"$x" |grep -v "/$")
39 done