refactor user install and how $BASH_SHELL_USER_DIR is exported early.
parent
2e4ecc3539
commit
1bce77c432
|
@ -1,7 +1,3 @@
|
||||||
functions
|
|
||||||
function
|
|
||||||
alias
|
alias
|
||||||
env
|
env
|
||||||
lang
|
functions
|
||||||
app
|
|
||||||
tools
|
|
||||||
|
|
|
@ -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"
|
|
|
@ -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"
|
|
@ -8,15 +8,29 @@
|
||||||
# env | grep BASH
|
# env | grep BASH
|
||||||
# echo ---------------------
|
# echo ---------------------
|
||||||
|
|
||||||
|
# should always be true but check anyway
|
||||||
if ( [[ $SHELL_INTERACTIVE ]] );then
|
if ( [[ $SHELL_INTERACTIVE ]] );then
|
||||||
if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then
|
if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then
|
||||||
# echo loading user $USER shell at BASH_SHELL_USER_DIR
|
if [[ $BASH_SHELL_USER_DIR ]]; then
|
||||||
[[ -d $HOME/BASH_SHELL_USER_DIR ]] && shell_process_directory "BASH_SHELL_USER_DIR" ||\
|
# echo loading user $USER shell at $BASH_SHELL_USER_DIR
|
||||||
echo no user shell directory at $BASH_SHELL_USER_DIR to process, create one or clone a template
|
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
|
fi
|
||||||
# uncomment to add non-interactive setup/sourcing
|
# uncomment to add non-interactive setup/sourcing
|
||||||
# else
|
# else
|
||||||
# echo non-login and non-interactive
|
# echo non-login and non-interactive
|
||||||
fi
|
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
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
uci_bash_shell_etc_copy () {
|
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 ********"
|
echo -e "************ copying uci shell profile and bash.bashrc files to /etc ********"
|
||||||
files=$(find $BASH_SHELL_BASE/install/files/etc/ -maxdepth 1 -type f)
|
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
|
for file in $files; do install -m 644 -o root -g root $file /etc; done
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
uci_bash_shell_root_copy () {
|
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 ********"
|
echo -e "************ copying uci shell .profile and .bashrc files to /root ********"
|
||||||
group=root
|
group=root
|
||||||
files=$(find $install_dir/files/root -type f)
|
files=$(find $install_dir/files/root -type f)
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
uci_bash_shell_user_create () {
|
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}
|
user=${1:-$USER}
|
||||||
dir=${2:-shell}
|
echo $subdir $user $USER
|
||||||
[[ $(id -u $1 2> /dev/null) -eq 0 ]] && echo user is root use root user copy script, exiting && return 1
|
|
||||||
|
[[ $(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
|
[[ ! $(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=$( 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 *******"
|
echo -e "*********** copying UCI BASH Shell .profile and bash_profile and .bashrc for user: $user *******"
|
||||||
files=$(find $install_dir/files/user -type f)
|
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
|
install -C -m 660 -o $user -g ${2:-$user} $file $user_home
|
||||||
done
|
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 *******"
|
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
|
sdir=$user_home/$subdir
|
||||||
chown -R $user:${2:-$user} $dir
|
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
|
# # if script was executed then call the function
|
||||||
(return 0 2>/dev/null) || uci_bash_shell_user_create "$@"
|
(return 0 2>/dev/null) || uci_bash_shell_user_create "$@"
|
|
@ -63,27 +63,7 @@ function shell_process_directory () {
|
||||||
source "$DIR/load.sh"
|
source "$DIR/load.sh"
|
||||||
else
|
else
|
||||||
shell_source_subdirs $DIR
|
shell_source_subdirs $DIR
|
||||||
# # default processing
|
fi
|
||||||
# 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
|
|
||||||
# echo "done sourcing directory $DIR"
|
# echo "done sourcing directory $DIR"
|
||||||
# else
|
# else
|
||||||
# echo $DIR does not exist nothing to source
|
# echo $DIR does not exist nothing to source
|
||||||
|
|
12
shell.env
12
shell.env
|
@ -1,4 +1,5 @@
|
||||||
# !/bin/bash
|
# !/bin/bash
|
||||||
|
|
||||||
# UCI SHELL REPOS ENVIRONMENT
|
# UCI SHELL REPOS ENVIRONMENT
|
||||||
# see README.md for details of how the system work
|
# 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
|
# 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}
|
BASH_SHELL_DEV=${BASH_SHELL_DEV:-/opt/shell}
|
||||||
[[ -d $BASH_SHELL_DEV ]] && export BASH_SHELL_DEV
|
[[ -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 #########################
|
# #################### NETWORKING #########################
|
||||||
|
|
||||||
# set up default location to look for other network shell directories
|
# 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
|
# BASH_NETWORKS_DIR=<some directory> # alt directory to look for networks
|
||||||
export BASH_NETWORKS_DIR
|
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
|
# if you want to load networks with every shell
|
||||||
# export BASH_SHELL_HOME_NETWORK_LOAD=true
|
# export BASH_SHELL_HOME_NETWORK_LOAD=true
|
||||||
# export BASH_SHELL_NETWORKS_LOAD=true
|
# export BASH_SHELL_NETWORKS_LOAD=true
|
||||||
# export BASH_SHELL_NETWORK=<some directory>
|
# 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
|
# now load and export bootstrap module loading functions library so it is always available
|
||||||
set -a;source $BASH_SHELL_BASE/module.lib;set +a
|
set -a;source $BASH_SHELL_BASE/module.lib;set +a
|
||||||
|
|
Loading…
Reference in New Issue