-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathdeleteWorkspace.sh
executable file
·188 lines (169 loc) · 5.97 KB
/
deleteWorkspace.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
188
#!/bin/env bash
#===================================================================================
# NAME: deleteWorkspace.sh
#
# DESCRIPTION: Deletes the build workspace from Unix System Services
#
#
# SYNTAX: See Help() Section Below
#
# OPTIONS: See Help() Section Below
#
# RETURN CODES:
#
# 0 - Successful
# 4 - Warning message(s) issued. See Console messages.
# 8 - Error encountered. See Console messages.
#
# NOTE(S):
#
# 1. Review the pipeline backend configuration file
# (pipelineBackend.config)
#
# Maintenance Log
#
# Date Who Vers Description
# ---------- --- ---- --------------------------------------------------------------
# 2024/01/10 DB 1.00 Initial Release
#===================================================================================
Help() {
echo "deleteWorkspace.sh ("$PGMVERS") "
echo " "
echo "DESCRIPTION: Deletes the build workspace from Unix System Services "
echo " "
echo "Syntax: "
echo " "
echo " "$PGM" [Options] "
echo " "
echo "Options: "
echo " "
echo " -h - Display this Help. "
echo " "
echo " -w <workspace> - Directory Path to a unique "
echo " working directory "
echo " Either an absolute path "
echo " or relative path. "
echo " If a relative path is provided, "
echo " buildRootDir and the workspace "
echo " path are combined. "
echo " Default=None, Required. "
echo " "
echo " Ex: MortgageApplication/main/build-1 "
echo " "
exit 0
}
#
# Customization
# Configuration file leveraged by the backend scripts
# Either an absolute path or a relative path to the current working directory
SCRIPT_HOME="$(dirname "$0")"
pipelineConfiguration="${SCRIPT_HOME}/pipelineBackend.config"
# Customization - End
#
# Internal Variables
#set -x # Uncomment to enable shell script debug
#export BASH_XTRACEFD=1 # Write set -x trace to file descriptor
PGM=$(basename "$0")
PGMVERS="1.00"
USER=$(whoami)
SYS=$(uname -Ia)
rc=0
ERRMSG=""
# Initialized option variables passed to this script
Workspace=""
# Local Variables
HELP=$1
if [ "$HELP" = "?" ]; then
Help
fi
# Validate Shell environment
currentShell=$(ps -p $$ | grep bash)
if [ -z "${currentShell}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] The scripts are designed to run in bash. You are running a different shell. rc=${rc}. \n. $(ps -p $$)."
echo $ERRMSG
fi
#
# Print script info
if [ $rc -eq 0 ]; then
echo $PGM": [INFO] Delete Workspace script. Version="$PGMVERS
fi
# Read and import pipeline configuration
if [ $rc -eq 0 ]; then
if [ ! -f "${pipelineConfiguration}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Pipeline Configuration File (${pipelineConfiguration}) was not found. rc="$rc
echo $ERRMSG
else
source $pipelineConfiguration
fi
fi
#
# Get Options
if [ $rc -eq 0 ]; then
while getopts "hw:" opt; do
case $opt in
h)
Help
;;
w)
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
if [ -z "$argument" ] || [ "$nextchar" = "-" ]; then
rc=4
ERRMSG=$PGM": [WARNING] Build Workspace Folder Name is required. rc="$rc
echo $ERRMSG
break
fi
Workspace="$argument"
;;
:)
rc=4
ERRMSG=$PGM": [WARNING] Option -$OPTARG requires an argument. rc="$rc
echo $ERRMSG
break
;;
esac
done
fi
#
# Validate Options
validateOptions() {
if [ -z "${Workspace}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Unique Workspace parameter (-w) is required. rc="$rc
echo $ERRMSG
else
if [ ! -d "$(getWorkDirectory)" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Workspace Directory ($(getWorkDirectory)) was not found. rc="$rc
echo $ERRMSG
fi
fi
}
# Call validate Options
if [ $rc -eq 0 ]; then
validateOptions
fi
# Print info
if [ $rc -eq 0 ]; then
echo $PGM": [INFO] **************************************************************"
echo $PGM": [INFO] ** Started - Delete Workspace on HOST/USER: ${SYS}/${USER} "
echo $PGM": [INFO] ** Working Directory:" $(getWorkDirectory)
echo $PGM": [INFO] ** Workspace :" $Workspace
echo $PGM": [INFO] **************************************************************"
fi
# Delete build directory
if [ $rc -eq 0 ]; then
echo $PGM": [INFO] Deleting working directory $(getWorkDirectory): "
CMD="rm -Rf $(getWorkDirectory)"
echo $PGM": [INFO] ${CMD}"
${CMD}
rc=$?
fi
if [ $rc -eq 0 ]; then
echo $PGM": [INFO] Workspace directory successfully deleted. rc="$rc
else
echo $PGM": [ERROR] Deleting workspace directory $(getWorkDirectory) failed. rc="$rc
fi
exit $rc