68 lines
1.7 KiB
Bash
68 lines
1.7 KiB
Bash
#!/bin/bash
|
|
#
|
|
# vhost-stack
|
|
# https://git.stack-source.com/msb/vhost-stack
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
# load include file
|
|
source $(dirname $0)/vhost.sh
|
|
|
|
# check for and set username
|
|
if [ -n "$1" ]; then
|
|
username=$1
|
|
else
|
|
echo "username not set"
|
|
exit 1
|
|
fi
|
|
|
|
# check for and set password
|
|
if [ -n "$2" ]; then
|
|
password=$2
|
|
else
|
|
echo "password not set"
|
|
exit 1
|
|
fi
|
|
|
|
# check for and set userid
|
|
if [ -n "$3" ]; then
|
|
userid=$3
|
|
else
|
|
echo "userid not set"
|
|
exit 1
|
|
fi
|
|
|
|
if ! /bin/grep -q "^$username:" /etc/passwd; then
|
|
newusers="$username:$password:$userid:$userid::/home/$username:/bin/bash"
|
|
echo "$newusers"|newusers
|
|
pwck -s
|
|
grpck -s
|
|
fi
|
|
|
|
if [[ ! -d "/home/$username" ]]; then
|
|
install -d -o $username -g $username -m 755 /home/$username
|
|
else
|
|
chown -R $username:$username /home/$username
|
|
fi
|
|
|
|
if [[ ! -f "/home/$username/.bash_logout" ]]; then
|
|
install -o $username -g $username -m 640 /etc/skel/.bash_logout /home/$username
|
|
fi
|
|
|
|
if [[ ! -f "/home/$username/.bashrc" ]]; then
|
|
install -o $username -g $username -m 640 /etc/skel/.bashrc /home/$username
|
|
echo '' >> /home/$username/.bashrc
|
|
echo '# local settings' >> /home/$username/.bashrc
|
|
echo '' >> /home/$username/.bashrc
|
|
echo 'export TERM=xterm-256color' >> /home/$username/.bashrc
|
|
echo '' >> /home/$username/.bashrc
|
|
echo 'command_not_found_handle () {' >> /home/$username/.bashrc
|
|
echo ' /usr/local/bin/command-not-found-handle $@' >> /home/$username/.bashrc
|
|
echo ' return 127' >> /home/$username/.bashrc
|
|
echo '}' >> /home/$username/.bashrc
|
|
fi
|
|
|
|
if [[ ! -f "/home/$username/.profile" ]]; then
|
|
install -o $username -g $username -m 640 /etc/skel/.profile /home/$username
|
|
fi
|
|
|