-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
osx-ssl-certs
executable file
·187 lines (172 loc) · 4.4 KB
/
osx-ssl-certs
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
#!/usr/bin/env bash
source "$rvm_scripts_path/functions/osx-ssl-certs"
source "$rvm_scripts_path/functions/osx-ssl-certs-curl"
__rvm_osx_ssl_certs_run_select_rubies()
{
case "$2" in
(all)
__rvm_read_lines __rubies <(
__rvm_cd "$rvm_rubies_path"
__rvm_find . -maxdepth 1 -mindepth 1 -type d 2>/dev/null | cut -c 3-
)
__rubies+=(curl)
;;
(*,*)
__rvm_custom_separated_array __rubies , "$2"
;;
("")
__rubies=( "${GEM_HOME##*/}" )
;;
(*)
__rubies=( "$2" )
;;
esac
rvm_log "Selected SSL certs for: $__rubies"
}
__rvm_osx_ssl_certs_run_filter_and_run()
{
\typeset cert_file
for __ruby in "${__rubies[@]}"
do
if
[[ "${__ruby}" == "curl" ]]
then
rvm_debug "Getting SSL certs path for ${__ruby}"
__path=$(__rvm_osx_ssl_certs_curl_cert_find_path)
[[ -z $__path || " ${__paths[*]} " == *" ${__path} "* ]] || __paths+=( "${__path}" )
elif
[[ -f "${__ruby}" && -x "${__ruby}" ]]
then
rvm_debug "Getting SSL certs for ${__ruby}"
__rvm_osx_ssl_certs_file_from_openssl "${__ruby}" || return $?
__path="$cert_file"
[[ " ${__paths[*]} " == *" ${__path} "* ]] || __paths+=( "${__path}" )
elif
[[ -f "${__ruby}" ]] &&
__rvm_grep -- "-----BEGIN CERTIFICATE-----" "${__ruby}" 1>/dev/null 2>&1
then
rvm_debug "SSL certs file for ${__ruby}"
[[ " ${__paths[*]} " == *" ${__ruby} "* ]] || __paths+=( "${__ruby}" )
elif
[[ -d "${__ruby}" ]]
then
rvm_debug "SSL certs path for ${__ruby}"
[[ " ${__paths[*]} " == *" ${__ruby} "* ]] || __paths+=( "${__ruby}" )
else
rvm_debug "Getting ruby certs path for ${__ruby}"
__path="$( __rvm_with "${__ruby}" "__rvm_osx_ssl_certs_file_for_ruby" )"
[[ " ${__paths[*]} " == *" ${__path} "* ]] || __paths+=( "${__path}" )
fi
done
for __path in "${__paths[@]}"
do
rvm_debug "Updating SSL certs ${__path}"
"$1" "${__path}"
done
}
__rvm_osx_ssl_certs_run()
{
\typeset __ruby __path
\typeset -a __rubies __paths
__rubies=()
__paths=()
__rvm_osx_ssl_certs_run_select_rubies "$@"
__rvm_osx_ssl_certs_run_filter_and_run "$@"
}
__rvm_osx_ssl_certs_status()
{
__rvm_osx_ssl_certs_run __rvm_osx_ssl_certs_status_for_path "$1"
}
__rvm_osx_ssl_certs_update()
{
__rvm_osx_ssl_certs_run __rvm_osx_ssl_certs_update_for_path "$1"
}
__rvm_osx_ssl_certs_cron_status()
{
if __rvm_cron_find "$RVM_OSX_SSL_UPDATER"
then rvm_log "Automatic certs updating installed."
else rvm_warn "Automatic certs updating not installed."
fi
}
__rvm_osx_ssl_certs_cron_install()
{
if
__rvm_cron_find "$RVM_OSX_SSL_UPDATER"
then
__rvm_cron_uninstall "$RVM_OSX_SSL_UPDATER" ||
{
\typeset result=$?
rvm_error "Automatic certs updating failed uninstalling."
return $result
}
fi
if
__rvm_cron_install "$RVM_OSX_SSL_UPDATER"
then
rvm_log "Automatic certs updating installed."
else
\typeset result=$?
rvm_error "Automatic certs updating failed installing."
return $result
fi
}
__rvm_osx_ssl_certs_cron_uninstall()
{
if
__rvm_cron_find "$RVM_OSX_SSL_UPDATER"
then
if
__rvm_cron_uninstall "$RVM_OSX_SSL_UPDATER"
then
rvm_log "Automatic certs updating uninstalled."
else
\typeset result=$?
rvm_error "Automatic certs updating failed uninstalling."
return $result
fi
else
rvm_log "Automatic certs updating already uninstalled."
fi
}
__rvm_osx_ssl_certs_cron()
{
\typeset cron_action="${1:-status}"
shift 1
case "${cron_action}" in
(status|install|uninstall)
__rvm_osx_ssl_certs_cron_${cron_action}
;;
(help)
rvm_help osx-ssl-certs cron "$@"
;;
(*)
rvm_error_help "Unknown subcommand '$*' for osx-ssl-certs cron" osx-ssl-certs cron "$@"
return 1
;;
esac
}
__rvm_osx_ssl_certs()
{
\typeset action="${1:-status}"
shift 1
case "${action}" in
(status|update|cron)
if
[[ "${_system_name}" == "OSX" ]]
then
__rvm_osx_ssl_certs_${action} "$@"
else
rvm_error "'rvm osx-ssl-certs' is intended only for OSX systems, it is not required on ${_system_name}."
return 1
fi
;;
(help)
rvm_help osx-ssl-certs "$@"
;;
(*)
rvm_error_help "Unknown subcommand '$*' for osx-ssl-certs" osx-ssl-certs "$@"
return 1
;;
esac
}
__rvm_osx_ssl_certs "${args[@]}"