lamp_setup()
{
    # Update MYSQL
    mysql -u root -e "UPDATE mysql.user SET authentication_string=PASSWORD('$panelpassword') WHERE User='root'; FLUSH PRIVILEGES;"

}

# Change password for debian-sys-maint
change_dsm_pwd() {
    dsm_usr="$(awk '/user/{print $NF; exit;}' /etc/mysql/debian.cnf)"
    old_dsm_usr_pwd="$(awk '/password/{print $NF; exit;}' /etc/mysql/debian.cnf)"
    rnd_dsm_pwd="$(< /dev/urandom tr -dc A-Za-z0-9 | head -c 32;echo)"
    mysql --user=${dsm_usr} --password=${old_dsm_usr_pwd} --execute="GRANT ALL PRIVILEGES ON *.* TO '${dsm_usr}'@'localhost' IDENTIFIED BY '${rnd_dsm_pwd}';"

    cat > /etc/mysql/debian.cnf <<EOF
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = ${dsm_usr}
password = ${rnd_dsm_pwd}
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = ${dsm_usr}
password = ${rnd_dsm_pwd}
socket   = /var/run/mysqld/mysqld.sock
EOF

    systemctl restart mysql.service
}

app_setup()
{
    lamp_setup
    if [ $? != 0 ]; then
        error "ERROR: Failed to setup LAMP..."
        exit 3
    fi
    change_dsm_pwd
    if [ $? != 0 ]; then
        error "ERROR: Failed to change debian-sys-maint"
        exit 3
    fi
}

