#!/bin/bash

if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
    set -x
fi
set -eu
set -o pipefail

if [ -z "$DIB_PASSWORD" ]; then
    echo "Error during setup password for root"
    exit 1
fi
sed -i "s/disable_root: true/disable_root: false/" /etc/cloud/cloud.cfg
augtool -s set /files/etc/ssh/sshd_config/PasswordAuthentication yes
augtool -s set /files/etc/ssh/sshd_config/PermitRootLogin yes
augtool -s set /files/etc/ssh/ssh_config/PasswordAuthentication yes
echo -e "$DIB_PASSWORD\n$DIB_PASSWORD\n" | passwd
