27 lines
882 B
Bash
27 lines
882 B
Bash
#!/bin/bash
|
|
# Task to set password for user (alpine::set_user_password)
|
|
|
|
# Input Variables
|
|
STAGING_IP="${PT_staging_ip}"
|
|
USERNAME="${PT_username:-moeny}"
|
|
|
|
# Function to check last command status
|
|
check_status() {
|
|
if [ $? -ne 0 ]; then
|
|
echo '{"status": "error", "message": "'"$1"'"}'
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Generate a random 15-character password locally
|
|
echo "Generating password..."
|
|
USER_PASSWORD=$(head -c 30 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 15)
|
|
echo "Debug - Generated password: ${USER_PASSWORD}"
|
|
check_status "Failed to generate password"
|
|
|
|
# Set the password for the user
|
|
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "echo '${USERNAME}:${USER_PASSWORD}' | chpasswd"
|
|
check_status "Failed to set password for ${USERNAME} user"
|
|
|
|
echo "{\"status\": \"success\", \"message\": \"User ${USERNAME} password set to: ${USER_PASSWORD}\"}"
|
|
exit 0 |