refactor shell install scripts

add bindfs and new dir_copy script
master
Kebler Network System Administrator 2023-01-18 16:43:21 -08:00
parent 96127ca89f
commit bcba8bbfd4
70 changed files with 442 additions and 748 deletions

View File

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

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*/archive/*
*archive*
/ssh/config/_config

View File

@ -1,4 +0,0 @@
# TODOS
add ability to disable loading shell repos
add ability to disable alias in non-interactive and interactive shells

View File

@ -1,3 +0,0 @@
alias ports="netstat -tulpn"
alias flushdns="systemctl restart systemd-resolved"
alias essh="sudo editor /etc/ssh/sshd_config"

18
env/01-path vendored
View File

@ -1,18 +0,0 @@
#!/bin/bash
# if [[ $(groups | grep sudo ) ]]; then
# path_insert /sbin after /usr/bin
# pathg bin
# path_insert /usr/sbin after :/sbin
# pathg bin
# path_insert /usr/local/sbin after /usr/sbin
# pathg sbin
# fi
if [[ $(groups | grep sudo ) ]]; then
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
fi
# with prependthese take prescendence over stuff ones in /usr and /bin
path_prepend /opt/bin
path_prepend "$HOME/bin"
path_prepend "$HOME/.local/bin"

12
env/01-system-path vendored Normal file
View File

@ -0,0 +1,12 @@
#!/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"

5
env/02-defaults.env vendored
View File

@ -1,5 +0,0 @@
# used by aliases that need an editor
# export EDITOR=atom
# export ELECTRON_TRASH=gio
export EDITOR=nano
export BROWSER=google-chrome

2
env/02-prompt vendored Normal file
View File

@ -0,0 +1,2 @@
module_load fancy-prompt
fancy_prompt

17
env/archive/path vendored
View File

@ -1,17 +0,0 @@
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

20
env/colors.env vendored
View File

@ -1,22 +1,2 @@
# !/bin/bash
export TERM=xterm-color
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
export COLOR_NC='\e[0m' # No Color
export COLOR_BLACK='\e[0;30m'
export COLOR_GRAY='\e[1;30m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_LIGHT_GRAY='\e[0;37m'
export COLOR_WHITE='\e[1;37m'

View File

@ -1 +0,0 @@
module_load acl

View File

@ -1,46 +0,0 @@
#!/bin/bash
# aws cli from docker image on any machine
function aws() {
AWS_CLI_IMAGE=${AWS_CLI_IMAGE:-amazon/aws-cli:latest}
AWS_WORKING_DIR=${AWS_WORKING_DIR:-$HOME/awscli}
local cmd
cmd="docker run --rm -ti
--env AWS_ACCESS_KEY_ID
--env AWS_CONFIG_FILE
--env AWS_SHARED_CREDENTIALS_FILE
--env AWS_SECRET_ACCESS_KEY
--env AWS_DEFAULT_REGION
-v ${HOME}/.aws:/root/.aws
-v ${AWS_WORKING_DIR}:/aws
${AWS_CLI_IMAGE} $*
--no-cli-pager
"
# echo ${cmd}
# local res
echo "$(eval ${cmd})"
# echo $RES
}
# `! [ -z $AWS_ACCESS_KEY_ID ] && echo "--env AWS_ACCESS_KEY_ID"` \
# `! [ -z $AWS_SECRET_ACCESS_KEY ] && echo "--env AWS_SECRET_ACCESS_KEY"` \
# `! [ -z $AWS_DEFAULT_REGION ] && echo "--env AWS_DEFAULT_REGION"` \
test () {
echo $(aws route53 list-hosted-zones)
}
aws-get-zone-id () {
local records
local domain
domain=$(get-domain $1)
echo $domain
aws route53 list-hosted-zones --query "'HostedZones[?Name==\`${domain}.\`]'"
echo returned
echo $RES
# local res
# res=$(echo $records | grep ID | awk -F'[\"#]+' '{print $4}' | awk -F'[/#]+' '{print $3}')
# echo "$res"
}

View File

@ -1,86 +0,0 @@
#!/bin/bash
function aws-get-zone-record () {
local record
echo get record $1 $(get-domain $1)
record=$(
aws route53 list-resource-record-sets \
--hosted-zone-id $(aws-get-zone-id $1)
)
echo "$record"
}
function aws-get-zone-record-prop () {
local record
record=$(aws-get-zone-record $1)
local res
res=$(get-prop-value "$record" $2)
echo "$res"
}
function aws-get-zone-record-value () {
local record
record=$(aws-get-zone-record $1)
local res
res=$(get-prop-value "$record" "ResourceRecords[0].Value")
echo "$res"
}
function aws-update-zone-record-value () {
if [ "$#" -ne 2 ]; then
echo "Both recordset and value required"
exit 0
fi
RECORDSET=$1
VALUE=$2
COMMENT=${3:-"Updating Record"}
RECORD=$(aws-get-zone-record "$RECORDSET")
echo the reccord $RECORD
# ZONENAME=$(get-domain $RECORDSET)
ZONEID=$(aws-get-zone-id "$(get-domain $RECORDSET )")
# The Time-To-Live of this recordset
# echo Zone Name and ID for recordset $RECORDSET $ZONENAME $ZONEID
# TTL=60 # call this later with increase
# Fill a temp file with valid JSON
CHANGE="{
\"Comment\":\"$COMMENT\",
\"Changes\":[
{
\"Action\":\"UPSERT\",
\"ResourceRecordSet\":{
\"ResourceRecords\":[
{
\"Value\":\"$VALUE\"
}
],
\"Name\":\"$RECORDSET\",
\"Type\":\"$(get-prop-value "$RECORD" Type)\",
\"TTL\":\"$(get-prop-value "$RECORD" TTL)\"
}
}
]
}
"
echo updating record with
batch=\'${CHANGE}\'
echo batch
# Update the Hosted Zone record
CMD="aws route53 change-resource-record-sets
--hosted-zone-id ${ZONEID}
--change-batch $batch
"
echo "${CMD}"
local res
res=$($CMD)
echo "$res"
# echo confirm change $(aws-get-zone-record-value $RECORDSET)
# end function
}

View File

@ -1,105 +0,0 @@
#!/bin/bash
function route53-set-record () {
# (optional) You might need to set your PATH variable at the top here
# depending on how you run this script
# PATH=PATH
# Hosted Zone ID e.g. BJBK35SKMM9OE
ZONEID="ZF04FGKB9QHN2"
# The CNAME you want to update e.g. hello.example.com
RECORDSET="238.kebler.net"
# More advanced options below
# The Time-To-Live of this recordset
TTL=300
# Change this if you want
COMMENT="Auto updating @ `date`"
# Change to AAAA if using an IPv6 address
TYPE="A"
# Get the external IP address from OpenDNS (more reliable than other providers)
IP=`dig +short myip.opendns.com @resolver1.opendns.com`
echo current ip is $IP
# Get current dir
# (from http://stackoverflow.com/a/246128/920350)
# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR=$HOME
LOGFILE="$DIR/update-route53.log"
IPFILE="$DIR/update-route53.ip"
if ! valid_ip $IP; then
echo "Invalid IP address: $IP" >> "$LOGFILE"
exit 1
fi
# Check if the IP has changed
if [ ! -f "$IPFILE" ]
then
touch "$IPFILE"
fi
if grep -Fxq "$IP" "$IPFILE"; then
# code if found
echo "IP is still $IP. Exiting" >> "$LOGFILE"
exit 0
else
echo "IP has changed to $IP" >> "$LOGFILE"
# Fill a temp file with valid JSON
TMPFILE=$(mktemp /tmp/temporary-file.XXXXXXXX)
cat > ${TMPFILE} << EOF
{
"Comment":"$COMMENT",
"Changes":[
{
"Action":"UPSERT",
"ResourceRecordSet":{
"ResourceRecords":[
{
"Value":"$IP"
}
],
"Name":"$RECORDSET",
"Type":"$TYPE",
"TTL":$TTL
}
}
]
}
EOF
# Update the Hosted Zone record
aws route53 change-resource-record-sets \
--hosted-zone-id $ZONEID \
--change-batch file://"$TMPFILE" >> "$LOGFILE"
echo "IP Changed in Route53" >> "$LOGFILE"
# Clean up
rm $TMPFILE
fi
# All Done - cache the IP address for next time
echo "$IP" > "$IPFILE"
}
# end function
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}

View File

@ -1,12 +0,0 @@
#!/bin/bash
function caddye(){
rrem sysadmin@nas.kebler.net "gedit /opt/caddy/caddy.conf"
}
function caddys(){
rrem sysadmin@nas.kebler.net "sudo systemctl status caddy"
}
function caddyj(){
rrem sysadmin@nas.kebler.net "journalctl -u caddy | tail -f -n -100"
}

View File

@ -1,21 +0,0 @@
#!/bin/bash
# nas
## rrem already loaded in 00-basic
function nasfm(){
rrem sysadmin@nas.kebler.net "nemo $1"
}
function nasdisk(){
rrem sysadmin@nas.kebler.net "sudo gnome-disks"
}
function nasgparted(){
rrem sysadmin@nas.kebler.net "sudo gparted"
}
function nasdata(){
rrem sysadmin@nas.kebler.net "nemo /mnt/data"
}

View File

@ -1 +0,0 @@
A test

View File

@ -1,16 +0,0 @@
#!/bin/bash
# simple copy using rsync. Preserves everything
# present working directory to supplied destination
module_load confirm
function cprs () {
local usesudo
local cmd
[[ $1 == "-s" ]] && usesudo='sudo' && shift
[ $# -ne 2 ] && echo two directories source and destination need to be passed && return 1
[ ! -d "$1" ] && echo source: $1 is not a directory && return 1
cmd="$usesudo rsync --exclude *[C]ache* --exclude node_modules --progress -aAru $1 $2"
echo $cmd
confirm Do you want to start the rsync copy? || return 0
echo copying.....
eval $cmd
}

View File

@ -1,13 +1,7 @@
#!/bin/bash
# 00 will get loaded first
##-- functions which may be used by any of the alias file --#
group_add() {
[[ ! $(getent group $1) ]] && echo "no group $1, aborting" && return 1
echo adding group $1 to $USER
sudo usermod -a -G $1 $USER
}
##
user_reload() {
save=$PWD
@ -95,13 +89,6 @@ osinfo () {
cat /etc/upstream-release/lsb-release
}
# adduserid name id#
# add a suer with specific id number
adduserid () {
sudo groupadd -g $2 $1
sudo useradd -d ${/home/$1} -s /bin/bash -u $2 -g $1 $1
}
fsudo () # run a function as sudo
{
[[ "$(type -t $1)" == "function" ]] &&

1
functions/02-system-path Normal file
View File

@ -0,0 +1 @@
module_load system-path

1
functions/03-security Normal file
View File

@ -0,0 +1 @@
module_load security

1
functions/logging Normal file
View File

@ -0,0 +1 @@
module_load logit

View File

@ -1,2 +1,3 @@
/backup-users/
/backup/
/scripts/archive

View File

@ -0,0 +1,23 @@
# This .bash_profile is for use ONLY! with UCI bash shell system
# this is only sourced for login shell
# uncomment these for UCI Shell debugging.
# echo ---- sourcing system .bash_profile for user root ---
# [[ $USER_ROOT ]] && echo 'Root User' || echo 'Non Root User'
# [[ $SHELL_INTERACTIVE ]] && echo 'Interactive' || echo 'Not interactive'
# [[ $SHELL_LOGIN ]] && echo 'Login shell' || echo 'Not login shell'
# [[ $SSH_SESSION ]] && echo ssh remote user || echo local user
# env | grep BASH
# echo ---------------------
if [[ $SHELL_INTERACTIVE ]]; then
# only source .bashrc if interactive login shell
[[ -f "/root/.bashrc" ]] && source "/root/.bashrc"
else
# non-interactive root login commands
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
fi
# any (interactive or not) root login shell commands can go here.

View File

@ -0,0 +1,24 @@
# this .bashrc for use ONLY with uci bash shell system
# uncomment these for debugging.
# echo ---- sourcing system .bashrc for user $USER ---
# [[ $USER_ROOT ]] && echo 'Root User' || echo 'Non Root User'
# [[ $SHELL_INTERACTIVE ]] && echo 'Interactive' || echo 'Not interactive'
# [[ $SHELL_LOGIN ]] && echo 'Login shell' || echo 'Not login shell'
# [[ $SSH_SESSION ]] && echo ssh remote user || echo local user
# env | grep BASH
# echo ---------------------
# uncomment for custom processing
#if [[ $SHELL_LOGIN ]]; then
# echo "login shell (called from .bash_profile)"
# fi
if [[ $SSH_SESSION ]]; then
# echo remote ssh session
cd /opt
fi
# anything below will be sourced by all shell types (except non-interactive/login)
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin

View File

@ -0,0 +1,7 @@
## This .profile is for use ONLY! with UCI bash shell system
# this is only sourced for non bash login shell which should never happen
echo /root/.profile being sourced
echo WARNING: /root/.profile should never be sourced for root
[[ ! -f /root/.bash_profile ]] && echo unless .bash_profile does not exist which it does not!
echo corrective action required

View File

@ -0,0 +1,27 @@
#!/bin/bash
# sourced for bash login shell only
# uncomment these for debugging.
# echo ---- sourcing system .bash_profile for user $USER ---
# [[ $USER_ROOT ]] && echo 'Root User' || echo 'Non Root User'
# [[ $SHELL_INTERACTIVE ]] && echo 'Interactive' || echo 'Not interactive'
# [[ $SHELL_LOGIN ]] && echo 'Login shell' || echo 'Not login shell'
# [[ $SSH_SESSION ]] && echo ssh remote user || echo local user
# env | grep BASH
# echo ---------------------
# only source .bashrc if interactive login shell
if [[ $SHELL_INTERACTIVE ]]; then
[[ -f "/root/.bashrc" ]] && source "/root/.bashrc"
else
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
fi
# only source .bashrc if interactive login shell
if [[ $SHELL_INTERACTIVE ]];then
[[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"
else
# noninteractive login shell
:
fi

View File

@ -10,10 +10,9 @@
if ( [[ $SHELL_INTERACTIVE ]] );then
if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then
export BASH_SHELL_USER=${BASH_SHELL_USER:-"shell"}
# echo loading user $USER shell at BASH_SHELL_USER_DIR
[[ -d BASH_SHELL_USER_DIR ]] && shell_process_directory "BASH_SHELL_USER_DIR" ||\
echo no user shell directory BASH_SHELL_USER_DIR to process, create one or clone a template
[[ -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
fi
# uncomment to add non-interactive setup/sourcing
# else

View File

@ -0,0 +1,2 @@
# echo $USER .profile
# called at GUI login or when .bash_profile does not exist"

17
install/install.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
uci_bash_shell_install () {
local usesudo
export install_dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))"
export BASH_SHELL_BASE="$(dirname $install_dir)"
# export BASH_SHELL_BASE="$(dirname "$(cd "$(dirname "${BASH_SOURCE:-$0}")" >/dev/null 2>&1 ; pwd -P )")"
echo "Detected The UCI BASH Shell install directory: BASH_INSTALL_DIR=$install_dir"
echo "Detected The UCI BASH Shell base directory: BASH_SHELL_BASE=$BASH_SHELL_BASE"
[[ $EUID -ne 0 ]] && usesudo=sudo
$usersudo $SHELL $BASH_SHELL_BASE/install/script/copy-etc.sh
echo $usersudo $SHELL $BASH_SHELL_BASE/install/script/copy-root.sh
[[ $(id -u $1 2> /dev/null) ]] && echo $usersudo $SHELL $BASH_SHELL_BASE/install/script/copy-user.sh $1
}
# # if script was executed then call the function
(return 0 2>/dev/null) || uci_bash_shell_install "$@"

16
install/scripts/copy-etc.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
uci_bash_shell_etc_copy () {
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
echo setting BASH_SHELL_BASE to $BASH_SHELL_BASE in etc/bash.bashrc and /etc/profile
sed -i 's:_BASH_SHELL_BASE_:'${BASH_SHELL_BASE}':' /etc/bash.bashrc
sed -i 's:BASH_SHELL_BASE=.*:BASH_SHELL_BASE='${BASH_SHELL_BASE}':' /etc/profile
echo -e "************ copying uci shell profile.d/ files /etc/profile.d/ ********"
files=$(find $BASH_SHELL_BASE/install/files/etc/profile.d -maxdepth 1 -type f)
for file in $files; do install -m 644 -o root -g root $file /etc/profile.d; done
}
# # if script was executed then call the function
(return 0 2>/dev/null) || uci_bash_shell_etc_copy "$@"

11
install/scripts/copy-root.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
uci_bash_shell_root_copy () {
echo -e "************ copying uci shell .profile and .bashrc files to /root ********"
group=root
files=$(find $BASH_SHELL_BASE/setup/root/ -type f)
for file in $files; do install -m 640 -o root -g $group $file /root; done
}
# # if script was executed then call the function
(return 0 2>/dev/null) || uci_bash_shell_root_copy "$@"

View File

@ -0,0 +1,31 @@
#!/bin/bash
uci_bash_shelluser_copy () {
local user; local user_home; local dir
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
[[ ! $(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
user_home=$( getent passwd $user | cut -d: -f6 )
[[ ! $user_home ]] && echo no user home directory in which to install shell files, exiting && return 4
echo -e "*********** copying UCI BASH Shell .profile and bash_profile and .bashrc for user: $user *******"
mkdir -P
files=$(find $Install_dir/files/user -type f)
for file in $files; do
install -C -m 660 -o $user -g $user $file $user_home
done
sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER_DIR='$dir'' $user_home/.bashrc
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:$user $dir
}
# # if script was executed then call the function
(return 0 2>/dev/null) || uci_bash_shelluser "$@"

View File

@ -0,0 +1,6 @@
#!/bin/bash
# module will install the uci-shell system on a remote machine
# must be run as sudo
mkdir -p /shell
chown 1000:users /shell
git clone https://git.kebler.net/base/shell-base.git /shell/base

View File

@ -1,2 +0,0 @@
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

View File

@ -1,2 +0,0 @@
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

View File

@ -1 +0,0 @@
export QT_SELECT=qt5

View File

@ -1,5 +0,0 @@
#!/bin/bash
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm|xterm-color|*-256color) color_prompt=yes;;
esac

View File

@ -1,117 +0,0 @@
#!/bin/bash
add-ppa () {
if [ $EUID != 0 ]; then
sudo bash -c "$(declare -f add-ppa); add-ppa $*"
else
VERSION=jammy
KEYSDIR=/etc/apt/trusted.gpg.d
KEYSERVER=keyserver.ubuntu.com
declare OPTION; declare OPTARG; declare OPTIND
while getopts 'v:p:s:k:c:d:oi' OPTION; do
echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
case "$OPTION" in
i)
INSTALL=true
;;
v)
VERSION=$OPTARG
;;
p)
PACKAGE=$OPTARG
;;
c)
CMD=$OPTARG
;;
d)
KEYSDIR=$OPTARG
;;
s)
KEYSERVER=$OPTARG
;;
o)
# overwrite any exising public key
KEYOVERWRITE=true
;;
*) echo unknown run option -$OPTARG
echo "USAGE: add-ppa <options> package/branch (e.g. git-core/ppa)"
echo "available options -v <ubnutu version name - default Jammy>; -p <apt install package name if not the same>"
;;
esac
done
shift $((OPTIND - 1))
#check input
if [ -z ${1+x} ]; then
echo "No ppa provided!"
return 1
fi
LAUNCHPAD="https://ppa.launchpadcontent.net"
DEV=$(echo $1 | cut -d ':' -f 2 | cut -d '/' -f1 )
PACKAGE=${PACKAGE:-$DEV}
CMD=${CMD:-$PACKAGE}
BRANCH=${2:-$(echo $1| cut -d '/' -f 2)}
URL="$LAUNCHPAD/$DEV/$BRANCH/ubuntu $VERSION main"
echo "*********** Adding PPA Repository ************"
echo DEVELOPER: $DEV
echo BRANCH: $BRANCH
echo PACKAGE: $PACKAGE
echo COMMAND: $CMD
echo URL: $URL
if [[ -t 0 ]]; then
read -n 1 -p "do you want to continue [y]=>" REPLY
[[ $REPLY != "y" ]] && return 0
fi
echo -e "\n*********************************************"
#create source list file
echo "deb $URL" > /etc/apt/sources.list.d/$DEV.list
echo "***** added /etc/apt/sources.list.d/$DEV.list with****"
cat /etc/apt/sources.list.d/$DEV.list
echo "*********************************************"
KEYFILE=$KEYSDIR/$DEV.gpg
[[ $KEYOVERWRITE ]] && rm $KEYFILE
if [ ! -f $KEYFILE ]; then
# using an update error to grab key id
KEY_ERROR=/tmp/${DEV}_key_error
touch $KEY_ERROR
apt-get update > /dev/null 2> $KEY_ERROR
cat $KEY_ERROR
KEY=$(sed -n 's/^.*NO_PUBKEY //p' "$KEY_ERROR" | head -1)
# echo Reposity Public Key Settings
# echo KEYS DIRECTORY: $KEYSDIR
# echo KEY SERVER: $KEYSERVER
# echo KEY: $KEY
if [ ! $KEY ]; then
echo can not determine $DEV/$BRANCH key sign
echo "removing file: /etc/apt/sources.list.d/$DEV.list and aborting"
rm /etc/apt/sources.list.d/$DEV.list
return 1
fi
echo downloading and saving public key $KEY for $DEV/$BRANCH to $KEYFILE
gpg --keyserver $KEYSERVER --recv $KEY
gpg --export $KEY > $KEYFILE
else
echo " >>>>>> $KEYFILE already exists, using that key $KEY <<<<<"
fi
echo ppa repo $DEV/$BRANCH for package $PACKAGE now registered, updating...
apt-get update 1> /dev/null
if [[ $INSTALL ]]; then
echo installing $PACKAGE
[[ -t 0 ]] && apt policy $PACKAGE
apt-get install $PACKAGE -y
$CMD --version
fi
fi
}
# # if script was executed then call the function
(return 0 2>/dev/null) || add-ppa $@

View File

@ -10,15 +10,24 @@
bundle () {
[[ ! -f $1 ]] && return 1
local file
if [[ $1 == "-m" ]]; then
shift 1
file=$(module_find $1)
else
file=$1
fi
[[ ! -f $file ]] && return 1
module_load file
if [[ ! $2 == "__recurse__" ]]; then
tmp_file=$( mktemp -t TEMP_FILE_bundle.XXXXXXXX )
chmod 600 "$tmp_file"
\cp $1 $tmp_file
\cp $file $tmp_file
else
tmp_file=$1
tmp_file=$file
fi
# echo current temp file: $tmp_file
modules=$(sed -n -e 's/^module_load //p' < $tmp_file)

View File

@ -0,0 +1,33 @@
#!/bin/bash
#bmount () {}
# sudo bindfs -o allow_other -o map=root/1001:@root/@1001 /var/lib/docker/volumes /data/dvols
dir_rebind_user () {
local usesudo; local dir;local user;local group
# $1 new owner
# $2 dir
[ $# -lt 2 ] && echo minimum args needed to rebind are user and directory && return 1
[[ $EUID -ne 0 ]] && usesudo=sudo
[[ $(id -u $1 2> /dev/null) ]] || { echo user $1 does not exist can not continue; return 2; }
dir=$(realpath $2)
user=$(stat -c '%U' $dir)
group=$(stat -c '%G' $dir)
$usesudo bindfs --force-user=$1 --force-group=$1 --create-for-user=$user --create-for-group=$group --chown-ignore --chgrp-ignore $dir $dir
# echo use \'dir_rebind_user_remove $dir\' to remove
}
dir_rebind_user_remove () {
local usersudo
[[ $EUID -ne 0 ]] && usesudo=sudo
$usesudo fusermount -u $1
}
if [ -v PS1 ]; then
alias dru="dir_rebind_user"
alias drur="dir_rebind_user_remove"
fi

56
modules/utility/dir.lib Normal file
View File

@ -0,0 +1,56 @@
#!/bin/bash
# simple local copy wintin or merge one directory to another using rsync. Preserves everything
# present working directory to supplied destination
isDir() {
if [[ -d $1 ]]
then
echo "true"
return 0
else
return 1
fi
}
function dir_copy () {
[[ ! $(which rsync) ]] && { echo rsync must be installed to use this function; return 5; }
module_load confirm
local usesudo;local cmd;local src;local noconfirm;local merge
declare OPTION
declare OPTARG
declare OPTIND
while getopts 'sem' OPTION; do
case "$OPTION" in
s)
usesudo=true
;;
e)
noconfirm=true
;;
m)
merge=true
;;
*)
echo unknown option $OPTION
return 1
;;
esac
done
shift $(( OPTIND - 1 ))
[ $# -ne 2 ] && echo two directories source and destination need to be passed && return 2
src=$(realpath -s $1)
dest=$(realpath -s $2)
[ ! -d "$src" ] && echo source: $src is not a directory && return 3
[[ $merge ]] && src=${src}/
cmd="$usesudo rsync --exclude *[C]ache* --exclude node_modules --progress -aAru $src $dest"
echo $cmd
[[ ! -v PS1 ]] && noconfirm=true
[[ ! $noconfirm ]] && { confirm Do you want to $([[ $merge ]] && echo merge $src into || echo copy $src within) $dest? || return 0; }
echo copying.....
eval $cmd
}

View File

@ -1,81 +0,0 @@
################## BEGIN: MODULE dirs ###############
isDir() {
if [[ -d $1 ]]
then
echo "true"
return 0
else
return 1
fi
}
chmodr () {
# Generic Script for recursively setting permissions for directories and files
# to defined or default permissions using chmod.
#
# Takes a path to recurse through and options for specifying directory and/or
# file permissions.
# Outputs a list of affected directories and files.
#
# If no options are specified, it recursively resets all directory and file
# permissions to the default for most OSs (dirs: 755, files: 644).
usage()
{
echo "Usage: $0 PATH -d DIRPERMS -f FILEPERMS"
echo "Arguments:"
echo "PATH: path to the root directory you wish to modify permissions for"
echo "Options:"
echo " -d DIRPERMS, directory permissions"
echo " -f FILEPERMS, file permissions"
return 1
}
# Check if user entered arguments
if [ $# -lt 1 ] ; then
usage
return 1
fi
# Get options
while getopts d:f: opt
do
case "$opt" in
d) DIRPERMS="$OPTARG";;
f) FILEPERMS="$OPTARG";;
\?) usage;;
esac
done
# Shift option index so that $1 now refers to the first argument
shift $(($OPTIND - 1))
# Default directory and file permissions, if not set on command line
if [ -z "$DIRPERMS" ] && [ -z "$FILEPERMS" ] ; then
DIRPERMS=755
FILEPERMS=644
fi
# Set the root path to be the argument entered by the user
ROOT=$1
# Check if the root path is a valid directory
if [ ! -d $ROOT ] ; then
echo "$ROOT does not exist or isn't a directory!" ; return 2
fi
# Recursively set directory/file permissions based on the permission variables
if [ -n "$DIRPERMS" ] ; then
find $ROOT -type d -print0 | xargs -0 chmod -v $DIRPERMS
fi
if [ -n "$FILEPERMS" ] ; then
find $ROOT -type f -print0 | xargs -0 chmod -v $FILEPERMS
fi
}
################## END: MODULE dirs ###############

View File

@ -1,6 +1,7 @@
#!/bin/bash
# environment and environment file functions
module_load iecho
clean_env_file () {
local compact
@ -29,7 +30,7 @@ env_file () {
# ignore non assignment lines
list_env_file_vars () {
env=$(env_file $1)
# cat $env
cat $env
[[ ! $env ]] && { iecho "Env file ${1} doesn't exist"; return 1; }
clean_env_file $env | grep -v '^#'| sed -n -E 's/(.*)=[^ =].*/\1/p' | xargs
}

View File

@ -1,16 +1,45 @@
#!/bin/bash
# load module and call fancy_prompt
# see
# used http://bashrcgenerator.com/
# and
# https://unix.stackexchange.com/questions/148/colorizing-your-terminal-and-shell-environment/174#174
# TODO move parse_git_branch, check for git before returning a value
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
function set_prompt_colors () {
export TERM=xterm-color
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
export COLOR_NC='\e[0m' # No Color
export COLOR_BLACK='\e[0;30m'
export COLOR_GRAY='\e[1;30m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_LIGHT_GRAY='\e[0;37m'
export COLOR_WHITE='\e[1;37m'
}
function fancy_prompt () {
# if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
set_prompt_colors
function c () {
local color
@ -53,5 +82,4 @@ PS1=$(echo "$user$machine$dir$branch$promptc")
# echo $PS1
}
# fancy prompt is on by default comment out to disable default
fancy_prompt

View File

@ -15,3 +15,4 @@ find_mountpoint () {
return 1
fi
}

View File

@ -1,6 +1,7 @@
#!/bin/bash
# if you have run into github api anonymous access limits which happens during debugging/dev then add user and token here or sourced from a separate file
# set to location for tokens in file
# DEPRECATED use python based lastversion https://github.com/dvershinin/lastversion
source ~/githubapitoken
if [ "$GITHUB_TOKEN" != "" ]; then

75
modules/acl.lib → modules/utility/security.lib Executable file → Normal file
View File

@ -1,4 +1,6 @@
#!/bin/bash
################## BEGIN: MODULE security ###############
module_load confirm
module_load helpers
#source ${BASH_SOURCE[0]}/confirm.sh
@ -147,3 +149,76 @@ share_dir() {
getfacl -p $dir
}
chmodr () {
# Generic Script for recursively setting permissions for directories and files
# to defined or default permissions using chmod.
#
# Takes a path to recurse through and options for specifying directory and/or
# file permissions.
# Outputs a list of affected directories and files.
#
# If no options are specified, it recursively resets all directory and file
# permissions to the default for most OSs (dirs: 755, files: 644).
usage()
{
echo "Usage: $0 PATH -d DIRPERMS -f FILEPERMS"
echo "Arguments:"
echo "PATH: path to the root directory you wish to modify permissions for"
echo "Options:"
echo " -d DIRPERMS, directory permissions"
echo " -f FILEPERMS, file permissions"
return 1
}
# Check if user entered arguments
if [ $# -lt 1 ] ; then
usage
return 1
fi
# Get options
while getopts d:f: opt
do
case "$opt" in
d) DIRPERMS="$OPTARG";;
f) FILEPERMS="$OPTARG";;
\?) usage;;
esac
done
# Shift option index so that $1 now refers to the first argument
shift $(($OPTIND - 1))
# Default directory and file permissions, if not set on command line
if [ -z "$DIRPERMS" ] && [ -z "$FILEPERMS" ] ; then
DIRPERMS=755
FILEPERMS=644
fi
# Set the root path to be the argument entered by the user
ROOT=$1
# Check if the root path is a valid directory
if [ ! -d $ROOT ] ; then
echo "$ROOT does not exist or isn't a directory!" ; return 2
fi
# Recursively set directory/file permissions based on the permission variables
if [ -n "$DIRPERMS" ] ; then
find $ROOT -type d -print0 | xargs -0 chmod -v $DIRPERMS
fi
if [ -n "$FILEPERMS" ] ; then
find $ROOT -type f -print0 | xargs -0 chmod -v $FILEPERMS
fi
}
################## END: MODULE dirs ###############

View File

@ -1,7 +1,50 @@
#!/bin/bash
is_user () {
local id;local user
echo -n $(id -u $1 2> /dev/null)
}
user_group_add() {
[[ ! $(getent group $1) ]] && echo "no group $1, aborting" && return 1
echo adding group $1 to $USER
sudo usermod -a -G $1 $USER
}
# TODO change a user name
# sudo usermod -d /home/joedoe -m johndoe
# sudo groupmod -n johndoe student1
# sudo usermod -u 5001 johndoe
# clone a user
# adduserid name id#
# add a suer with specific id number
# adduserid () {
# sudo groupadd -g $2 $1
# sudo useradd -d ${/home/$1} -s /bin/bash -u $2 -g $1 $1
# }
adduserid() {
[[ "$#" -lt 1 ]] && echo a user name is requied, aborting && return 1
name=$1
uid=${2:-1000}
gid=${3:-$uid}
echo $name, $uid, $gid
[[ $(getent group $gid) ]] && echo group id $gid already exists, aborting && return 3
[[ $(getent group $name) ]] && echo group name $name already exists, aborting && return 3
[[ $(getent passwd $uid) ]] && echo user id $uid already exists, aborting && return 2
[[ $(getent passwd $name) ]] && echo user name $name already exists, aborting && return 2
addgroup --gid $gid $name
adduser --uid $uid --ingroup $name --gecos "" --disabled-password --no-create-home $name
# cat /etc/group | grep $name && cat /etc/passwd | grep $name
}
function clone_user_ () {
module_load confirm

View File

@ -1,36 +0,0 @@
#!/bin/bash
[[ ! $(groups | grep sudo) ]] && echo this script must be run by a user with sudo privileges && exit 1
[[ ! $BASH_SHELL_BASE ]] && BASH_SHELL_BASE="$(dirname "$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")"
echo Backng up to $BASH_SHELL_BASE/setup/backup
echo ok to continue?
echo "type \`yes\` fully or just <enter> for no"
read -e answer
[[ ! $answer = "yes" ]] && exit 1
set -o errexit
mkdir -p $BASH_SHELL_BASE/setup/backup/etc/profile.d
# mkdir -p $BASH_SHELL_BASE/setup/backup/user
mkdir -p $BASH_SHELL_BASE/setup/backup/root
# host system files in /etc
[[ -f /etc/profile ]] && cp -v /etc/profile $BASH_SHELL_BASE/setup/backup/etc
[[ -f /etc/bash.bashrc ]] && cp -v /etc/bash.bashrc $BASH_SHELL_BASE/setup/backup/etc
[[ -d /etc/profile.d ]] && cp -vR /etc/profile.d/ $BASH_SHELL_BASE/setup/backup/etc/
# current user files in $HOME
# [[ -f $HOME/.bash_profile ]] && cp -v $HOME/.bash_profile $BASH_SHELL_BASE/setup/backup/user
# [[ -f $HOME/.profile ]] && cp -v $HOME/.profile $BASH_SHELL_BASE/setup/backup/user
# [[ -f $HOME/.bashrc ]] && cp -v $HOME/.bashrc $BASH_SHELL_BASE/setup/backup/user
# [[ -f $HOME/.bash_logout ]] && cp -v $HOME/.bash_logout $BASH_SHELL_BASE/setup/backup/user
if [[ $(stat -c "%G" /root) = "sudo" ]]; then
[[ -f /root/.bash_profile ]] && cp -v /root/.bash_profile $BASH_SHELL_BASE/setup/backup/root
[[ -f /root/.profile ]] && cp -v /root/.profile $BASH_SHELL_BASE/setup/backup/root
[[ -f /root/.bashrc ]] && cp -v /root/.bashrc $BASH_SHELL_BASE/setup/backup/root
[[ -f /root/.bash_logout ]] && cp -v /root/.bash_logout $BASH_SHELL_BASE/setup/backup/root
else
echo no sudo group read access to /root so backing up /root as root
sudo -E -- bash -c '[[ ! -f /root/.profile ]] && exit 0; cp -v /root/.profile $BASH_SHELL_BASE/setup/backup/root'
sudo -E -- bash -c '[[ ! -f /root/.bashrc ]] && exit 0; cp -v /root/.bashrc $BASH_SHELL_BASE/setup/backup/root'
sudo -E -- bash -c '[[ ! -f /root/.bash_profile ]] && exit 0; cp -v /root/.bash_profile $BASH_SHELL_BASE/setup/backup/root'
sudo -E -- bash -c '[[ ! -f /root/.bash_logout ]] && exit 0; cp -v /root/.bash_logout $BASH_SHELL_BASE/setup/backup/root'
fi
set +o errexit
echo backup of system shell files complete!
exit 0

View File

@ -1,42 +0,0 @@
#!/bin/bash
_USER=${1:-$USER}
[[ ! $(id -u $_USER) -ge 1000 ]] && echo "no user $_USER or user not a regular" && exit 1
echo user: $_USER deployment
[[ ! $BASH_SHELL_BASE ]] && BASH_SHELL_BASE="$(dirname "$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")"
echo Base Shell Directory as detected is $BASH_SHELL_BASE
echo ok to continue?
echo "type \`yes\` fully or just <enter> to exit"
read -e answer
[[ ! $answer = "yes" ]] && exit 1
UBDIR=$BASH_SHELL_BASE/setup/backup-users/$_USER
_USER_DIR=$(getent passwd "$USER" | cut -d : -f 6)
files=".bash_profile .profile .bashrc .bash_logout"
# uncomment for debugging
# rm -rf $UBDIR
if [[ ! -d $UBDIR ]]; then
echo "first backing up $_USER_DIR shell files before deploying"
mkdir -p $UBDIR
for file in $files ; do
[[ -f $_USER_DIR/$file ]] && sudo install -C -m 660 -o root -g sudo $_USER_DIR/$file $UBDIR
done
fi
echo "ready to deploy $_USER shell files"
echo "Double check files in $UBDIR"
echo "continue? type \`yes\` fully or just <enter> for no"
read -e answer
[[ ! $answer = "yes" ]] && echo aborting deploy && exit 1
echo -----------------;echo deploying user shell files to /home/$_USER
echo
files=$(find $BASH_SHELL_BASE/setup/user/ -type f)
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 "enter an alternative subdirectory under $_USER_DIR or just <enter> to accept default"
read -e answer
[[ ! $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

View File

@ -1,49 +0,0 @@
#!/bin/bash
BASH_SHELL_BASE="$(dirname "$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")"
echo Base Shell Directory as detected is $BASH_SHELL_BASE
echo ok to continue?
echo "type \`yes\` fully or just <enter> for no"
read -e answer
[[ ! $answer = "yes" ]] && exit 1
[[ ! $(groups | grep sudo) ]] && echo this script must be run by a user with sudo privileges && exit 1
# uncomment for debugging
# rm -rf $BASH_SHELL_BASE/setup/backup/
if [[ ! $(stat -c "%G" /root) = "sudo" ]]; then
echo "Allow all sudoers read access to /root directory and files?"
echo "type \`yes\` fully or just <enter> for no"
read -e answer
if [[ $answer = "yes" ]]; then
sudo chown -R root:sudo /root
sudo chmod -R g+rX /root
echo sudo group and permissions on /root were set || \
echo error during sudo access setup
else
echo;echo sudoer access to /root was declined
fi
fi
if [[ ! -d $BASH_SHELL_BASE/setup/backup ]]; then
echo "backing up shell files before deploying"
$BASH_SHELL_BASE/setup/backup.sh
[[ $? -ne 0 ]] && echo issue with backup did not deploy && exit 1
# echo backup finished to $BASH_SHELL_BASE/setup/backup
fi
echo "ready to deploy shell files"
echo "Double check files in $BASH_SHELL_BASE/setup/backup"
echo "continue? type \`yes\` fully or just <enter> for no"
read -e answer
[[ ! $answer = "yes" ]] && echo aborting deploy && exit 1
echo -----------------;echo deploying /etc shell files
files=$(find $BASH_SHELL_BASE/setup/etc/ -maxdepth 1 -type f)
for file in $files; do sudo install -C -m 644 -o root -g root $file /etc; done
echo setting BASH_SHELL_BASE to $BASH_SHELL_BASE in etc/bash.bashrc and /etc/profile
sudo sed -i 's:_BASH_SHELL_BASE_:'${BASH_SHELL_BASE}':' /etc/bash.bashrc
sudo sed -i 's:BASH_SHELL_BASE=.*:BASH_SHELL_BASE='${BASH_SHELL_BASE}':' /etc/profile
files=$(find $BASH_SHELL_BASE/setup/etc/profile.d -maxdepth 1 -type f)
for file in $files; do sudo install -C -m 644 -o root -g root $file /etc/profile.d; done
echo -----------------;echo deploying /root shell files
group=root
[[ $(stat -c "%G" /root) = "sudo" ]] && group=sudo
files=$(find $BASH_SHELL_BASE/setup/root/ -type f)
for file in $files; do sudo install -C -m 640 -o root -g $group $file /root; done
echo -----------------
source $BASH_SHELL_BASE/setup/deploy-user.sh

View File

@ -1,16 +0,0 @@
#!/bin/bash
mkdir -p $BASH_SHELL_BASE/setup/etc/profile.d
mkdir -p $BASH_SHELL_BASE/setup/user
mkdir -p $BASH_SHELL_BASE/setup/root
cp -vi /etc/profile $BASH_SHELL_BASE/setup/etc
cp -vi /etc/bash.bashrc $BASH_SHELL_BASE/setup/etc
cp -vi /etc/profile.d/02-root.sh $BASH_SHELL_BASE/setup/etc/profile.d
cp -vi /etc/profile.d/03-startup.sh $BASH_SHELL_BASE/setup/etc/profile.d
cp -vi $HOME/.bash_profile $BASH_SHELL_BASE/setup/user
cp -vi $HOME/.profile $BASH_SHELL_BASE/setup/user
cp -vi $HOME/.bashrc $BASH_SHELL_BASE/setup/user
cp -vi $HOME/.bash_logout $BASH_SHELL_BASE/setup/user
cp -vi /root/.bash_profile $BASH_SHELL_BASE/setup/root
cp -vi /root/.profile $BASH_SHELL_BASE/setup/root
cp -vi /root/.bashrc $BASH_SHELL_BASE/setup/root
cp -vi /root/.bash_logout $BASH_SHELL_BASE/setup/root

View File

@ -1,5 +0,0 @@
# echo $USER .bash_profile
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

View File

@ -1 +0,0 @@
# echo $USER .bashrc

View File

@ -1,2 +0,0 @@
echo $USER .profile
echo "for bash login shell only called if .bash_profile does not exist"

View File

@ -1,6 +0,0 @@
#!/bin/bash
# uncomment for debugging
# echo ".bash_profile sourced at user $USER login"
# only source .bashrc if interactive login shell
[[ $SHELL_INTERACTIVE ]] && [[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"

View File

@ -1,2 +0,0 @@
echo .profile, user $USER
echo "warning: this only is sourced if .bash_profile doesn't exist"