Created
November 25, 2020 09:26
-
-
Save Commifreak/8b247604a336ed46a2cb468fba4eb130 to your computer and use it in GitHub Desktop.
Create a new user for rstudio free
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 | |
HTTPADDR=http://rstudio-webpage/ | |
HELPADDR=http://helppage/ | |
#Skeleton to use (put Renviron in there for example | |
SKEL=/opt/ruser-skel | |
MAILSENDER=rsupport@domain.tld | |
# This script uses the folder name of the user and adds this suffix to it (without the @!) | |
MAILSUFFIX=mydomain.tld | |
echo "This script let you create a new R user easily!" | |
echo "This requires, that you enabled mail functionality" | |
echo | |
read -p "Enter the username for the new user: " UNAME | |
if [ "$UNAME" == "" ]; then | |
echo "No user provided!" | |
exit 1; | |
fi | |
echo | |
echo "Creating user..." | |
useradd -m $UNAME | |
if [ ! -d "/home/$UNAME" ]; then | |
echo "Homefolder does not exist, something went wrong!" | |
exit 1 | |
fi | |
echo "Generate a new password for the user..." | |
PW=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8` | |
echo "Set new password ($PW)..." | |
echo -e "$PW\n$PW" | passwd $UNAME | |
echo "Create default Reinviron..." | |
cp -r $SKEL/. /home/$UNAME | |
echo "Fix Home permissions" | |
chmod o-rwx /home/$UNAME | |
echo "Adding user to smbpasswd file..." | |
echo -e "$PW\n$PW" | smbpasswd -a -s $UNAME | |
tmp=$(tempfile) | |
echo "From: RServer Support <$MAILSENDER>" >> $tmp | |
echo "Subject: Your new R-Server account" >> $tmp | |
echo >> $tmp | |
echo "Hello new R User!" >> $tmp | |
echo >> $tmp | |
echo "An administrator just created a new account for the R-Server at $HTTPADDR !" >> $tmp | |
echo "You may login with the follwing credentials:" >> $tmp | |
echo >> $tmp | |
echo " * Username: $UNAME" >> $tmp | |
echo " * Password: $PW" >> $tmp | |
echo >> $tmp | |
echo "IMPORTANT: Please change your password after your first login!" >> $tmp | |
echo "You can find a tutorial (among others) for how to do it here: $HELPADDR" >> $tmp | |
echo >> $tmp | |
echo "INFO: Please have a look at $HELPADDR for other useful informations, like connecting a network drive for data exchange, as well!" >> $tmp | |
echo >> $tmp | |
echo "Regards," >> $tmp | |
echo "-The R-Server" >> $tmp | |
MAIL="$UNAME@$MAILSUFFIX" | |
read -p "Is this email correct: '$MAIL'? " YN | |
case "$YN" in | |
"n" | "N") | |
read -p "Enter correct email: " MAIL | |
;; | |
esac | |
sendmail $MAIL < $tmp | |
echo "User created, mail sent!" | |
rm $tmp | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment