2023-09-22 15:15:43 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-09-23 14:43:41 +08:00
|
|
|
set +e
|
2023-09-22 15:15:43 +08:00
|
|
|
username="help@websoft9.com"
|
|
|
|
password=$(openssl rand -base64 16 | tr -d '/+' | cut -c1-16)
|
|
|
|
token=""
|
2023-10-17 14:34:36 +08:00
|
|
|
cred_path="/data/credential"
|
2023-09-22 15:15:43 +08:00
|
|
|
|
2023-10-17 14:34:36 +08:00
|
|
|
echo "Start to change nginxproxymanage users"
|
2023-09-22 15:15:43 +08:00
|
|
|
if [ -e "$cred_path" ]; then
|
|
|
|
echo "File $cred_path exists. Exiting script."
|
2023-09-22 16:38:33 +08:00
|
|
|
exit 0
|
2023-09-22 15:15:43 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "create diretory"
|
|
|
|
mkdir -p "$(dirname "$cred_path")"
|
|
|
|
|
2023-10-17 14:34:36 +08:00
|
|
|
sleep 10
|
2023-09-22 15:15:43 +08:00
|
|
|
while [ -z "$token" ]; do
|
|
|
|
sleep 5
|
|
|
|
login_data=$(curl -X POST -H "Content-Type: application/json" -d '{"identity":"admin@example.com","scope":"user", "secret":"changeme"}' http://localhost:81/api/tokens)
|
|
|
|
token=$(echo $login_data | jq -r '.token')
|
|
|
|
done
|
|
|
|
|
2023-10-17 14:34:36 +08:00
|
|
|
echo "Change username(email)"
|
2023-09-23 11:29:08 +08:00
|
|
|
while true; do
|
|
|
|
response=$(curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"email": "'$username'", "nickname": "admin", "is_disabled": false, "roles": ["admin"]}' http://localhost:81/api/users/1)
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "HTTP call successful"
|
|
|
|
break
|
|
|
|
else
|
2023-10-17 14:34:36 +08:00
|
|
|
echo "HTTP call Change username failed, retrying..."
|
2023-09-23 11:29:08 +08:00
|
|
|
sleep 5
|
|
|
|
fi
|
|
|
|
done
|
2023-09-22 15:15:43 +08:00
|
|
|
|
2023-10-17 14:34:36 +08:00
|
|
|
echo "Update password"
|
2023-09-23 11:29:08 +08:00
|
|
|
while true; do
|
|
|
|
response=$(curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"type":"password","current":"changeme","secret":"'$password'"}' http://localhost:81/api/users/1/auth)
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "HTTP call successful"
|
|
|
|
break
|
|
|
|
else
|
2023-10-17 14:34:36 +08:00
|
|
|
echo "HTTP call Update password failed, retrying..."
|
2023-09-23 11:29:08 +08:00
|
|
|
sleep 5
|
|
|
|
fi
|
|
|
|
done
|
2023-09-22 15:15:43 +08:00
|
|
|
|
|
|
|
echo "Save to credential"
|
|
|
|
json="{\"username\":\"$username\",\"password\":\"$password\"}"
|
2023-09-23 14:43:41 +08:00
|
|
|
echo "$json" > "$cred_path"
|
2023-09-26 16:06:28 +08:00
|
|
|
set -e
|