-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcleaner.sh
executable file
·215 lines (165 loc) · 7.47 KB
/
cleaner.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
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
#!/bin/bash
# Copyright (c) 2024 Callum Turino
# SPDX-License-Identifier: MIT
# This is a utility script for cleaning the various project files produced from compiling and benchmarking. The script
# provides functionality for either uninstalling the OQS-OpenSSL libraries from the system, clearing the old results and generated TLS keys, or both.
# When uninstalling, the script will remove the liboqs, OQS-Provider, and OpenSSL 3.2.1 libraries from the system. When clearing the old results and keys,
# the script will remove the old test results and generated keys directories from the test-data directory.
#-------------------------------------------------------------------------------------------------------------------------------
function setup_base_env() {
# Function for setting up the basic global variables for the test suite. This includes setting the root directory
# and the global library paths for the test suite. The function establishes the root path by determining the path of the script and
# using this, determines the root directory of the project.
# Determine directory that the script is being run from
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Try and find the .dir_marker.tmp file to determine the root directory
current_dir="$script_dir"
while true; do
# Check if the .pqc_eval_dir_marker.tmp file is present
if [ -f "$current_dir/.pqc_eval_dir_marker.tmp" ]; then
root_dir="$current_dir" # Set root_dir to the directory, not including the file name
break
fi
# Move up a directory and check again
current_dir=$(dirname "$current_dir")
# If the root directory is reached and the file is not found, exit the script
if [ "$current_dir" == "/" ]; then
echo -e "Root directory path file not present, please ensure the path is correct and try again."
exit 1
fi
done
# Declaring main dir path variables based on root dir
dependency_dir="$root_dir/dependency-libs"
libs_dir="$root_dir/lib"
tmp_dir="$root_dir/tmp"
test_data_dir="$root_dir/test-data"
# Declaring global library path files
open_ssl_path="$libs_dir/openssl_3.2"
liboqs_path="$libs_dir/liboqs"
oqs_openssl_path="$libs_dir/oqs-openssl"
# Declaring global source-code path files
liboqs_source="$tmp_dir/liboqs-source"
oqs_openssl_source="$tmp_dir/oqs-openssl-source"
openssl_source="$tmp_dir/openssl-3.2.1"
}
#------------------------------------------------------------------------------
function select_uninstall_mode() {
# Function for selecting the uninstall option for the currently installed OQS libraries
echo -e "\n########################"
echo "Uninstalling Libraries"
echo -e "########################"
# Loop for setup option selection
while true; do
# Outputting options to user and getting input
echo -e "\nPlease Select one of the following uninstall options"
echo "1 - Uninstall Liboqs Library Only"
echo "2 - Uninstall OQS-Provider Library only"
echo "3 - Uninstall OpenSSL 3.2.1 Only"
echo "4 - Uninstall all Libraries"
echo "5 - Exit Setup"
read -p "Enter your choice (1-5): " user_opt
# Determining action from user input
case "$user_opt" in
1)
# Uninstall liboqs only
rm -rf "$liboqs_path"
echo -e "\nLiboqs Uninstalled"
break;;
2)
# Uninstal OQS-Provider only
rm -rf "$oqs_openssl_path"
echo -e "\nOQS-Provider Uninstalled"
break;;
3)
# Uninstall OpenSSL 3.2.1 only
rm -rf "$open_ssl_path"
echo -e "\nOpenSSL 3.2.1 Uninstalled"
break;;
4)
# Uninstall all libs
rm -rf "$libs_dir" && rm -rf "$tmp_dir" && rm -rf "$dependency_dir"
rm -rf "$root_dir/.pqc_eval_dir_marker.tmp"
echo -e "\nAll Libraries Uninstalled"
break;;
5)
echo "Exiting Uninstall Script!"
exit 1
;;
*)
echo -e "\nInvalid option, please select valid option value (1-4)\n"
;;
esac
done
}
#------------------------------------------------------------------------------
function remove_old_results() {
# Function for removing old test results and generated keys directories from the test-data directory
echo -e "\n###############################"
echo "Clearing Results and TLS Keys"
echo -e "\n###############################\n"
# Verify the user definitely wants to remove all results and keys
while true; do
read -p "Are you sure you want to remove all stored results and generated keys? This cannot be reversed if you do not have backup copies! (y/n): " user_input
# Check if user wants to remove all results and keys
if [ "$user_input" == "y" ]; then
break
elif [ "$user_input" == "n" ]; then
echo "Exiting Cleaning Script!"
exit 1
else
echo -e "\nInvalid input, please enter 'y' or 'n'\n"
fi
done
# Remove all relevant directories
rm -rf "$test_data_dir/results"
rm -rf "$test_data_dir/up-results"
rm -rf "$test_data_dir/keys"
rm -rf "$tmp_dir/*"
echo -e "\nAll results and generated keys cleared\n"
}
#------------------------------------------------------------------------------
function main() {
# Main function for controlling the uninstall utility script
# Setting up the base environment for the test suite
setup_base_env
# Outputting script title to the terminal
echo "#################################"
echo "Project Cleaner Utility Script"
echo "#################################"
# Determine what clearing action the user would like to perform
while true; do
echo -e "\nPlease select what clearing action you would like to perform"
echo "1 - Uninstall Libraries Only"
echo "2 - Clear old test results and generated TLS Keys Only"
echo "3 - Uninstall libraries and clear old test results/generated TLS keys"
echo "4 - Exit Cleaning Script"
read -p "Enter your choice (1-4): " user_opt
# Calling relevant cleaning functions based on user input
case "$user_opt" in
1)
# Uninstall Libraries Only
echo -e "\nOption 1 Selected: Uninstall Libraries Only"
select_uninstall_mode
break;;
2)
# Clear old test results and generated keys only
echo -e "\nOption 2 Selected: Clear Old Test Results and Generated TLS Keys"
remove_old_results
break;;
3)
# Uninstall both OQS libraries and clear old test results and generated keys
echo -e "\nOption 4 Selected: Uninstall Libraries and Clear Old Test Results/Generated TLS Keys"
select_uninstall_mode
remove_old_results
break;;
4)
echo "Exiting Uninstall Script!"
exit 1
;;
*)
echo -e "\nInvalid option, please select valid option value (1-4)\n"
;;
esac
done
}
main