Update truenas.sh

This commit is contained in:
F-Plass 2021-02-07 21:20:56 +01:00
parent f8c11a324a
commit a836842a7e

View File

@ -63,6 +63,7 @@ truenas_deploy() {
_info "Testing Connection TrueNAS" _info "Testing Connection TrueNAS"
_response=$(_get "$_api_url/system/state") _response=$(_get "$_api_url/system/state")
_info "TrueNAS System State: $_response." _info "TrueNAS System State: $_response."
_debug _response "$_response"
if [ -z "$_response" ]; then if [ -z "$_response" ]; then
_err "Unable to authenticate to $_api_url." _err "Unable to authenticate to $_api_url."
@ -78,7 +79,6 @@ truenas_deploy() {
_saveaccountconf DEPLOY_TRUENAS_HOSTNAME "$DEPLOY_TRUENAS_HOSTNAME" _saveaccountconf DEPLOY_TRUENAS_HOSTNAME "$DEPLOY_TRUENAS_HOSTNAME"
_saveaccountconf DEPLOY_TRUENAS_SCHEME "$DEPLOY_TRUENAS_SCHEME" _saveaccountconf DEPLOY_TRUENAS_SCHEME "$DEPLOY_TRUENAS_SCHEME"
_info "Getting active certificate from TrueNAS" _info "Getting 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: ,')
@ -96,34 +96,29 @@ truenas_deploy() {
_saveaccountconf DEPLOY_TRUENAS_SCHEME "$DEPLOY_TRUENAS_SCHEME" _saveaccountconf DEPLOY_TRUENAS_SCHEME "$DEPLOY_TRUENAS_SCHEME"
fi fi
_info "Upload new certifikate to TrueNAS" _info "Upload new certifikate to TrueNAS"
_date_now() { _certname="Letsencrypt_$(_utc_date | tr ' ' '_' | tr -d -- ':')"
date -u "+%Y-%m-%d_%H%M%S"
}
_certname="Letsencrypt_$(_date_now)"
_debug3 _certname "$_certname" _debug3 _certname "$_certname"
return 0
_certData="{\"create_type\": \"CERTIFICATE_CREATE_IMPORTED\", \"name\": \"${_certname}\", \"certificate\": \"$(_json_encode <"$_cfullchain")\", \"privatekey\": \"$(_json_encode <"$_ckey")\"}" _certData="{\"create_type\": \"CERTIFICATE_CREATE_IMPORTED\", \"name\": \"${_certname}\", \"certificate\": \"$(_json_encode <"$_cfullchain")\", \"privatekey\": \"$(_json_encode <"$_ckey")\"}"
_add_cert_result="$(_post "$_certData" "$_api_url/certificate" "" "POST" "application/json")" _add_cert_result="$(_post "$_certData" "$_api_url/certificate" "" "POST" "application/json")"
_debug3 _add_cert_result "$_add_cert_result" _debug3 _add_cert_result "$_add_cert_result"
_info "Getting Certificate list to get new Cert ID" _info "Getting Certificate list to get new Cert ID"
_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 "Activate Certificate ID: $_cert_id" _info "Activate Certificate 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 if WebDAV certificate is the same as the 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: ,')
@ -147,7 +142,6 @@ truenas_deploy() {
_info "WebDAV certificate not set or not the same as Web UI" _info "WebDAV certificate not set or not the same as Web UI"
fi fi
_info "Check if FTP certificate is the same as the WEB UI" _info "Check if FTP certificate is the same as the 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:_ ,')
@ -171,18 +165,16 @@ truenas_deploy() {
_info "FTP certificate not set or not the same as Web UI" _info "FTP certificate not set or not the same as Web UI"
fi fi
_info "Delete old Certificate" _info "Delete old Certificate"
_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"
# the command # the command
# _restart_UI=$(_get "$_api_url/system/general/ui_restart") # _restart_UI=$(_get "$_api_url/system/general/ui_restart")
# throws the Error 52 # throws the Error 52
# for this command direct curl command # for this command direct curl command
_info "Reload WebUI from TrueNAS"
curl --silent -L --no-keepalive --user-agent "$USER_AGENT" -H "$_H1" "$_api_url/system/general/ui_restart" curl --silent -L --no-keepalive --user-agent "$USER_AGENT" -H "$_H1" "$_api_url/system/general/ui_restart"
_ret=$? _ret=$?
_debug2 CURL_RETURN "$_ret" _debug2 CURL_RETURN "$_ret"