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

46 lines
1.9 KiB
Bash

#!/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}
echo $subdir $user $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 $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 -C -m 660 -o $user -g ${2:-$user} $file $user_home
done
# sed -i 's/BASH_SHELL_USER_DIR=/export "$user_home\/$dir/' $user_home/.bashrc
if [[ ! subdir == "shell" ]]; then
echo "export BASH_SHELL_USER_DIR=$user_home/$subdir" >> $user_home/.ucishell
# var="export BASH_SHELL_USER_DIR="
# using $dir
# sed -i "s:${var}*.:${var}${dir}:" $user_home/.bashrc
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 $BASH_SHELL_BASE/.bash-shell-include; do
echo mkdir -p $sdir/$dir
done
}
echo chown -R $user:$user $sdir
# # if script was executed then call the function
(return 0 2>/dev/null) || uci_bash_shell_user_create "$@"