-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented truenas pool managment using curl
Signed-off-by: bornav <[email protected]>
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
#to use this script the you need to provide host, api_token and pool, optionaly my_secret if you would like to use decryption pasword for your master password | ||
|
||
|
||
#to create secret encrypted using base64 | ||
#echo $MY_SECRET|base64 --decode|openssl enc -aes-256-cbc -a -d -salt -pbkdf2 | ||
|
||
host="" # ip:port ie 10.0.0.200:500 | ||
API_TOKEN="" #api token from truenas | ||
pool="" #example "pool_name/dataset_name" | ||
|
||
export MY_SECRET="" #save here the encrypted password to use password_prottected secret | ||
|
||
user_input(){ | ||
read -p "$1 [l/u/Q]" | ||
if [[ $REPLY =~ ^[Qq]$ ]] | ||
then | ||
exit | ||
fi | ||
} | ||
|
||
if [ -z "$API_TOKEN" ] | ||
then | ||
echo "API_TOKEN is missing" | ||
exit | ||
fi | ||
|
||
user_input "Do you want to lock or unlock the dataset" | ||
if [[ $REPLY =~ ^[Uu]$ ]] | ||
then | ||
if [ -z "$MY_SECRET" ] | ||
then | ||
echo "please enter your pool secret: " | ||
read MY_SECRET | ||
else | ||
MY_SECRET=$(echo -n $MY_SECRET|base64 --decode|openssl enc -aes-256-cbc -a -d -salt -pbkdf2) | ||
fi | ||
|
||
echo $MY_SECRET | ||
curl "https://$host/api/v2.0/pool/dataset/unlock" -k -X POST -H "accept: */*" -H "Content-Type: application/json" -H "Authorization: Bearer 1-$API_TOKEN" -d "{\"id\": \"$pool\",\"unlock_options\": {\"key_file\": false,\"recursive\": false,\"toggle_attachments\": true,\"datasets\": [{\"name\" : \"$pool\" , \"passphrase\" : \"$MY_SECRET\"}]}}" | ||
elif [[ $REPLY =~ ^[Ll]$ ]] | ||
then | ||
curl "https://$host/api/v2.0/pool/dataset/lock" -k -X POST -H "accept: */*" -H "Content-Type: application/json" -H "Authorization: Bearer 1-$API_TOKEN" -d "{\"id\": \"$pool\"}" | ||
else | ||
exit | ||
fi | ||
|
||
|
||
|
||
|