Created
June 18, 2021 11:58
-
-
Save raj1rana/c6d4aeb9d30db97b9a40b8cd156c7322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
else | |
create_user(){ | |
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) | |
useradd -m -p "$pass" "$username" | |
[ $? -eq 0 ] && echo "User $username has been added to system!" || echo "Failed to add a user!" | |
} | |
create_file(){ | |
echo " | |
[$username] | |
path = /samba/$username | |
browsable =yes | |
writable = yes | |
guest ok = no | |
wins support = yes | |
valid users = share | |
read only = no | |
create mode = 0777 | |
directory mode = 0777 | |
" >> /etc/samba/smb.conf | |
} | |
create_dir(){ | |
echo "creating directory" | |
mkdir /samba/$username | |
echo "directory created /smb/$username" | |
} | |
giving_permissions(){ | |
echo "giving permission to the directory" | |
chown -R $username:sambashare /samba/$username | |
} | |
read -p "enter the username :" username \n | |
read -s -p "Enter password : " password \n | |
echo "please verify, username is :- $username" | |
echo "please verify, the password is :- $password" | |
if [[ -d "/home/$username" ]]; then | |
create_file | |
create_dir | |
create_dir | |
giving_permissions | |
else | |
create_user | |
create_file | |
create_dir | |
create_dir | |
giving_permissions | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment