fix: change back to just 'shell' not .shell for user default shell directory as . is ignored by default,

feat: added 'user_exists' function
master
Kebler Network System Administrator 2021-12-31 17:38:58 -08:00
parent a15a290328
commit ec601fbb15
7 changed files with 13 additions and 9 deletions

View File

@ -29,7 +29,7 @@ if you include any of these environment variables all files in there directories
# $BASH_SHELL_HOST/all # $BASH_SHELL_HOST/all
# $BASH_SHELL_HOST/<hostname> # $BASH_SHELL_HOST/<hostname>
# sourced via $HOME/.bashrc # sourced via $HOME/.bashrc
# $HOME/.shell or $HOME/BASH_SHELL_USER # $HOME/shell or $HOME/BASH_SHELL_USER
# within each of those directories if setup.sh exits it will be run # within each of those directories if setup.sh exits it will be run
# otherwise files will be sourced exactly like in the base # otherwise files will be sourced exactly like in the base
@ -44,7 +44,7 @@ export BASH_SHELL_NETWORK=$BASH_SHELL/network
# will use $BASH_SHELL_HOST/<hostname> unless specifically set # will use $BASH_SHELL_HOST/<hostname> unless specifically set
export BASH_SHELL_HOST=$BASH_SHELL/host export BASH_SHELL_HOST=$BASH_SHELL/host
# by default SHELL sources will be looked for under $HOME/.shell # by default SHELL sources will be looked for under $HOME/shell
# but can be user set below to $HOME/$BASH_SHELL_USER # but can be user set below to $HOME/$BASH_SHELL_USER
# export BASH_SHELL_USER=<some directory under $HOME> # export BASH_SHELL_USER=<some directory under $HOME>
if there is a script setup.sh in the root of these directoies it will be run. If not then all files no matter how deep will be sourced in alpha order order. if there is a script setup.sh in the root of these directoies it will be run. If not then all files no matter how deep will be sourced in alpha order order.

View File

@ -80,7 +80,7 @@ function shell_process_directory () {
if [ -e "$DIR/$SUBDIR" ]; then if [ -e "$DIR/$SUBDIR" ]; then
# echo processing subdirectory $DIR/$SUBDIR # echo processing subdirectory $DIR/$SUBDIR
# must quote all globs to avoid bash glob expansion which is likely on # must quote all globs to avoid bash glob expansion which is likely on
# TODO have default set of ignores plus check for .shell-ignore # 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 '"*.off" "*.md" "*TODO*" "LICENSE" "*.sample"' -d 0 $DIR/$SUBDIR
# source_dir -p "archive" -x "$excludes" -d 0 $DIR/$SUBDIR # source_dir -p "archive" -x "$excludes" -d 0 $DIR/$SUBDIR
source_dir -f "$IGNORE_FILE" -d 0 $DIR/$SUBDIR source_dir -f "$IGNORE_FILE" -d 0 $DIR/$SUBDIR
@ -103,7 +103,7 @@ unset BASH_SHELL_LOADED
# add in any network directories # add in any network directories
declare networks declare networks
source "$HOME/.bashrc" source "$HOME/.bashrc"
networks="$HOME/${BASH_SHELL_USER:-".shell"}/.networks" networks="$HOME/${BASH_SHELL_USER:-"shell"}/.networks"
NETWORK_DOMAINS="$([[ -f $networks ]] && cat $networks) " NETWORK_DOMAINS="$([[ -f $networks ]] && cat $networks) "
# These will be loaded for all users # These will be loaded for all users
networks="$BASH_SHELL_HOST/$(hostname)/.networks" networks="$BASH_SHELL_HOST/$(hostname)/.networks"

View File

@ -36,7 +36,7 @@ local DIRS
local MODULE=$1 local MODULE=$1
# Precidence is user. current hosts, all hosts, current network, all networks, base # Precidence is user. current hosts, all hosts, current network, all networks, base
DIRS=( \ DIRS=( \
$([ $BASH_SHELL_USER ] && echo $HOME/$BASH_SHELL_USER || echo $HOME/.shell) \ $([ $BASH_SHELL_USER ] && echo $HOME/$BASH_SHELL_USER || echo $HOME/shell) \
$BASH_SHELL_HOST/$(hostname) $BASH_SHELL_HOST/$(hostname)
$BASH_SHELL_HOST/all \ $BASH_SHELL_HOST/all \
$BASH_SHELL_NETWORK/$NETWORKNAME \ $BASH_SHELL_NETWORK/$NETWORKNAME \

View File

@ -22,6 +22,10 @@ adirname() {
echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )" echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )"
} }
user_exists() {
id -u $1 > /dev/null 2>&1
[[ $? == 1 ]] || echo $1
}
chmod_dirs() { chmod_dirs() {

View File

@ -34,9 +34,9 @@ for file in $files; do
cmd="install -C -m 660 -o $_USER -g sudo $file $_USER_DIR" cmd="install -C -m 660 -o $_USER -g sudo $file $_USER_DIR"
[[ $USER = "$_USER" ]] && eval $cmd || sudo -E -- bash -c "$cmd" [[ $USER = "$_USER" ]] && eval $cmd || sudo -E -- bash -c "$cmd"
done done
echo "the default user bash shell repo subdirecty is \`.shell\`" echo "the default user bash shell repo subdirecty is \`shell\`"
echo "enter an alternative subdirectory under $_USER_DIR or just <enter> to accept default" echo "enter an alternative subdirectory under $_USER_DIR or just <enter> to accept default"
read -e answer read -e answer
[[ ! $answer ]] && echo will source default user shell repo at $_USER_DIR/.shell && exit 0 [[ ! $answer ]] && echo will source default user shell repo at $_USER_DIR/shell && exit 0
sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER='$answer'' $_USER_DIR/.bashrc sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER='$answer'' $_USER_DIR/.bashrc
echo will be processing user shell repo at $_USER_DIR/$answer echo will be processing user shell repo at $_USER_DIR/$answer

View File

@ -11,7 +11,7 @@
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 shell sources # echo loading user shell sources
export BASH_SHELL_USER=${BASH_SHELL_USER:-".shell"} export BASH_SHELL_USER=${BASH_SHELL_USER:-"shell"}
[[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\ [[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\
echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template
fi fi

View File

@ -67,7 +67,7 @@ export BASH_SHELL_NETWORK=$([[ -d $parent/network ]] && echo $parent/network ||
# or comment above and set explictly # or comment above and set explictly
# export BASH_SHELL_NETWORK=<some directory> # export BASH_SHELL_NETWORK=<some directory>
# by default USER shell sources will be looked for under $HOME/.shell # by default USER shell sources will be looked for under $HOME/shell
# but the default directory for all users can be set manually below # but the default directory for all users can be set manually below
# export BASH_SHELL_USER=<some directory under $HOME> # export BASH_SHELL_USER=<some directory under $HOME>
# add this export to .bashrc for custom directory. This can be done during or after using the user setup script # add this export to .bashrc for custom directory. This can be done during or after using the user setup script