Skip to content

Instantly share code, notes, and snippets.

@xerrni
Created Apr 28, 2017
Embed
What would you like to do?
MOUNT DIR SHAREABLE FOLDER
#!/bin/bash
user_list=( usr_1 usr_2 usr_3 ) #add users to this array
dst="share_name" #name of sherable dir
src="" #source dir e.g. /dir/to/share
group_name="__no_usr__" #unix group name, if not set group_name="usr_name"
if [ "$src" == "" ]
then
echo "edit source directory"
exit 10
fi
for user in ${user_list[@]}
do
s_dst="/home/${user}/${dst}"
if [ ! -d $s_dst ] #checking if dir exists
then
echo "$s_dst dont exist"
mkdir $s_dst
if [ $? -ne 0 ]
then
echo "Cant create dir: $s_dst"
exit 1
fi
chmod 770 $s_dst #adjusting permissions
if [ $? -ne 0 ]
then
echo "Cant update permissions for: $s_dst"
exit 2
fi
if [ "$group_name" == "__no_usr__" ]
then
chown root:$user $s_dst #adjusting owner and group
fi
if [ $? -ne 0 ]
then
echo "Cant update owner and group for: $s_dst"
exit 3
fi
if [ ! "$group_name" == "__no_usr__" ]
then
chown root:$group_name $s_dst #adjusting owner and group
fi
if [ $? -ne 0 ]
then
echo "Cant update owner and group for: $s_dst"
exit 4
fi
fi
mount --bind "$src" "$s_dst" #mounting dir
if [ $? -ne 0 ]
then
echo "Cant mount: $src to: $s_dst"
exit 5
fi
echo "Src: /$src Destination: $s_dst is successfully mounted."
done
echo "Executed successfully. Exit code 0"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment