-
-
Save anonymous/5f134f341433556d93a8 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
USER="$1"; | |
FTP_USER="$2"; | |
FTP_PASSWORD="$3"; | |
FTP_PATH="$4"; | |
FTP_PASSWD_FILE="/etc/pure-ftpd/pureftpd.passwd"; | |
CHECK_USER=`cat /etc/passwd | awk -F ":" '{ print $1 }' | grep -e "^$USER$" | wc -l`; | |
CHECK_LOGIN=`cat "$FTP_PASSWD_FILE" | grep "$FTP_USER:" | cut -d ':' -f 1 | wc -l`; | |
USER_ID=`cat /etc/passwd | grep "$USER:" | cut -d ':' -f 3`; | |
GROUP_ID=`cat /etc/passwd | grep "$USER:" | cut -d ':' -f 4`; | |
DieWithError() | |
{ | |
echo "$1" 1>&2; | |
exit 1; | |
} | |
[ -z "$USER" ] && DieWithError "Usage: $0 <user> <ftp_login> <ftp_password> <ftp_path>"; | |
[ -z "$FTP_USER" ] && DieWithError "Usage: $0 <user> <ftp_login> <ftp_password> <ftp_path>"; | |
[ -z "$FTP_PASSWORD" ] && DieWithError "Usage: $0 <user> <ftp_login> <ftp_password> <ftp_path>"; | |
[ -z "$FTP_PATH" ] && DieWithError "Usage: $0 <user> <ftp_login> <ftp_password> <ftp_path>"; | |
[ ! -d "$FTP_PATH" ] && DieWithError "Error: the specified path does not exist"; | |
[ $CHECK_USER -eq 0 ] && DieWithError "Error: the specified user does not exist"; | |
[ $CHECK_LOGIN -ne 0 ] && DieWithError "Error: the specified login already exists"; | |
echo -e "${FTP_PASSWORD}\n${FTP_PASSWORD}\n" | /usr/bin/pure-pw useradd ${FTP_USER} -u $USER_ID -g $GROUP_ID -D "$FTP_PATH" > /dev/null 2>&1; | |
pure-pw mkdb > /dev/null 2>&1; | |
/etc/init.d/pure-ftpd restart > /dev/null 2>&1; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment