Skip to content

Commit 808d2c3

Browse files
committed
search api for file manager
1 parent bfd900a commit 808d2c3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

bin/v-search-fs-object

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# info: search file or directory
3+
# options: USER OBJECT [PATH]
4+
#
5+
# The function search files and directories on the file system
6+
7+
user=$1
8+
object=$2
9+
path=$3
10+
11+
# Checking arguments
12+
if [ -z "$object" ]; then
13+
echo "Usage: USER OBJECT [PATH]"
14+
exit 1
15+
fi
16+
17+
# Checking vesta user
18+
if [ ! -e "$VESTA/data/users/$user" ]; then
19+
echo "Error: vesta user $user doesn't exist"
20+
exit 3
21+
fi
22+
23+
# Checking user homedir
24+
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
25+
if [ -z $homedir ]; then
26+
echo "Error: user home directory doesn't exist"
27+
exit 12
28+
fi
29+
30+
# Checking path
31+
if [ ! -z "$path" ]; then
32+
rpath=$(readlink -f "$path")
33+
if [ -z "$(echo $rpath |grep $homedir)" ]; then
34+
echo "Error: invalid path $dst_dir"
35+
exit 2
36+
fi
37+
else
38+
path=$homedir
39+
fi
40+
41+
# Listing directory
42+
sudo -u $user find "$path" -name "$object" \
43+
-printf "%y|%m|%TY-%Tm-%Td|%TH:%TM|%u|%g|%s|%P\n" 2>/dev/null
44+
# -printf "%y|%m|%TY-%Tm-%Td|%TH:%TM:%TS|%u|%g|%s|%P\n" 2>/dev/null
45+
46+
# Exiting
47+
exit $?

0 commit comments

Comments
 (0)