refactor user install and how $BASH_SHELL_USER_DIR is exported early.

master
Kebler Network System Administrator 2023-01-20 17:17:55 -08:00
parent 2e4ecc3539
commit 1bce77c432
9 changed files with 68 additions and 60 deletions

View File

@ -1,7 +1,3 @@
functions
function
alias
env
lang
app
tools
functions

12
env/01-system-path vendored
View File

@ -1,12 +0,0 @@
#!/bin/bash
# if sudo user then give access to these paths
if [[ $(groups | grep sudo ) ]]; then
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
fi
# prepend these take prescendence over stuff ones in /usr and /bin
# requires system-path module loaded
path_prepend /opt/bin
path_prepend "$HOME/bin"
path_prepend "$HOME/.local/bin"

View File

@ -1 +1,13 @@
module_load system-path
#!/bin/bash
module_load system-path
# if sudo user then give access to these paths
if [[ $(groups | grep sudo ) ]]; then
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
fi
# prepend these take prescendence over stuff ones in /usr and /bin
# requires system-path module loaded
path_prepend /opt/bin
path_prepend "$HOME/bin"
path_prepend "$HOME/.local/bin"

View File

@ -8,15 +8,29 @@
# env | grep BASH
# echo ---------------------
# should always be true but check anyway
if ( [[ $SHELL_INTERACTIVE ]] );then
if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then
# echo loading user $USER shell at BASH_SHELL_USER_DIR
[[ -d $HOME/BASH_SHELL_USER_DIR ]] && shell_process_directory "BASH_SHELL_USER_DIR" ||\
echo no user shell directory at $BASH_SHELL_USER_DIR to process, create one or clone a template
if [[ $BASH_SHELL_USER_DIR ]]; then
# echo loading user $USER shell at $BASH_SHELL_USER_DIR
if [[ -d $BASH_SHELL_USER_DIR ]]; then
shell_process_directory "$BASH_SHELL_USER_DIR"
else
echo no user shell directory at $BASH_SHELL_USER_DIR to process
echo creating one now
declare dir
for dir in $(cat $BASH_SHELL_BASE/.bash-shell-include); do
mkdir -p $BASH_SHELL_USER_DIR/$dir
done
fi
else
echo WARNING! user environment variable BASH_SHELL_USER_DIR was not set in $BASH_SHELL_BASE/shell.env
echo user uci shell will not load
fi
fi
# uncomment to add non-interactive setup/sourcing
# else
# echo non-login and non-interactive
fi
# anything below will be sourced by all shell types (except non-interactive/login)
# anything below will be sourced whether or not UCI shell was invoked

View File

@ -1,6 +1,7 @@
#!/bin/bash
uci_bash_shell_etc_copy () {
install_dir=${install_dir:-"$(dirname $(dirname $(realpath "${BASH_SOURCE:-$0}")))"}
echo -e "************ copying uci shell profile and bash.bashrc files to /etc ********"
files=$(find $BASH_SHELL_BASE/install/files/etc/ -maxdepth 1 -type f)
for file in $files; do install -m 644 -o root -g root $file /etc; done

View File

@ -1,6 +1,7 @@
#!/bin/bash
uci_bash_shell_root_copy () {
install_dir=${install_dir:-"$(dirname $(dirname $(realpath "${BASH_SOURCE:-$0}")))"}
echo -e "************ copying uci shell .profile and .bashrc files to /root ********"
group=root
files=$(find $install_dir/files/root -type f)

View File

@ -1,15 +1,22 @@
#!/bin/bash
uci_bash_shell_user_create () {
local user; local user_home; local dir
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}
dir=${2:-shell}
[[ $(id -u $1 2> /dev/null) -eq 0 ]] && echo user is root use root user copy script, exiting && return 1
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
[[ ! $(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 in which to install shell files, exiting && return 4
[[ ! $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)
@ -17,14 +24,23 @@ for file in $files; do
install -C -m 660 -o $user -g ${2:-$user} $file $user_home
done
sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER_DIR='$dir'' $user_home/.bashrc
# 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
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
chown -R $user:${2:-$user} $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 "$@"

View File

@ -63,27 +63,7 @@ function shell_process_directory () {
source "$DIR/load.sh"
else
shell_source_subdirs $DIR
# # default processing
# local SUBDIRS
# local IGNORE_FILE
# SUBDIRS=$([[ -f "$DIR/.bash-shell-include" ]] && cat "$DIR/.bash-shell-include" || cat "$BASH_SHELL_BASE/.bash-shell-include")
# [[ $SSH_SESSION ]] && SUBDIRS+=" ssh/session"
# IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore"
# # echo $DIR
# # echo $SUBDIRS
# for SUBDIR in $SUBDIRS; do
# if [ -e "$DIR/$SUBDIR" ]; then
# # echo processing subdirectory $DIR/$SUBDIR
# # must quote all globs to avoid bash glob expansion which is likely on
# # TODO have default set of ignores plus check for shell-ignore
# # source_dir -p "archive" -x '"*.off" "*.md" "*TODO*" "LICENSE" "*.sample"' -d 0 $DIR/$SUBDIR
# # source_dir -p "archive" -x "$excludes" -d 0 $DIR/$SUBDIR
# source_dir -f "$IGNORE_FILE" -d 0 $DIR/$SUBDIR
# # else
# # echo no subdirectory $DIR/$SUBDIR to process, ignorning
# fi
# done
fi
fi
# echo "done sourcing directory $DIR"
# else
# echo $DIR does not exist nothing to source

View File

@ -1,4 +1,5 @@
# !/bin/bash
# UCI SHELL REPOS ENVIRONMENT
# see README.md for details of how the system work
# In a nutshell its a set of directories that are sourced when creating a shell
@ -100,11 +101,6 @@ BASH_SHELL_HOST=$parent/$(hostname)
BASH_SHELL_DEV=${BASH_SHELL_DEV:-/opt/shell}
[[ -d $BASH_SHELL_DEV ]] && export BASH_SHELL_DEV
# by default USER shell sources will be looked for under $HOME/shell
export BASH_SHELL_USER_DIR=$HOME/shell
# #################### NETWORKING #########################
# set up default location to look for other network shell directories
@ -112,12 +108,16 @@ BASH_NETWORKS_DIR=$parent/networks
# BASH_NETWORKS_DIR=<some directory> # alt directory to look for networks
export BASH_NETWORKS_DIR
# set one or the other of these in custom shell.env under HOST/USER/DEV directories
# NOTE: one can set one or the other of these in custom shell.env under HOST/USER/DEV repo directories
# if you want to load networks with every shell
# export BASH_SHELL_HOME_NETWORK_LOAD=true
# export BASH_SHELL_NETWORKS_LOAD=true
# export BASH_SHELL_NETWORK=<some directory>
# source any custom environment or early overrides for current user, in particular BASH_SHELL_USER_DIR
[[ -f $HOME/.ucishell ]] && source $HOME/.ucishell > /dev/null
# by default USER shell sources will be looked for under $HOME/shell
export BASH_SHELL_USER_DIR=${BASH_SHELL_USER_DIR:-$HOME/shell}
# now load and export bootstrap module loading functions library so it is always available
set -a;source $BASH_SHELL_BASE/module.lib;set +a