-
Notifications
You must be signed in to change notification settings - Fork 0
/
regensso.sh
188 lines (151 loc) · 5.85 KB
/
regensso.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
#!/bin/bash
#############################################
# Purpose: Gather data that must be provided by an admin for a new OS setup
# Author: SDW / DGL
# Incept: 2014/01/10
# Revision: $Rev$
# Updated by: $Author$
# Last change date: $LastChangedDate$
# SVN URL: $HeadURL$
#############################################
#################FUNCTION DEFINITIONS########################
# Include common_functions.h
if [[ -s /maint/scripts/common_functions.h ]]; then
source /maint/scripts/common_functions.h
elif [[ -s common_functions.h ]]; then
source common_functions.h
else
echo "Critical dependency failure: unable to locate common_functions.h"
exit 1
fi
if [[ $EUID != 0 ]]; then
echo "FAILURE: This script must be run as root or with equivalent privilege."
echo " Setup has not been completed on this system."
exit 2
fi
if [[ -z $VTS ]]; then
export VTS="date +%Y%m%d%H%M%S"
fi
if [[ -z $LOGFILE ]]; then
export LOGFILE=/var/log/install/`basename $0`.log
f_SetLogLevel 0
fi
# Variables
TPUT=/usr/bin/tput
# Server Statement of Origin
SSO=/etc/sso
# The WestCloud generated InfoSheet.
INFOSHEET=/data/westcorp/InfoSheet.xml
if [[ -s "${SSO}" ]]; then
if [[ ! -s "${SSO}.${TS}" ]]; then
/bin/mv "${SSO}" "${SSO}.${TS}"
fi
fi
# Copy the Timestamp and original generation dateS
grep "^#" ${SSO}.${TS} | grep "Server Statement of Origin generated by" > $SSO
grep "^#" ${SSO}.${TS} | grep "Generated on" >> $SSO
echo "# Server Statement of Origin last updated by $0" >> $SSO
echo "# Last updated on `date`" >> $SSO
# Copy the old values - we'll update the ones that will be refreshed
grep -v "^#" ${SSO}.${TS} >> $SSO
# Update the sitenum and sitename if needed
if [[ -e $INFOSHEET ]]; then
f_DEBUG "Using ${INFOSHEET} data."
# Use minimal tools to get the data out of the XML file.
# Blank out the name and email address to avoid confusion.
VA="unset"
sed -i "s/^VA=.*/VA=$SITENAME/" $SSO
VAFN="unset"
sed -i "s/^VAFN=.*/VAFN=$SITENAME/" $SSO
# Set the site name based on InfoSheet.xml file
SITENAME=$(echo "ls /VM_Details/vCAC_Build_Properties/Global.Site.Location" | xmllint --shell $INFOSHEET | awk '{ printf "%s",$5 }')
sed -i "s/^SITENAME=.*/SITENAME=$SITENAME/" $SSO
# Set the site number based on the site name.
SITENUM=$(grep :$SITENAME /maint/scripts/sitelist.cfg | awk -F':' '{ print $1 }')
sed -i "s/^SITENUM=.*/SITENUM=$SITENUM/" $SSO
# Set the BU name based on InfoSheet.xml file
BU=$(echo "ls /VM_Details/vCAC_Build_Properties/Global.Business.Group" | xmllint --shell $INFOSHEET | awk '{ printf "%s",$5 }')
sed -i "s/^BU=.*/BU=$BU/" $SSO
# Set the VA
VA=$(echo "ls /VM_Details/vCAC_Build_Properties/__Legacy.Workflow.User" | xmllint --shell /data/westcorp/InfoSheet.xml | awk '{ printf "%s",$5 }')
sed -i "s/^VA=.*/VA=$VA/" $SSO
# Set the SERIAL
SERIAL=$(dmidecode --type 1 | grep Serial\ Number: | cut -d: -f 2-)
sed -i "s/^SERIAL=.*/SERIAL=$SERIAL/" $SSO
# Set the NAME
NAME=$(hostname | awk -F'.' '{print $1}')
sed -i "s/^NAME=.*/NAME=$NAME/" $SSO
# Set the VCN
VCN=$(xmllint --format /data/westcorp/InfoSheet.xml | grep VirtualMachine.Admin.HostIdentity | head -1 | sed 's/.*<VirtualMachine.Admin.HostIdentity>//g' | sed 's/<.VirtualMachine.Admin.HostIdentity>//g' | sed 's/\//:/g' | rev | cut -d: -f 1 | rev)
sed -i "s/^VCN=.*/VCN=$VCN/" $SSO
fi
# Populate legacy locations with the site number
if [[ ! -d /usr/eos/data/ ]]; then mkdir -p /usr/eos/data; fi
echo "site $SITE" > /usr/eos/data/expcfg
echo "$SITE" >/etc/sitenum
## If this is a VM, then ask for the cluster or VCENTER name
#CURVCN=`grep "^VCN=" ${SSO}.${TS} | awk -F'=' '{print $2}'`
#read -p "VCenter or Cluster name [$CURVCN]: " VCN
#SAMEVCN=NO
#if [[ -z $VCN ]]; then
# VCN=CURVCN
# SAMEVCN=YES
#fi
#if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
# echo "`$VTS`:$0:User [$SUSER] Input [VCenter or Cluster name?] value entered \"$ITC\"" | $LOG1
#fi
#if [[ $SAMEVCN != YES ]]; then
# sed -i "s/^VCN=.*/VCN=$VCN/" $SSO
#fi
## Ask about the purpose of the server
#echo ""
#echo "What will this server be used for?"
#read -p "A short description such as \"Web Server\": " PURPOSE
#if [[ -z $PURPOSE ]]; then
# PURPOSE=UNSET
# if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
# echo "`$VTS`:$0:Info - User [$SUSER] declined to provide a purpose for the server" | $LOG1
# fi
#else
# if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
# echo "`$VTS`:$0:User [$SUSER] Input [Server Purpose?] value entered \"$PURPOSE\"" | $LOG1
# fi
#fi
#sed -i "s/^PURPOSE=.*/PURPOSE=$PURPOSE/" $SSO
###########NON-INTERACTIVE DETAILS##############
HN=`hostname`
CL=`uname -s`
if [[ "`f_DetectVM`" != "TRUE" ]]; then
FAMILY="Hardware.Server"
else
FAMILY="Hardware.Virtual Machine"
fi
SERIAL=`/usr/sbin/dmidecode | awk /"System Information"/,/"Serial Number"/ | grep "Serial Number" | awk -F':' '{print $NF}'`
PUBIF=`f_FindPubIF`
if [[ "$PUBIF" != "FAILURE" ]]; then
if [[ -f "/sys/class/net/${PUBIF}/address" ]]; then
MACADDR=`cat /sys/class/net/${PUBIF}/address`
else
MACADDR=UNKNOWN
fi
MACADDR=UNKNOWN
fi
NAME=`hostname | awk -F'.' '{print $1}'`
FQDN=`host $HN | awk '{print $1}'`
PTYPE=`/usr/sbin/dmidecode -t4 | grep Family: | awk -F': ' '{print $2}' | head -1`
PCACHESIZEK=`grep "cache size" /proc/cpuinfo | head -1 | awk '{print $4}'`
if [[ $PCACHESIZEK -lt 1024 ]]; then
PCACHESTRING="${PCACHESIZEK}K"
else
PCACHESTRING="$( expr $PCACHESIZEK / 1024 )M"
fi
# Add non-interactive details to SSO
sed -i "s/^CLASS=.*/CLASS=Linux/" $SSO
sed -i "s/^FAMILY=.*/FAMILY=${FAMILY}/" $SSO
sed -i "s/^NAME=.*/NAME=${NAME}/" $SSO
sed -i "s/^SERIAL=.*/SERIAL=${SERIAL}/" $SSO
sed -i "s/^DNS_HOSTNAME=.*/DNS_HOSTNAME=${FQDN}/" $SSO
sed -i "s/^MAC_ADDRESS=.*/MAC_ADDRESS=${MACADDR}/" $SSO
sed -i "s/^PROCESSOR_TYPE=.*/PROCESSOR_TYPE=${PTYPE}/" $SSO
sed -i "s/^PROCESSOR_CACHE=.*/PROCESSOR_CACHE=${PCACHESTRING}/" $SSO
exit