shell-base/install/scripts/copy-user.sh

31 lines
1.2 KiB
Bash

#!/bin/bash
uci_bash_shelluser_copy () {
local user; local user_home; local dir
user=${1:-$USER}
dir=${2:-shell}
[[ $(id -u $1 2> /dev/null) -eq 0 ]] && echo user is root use root user copy script, exiting && return 1
[[ ! $(id -u $user) -ge 1000 ]] && echo "no user $user or user not a regular" && return 2
[[! $(getent passwd | grep $user | grep /bin/bash) ]] && echo user $user is not using bash shell, exiting && return 3
user_home=$( getent passwd $user | cut -d: -f6 )
[[ ! $user_home ]] && echo no user home directory in which to install shell files, exiting && return 4
echo -e "*********** copying UCI BASH Shell .profile and bash_profile and .bashrc for user: $user *******"
mkdir -P
files=$(find $Install_dir/files/user -type f)
for file in $files; do
install -C -m 660 -o $user -g $user $file $user_home
done
sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER_DIR='$dir'' $user_home/.bashrc
dir=$user_home/$dir
echo -e "*********** create UCI BASH Shell directories for user in $dir *******"
mkdir -p $dir/env $dir/functions $dir/modules $dir/ssh/config $dir/ssh/mounts $dir/startup
chown -R $user:$user $dir
}
# # if script was executed then call the function
(return 0 2>/dev/null) || uci_bash_shelluser "$@"