-
Notifications
You must be signed in to change notification settings - Fork 21
/
build-cacert.sh
executable file
·94 lines (74 loc) · 2.97 KB
/
build-cacert.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
#!/usr/bin/env bash
# Written and placed in public domain by Jeffrey Walton
# This script writes several Root CA certifcates needed
# for other scripts and wget downloads over HTTPS.
PKG_NAME=cacert
###############################################################################
# Get the environment as needed.
if [[ "${SETUP_ENVIRON_DONE}" != "yes" ]]; then
if ! source ./setup-environ.sh
then
echo "Failed to set environment"
exit 1
fi
fi
# The password should die when this subshell goes out of scope
if [[ "${SUDO_PASSWORD_DONE}" != "yes" ]]; then
if ! source ./setup-password.sh
then
echo "Failed to process password"
exit 1
fi
fi
###############################################################################
# setup-cacert.sh writes the certs locally for the user so we
# can download cacerts.pem using cURL or Wget. build-cacert.sh
# installs cacerts.pem in ${INSTX_CACERT_PATH}. Programs like
# cURL, Git and Wget use cacerts.pem.
if [[ ! -e "$HOME/.build-scripts/cacert/cacert.pem" ]]; then
# Hide output to cut down on noise.
./setup-cacerts.sh &>/dev/null
fi
# Line 4 is a date/time stamp
bootstrap_cacert="$(sed '4!d' "bootstrap/cacert.pem" 2>/dev/null | cut -b 40- | awk '$1=$1')"
installed_cacert="$(sed '4!d' "$INSTX_CACERT_FILE" 2>/dev/null | cut -b 40- | awk '$1=$1')"
# Wipe installed if the key is not present
if [[ ! -f "${INSTX_PKG_CACHE}/${PKG_NAME}" ]]; then
installed_cacert=""
fi
if [[ -z "${installed_cacert}" ]]; then
installed_cacert="Not available"
fi
# The bootstrap cacert.pem is the latest
if [[ "$bootstrap_cacert" == "$installed_cacert" ]]; then
#echo ""
#echo "$PKG_NAME is already installed."
exit 0
fi
###############################################################################
echo ""
echo "========================================"
echo "=========== Mozilla Root CAs ==========="
echo "========================================"
echo ""
echo "Installing cacert.pem"
echo " installed: ${installed_cacert}"
echo " available: ${bootstrap_cacert}"
BOOTSTRAP_CACERT_FILE="${INSTX_TOPDIR}/bootstrap/cacert.pem"
FIX_PERMISSIONS="${INSTX_TOPDIR}/fix-permissions.sh"
if [[ -n "${SUDO_PASSWORD}" ]]
then
printf "%s\n" "${SUDO_PASSWORD}" | sudo ${SUDO_ENV_OPT} -S mkdir -p "$INSTX_CACERT_PATH"
printf "%s\n" "${SUDO_PASSWORD}" | sudo ${SUDO_ENV_OPT} -S cp "$BOOTSTRAP_CACERT_FILE" "$INSTX_CACERT_FILE"
printf "%s\n" "${SUDO_PASSWORD}" | sudo ${SUDO_ENV_OPT} -S chmod u=rw,go=r "$INSTX_CACERT_FILE"
printf "%s\n" "${SUDO_PASSWORD}" | sudo ${SUDO_ENV_OPT} -S bash ${FIX_PERMISSIONS} "${INSTX_PREFIX}"
else
mkdir -p "$INSTX_CACERT_PATH"
cp "$BOOTSTRAP_CACERT_FILE" "$INSTX_CACERT_FILE"
chmod u=rw,go=r "$INSTX_CACERT_FILE"
bash ${FIX_PERMISSIONS} "${INSTX_PREFIX}"
fi
###############################################################################
touch "${INSTX_PKG_CACHE}/${PKG_NAME}"
###############################################################################
exit 0