add_new_user.sh: add webadmin as new user.

This commit is contained in:
2018-09-13 14:17:07 +02:00
parent 5b582a6f4c
commit c12e070e67
4 changed files with 72 additions and 9 deletions

View File

@@ -36,6 +36,7 @@ else
min_uid=1000
skel_dir=/etc/skel
fi
home_dir="${home_base_dir}/${user_name}"
# - Create user if not exists
@@ -44,7 +45,11 @@ if ! id -u "${user_name}" > /dev/null 2>&1 ; then
# - Get uid/gid
# -
if [[ "$user_name" = 'sysadm' ]]; then
if [[ "$user_name" = 'webadmin' ]]; then
user_uid=1040
user_gid=1040
home_dir="/var/www"
elif [[ "$user_name" = 'sysadm' ]]; then
user_uid=1050
user_gid=1050
elif [[ "$user_name" = 'back' ]]; then
@@ -69,17 +74,17 @@ if ! id -u "${user_name}" > /dev/null 2>&1 ; then
# - Add user to system
# -
echo "$user_name:${password}:${user_uid}:${user_gid}:${user_name},,,:${home_base_dir}/${user_name}:/bin/bash" | newusers
echo "$user_name:${password}:${user_uid}:${user_gid}:${user_name},,,:${home_dir}:/bin/bash" | newusers
if [[ -d "$skel_dir" ]]; then
cp -a "${skel_dir}/.bash_logout" "${home_base_dir}/${user_name}/"
chown ${user_name}:${user_name} "${home_base_dir}/${user_name}/.bash_logout"
cp -a "${skel_dir}/.bash_logout" "${home_dir}/"
chown ${user_name}:${user_name} "${home_dir}/.bash_logout"
cp -a "${skel_dir}/.bashrc" "${home_base_dir}/${user_name}/"
chown ${user_name}:${user_name} "${home_base_dir}/${user_name}/.bashrc"
cp -a "${skel_dir}/.bashrc" "${home_dir}/"
chown ${user_name}:${user_name} "${home_dir}/.bashrc"
cp -a "${skel_dir}/.profile" "${home_base_dir}/${user_name}/"
chown ${user_name}:${user_name} "${home_base_dir}/${user_name}/.profile"
cp -a "${skel_dir}/.profile" "${home_dir}/"
chown ${user_name}:${user_name} "${home_dir}/.profile"
fi
else
user_uid=$(id -u ${user_name})
@@ -90,9 +95,14 @@ fi
# -
if $password_needed ; then
# - sysadm
# - webadmin
# -
if [[ "$user_name" = 'sysadm' ]]; then
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$6\\\$P1UvKv/0\\\$0hWHiUXQTrNl5SFf52iAY1qDYsJFhjHaVC6F6BuvazcNXkzjAcnuX5PMml5DLh4tyFpqVdPpCyAyd92YypNbu/:\2#" /etc/shadow
# - sysadm
# -
elif [[ "$user_name" = 'sysadm' ]]; then
perl -i -n -p -e "s#^(${user_name}):[^:]+:(.+)#\1:\\\$6\\\$vvccwrTc\\\$Sz1HaSb3ujObprltiG7D6U1Rr3fpgfjkKuDDWYdHzPkPx/0pEofCWC.vyTn78hcemkntl.6wVUOnJnNloKt/E/:\2#" /etc/shadow
# - chris
@@ -171,6 +181,17 @@ elif [[ -d "${home_dir}/.ssh.BAK" ]] ; then
rm -rf "${home_dir}/.ssh.BAK"
fi
if [[ -f "${templates_base_dir}/${user_name}/.ssh/config" ]]; then
ssh_config_dir="${templates_base_dir}/${user_name}/.ssh/config"
elif [[ -f "${templates_all_dir}/.ssh/config" ]] ; then
ssh_config_dir="${templates_base_dir}/${user_name}/.ssh/config"
fi
if [[ -n "$ssh_config_dir" ]] ; then
cp -a "$ssh_config_dir" "${home_dir}/.ssh/"
fi
chmod 700 ${home_dir}/.ssh
chown -R ${user_name}:${user_name} ${home_dir}/.ssh