-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentView.sh
More file actions
88 lines (68 loc) · 3.43 KB
/
contentView.sh
File metadata and controls
88 lines (68 loc) · 3.43 KB
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
#!/usr/bin/bash
#Written By D. Israel - Last Update 9/6/2019
#Recommend this be run once a month with similar contab entry:
#0 6 15-21 * * /usr/bin/test $(/usr/bin/date +\%u) -eq 2 && /usr/local/bin/contentView.sh
#Number of unused Content View Versions to be retained
cvCount=3
#Organization Name, if you want to set it manually
#ORG='ORG_COMPANY1234'
#Gets Orginzation Name that isn't named "Default" automatically
ORG=$(hammer --csv organization list | tail -n +2 | grep -vi default | awk -F',' '{print $2}')
#Get Content View Names
IFS=$'\n'
cvNames=($(hammer --csv content-view list | egrep -v 'Default Organization View|Name' | awk -F',' '{print $2}'))
unset IFS
#Get all Life Cycles
lcEnvs=($(hammer --csv lifecycle-environment paths --organization $ORG | tail -n +2 | sed 's/>>//g'))
echo "$(date) Generating new content view" >> /var/log/patching
for i in "${cvNames[@]}"
do
prevLCE=''
unset reverseMe
for s in "${lcEnvs[@]}"
do
curVer=''
#Skip this round, if it is Library.
if [ "$s" == "Library" ]; then
prevLCE="$s"
echo "$(date) Top level Lifecycle Environment is $s for $i." >> /var/log/patching
continue
fi
#Current contentview version ID for this contentview
curVer=$(hammer --csv content-view version list --content-view $i --environment $prevLCE --organization $ORG | tail -n +2 | awk -F',' '{print $1}')
#Check to see if Lifecycle Environment exists in org
newVer=$(hammer --csv content-view version list --content-view $i --environment $s --organization $ORG | tail -n +2 | awk -F',' '{print $1}')
if [ -n "$newVer" ]; then
echo "$(date) Promoting $s Lifecycle Environment for $i" >> /var/log/patching
#Build Array to reverse them to avoid protection errrors.
reverseMe+=("hammer content-view version promote --content-view $i --to-lifecycle-environment $s --organization $ORG --id $curVer")
else
echo "$(date) Skipping, no $s Lifecyle Environment for $i" >> /var/log/patching
prevLCE="$s"
continue
fi
prevLCE="$s"
done
min=0
max=$(( ${#reverseMe[@]} -1 ))
#Loop to reverse order of array to avoid protection errors
while [[ min -lt max ]]
do
x="${reverseMe[$min]}"
reverseMe[$min]="${reverseMe[$max]}"
reverseMe[$max]="$x"
(( min++, max-- ))
done
for t in "${reverseMe[@]}"
do
#echo $t
$($t)
done
echo "$(date) Publishing new Content View for $i Library" >> /var/log/patching
#echo "hammer content-view publish --name $i --organization $ORG"
hammer content-view publish --name $i --organization $ORG
echo "$(date) Cleanup - Leaving only $cvCount unused Content Views for $i" >> /var/log/patching
#echo "hammer content-view purge --count $cvCount --name $i --organization $ORG"
hammer content-view purge --count $cvCount --name $i --organization $ORG
echo "$(date) $i Tasks Completed" >> /var/log/patching
done