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

40 lines
1.7 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
2023-01-18 18:36:28 -08:00
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}
2023-01-20 18:21:18 -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
[[ ! $(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 *******"
2023-01-18 18:36:28 -08:00
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
2023-03-19 11:42:55 -07:00
if [[ ! $subdir == "shell" ]]; then
echo "export BASH_SHELL_USER_DIR=$user_home/$subdir" >> $user_home/.ucishell
fi
sdir=$user_home/$subdir
2024-02-16 23:45:59 -08:00
echo -e "*********** create UCI BASH Shell directories for user in $sdir *******"
2023-03-19 11:42:55 -07:00
# subdirs="alias env ssh/config ssh/mounts /startup"
2024-02-16 23:45:59 -08:00
mkdir -p $sdir
2023-01-20 18:21:18 -08:00
for dir in $(cat $BASH_SHELL_BASE/.bash-shell-include); do
mkdir -p $sdir/$dir
done
2023-01-20 18:21:18 -08:00
chown -R $user:$user $sdir
}
# # 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 "$@"