#!/bin/bash
# info: duplicate existing package
#
# The function allows the user to duplicate an existing
# package file to facilitate easier configuration.

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

# Argument definition
package=$1
new_package=$2

# Includes
source $HESTIA/func/main.sh
source $HESTIA/conf/hestia.conf


# Perform verification if read-only mode is enabled
check_hestia_demo_mode

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

if [ ! -z $1 ]; then 
    if [ ! -f $HESTIA/data/packages/$package.pkg ]; then
        echo "Error: package does not exist."
        exit
    fi
    if [ ! -z $2 ]; then
        # Copy package
        cp -f $HESTIA/data/packages/$package.pkg $HESTIA/data/packages/$new_package.pkg
    else
        echo "Error: new package name not specified."
    fi
else
    echo "Error: package name not specified."
fi

#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#
log_event "$OK" "$ARGUMENTS"

exit
