-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_cert.sh
More file actions
executable file
·63 lines (47 loc) · 1.19 KB
/
update_cert.sh
File metadata and controls
executable file
·63 lines (47 loc) · 1.19 KB
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
#!/bin/bash
. /usr/share/openmediavault/scripts/helper-functions
. /etc/default/openmediavault
if [[ $(id -u) -ne 0 ]]; then
echo "This script must be executed as root or using sudo."
exit 99
fi
uuid="${1}"
cert="${2}"
key="${3}"
if [ -z "${uuid}" ]; then
xpath="/config/webadmin/sslcertificateref"
uuid=$(omv_config_get "${xpath}")
fi
if ! omv_isuuid "${uuid}"; then
echo "Invalid uuid"
exit 1
fi
if [ ! -f "${cert}" ]; then
echo "Cert not found"
exit 2
fi
if [ ! -f "${key}" ]; then
echo "Key not found"
exit 3
fi
echo "Cert file :: ${cert}"
echo "Key file :: ${key}"
xpath="/config/system/certificates/sslcertificate[uuid='${uuid}']"
echo "xpath :: ${xpath}"
echo
if ! omv_config_exists "${xpath}"; then
echo "Config for ${uuid} does not exist"
exit 4
fi
echo "Updating certificate in database ..."
omv_config_update "${xpath}/certificate" "$(cat ${cert})"
echo "Updating private key in database ..."
omv_config_update "${xpath}/privatekey" "$(cat ${key})"
if [ -n "${4}" ]; then
echo "Updating comment in database ..."
omv_config_update "${xpath}/comment" "${4}"
fi
echo "Updating certs and nginx..."
omv-salt deploy run certificates nginx
systemctl restart nginx
exit 0