#!/bin/bash

# get Email Secret ID :
last_id=$( ./ovhcli get me/notification/email/history | jq 'last(.[])' )
secret_id=$( ./ovhcli get "me/notification/email/history/${last_id}"  | jq -r '.body' | awk '/secret/ { split($NF,a,"=") ; print a[2] }' )

# retrieve or set Password from email link
./ovhcli post secret/retrieve '{ "id": "'"${secret_id}"'" }' | jq -r '.secret'

exit $?
