You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hestiacp/bin/v-get-fs-file-type

47 lines
1.0 KiB

#!/bin/bash
# info: get file type
# options: USER FILE
#
# example: v-get-fs-file-type admin index.html
#
# This function shows file type
user=$1
path=$2
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
#----------------------------------------------------------#
# 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 $?