#!/usr/bin/env sh # TrueNAS deploy script for SCALE/CORE using websocket # It is recommend to use a wildcard certificate # # Websocket Documentation: https://www.truenas.com/docs/api/scale_websocket_api.html # # Tested with TrueNAS Scale - Electric Eel 24.10 # Changes certificate in the following services: # - Web UI # - FTP # - iX Apps # # The following environment variables must be set: # ------------------------------------------------ # # # API KEY # # Use the folowing URL to create a new API token: /ui/apikeys # export DEPLOY_TRUENAS_APIKEY="" # Optional: # export DEPLOY_TRUENAS_HOSTNAME="" # export DEPLOY_TRUENAS_PROTOCOL="wss" # ws or wss # export DEPLOY_TRUENAS_PORT="443" # optional, e.g. 80, 443, 8443 # ### Private functions # Call websocket method # Usage: # _ws_response=$(_ws_call "math.dummycalc" "'{"x": 4, "y": 5}'") # _info "$_ws_response" # # Output: # {"z": 9} # # Arguments: # $@ - midclt arguments for call # # Returns: # JSON/JOBID _ws_call() { _debug "_ws_call arg1" "$1" _debug "_ws_call arg2" "$2" _debug "_ws_call arg3" "$3" if [ $# -eq 3 ]; then _ws_response=$(midclt --uri "$_ws_uri" -K "$DEPLOY_TRUENAS_APIKEY" call "$1" "$2" "$3") fi if [ $# -eq 2 ]; then _ws_response=$(midclt --uri "$_ws_uri" -K "$DEPLOY_TRUENAS_APIKEY" call "$1" "$2") fi if [ $# -eq 1 ]; then _ws_response=$(midclt --uri "$_ws_uri" -K "$DEPLOY_TRUENAS_APIKEY" call "$1") fi _debug "_ws_response" "$_ws_response" printf "%s" "$_ws_response" return 0 } # Upload certificate with webclient api _ws_upload_cert() { /usr/bin/env python - <