From 808d2c3849703f6021ce0db1dcc7190788c01f7b Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Mon, 28 Sep 2015 01:58:31 +0300 Subject: [PATCH] search api for file manager --- bin/v-search-fs-object | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 bin/v-search-fs-object diff --git a/bin/v-search-fs-object b/bin/v-search-fs-object new file mode 100755 index 000000000..3c7785682 --- /dev/null +++ b/bin/v-search-fs-object @@ -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 $?