Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
afa06267
Commit
afa06267
authored
Mar 19, 2022
by
Ian Grant
Browse files
style: Neaten up some of the info & error messages, fix some typos
parent
d4a6d9c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
deploy/truenas.sh
View file @
afa06267
...
@@ -38,7 +38,7 @@ truenas_deploy() {
...
@@ -38,7 +38,7 @@ truenas_deploy() {
_getdeployconf DEPLOY_TRUENAS_APIKEY
_getdeployconf DEPLOY_TRUENAS_APIKEY
if
[
-z
"
$DEPLOY_TRUENAS_APIKEY
"
]
;
then
if
[
-z
"
$DEPLOY_TRUENAS_APIKEY
"
]
;
then
_err
"TrueNAS A
pi Key is
not found, please
defin
e DEPLOY_TRUENAS_APIKEY."
_err
"TrueNAS A
PI key
not found, please
set th
e DEPLOY_TRUENAS_APIKEY
environment variable
."
return
1
return
1
fi
fi
_secure_debug2 DEPLOY_TRUENAS_APIKEY
"
$DEPLOY_TRUENAS_APIKEY
"
_secure_debug2 DEPLOY_TRUENAS_APIKEY
"
$DEPLOY_TRUENAS_APIKEY
"
...
@@ -62,15 +62,14 @@ truenas_deploy() {
...
@@ -62,15 +62,14 @@ truenas_deploy() {
_info
"Testing Connection TrueNAS"
_info
"Testing Connection TrueNAS"
_response
=
$(
_get
"
$_api_url
/system/state"
)
_response
=
$(
_get
"
$_api_url
/system/state"
)
_info
"TrueNAS
S
ystem
S
tate:
$_response
."
_info
"TrueNAS
s
ystem
s
tate:
$_response
."
if
[
-z
"
$_response
"
]
;
then
if
[
-z
"
$_response
"
]
;
then
_err
"Unable to authenticate to
$_api_url
."
_err
"Unable to authenticate to
$_api_url
."
_err
'Check your Connection and set DEPLOY_TRUENAS_HOSTNAME="192.168.178.x".'
_err
'Check your connection settings are correct, e.g.'
_err
'or'
_err
'DEPLOY_TRUENAS_HOSTNAME="192.168.x.y" or DEPLOY_TRUENAS_HOSTNAME="truenas.example.com".'
_err
'set DEPLOY_TRUENAS_HOSTNAME="<truenas_dnsname>".'
_err
'DEPLOY_TRUENAS_SCHEME="https" or DEPLOY_TRUENAS_SCHEME="http".'
_err
'Check your Connection and set DEPLOY_TRUENAS_SCHEME="https".'
_err
"Verify your TrueNAS API key is valid and set correctly, e.g. DEPLOY_TRUENAS_APIKEY=xxxx...."
_err
"Check your Api Key."
return
1
return
1
fi
fi
...
@@ -78,7 +77,7 @@ truenas_deploy() {
...
@@ -78,7 +77,7 @@ truenas_deploy() {
_savedeployconf DEPLOY_TRUENAS_HOSTNAME
"
$DEPLOY_TRUENAS_HOSTNAME
"
_savedeployconf DEPLOY_TRUENAS_HOSTNAME
"
$DEPLOY_TRUENAS_HOSTNAME
"
_savedeployconf DEPLOY_TRUENAS_SCHEME
"
$DEPLOY_TRUENAS_SCHEME
"
_savedeployconf DEPLOY_TRUENAS_SCHEME
"
$DEPLOY_TRUENAS_SCHEME
"
_info
"Getting active certificate from TrueNAS"
_info
"Getting
current
active certificate from TrueNAS"
_response
=
$(
_get
"
$_api_url
/system/general"
)
_response
=
$(
_get
"
$_api_url
/system/general"
)
_active_cert_id
=
$(
echo
"
$_response
"
|
grep
-B2
'"name":'
|
grep
'id'
|
tr
-d
--
'"id: ,'
)
_active_cert_id
=
$(
echo
"
$_response
"
|
grep
-B2
'"name":'
|
grep
'id'
|
tr
-d
--
'"id: ,'
)
_active_cert_name
=
$(
echo
"
$_response
"
|
grep
'"name":'
|
sed
-n
's/.*: "\(.\{1,\}\)",$/\1/p'
)
_active_cert_name
=
$(
echo
"
$_response
"
|
grep
'"name":'
|
sed
-n
's/.*: "\(.\{1,\}\)",$/\1/p'
)
...
@@ -88,14 +87,14 @@ truenas_deploy() {
...
@@ -88,14 +87,14 @@ truenas_deploy() {
_debug Active_UI_http_redirect
"
$_param_httpsredirect
"
_debug Active_UI_http_redirect
"
$_param_httpsredirect
"
if
[
"
$DEPLOY_TRUENAS_SCHEME
"
=
"http"
]
&&
[
"
$_param_httpsredirect
"
=
"true"
]
;
then
if
[
"
$DEPLOY_TRUENAS_SCHEME
"
=
"http"
]
&&
[
"
$_param_httpsredirect
"
=
"true"
]
;
then
_info
"
http Redirect active
"
_info
"
HTTP->HTTPS redirection is enabled
"
_info
"Setting DEPLOY_TRUENAS_SCHEME to 'https'"
_info
"Setting DEPLOY_TRUENAS_SCHEME to 'https'"
DEPLOY_TRUENAS_SCHEME
=
"https"
DEPLOY_TRUENAS_SCHEME
=
"https"
_api_url
=
"
$DEPLOY_TRUENAS_SCHEME
://
$DEPLOY_TRUENAS_HOSTNAME
/api/v2.0"
_api_url
=
"
$DEPLOY_TRUENAS_SCHEME
://
$DEPLOY_TRUENAS_HOSTNAME
/api/v2.0"
_savedeployconf DEPLOY_TRUENAS_SCHEME
"
$DEPLOY_TRUENAS_SCHEME
"
_savedeployconf DEPLOY_TRUENAS_SCHEME
"
$DEPLOY_TRUENAS_SCHEME
"
fi
fi
_info
"Upload new certifi
k
ate to TrueNAS"
_info
"Upload
ing
new certifi
c
ate to TrueNAS"
_certname
=
"Letsencrypt_
$(
_utc_date |
tr
' '
'_'
|
tr
-d
--
':'
)
"
_certname
=
"Letsencrypt_
$(
_utc_date |
tr
' '
'_'
|
tr
-d
--
':'
)
"
_debug3 _certname
"
$_certname
"
_debug3 _certname
"
$_certname
"
...
@@ -104,30 +103,30 @@ truenas_deploy() {
...
@@ -104,30 +103,30 @@ truenas_deploy() {
_debug3 _add_cert_result
"
$_add_cert_result
"
_debug3 _add_cert_result
"
$_add_cert_result
"
_info
"
G
et
t
ing
Certificate list to get new Cert ID
"
_info
"
F
et
ch
ing
list of installed certificates
"
_cert_list
=
$(
_get
"
$_api_url
/system/general/ui_certificate_choices"
)
_cert_list
=
$(
_get
"
$_api_url
/system/general/ui_certificate_choices"
)
_cert_id
=
$(
echo
"
$_cert_list
"
|
grep
"
$_certname
"
|
sed
-n
's/.*"\([0-9]\{1,\}\)".*$/\1/p'
)
_cert_id
=
$(
echo
"
$_cert_list
"
|
grep
"
$_certname
"
|
sed
-n
's/.*"\([0-9]\{1,\}\)".*$/\1/p'
)
_debug3 _cert_id
"
$_cert_id
"
_debug3 _cert_id
"
$_cert_id
"
_info
"
A
ctivate
C
ertificate ID:
$_cert_id
"
_info
"
Current a
ctivate
c
ertificate ID:
$_cert_id
"
_activateData
=
"{
\"
ui_certificate
\"
:
\"
${
_cert_id
}
\"
}"
_activateData
=
"{
\"
ui_certificate
\"
:
\"
${
_cert_id
}
\"
}"
_activate_result
=
"
$(
_post
"
$_activateData
"
"
$_api_url
/system/general"
""
"PUT"
"application/json"
)
"
_activate_result
=
"
$(
_post
"
$_activateData
"
"
$_api_url
/system/general"
""
"PUT"
"application/json"
)
"
_debug3 _activate_result
"
$_activate_result
"
_debug3 _activate_result
"
$_activate_result
"
_info
"Check if WebDAV certificate is the same as the
WEB
UI"
_info
"Check
ing
if WebDAV certificate is the same as the
TrueNAS web
UI"
_webdav_list
=
$(
_get
"
$_api_url
/webdav"
)
_webdav_list
=
$(
_get
"
$_api_url
/webdav"
)
_webdav_cert_id
=
$(
echo
"
$_webdav_list
"
|
grep
'"certssl":'
|
tr
-d
--
'"certsl: ,'
)
_webdav_cert_id
=
$(
echo
"
$_webdav_list
"
|
grep
'"certssl":'
|
tr
-d
--
'"certsl: ,'
)
if
[
"
$_webdav_cert_id
"
=
"
$_active_cert_id
"
]
;
then
if
[
"
$_webdav_cert_id
"
=
"
$_active_cert_id
"
]
;
then
_info
"Updat
e
the WebDAV
C
ertificate"
_info
"Updat
ing
the WebDAV
c
ertificate"
_debug _webdav_cert_id
"
$_webdav_cert_id
"
_debug _webdav_cert_id
"
$_webdav_cert_id
"
_webdav_data
=
"{
\"
certssl
\"
:
\"
${
_cert_id
}
\"
}"
_webdav_data
=
"{
\"
certssl
\"
:
\"
${
_cert_id
}
\"
}"
_activate_webdav_cert
=
"
$(
_post
"
$_webdav_data
"
"
$_api_url
/webdav"
""
"PUT"
"application/json"
)
"
_activate_webdav_cert
=
"
$(
_post
"
$_webdav_data
"
"
$_api_url
/webdav"
""
"PUT"
"application/json"
)
"
_webdav_new_cert_id
=
$(
echo
"
$_activate_webdav_cert
"
| _json_decode |
grep
'"certssl":'
|
sed
-n
's/.*: \([0-9]\{1,\}\),\{0,1\}$/\1/p'
)
_webdav_new_cert_id
=
$(
echo
"
$_activate_webdav_cert
"
| _json_decode |
grep
'"certssl":'
|
sed
-n
's/.*: \([0-9]\{1,\}\),\{0,1\}$/\1/p'
)
if
[
"
$_webdav_new_cert_id
"
-eq
"
$_cert_id
"
]
;
then
if
[
"
$_webdav_new_cert_id
"
-eq
"
$_cert_id
"
]
;
then
_info
"WebDAV
C
ertificate update successfully"
_info
"WebDAV
c
ertificate update
d
successfully"
else
else
_err
"Unable to set WebDAV certificate"
_err
"Unable to set WebDAV certificate"
_debug3 _activate_webdav_cert
"
$_activate_webdav_cert
"
_debug3 _activate_webdav_cert
"
$_activate_webdav_cert
"
...
@@ -136,21 +135,21 @@ truenas_deploy() {
...
@@ -136,21 +135,21 @@ truenas_deploy() {
fi
fi
_debug3 _webdav_new_cert_id
"
$_webdav_new_cert_id
"
_debug3 _webdav_new_cert_id
"
$_webdav_new_cert_id
"
else
else
_info
"WebDAV certificate not
set
or not the same as
W
eb UI"
_info
"WebDAV certificate
is
not
configured
or
is
not the same as
TrueNAS w
eb UI"
fi
fi
_info
"Check if FTP certificate is the same as the
WEB
UI"
_info
"Check
ing
if FTP certificate is the same as the
TrueNAS web
UI"
_ftp_list
=
$(
_get
"
$_api_url
/ftp"
)
_ftp_list
=
$(
_get
"
$_api_url
/ftp"
)
_ftp_cert_id
=
$(
echo
"
$_ftp_list
"
|
grep
'"ssltls_certificate":'
|
tr
-d
--
'"certislfa:_ ,'
)
_ftp_cert_id
=
$(
echo
"
$_ftp_list
"
|
grep
'"ssltls_certificate":'
|
tr
-d
--
'"certislfa:_ ,'
)
if
[
"
$_ftp_cert_id
"
=
"
$_active_cert_id
"
]
;
then
if
[
"
$_ftp_cert_id
"
=
"
$_active_cert_id
"
]
;
then
_info
"Updat
e
the FTP
C
ertificate"
_info
"Updat
ing
the FTP
c
ertificate"
_debug _ftp_cert_id
"
$_ftp_cert_id
"
_debug _ftp_cert_id
"
$_ftp_cert_id
"
_ftp_data
=
"{
\"
ssltls_certificate
\"
:
\"
${
_cert_id
}
\"
}"
_ftp_data
=
"{
\"
ssltls_certificate
\"
:
\"
${
_cert_id
}
\"
}"
_activate_ftp_cert
=
"
$(
_post
"
$_ftp_data
"
"
$_api_url
/ftp"
""
"PUT"
"application/json"
)
"
_activate_ftp_cert
=
"
$(
_post
"
$_ftp_data
"
"
$_api_url
/ftp"
""
"PUT"
"application/json"
)
"
_ftp_new_cert_id
=
$(
echo
"
$_activate_ftp_cert
"
| _json_decode |
grep
'"ssltls_certificate":'
|
sed
-n
's/.*: \([0-9]\{1,\}\),\{0,1\}$/\1/p'
)
_ftp_new_cert_id
=
$(
echo
"
$_activate_ftp_cert
"
| _json_decode |
grep
'"ssltls_certificate":'
|
sed
-n
's/.*: \([0-9]\{1,\}\),\{0,1\}$/\1/p'
)
if
[
"
$_ftp_new_cert_id
"
-eq
"
$_cert_id
"
]
;
then
if
[
"
$_ftp_new_cert_id
"
-eq
"
$_cert_id
"
]
;
then
_info
"FTP
C
ertificate update successfully"
_info
"FTP
c
ertificate update
d
successfully"
else
else
_err
"Unable to set FTP certificate"
_err
"Unable to set FTP certificate"
_debug3 _activate_ftp_cert
"
$_activate_ftp_cert
"
_debug3 _activate_ftp_cert
"
$_activate_ftp_cert
"
...
@@ -185,19 +184,19 @@ truenas_deploy() {
...
@@ -185,19 +184,19 @@ truenas_deploy() {
_info
"S3 certificate is not configured or is not the same as TrueNAS web UI"
_info
"S3 certificate is not configured or is not the same as TrueNAS web UI"
fi
fi
_info
"Delet
e
old
C
ertificate"
_info
"Delet
ing
old
c
ertificate"
_delete_result
=
"
$(
_post
""
"
$_api_url
/certificate/id/
$_active_cert_id
"
""
"DELETE"
"application/json"
)
"
_delete_result
=
"
$(
_post
""
"
$_api_url
/certificate/id/
$_active_cert_id
"
""
"DELETE"
"application/json"
)
"
_debug3 _delete_result
"
$_delete_result
"
_debug3 _delete_result
"
$_delete_result
"
_info
"Reload
WebUI from
TrueNAS"
_info
"Reload
ing
TrueNAS
web UI
"
_restart_UI
=
$(
_get
"
$_api_url
/system/general/ui_restart"
)
_restart_UI
=
$(
_get
"
$_api_url
/system/general/ui_restart"
)
_debug2 _restart_UI
"
$_restart_UI
"
_debug2 _restart_UI
"
$_restart_UI
"
if
[
-n
"
$_add_cert_result
"
]
&&
[
-n
"
$_activate_result
"
]
;
then
if
[
-n
"
$_add_cert_result
"
]
&&
[
-n
"
$_activate_result
"
]
;
then
return
0
return
0
else
else
_err
"Certupdate was not succesful
l
, please
use
--debug"
_err
"Cert
ificate
update was not succesful, please
try again with
--debug"
return
1
return
1
fi
fi
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment