mirror of
https://github.com/myvesta/vesta
synced 2025-08-19 21:04:07 -07:00
search api for file manager
This commit is contained in:
parent
bfd900a622
commit
808d2c3849
1 changed files with 47 additions and 0 deletions
47
bin/v-search-fs-object
Executable file
47
bin/v-search-fs-object
Executable file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# info: search file or directory
|
||||||
|
# options: USER OBJECT [PATH]
|
||||||
|
#
|
||||||
|
# The function search files and directories on the file system
|
||||||
|
|
||||||
|
user=$1
|
||||||
|
object=$2
|
||||||
|
path=$3
|
||||||
|
|
||||||
|
# Checking arguments
|
||||||
|
if [ -z "$object" ]; then
|
||||||
|
echo "Usage: USER OBJECT [PATH]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Checking vesta user
|
||||||
|
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||||
|
echo "Error: vesta user $user doesn't exist"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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
|
||||||
|
if [ ! -z "$path" ]; then
|
||||||
|
rpath=$(readlink -f "$path")
|
||||||
|
if [ -z "$(echo $rpath |grep $homedir)" ]; then
|
||||||
|
echo "Error: invalid path $dst_dir"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
path=$homedir
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Listing directory
|
||||||
|
sudo -u $user find "$path" -name "$object" \
|
||||||
|
-printf "%y|%m|%TY-%Tm-%Td|%TH:%TM|%u|%g|%s|%P\n" 2>/dev/null
|
||||||
|
# -printf "%y|%m|%TY-%Tm-%Td|%TH:%TM:%TS|%u|%g|%s|%P\n" 2>/dev/null
|
||||||
|
|
||||||
|
# Exiting
|
||||||
|
exit $?
|
Loading…
Add table
Add a link
Reference in a new issue