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-20 17:17:55 -08:00
|
|
|
local user; local user_home; local subdir; local dir
|
|
|
|
install_dir=${install_dir:-"$(dirname $(dirname $(realpath "${BASH_SOURCE:-$0}")))"}
|
|
|
|
[[ $1 == "-d" ]] && { shift; subdir=test; shift; } || subdir=shell
|
2023-01-18 16:43:21 -08:00
|
|
|
user=${1:-$USER}
|
2023-01-20 18:21:18 -08:00
|
|
|
|
2023-01-20 17:17:55 -08:00
|
|
|
[[ $(id -u $user 2> /dev/null) -eq 0 ]]
|
|
|
|
[[ $(id -u $user 2> /dev/null) -eq 0 ]] && echo user is root use root user copy script, exiting && return 1
|
2023-01-18 16:43:21 -08:00
|
|
|
[[ ! $(id -u $user) -ge 1000 ]] && echo "no user $user or user not a regular" && return 2
|
2023-01-20 17:17:55 -08:00
|
|
|
[[ ! $(getent passwd | grep $user | grep /bin/bash) ]] && echo user $user is not using bash shell, exiting && return 3
|
|
|
|
[[ ! $user == $USER ]] && [[ ! $(id -u $USER 2> /dev/null) -eq 0 ]] && echo user $user is not current user $USER must run with sudo && return 4
|
2023-01-18 16:43:21 -08:00
|
|
|
|
|
|
|
user_home=$( getent passwd $user | cut -d: -f6 )
|
2023-01-20 17:17:55 -08:00
|
|
|
[[ ! $user_home ]] && echo no user home directory for $user in which to install shell files, exiting && return 4
|
|
|
|
|
2023-01-21 08:18:40 -08:00
|
|
|
# echo DEBUG: $subdir $user $USER $user_home $dir
|
2023-01-18 16:43:21 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-01-20 17:17:55 -08:00
|
|
|
if [[ ! subdir == "shell" ]]; then
|
|
|
|
echo "export BASH_SHELL_USER_DIR=$user_home/$subdir" >> $user_home/.ucishell
|
|
|
|
fi
|
2023-01-18 16:43:21 -08:00
|
|
|
|
|
|
|
echo -e "*********** create UCI BASH Shell directories for user in $dir *******"
|
2023-01-20 17:17:55 -08:00
|
|
|
sdir=$user_home/$subdir
|
|
|
|
subdirs="alias env ssh/config ssh/mounts /startup"
|
2023-01-20 18:21:18 -08:00
|
|
|
for dir in $(cat $BASH_SHELL_BASE/.bash-shell-include); do
|
|
|
|
mkdir -p $sdir/$dir
|
2023-01-20 17:17:55 -08:00
|
|
|
done
|
2023-01-20 18:21:18 -08:00
|
|
|
chown -R $user:$user $sdir
|
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 "$@"
|