From ec601fbb15fb3332ac87e333949d488f0c6e7090 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Fri, 31 Dec 2021 17:38:58 -0800 Subject: [PATCH] fix: change back to just 'shell' not .shell for user default shell directory as . is ignored by default, feat: added 'user_exists' function --- README.md | 4 ++-- load.sh | 4 ++-- module.lib | 2 +- modules/utility/helpers.mod | 4 ++++ setup/deploy-user.sh | 4 ++-- setup/user/.bashrc | 2 +- shell.env | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 728ca20..9d49060 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ if you include any of these environment variables all files in there directories # $BASH_SHELL_HOST/all # $BASH_SHELL_HOST/ # 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 # 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/ unless specifically set 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 # export BASH_SHELL_USER= 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. diff --git a/load.sh b/load.sh index f53bd8e..92261ba 100755 --- a/load.sh +++ b/load.sh @@ -80,7 +80,7 @@ function shell_process_directory () { 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 + # 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 @@ -103,7 +103,7 @@ unset BASH_SHELL_LOADED # add in any network directories declare networks source "$HOME/.bashrc" -networks="$HOME/${BASH_SHELL_USER:-".shell"}/.networks" +networks="$HOME/${BASH_SHELL_USER:-"shell"}/.networks" NETWORK_DOMAINS="$([[ -f $networks ]] && cat $networks) " # These will be loaded for all users networks="$BASH_SHELL_HOST/$(hostname)/.networks" diff --git a/module.lib b/module.lib index b5878f0..01ff760 100644 --- a/module.lib +++ b/module.lib @@ -36,7 +36,7 @@ local DIRS local MODULE=$1 # Precidence is user. current hosts, all hosts, current network, all networks, base 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/all \ $BASH_SHELL_NETWORK/$NETWORKNAME \ diff --git a/modules/utility/helpers.mod b/modules/utility/helpers.mod index c3aa329..bd3b820 100644 --- a/modules/utility/helpers.mod +++ b/modules/utility/helpers.mod @@ -22,6 +22,10 @@ adirname() { echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )" } +user_exists() { + id -u $1 > /dev/null 2>&1 + [[ $? == 1 ]] || echo $1 + } chmod_dirs() { diff --git a/setup/deploy-user.sh b/setup/deploy-user.sh index 0b3a013..6634c67 100755 --- a/setup/deploy-user.sh +++ b/setup/deploy-user.sh @@ -34,9 +34,9 @@ for file in $files; do cmd="install -C -m 660 -o $_USER -g sudo $file $_USER_DIR" [[ $USER = "$_USER" ]] && eval $cmd || sudo -E -- bash -c "$cmd" 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 to accept default" 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 echo will be processing user shell repo at $_USER_DIR/$answer diff --git a/setup/user/.bashrc b/setup/user/.bashrc index 431624d..76274d2 100644 --- a/setup/user/.bashrc +++ b/setup/user/.bashrc @@ -11,7 +11,7 @@ if ( [[ $SHELL_INTERACTIVE ]] );then if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then # 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" ||\ echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template fi diff --git a/shell.env b/shell.env index 936bfb5..5ad2a48 100755 --- a/shell.env +++ b/shell.env @@ -67,7 +67,7 @@ export BASH_SHELL_NETWORK=$([[ -d $parent/network ]] && echo $parent/network || # or comment above and set explictly # export BASH_SHELL_NETWORK= -# 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 # export BASH_SHELL_USER= # add this export to .bashrc for custom directory. This can be done during or after using the user setup script