forked from Remzi1993/OpenSSL.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenssl-autoinstall.sh
executable file
·363 lines (327 loc) · 11.7 KB
/
openssl-autoinstall.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/usr/bin/env bash
## Author: Tommy Miland (@tmiland) - Copyright (c) 2019
######################################################################
#### OpenSSL AutoInstall ####
#### Automatic install script for OpenSSL ####
#### Maintained by @tmiland ####
######################################################################
version="1.0.1"
#------------------------------------------------------------------------------#
#
# MIT License
#
# Copyright (c) 2019 Tommy Miland
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#------------------------------------------------------------------------------#
## Uncomment for debugging purpose
#set -o errexit
#set -o pipefail
#set -o nounset
#set -o xtrace
# Detect absolute and full path as well as filename of this script
cd "$(dirname $0)"
CURRDIR=$(pwd)
SCRIPT_FILENAME=$(basename $0)
cd - > /dev/null
sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null)
if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi
SCRIPT_DIR=$(dirname "${sfp}")
if [[ $(lsb_release -si) == "Debian" || $(lsb_release -si) == "Ubuntu" ]]; then
export DEBIAN_FRONTEND=noninteractive
SUDO="sudo"
UPDATE="apt-get -o Dpkg::Progress-Fancy="1" update -qq"
INSTALL="apt-get -o Dpkg::Progress-Fancy="1" install -qq"
PKGCHK="dpkg -s"
# Pre-install packages
PRE_INSTALL_PKGS="apt-transport-https git curl sudo"
# Build-dep packages
BUILD_DEP_PKGS="build-essential ca-certificates wget libssl-dev libpcre3 libpcre3-dev autoconf unzip automake libtool tar zlib1g-dev uuid-dev lsb-release make"
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
exit 1;
fi
# Icons used for printing
ARROW='➜'
DONE='✔'
ERROR='✗'
WARNING='⚠'
# Colors used for printing
RED='\033[0;31m'
BLUE='\033[0;34m'
BBLUE='\033[1;34m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
DARKORANGE="\033[38;5;208m"
CYAN='\033[0;36m'
DARKGREY="\033[48;5;236m"
NC='\033[0m' # No Color
# Text formatting used for printing
BOLD="\033[1m"
DIM="\033[2m"
UNDERLINED="\033[4m"
INVERT="\033[7m"
HIDDEN="\033[8m"
# Repo name
REPO_NAME="tmiland/openssl-autoinstall"
# Script name
SCRIPT_NAME="openssl-autoinstall.sh"
# If you want to download a new version just change the OpenSSL version below.
OPENSSL_VERSION="1.1.1d"
# Set update check
UPDATE_SCRIPT="check"
# Make sure that the script runs with root permissions
chk_permissions() {
if [[ "$EUID" != 0 ]]; then
echo -e "${RED}${ERROR} This action needs root permissions.${NC} Please enter your root password...";
cd "$CURRDIR"
su -s "$(which bash)" -c "./$SCRIPT_FILENAME"
cd - > /dev/null
exit 0;
fi
}
##
# Download files
##
download_file () {
declare -r url=$1
declare -r tf=$(mktemp)
local dlcmd=''
dlcmd="wget -O $tf"
$dlcmd "${url}" &>/dev/null && echo "$tf" || echo '' # return the temp-filename (or empty string on error)
}
##
# Open files
##
open_file () { #expects one argument: file_path
if [ "$(uname)" == 'Darwin' ]; then
open "$1"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
xdg-open "$1"
else
echo -e "${RED}${ERROR} Error: Sorry, opening files is not supported for your OS.${NC}"
fi
}
# Get latest release tag from GitHub
get_latest_release_tag() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep '"tag_name":' |
sed -n 's/[^0-9.]*\([0-9.]*\).*/\1/p'
}
RELEASE_TAG=$(get_latest_release_tag ${REPO_NAME})
# Get latest release download url
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep '"browser_download_url":' |
sed -n 's#.*\(https*://[^"]*\).*#\1#;p'
}
LATEST_RELEASE=$(get_latest_release ${REPO_NAME})
# Get latest release notes
get_latest_release_note() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep '"body":' |
sed -n 's/.*"\([^"]*\)".*/\1/;p'
}
RELEASE_NOTE=$(get_latest_release_note ${REPO_NAME})
# Get latest release title
get_latest_release_title() {
curl --silent "https://api.github.com/repos/$1/releases/latest" |
grep -m 1 '"name":' |
sed -n 's/.*"\([^"]*\)".*/\1/;p'
}
RELEASE_TITLE=$(get_latest_release_title ${REPO_NAME})
# Header
header() {
echo -e "${GREEN}\n"
echo ' ╔═══════════════════════════════════════════════════════════════════╗'
echo ' ║ '${SCRIPT_NAME}' ║'
echo ' ║ Automatic install script for OpenSSL ║'
echo ' ║ Maintained by @tmiland ║'
echo ' ║ version: '${version}' ║'
echo ' ╚═══════════════════════════════════════════════════════════════════╝'
echo -e "${NC}"
echo -e "Documentation for this script is available here: ${ORANGE}\n${ARROW} https://github.com/tmiland/openssl-autoinstall${NC}\n"
}
# Update banner
show_update_banner () {
header
echo "Welcome to the ${SCRIPT_NAME} script."
echo ""
echo "There is a newer version of ${SCRIPT_NAME} available."
echo ""
echo ""
echo -e "${GREEN}${DONE} New version:${NC} "${RELEASE_TAG}" - ${RELEASE_TITLE}"
echo ""
echo -e "${ORANGE}${ARROW} Notes:${NC}\n"
echo -e "${BLUE}${RELEASE_NOTE}${NC}"
echo ""
}
##
# Returns the version number of ${SCRIPT_NAME} file on line 14
##
get_updater_version () {
echo $(sed -n '14 s/[^0-9.]*\([0-9.]*\).*/\1/p' "$1")
}
##
# Update script
##
# Default: Check for update, if available, ask user if they want to execute it
update_updater () {
echo -e "${GREEN}${ARROW} Checking for updates...${NC}"
# Get tmpfile from github
declare -r tmpfile=$(download_file "$LATEST_RELEASE")
if [[ $(get_updater_version "${SCRIPT_DIR}/$SCRIPT_FILENAME") < "${RELEASE_TAG}" ]]; then
if [ $UPDATE_SCRIPT = 'check' ]; then
show_update_banner
echo -e "${RED}${ARROW} Do you want to update [Y/N?]${NC}"
read -p "" -n 1 -r
echo -e "\n\n"
if [[ $REPLY =~ ^[Yy]$ ]]; then
mv "${tmpfile}" "${SCRIPT_DIR}/${SCRIPT_FILENAME}"
chmod u+x "${SCRIPT_DIR}/${SCRIPT_FILENAME}"
"${SCRIPT_DIR}/${SCRIPT_FILENAME}" "$@" -d
exit 1 # Update available, user chooses to update
fi
if [[ $REPLY =~ ^[Nn]$ ]]; then
return 1 # Update available, but user chooses not to update
fi
fi
else
echo -e "${GREEN}${DONE} No update available.${NC}"
return 0 # No update available
fi
}
##
# Ask user to update yes/no
##
if [ $# != 0 ]; then
while getopts ":ud" opt; do
case $opt in
u)
UPDATE_SCRIPT='yes'
;;
d)
UPDATE_SCRIPT='no'
;;
\?)
echo -e "${RED}\n ${ERROR} Error! Invalid option: -$OPTARG${NC}" >&2
usage
;;
:)
echo -e "${RED}${ERROR} Error! Option -$OPTARG requires an argument.${NC}" >&2
exit 1
;;
esac
done
fi
update_updater $@
cd "$CURRDIR"
# https://github.com/tmiland/latest-release
# Exit Script
exit_script() {
header
echo -e "
This script runs on coffee ☕
${GREEN}${DONE}${NC} ${BBLUE}Paypal${NC} ${ARROW} ${ORANGE}https://paypal.me/milanddata${NC}
${GREEN}${DONE}${NC} ${BBLUE}BTC${NC} ${ARROW} ${ORANGE}3MV69DmhzCqwUnbryeHrKDQxBaM724iJC2${NC}
${GREEN}${DONE}${NC} ${BBLUE}BCH${NC} ${ARROW} ${ORANGE}qznnyvpxym7a8he2ps9m6l44s373fecfnv86h2vwq2${NC}
"
echo -e "Documentation for this script is available here: ${ORANGE}\n${ARROW} https://github.com/tmiland/openssl-autoinstall${NC}\n"
echo -e "${ORANGE}${ARROW} Goodbye.${NC} ☺"
echo ""
exit
}
main() {
echo ""
echo "Choose your OpenSSL implementation :"
echo ""
echo " 1) System's OpenSSL ($(openssl version | cut -c9-14))"
echo ""
echo " 2) OpenSSL $OPENSSL_VERSION from source"
echo ""
echo " 3) Exit"
echo ""
while [[ $SSL != "1" && $SSL != "2" && $SSL != "3" ]]; do
read -p "Select an option [1-3]: " SSL
done
case $SSL in
2)
OPENSSL=y
;;
3)
exit_script
;;
esac
echo ""
read -n1 -r -p "OpenSSL is ready to be installed, press any key to continue..."
echo ""
if [[ "$OPENSSL" = 'y' ]]; then
if [[ $(lsb_release -si) == "Debian" || $(lsb_release -si) == "Ubuntu" ]]; then
# Setup Dependencies
if ! ${PKGCHK} $PRE_INSTALL_PKGS >/dev/null 2>&1; then
${UPDATE}
for i in $PRE_INSTALL_PKGS; do
${INSTALL} $i 2> /dev/null
done
fi
if ! ${PKGCHK} $BUILD_DEP_PKGS >/dev/null 2>&1; then
${SUDO} ${UPDATE}
for i in $BUILD_DEP_PKGS; do
${SUDO} ${INSTALL} $i 2> /dev/null
done
fi
# Switch to /usr/local/src and download the source package.
cd /usr/local/src
wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
# Extract the archive and move into the folder.
tar -xvzf openssl-${OPENSSL_VERSION}.tar.gz
cd openssl-${OPENSSL_VERSION}
${SUDO} ./config --prefix=/usr/local/openssl-${OPENSSL_VERSION} --openssldir=/usr/local/openssl-${OPENSSL_VERSION}
make
# Continue with install only if test succeeds
make test && ${SUDO} make install
# Create a symbolic link that points /usr/local/openssl to /usr/local/openssl-${OPENSSL_VERSION}
# This need to be done and if you have more than one installation of OpenSSL on your system you could easily switch just create a symbolic link.
${SUDO} ln -s openssl-${OPENSSL_VERSION} /usr/local/openssl
# Execute the following lines to update your Bash startup script.
echo 'export PATH=/usr/local/openssl/bin:$PATH' >> ~/.bash_profile
echo 'export MANPATH=/usr/local/openssl/ssl/man:$MANPATH' >> ~/.bash_profile
echo 'export LD_LIBRARY_PATH=/usr/local/openssl/lib' >> ~/.bash_profile
# Load the new shell configurations.
source ~/.bash_profile
# Execute the following lines to install the certificates.
# ${SUDO} security find-certificate -a -p /Library/Keychains/System.keychain > /usr/local/openssl/ssl/cert.pem
# ${SUDO} security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain >> /usr/local/openssl/ssl/cert.pem
# Take out the garbage
cd /usr/local/src
${SUDO} rm openssl-${OPENSSL_VERSION}.tar.gz
${SUDO} rm -rf openssl-${OPENSSL_VERSION}
echo -e "${GREEN}${DONE} OpenSSL has been successfully installed!${NC}"
openssl version -a
else
echo -e "${RED}${ERROR} Error: Sorry, your OS is not supported.${NC}"
exit 1;
fi
fi
}
header
chk_permissions
main $@
exit 0