Skip to content

Instantly share code, notes, and snippets.

@mcdamo
Created March 17, 2023 13:23
Show Gist options
  • Save mcdamo/ed7cdcaf51069cddd025b4bc1adf2250 to your computer and use it in GitHub Desktop.
Save mcdamo/ed7cdcaf51069cddd025b4bc1adf2250 to your computer and use it in GitHub Desktop.
Script to unlock TrueNAS dataset(s) by way of typed passphrase
#!/bin/bash
## Script to unlock TrueNAS dataset(s) by way of typed passphrase
set -e
# get dir of this script to load conf
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $DIR/api.conf
# the following should be defined in conf file:
#HOST=
#API_TOKEN=
#datasets=()
read -s -p "Enter passphrase: " PASS
echo
for dataset in "${datasets[@]}"; do
echo -n "Unlocking $dataset..."
curl "$HOST/api/v2.0/pool/dataset/unlock" -k -X POST \
-H "accept: */*" -H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{"id": "'$dataset'","unlock_options": {"key_file": false, "recursive": true, "toggle_attachments": false, "datasets": [{"name" : "'$dataset'" , "passphrase" : "'$PASS'"}]}}'
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment