added setup directory with set of user and system source files that can be copied in new machine
changed setup.sh to load.sh startup only loads system repos by default and allows passing directory argumentmaster
parent
378672e974
commit
e25e44a98d
|
@ -0,0 +1 @@
|
|||
*/archive/*
|
|
@ -66,3 +66,7 @@ If you are really done with something but want to keep a copy in the repo move i
|
|||
if sourcing some file depends on another preface with numbers to put it before. Functions are all sourced before aliases so can be refered to there.
|
||||
|
||||
Be aware that an alias or function set in the repo could be subsuming some existing binary or script.
|
||||
|
||||
|
||||
`[[ $BASHPID -eq $$ ]] && echo was called directly || echo was called in a subshell`
|
||||
https://unix.stackexchange.com/a/594809/201387
|
||||
|
|
4
app/pio
4
app/pio
|
@ -1,4 +0,0 @@
|
|||
# pio in path and completion for platformio subcommands
|
||||
export PATH=$PATH:~/.platformio/penv/bin
|
||||
eval "$(_PLATFORMIO_COMPLETE=source platformio)"
|
||||
eval "$(_PIO_COMPLETE=source pio)"
|
|
@ -1,4 +1,4 @@
|
|||
# set PATH so it includes user's private bin if it exists
|
||||
# include binaries in /optu
|
||||
if [ -d "/opt/bin" ] ; then
|
||||
PATH="/opt/bin:$PATH"
|
||||
fi
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
# set ssh agent socket for each session
|
||||
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
|
|
@ -0,0 +1,24 @@
|
|||
path_remove () {
|
||||
local IFS=':'
|
||||
local NEWPATH
|
||||
local DIR
|
||||
local PATHVARIABLE=${2:-PATH}
|
||||
for DIR in ${!PATHVARIABLE} ; do
|
||||
if [ "$DIR" != "$1" ] ; then
|
||||
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
|
||||
fi
|
||||
done
|
||||
export $PATHVARIABLE="$NEWPATH"
|
||||
}
|
||||
|
||||
path_prepend () {
|
||||
path_remove $1 $2
|
||||
local PATHVARIABLE=${2:-PATH}
|
||||
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
|
||||
}
|
||||
|
||||
path_append () {
|
||||
path_remove $1 $2
|
||||
local PATHVARIABLE=${2:-PATH}
|
||||
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
|
||||
}
|
|
@ -33,6 +33,11 @@ get_prop_value () {
|
|||
echo $value
|
||||
}
|
||||
|
||||
mounted () {
|
||||
[[ ! $1 ]] && echo no mount point to test && return 2
|
||||
mountpoint "$1" &> /dev/null && echo yes || return 1
|
||||
}
|
||||
|
||||
|
||||
is_array() {
|
||||
local variable_name=$1
|
||||
|
|
|
@ -17,3 +17,13 @@ function logit(){
|
|||
echo $(date) logging for $SCRIPT_PATH
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# LOG_DIR=/opt/bash/logs
|
||||
# mkdir -p $LOG_DIR
|
||||
# LOG_FILE=$LOG_DIR/bash_profile
|
||||
#
|
||||
# msg="$(date) \n Login for $USER \n $(env | grep BASH)"
|
||||
# [[ $- == *i* ]] && echo -e $msg || echo -e $msg 1> $LOG_FILE 2>&1
|
||||
#
|
||||
#
|
||||
|
|
|
@ -32,6 +32,7 @@ local MDIRS
|
|||
local MDIR
|
||||
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/bash/shell) \
|
||||
$BASH_SHELL_HOST/$(hostname)
|
||||
|
@ -66,12 +67,14 @@ for MDIR in "${MDIRS[@]}"
|
|||
|
||||
module_load () {
|
||||
[ ! $1 ] && echo "no module specified" && return 1
|
||||
# (return 0 2>/dev/null) && echo "module_load was sourced" || echo "module_log was executed"
|
||||
local FILE
|
||||
FILE=$(module_find $1)
|
||||
[ $? -ne 0 ] && echo no module $1 found && return 1
|
||||
# source $FILE "$0"
|
||||
[[ $BASHPID -eq $$ ]] || echo $FILE
|
||||
source $FILE
|
||||
echo $FILE
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
# remote start a program (with x11 forwarding will render locally if gui)
|
||||
function rrem(){
|
||||
ssh -X -t "$1" """$2" "$3"""
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
function startup_load () {
|
||||
|
||||
local SDIRS
|
||||
local SDIR
|
||||
local DIRS
|
||||
DIRS=( \
|
||||
$BASH_SHELL_HOST/$(hostname)
|
||||
$BASH_SHELL_HOST/all \
|
||||
$BASH_SHELL_NETWORK/$NETWORKNAME \
|
||||
$BASH_SHELL_NETWORK/all \
|
||||
$BASH_SHELL_BASE \
|
||||
)
|
||||
|
||||
[[ $1 ]] && DIRS=("$1")
|
||||
echo startup ${DIRS[@]}
|
||||
SDIRS=()
|
||||
j=0
|
||||
cnt=${#DIRS[@]}
|
||||
for ((i=0;i<cnt;i++)); do
|
||||
DIR="${DIRS[i]}/startup"
|
||||
[ -d $DIR ] && SDIRS[j]=$DIR && j+=1
|
||||
done
|
||||
|
||||
# STARTUP_DIRS is array of any other startup directores where scripts may be loaded from
|
||||
[ $STARTUP_DIRS ] && SDIRS=("$STARTUP_DIRS" "${SDIRS[@]}")
|
||||
|
||||
# echo -e "Statup Directories to source \n ${SDIRS[@]} \n"
|
||||
|
||||
for SDIR in "${SDIRS[@]}"
|
||||
do
|
||||
# echo startup dir to source $SDIR
|
||||
source_dir -p "archive" -x '"*.off" "*.md"' -d 0 $SDIR
|
||||
done
|
||||
}
|
|
@ -30,15 +30,16 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
if [ -f "$DIR/setup.sh" ] && [ "$DIR" != "$BASH_SHELL_BASE" ]; then
|
||||
echo "$DIR/setup.sh" found, running instead of default processing
|
||||
. "$DIR/setup.sh"
|
||||
if [ -f "$DIR/$BASH_SHELL_LOAD" ] && [ "$DIR" != "$BASH_SHELL_BASE" ]; then
|
||||
echo "$DIR/$BASH_SHELL_LOAD" found, running instead of default processing
|
||||
source "$DIR/$BASH_SHELL_LOAD"
|
||||
else
|
||||
# default processing
|
||||
local SUBDIRS
|
||||
local DSUBDIRS
|
||||
# default subdirectories to source
|
||||
DSUBDIRS="env function alias misc lang app"
|
||||
# TODO allow passing in additional directories
|
||||
DSUBDIRS="function env alias misc lang app"
|
||||
IFS=' ' read -r -a SUBDIRS <<< "${2:-$DSUBDIRS}"
|
||||
# echo ${SUBDIRS[@]}
|
||||
for SUBDIR in "${SUBDIRS[@]}"
|
||||
|
@ -46,7 +47,8 @@ else
|
|||
if [ -e "$DIR/$SUBDIR" ]; then
|
||||
# echo processing subdirectory $DIR/$SUBDIR
|
||||
# must quote all globs to avoid bash glob expansion which is likely on
|
||||
source_dir -p "archive" -x '"*.off" "*.md"' -d 0 $DIR/$SUBDIR
|
||||
# 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
|
||||
# else
|
||||
# echo no subdirectory $DIR/$SUBDIR to process, ignorning
|
||||
fi
|
|
@ -31,7 +31,7 @@ case $TERM in
|
|||
esac
|
||||
|
||||
local UC=WHITE # user's color
|
||||
[ $UID -eq "0" ] && UC=RED # root's color
|
||||
[ $UID -eq "0" ] && UC=LIGHT_RED # root's color
|
||||
|
||||
# PS1="$PARENTBASE\[${UC}\]\u@\h: \[${COLOR_LIGHT_GREEN}\]→\[${COLOR_NC}\] "
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#!/bin/bash
|
||||
# must have fuser and bindfs installed
|
||||
function bmount () {
|
||||
if [ "$1" == "-mp" ]; then
|
||||
MOUNTED=$(mountpoint "$2" | grep not)
|
||||
if [ -z "$MOUNTED" ]; then
|
||||
echo $2 is a mount point so bind mounting $2/$3 to $4
|
||||
notify-send "bind mounting ${2}/${3} to ${4}" --icon=dialog-information -t 2000
|
||||
bindfs "$2/$3" "$4"
|
||||
else
|
||||
notify-send "${2} not a mount point - Unable to bind mount ${2}/${3} to ${4}" --icon=dialog-error -t 2000
|
||||
fi
|
||||
else
|
||||
echo bind mounting $1 to $2
|
||||
notify-send "bind mounting ${1} to ${2}" --icon=dialog-information -t 2000
|
||||
bindfs "$1" "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
bumount () {
|
||||
echo "removing bind mount at $1"
|
||||
notify-send "removing bind mount at ${1}" --icon=dialog-information -t 2000
|
||||
fusermount -u "$1"
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
#!/bin/bash
|
||||
# depends on sshfs fuse for ssh
|
||||
function smount(){
|
||||
MOUNTED=$(mountpoint "$2" | grep not)
|
||||
if [ -z "$MOUNTED" ]; then
|
||||
echo "remote $1 already mounted at $2, aborting mount"
|
||||
else
|
||||
echo "mounting $1 at $2 via ssh"
|
||||
sshfs $1 $2 $3 $4 -o default_permissions
|
||||
fi
|
||||
}
|
||||
|
||||
function usmount(){
|
||||
MOUNTED=$(mountpoint $1 | grep not)
|
||||
if [ -z "$MOUNTED" ]; then
|
||||
echo "unmounting remote file system at $1"
|
||||
fusermount -u $1
|
||||
else
|
||||
echo "nothing mounted at $1, aborting unmount"
|
||||
fi
|
||||
}
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
|
||||
|
||||
for f in $DIR/*; do
|
||||
if [ ${f: -4} != ".off" ] && [ $(basename $f) != "sshfs.sh" ] && [ ! -d "$f" ] ; then
|
||||
# echo 'loading mount functions for '$f
|
||||
. $f
|
||||
fi
|
||||
done
|
|
@ -1,6 +0,0 @@
|
|||
BASH_MODULES="${BASH_MODULES:-/opt/bash/modules}"
|
||||
. $BASH_MODULES/load-modules.sh
|
||||
MODULES=(logit)
|
||||
load-modules $MODULES
|
||||
|
||||
logit v
|
|
@ -1,40 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
function get_platform () {
|
||||
|
||||
local OS
|
||||
local ARCH
|
||||
local PLATFORM
|
||||
|
||||
OS="$(uname -s)"
|
||||
ARCH="$(uname -m)"
|
||||
|
||||
case $OS in
|
||||
"Linux")
|
||||
case $ARCH in
|
||||
"x86_64")
|
||||
ARCH=amd64
|
||||
;;
|
||||
"aarch64")
|
||||
ARCH=arm64
|
||||
;;
|
||||
"armv6")
|
||||
ARCH=armv6l
|
||||
;;
|
||||
"armv8")
|
||||
ARCH=arm64
|
||||
;;
|
||||
.*386.*)
|
||||
ARCH=386
|
||||
;;
|
||||
esac
|
||||
PLATFORM="linux-$ARCH"
|
||||
;;
|
||||
"Darwin")
|
||||
PLATFORM="darwin-amd64"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo $PLATFORM
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
# moves a directory and then links it back
|
||||
# good for moving directories from one partition to another but without changing any settings
|
||||
|
||||
SCRIPT_NAME='mvln'
|
||||
USAGE_STRING='usage: '$SCRIPT_NAME' <source_path> <destination_dir_path>'
|
||||
|
||||
# Show usage and exit with status
|
||||
show_usage_and_exit () {
|
||||
echo $USAGE_STRING
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ERROR file does not exist
|
||||
no_file () {
|
||||
echo $SCRIPT_NAME': '$1': No such file or directory'
|
||||
exit 2
|
||||
}
|
||||
|
||||
# Check syntax
|
||||
if [ $# -ne 2 ]; then
|
||||
show_usage_and_exit
|
||||
fi
|
||||
|
||||
# Check file existence
|
||||
if [ ! -e "$1" ]; then
|
||||
no_file $1
|
||||
fi
|
||||
|
||||
# Get paths
|
||||
source_path=$1
|
||||
destination_path=$2
|
||||
|
||||
# Check that destination ends with a slash
|
||||
[[ $destination_path != */ ]] && destination_path="$destination_path"/
|
||||
|
||||
# Move source
|
||||
[[ -d "$destination_path" ]] || mkdir -p "$destination_path"
|
||||
mv "$source_path" "$destination_path"
|
||||
|
||||
# Get original path
|
||||
original_path=$destination_path$(basename $source_path)
|
||||
|
||||
# Create symlink in source dir
|
||||
ln -s "$original_path" "${source_path%/}"
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
function abs-path {
|
||||
local target="$1"
|
||||
if [ "$target" == "." ]; then
|
||||
echo "$(pwd)"
|
||||
elif [ "$target" == ".." ]; then
|
||||
echo "$(dirname "$(pwd)")"
|
||||
else
|
||||
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
||||
fi
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
# uncomment for debuggin
|
||||
echo ".bash_profile sourced at user $USER login"
|
||||
|
||||
[[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"
|
||||
[[ $- == *i* ]] || statup_load $HOME/$BASH_SHELL_USER
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
echo "$USER .bashrc"
|
||||
|
||||
# processing user's shell directory
|
||||
[[ $BASH_SHELL_BASE_SOURCED = true ]] && \
|
||||
BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"} && \
|
||||
shell_process_directory "$HOME/$BASH_SHELL_USER"
|
|
@ -0,0 +1,6 @@
|
|||
# root login setup only, put in if block
|
||||
if [ $EUID -eq 0 ] ; then # if root user
|
||||
echo root specific setup
|
||||
export PATH=$PATH:/sbin:/usr/sbin
|
||||
unset HISTFILE
|
||||
fi
|
|
@ -0,0 +1,20 @@
|
|||
# source bash.bashrc for both login and non login shells
|
||||
# note: bash.bashrc sources the base shell repo
|
||||
echo in profile.d/bash.sh
|
||||
if [ "${SHELL-}" ] && [ "$SHELL" != "/bin/sh" ] && [ -f /etc/bash.bashrc ]; then
|
||||
# uncomment for debugging
|
||||
echo sourcing bash.bashrc now from /etc/profile.d/bash.sh
|
||||
source /etc/bash.bashrc
|
||||
[ $EUID -ne 0 ] && startup_load # if not root source this
|
||||
else # set up basic stuff (e.g a prompt) if not able to source bash.bashrc
|
||||
echo Unable to source bash.bashrc, Setting up red prompt for root and a green one for users.
|
||||
NORMAL="\[\e[0m\]"
|
||||
RED="\[\e[1;31m\]"
|
||||
GREEN="\[\e[1;32m\]"
|
||||
if [[ $EUID == 0 ]] ; then
|
||||
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
||||
else
|
||||
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
||||
fi
|
||||
unset RED GREEN NORMAL
|
||||
fi
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
# uncomment these for debugging.
|
||||
echo sourcing system wide bash.bashrc
|
||||
[ $EUID -eq 0 ] && echo 'Root User' || echo 'Non Root User'
|
||||
[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
|
||||
shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
|
||||
|
||||
# Using base shell setup repository
|
||||
# https://git.kebler.net/kebler.net/bash-shell-base.git
|
||||
export BASH_SHELL_LOAD=load.sh # script to run that loads in base shell repo
|
||||
# use these two if you want a common directory for all shell repos
|
||||
export BASH_SHELL=/opt/bash/shell # set this based on where you cloned the base repo
|
||||
export BASH_SHELL_BASE=$BASH_SHELL/base
|
||||
# otherwise uncomment
|
||||
# export BASH_SHELL_BASE=/opt/shell/base # set this based on where you cloned the base repo
|
||||
# if uncommented next line sets up implicit sourcing for non-interactive shells
|
||||
export BASH_ENV=$BASH_SHELL_BASE/$BASH_SHELL_LOAD # use base repo
|
||||
# this gets the ball rolling my loading the base shell
|
||||
source $BASH_SHELL_BASE/$BASH_SHELL_LOAD
|
||||
|
||||
# if not using implicit sourcing for non-interactive shells then on can do this per script likely
|
||||
##################
|
||||
# source $BASH_SHELL_BASE/load.sh
|
||||
# shopt -s expand_aliases
|
||||
# < your script code >
|
||||
# shopt -u expand_aliases
|
||||
####################
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
# main /etc/profile loaded for all logins
|
||||
# more info see http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html
|
||||
|
||||
|
||||
# Set the initial path
|
||||
export PATH=/bin:/usr/bin
|
||||
# uncomment for debugging
|
||||
echo system profile /etc/profile sourced at login
|
||||
|
||||
# put no script code directly here.
|
||||
# organize all script code in files /etc/profile.d
|
||||
# sourcing
|
||||
if [[ $- == *i* ]] && [[ $EUID -ne 0 ]]; then
|
||||
echo non root interactive login shell, will not source /etc/profile.d
|
||||
if [[ $FORCE_LOAD_BASH_SHELL_BASE ]]; then
|
||||
echo "forcing source of shell base: $BASH_SHELL_BASE/$BASH_SHELL_LOAD"
|
||||
source "$BASH_SHELL_BASE/$BASH_SHELL_LOAD"
|
||||
else
|
||||
BASH_SHELL_BASE_SOURCED=false
|
||||
NORMAL="\[\e[0m\]"
|
||||
RED="\[\e[1;31m\]"
|
||||
GREEN="\[\e[1;32m\]"
|
||||
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
||||
unset RED GREEN NORMAL
|
||||
fi
|
||||
else
|
||||
echo sourcing /etc/profile.d
|
||||
if [ -d /etc/profile.d ]; then
|
||||
for i in /etc/profile.d/*.sh; do
|
||||
if [ -r $i ]; then
|
||||
source $i
|
||||
fi
|
||||
done
|
||||
unset i
|
||||
fi
|
||||
fi
|
|
@ -67,6 +67,8 @@ fi
|
|||
local FIND
|
||||
FIND="find $DIR"
|
||||
FIND+=$([ ! $DEPTH == 0 ] && echo " -maxdepth $DEPTH ")
|
||||
# ignore all .name and .path by default
|
||||
# TODO change to having a string
|
||||
FIND+=" -type f ! -path \"*/.*/*\" ! -name \".*\" "
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue