#!/bin/bash
# info: list vesta autoupdate settings
# options: [FORMAT]
#
# The function for obtaining autoupdate setings.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument definition
user='admin'
format=${1-shell}

# Includes
source $VESTA/func/main.sh

# JSON list function
json_list() {
    echo '['
    if [ -z "$check_cron" ]; then
        echo -e  "\t\"Disabled\","
    else
        echo -e  "\t\"Enabled\""
    fi
    echo "]"
}

# SHELL list function
shell_list() {
    echo -n "AUTOUPDATE:     "
    if [ -z "$check_cron" ]; then
        echo "Disabled"
    else
        echo "Enabled"
    fi
}

# PLAIN list function
plain_list() {
    if [ -z "$check_cron" ]; then
        echo "Disabled"
    else
        echo "Enabled"
    fi
}

# CSV list function
csv_list() {
    echo "AUTOUPDATE"
    if [ -z "$check_cron" ]; then
        echo "Disabled"
    else
        echo "Enabled"
    fi
}


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Check cron tab
check_cron=$(grep 'v-update-sys-vesta-all' $USER_DATA/cron.conf)

# Listing data
case $format in
    json)   json_list ;;
    plain)  plain_list ;;
    csv)    csv_list ;;
    shell)  shell_list;;
esac



#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

exit