1
0
mirror of https://github.com/serghey-rodin/vesta.git synced 2025-03-12 04:36:25 -07:00
vesta/bin/v-add-fs-directory

45 lines
896 B
Plaintext
Raw Normal View History

2015-07-16 02:21:22 +03:00
#!/bin/bash
# info: add directory
# options: USER DIRECTORY
#
# The function creates new directory on the file system
user=$1
dst_dir=$2
# Checking arguments
if [ -z "$dst_dir" ]; then
echo "Usage: USER DIRECTORY"
exit 1
fi
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
2015-08-20 18:01:27 +03:00
echo "Error: vesta user $user doesn't exist"
exit 3
2015-07-16 02:21:22 +03:00
fi
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
2015-08-20 18:01:27 +03:00
echo "Error: user home directory doesn't exist"
exit 12
2015-07-16 02:21:22 +03:00
fi
# Checking destination path
rpath=$(readlink -f "$dst_dir")
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
2015-08-20 18:01:27 +03:00
echo "Error: invalid destination path $dst_dir"
exit 2
2015-07-16 02:21:22 +03:00
fi
# Adding directory
2015-08-20 18:01:27 +03:00
sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: directory $dst_dir was not created"
exit 3
fi
2015-07-16 02:21:22 +03:00
# Extiging
2015-08-20 18:01:27 +03:00
exit