39 lines
1.7 KiB
Bash
Executable File
39 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
uci_bash_shell_user_create () {
|
|
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
|
|
user=${1:-$USER}
|
|
|
|
[[ $(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
|
|
[[ ! $(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 == $USER ]] && [[ ! $(id -u $USER 2> /dev/null) -eq 0 ]] && echo user $user is not current user $USER must run with sudo && return 4
|
|
|
|
user_home=$( getent passwd $user | cut -d: -f6 )
|
|
[[ ! $user_home ]] && echo no user home directory for $user in which to install shell files, exiting && return 4
|
|
|
|
# echo DEBUG: $subdir $user $USER $user_home $dir
|
|
|
|
echo -e "*********** copying UCI BASH Shell .profile and bash_profile and .bashrc for user: $user *******"
|
|
files=$(find $install_dir/files/user -type f)
|
|
for file in $files; do
|
|
install -m 660 -o $user -g ${2:-$user} $file $user_home
|
|
done
|
|
|
|
if [[ ! $subdir == "shell" ]]; then
|
|
echo "export BASH_SHELL_USER_DIR=$user_home/$subdir" >> $user_home/.ucishell
|
|
fi
|
|
|
|
echo -e "*********** create UCI BASH Shell directories for user in $dir *******"
|
|
sdir=$user_home/$subdir
|
|
# subdirs="alias env ssh/config ssh/mounts /startup"
|
|
for dir in $(cat $BASH_SHELL_BASE/.bash-shell-include); do
|
|
mkdir -p $sdir/$dir
|
|
done
|
|
chown -R $user:$user $sdir
|
|
}
|
|
|
|
# # if script was executed then call the function
|
|
(return 0 2>/dev/null) || uci_bash_shell_user_create "$@" |