#!/bin/bash

if [ ! -e "/usr/local/hestia/data/users/admin" ]; then
    exit
fi

###############################################################
#                Initialize functions/variables               #
###############################################################

# Load upgrade functions and refresh variables/configuration
source /usr/local/hestia/func/upgrade.sh
upgrade_refresh_config

###############################################################
#             Set new version numbers for packages            #
###############################################################
# Hestia Control Panel
new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')

# phpMyAdmin
pma_v='5.0.2'

###############################################################
#               Begin standard upgrade routines               #
###############################################################


# Set up console display and welcome message
upgrade_welcome_message

# Initialize backup directories
upgrade_init_backup

# Execute version-specific upgrade scripts
upgrade_start_routine

# Upgrade phpMyAdmin if applicable
upgrade_phpmyadmin

# Set new version number in hestia.conf
upgrade_set_version $new_version

# Perform account and domain rebuild to ensure configuration files are correct
upgrade_rebuild_users

# Restart necessary services for changes to take full effect
upgrade_restart_services

# Add upgrade notification to admin user's panel and display completion message
upgrade_complete_message

exit 0
