2023-01-18 16:43:21 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-01-18 18:36:28 -08:00
|
|
|
uci_bash_shell_user_create () {
|
2023-01-18 16:43:21 -08:00
|
|
|
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 *******"
|
2023-01-18 18:36:28 -08:00
|
|
|
files=$(find $install_dir/files/user -type f)
|
2023-01-18 16:43:21 -08:00
|
|
|
for file in $files; do
|
2023-01-18 18:36:28 -08:00
|
|
|
install -C -m 660 -o $user -g ${2:-$user} $file $user_home
|
2023-01-18 16:43:21 -08:00
|
|
|
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
|
2023-01-18 18:36:28 -08:00
|
|
|
chown -R $user:${2:-$user} $dir
|
2023-01-18 16:43:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# # if script was executed then call the function
|
2023-01-18 18:36:28 -08:00
|
|
|
(return 0 2>/dev/null) || uci_bash_shell_user_create "$@"
|