#!/bin/bash
# info: get file type
# options: USER FILE
#
# The function shows file type

user=$1
path=$2

# Includes
source $HESTIA/func/main.sh

#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '2' "$#" 'USER FILE'
is_format_valid 'user'
is_object_valid 'user' 'USER' "$user"

# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
    echo "Error: user home directory doesn't exist"
    exit 12
fi

# Checking path
rpath=$(readlink -f "$path")
if [ -z "$(echo $rpath |grep $homedir)" ]; then
    echo "Error: invalid path $path"
    exit 2
fi

# Listing file type
user_exec file -i -b "$path" 2>/dev/null

# Exiting
exit $?
