2022-06-26 02:40:39 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-06-28 03:49:39 +00:00
|
|
|
# echo $@ >> /etc/ttyserver/mkuser.log
|
|
|
|
# exit 0
|
|
|
|
|
|
|
|
#whoami >> /etc/ttyserver/mkuser.log
|
|
|
|
#exit 0
|
2022-06-26 02:40:39 +00:00
|
|
|
|
|
|
|
# $1 = username
|
|
|
|
# $2 = tempfile
|
|
|
|
LOGFILE="/etc/ttyserver/mkuser.log"
|
|
|
|
|
|
|
|
if [ "$EUID" -ne 0 ];then
|
|
|
|
#echo "Please run as root"
|
|
|
|
echo "Not run as root" >> $LOGFILE
|
|
|
|
exit 60
|
|
|
|
fi
|
|
|
|
|
|
|
|
#echo $1 >> $LOGFILE
|
2023-09-29 06:15:06 +00:00
|
|
|
# If not exists, create new user with
|
2022-06-26 02:40:39 +00:00
|
|
|
|
|
|
|
if [[ "$1" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]+$ ]]; then
|
|
|
|
echo "Valid username: \"$1\"" >> $LOGFILE
|
|
|
|
# Is valid username
|
|
|
|
CHECKUSER=`getent passwd "$1"`
|
|
|
|
if [[ ${#CHECKUSER} -gt 6 ]]; then
|
|
|
|
# User Exists
|
|
|
|
echo "\"$1\" Exists" >> $LOGFILE
|
|
|
|
else
|
2023-09-29 06:15:06 +00:00
|
|
|
mkdir -p /htusers
|
2022-06-28 03:49:39 +00:00
|
|
|
useradd -G webadd -m -b /htusers -s /usr/bin/bash --gid 1004 "$1"
|
|
|
|
ln -s "/htusers/$1/public_gemini /var/gemini/$1"
|
2022-06-26 02:40:39 +00:00
|
|
|
echo "Added \"$1\" to the system" >> $LOGFILE
|
|
|
|
fi
|
|
|
|
# Ensure SSH filder exists
|
|
|
|
USERDIR="$(eval echo "~$1")"
|
|
|
|
if [ ! -d "$USERDIR/.ssh" ]; then
|
|
|
|
echo "Generate ssh directory for \"$1\"" >> $LOGFILE
|
|
|
|
mkdir -p "$USERDIR/.ssh"
|
|
|
|
chown -R "$1" "USERDIR/.ssh"
|
|
|
|
else
|
|
|
|
echo "User .ssh exists" >> $LOGFILE
|
|
|
|
fi
|
|
|
|
# Append new key
|
|
|
|
echo "$2 -> $USERDIR/.ssh/authorized_keys" >> $LOGFILE
|
|
|
|
cat "$2" >> "$USERDIR/.ssh/authorized_keys"
|
|
|
|
chmod 700 "$USERDIR/.ssh/authorized_keys"
|
|
|
|
chown "$1" "$USERDIR/.ssh/authorized_keys"
|
|
|
|
# Remove temp file
|
|
|
|
rm -f "$2"
|
|
|
|
echo "Done appending key to \"$1\"" >> $LOGFILE
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "\"$1\" Was an invalid username" >> $LOGFILE
|
|
|
|
exit 64
|
|
|
|
fi
|