Merge remote-tracking branch 'git.kebler.net/master' into giskard

giskard
Kebler Network System Administrator 2021-02-18 10:45:59 -08:00
commit c7bd93723b
9 changed files with 509 additions and 5 deletions

7
all/app/backup Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
backup () {
DIR=$(dirname $(cd "$(dirname "$BASH_SOURCE")" >/dev/null 2>&1 ; pwd -P ))
$DIR/dev/backup/backup "$@"
#module_load backup
#run "$@"
}

367
all/dev/backup/backup Executable file
View File

@ -0,0 +1,367 @@
#!/usr/bin/env bash
# This script was generated by bashly (https://github.com/DannyBen/bashly)
# Modifying it manually is not recommended
# :command.root_command
root_command() {
# :src/root_command.sh
echo Running Backup Command
inspect_args
# module_load ssh
module_load confirm
local source=${args[source]}
local target=${args[target]}
local shost=$([[ ${args[--shost]} ]] && echo ${args[--shost]}::)
local suser=$([[ ${args[--suser]} ]] && echo ${args[--suser]}@)
local thost=$([[ ${args[--host]} ]] && echo ${args[--host]}::)
local tuser=$([[ ${args[--user]} ]] && echo ${args[--user]}@)
local mirror=${args[--mirror]}
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
local sudo=$([[ ${args[--sudo]} ]] && echo sudo)
local exclude=${args[--exclude_file]}
if [[ ! $exclude ]]; then
echo checking local excludes
[[ -f $source/exclude.bac ]] && exclude="$source/exclude.bac"
ls $source
# [[ $EXCLUDE_BACKUP ]] && exclude="$BACKUP_EXCLUDE"
fi
exclude=$([[ $exclude ]] && echo --exclude-globbing-filelist $exclude)
echo exclude file: $exclude
# local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\""
cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target"
echo $cmd
confirm run this command? || return 1
eval $cmd
}
# :command.version_command
version_command() {
echo "$version"
}
# :command.usage
backup_usage() {
if [[ -n $long_usage ]]; then
printf "backup - backup/mirror a directory using rdiff or rsync\n"
echo
else
printf "backup - backup/mirror a directory using rdiff or rsync\n"
echo
fi
printf "Usage:\n"
printf " backup [SOURCE] [TARGET] [options]\n"
printf " backup --help\n"
printf " backup --version | -v\n"
echo
if [[ -n $long_usage ]]; then
printf "Options:\n"
# :command.usage_fixed_flags
echo " --help"
printf " Show this help\n"
echo
echo " --version, -v"
printf " Show version number\n"
echo
# :command.usage_flags
# :flag.usage
echo " --host, -h THOST"
printf " host on remote to target to receive backup\n"
echo
# :flag.usage
echo " --shost SHOST"
printf " remote to host of source\n"
echo
# :flag.usage
echo " --user, -u TUSER"
printf " user on remote host\n"
echo
# :flag.usage
echo " --suser SUSER"
printf " remote user on source host\n"
echo
# :flag.usage
echo " --sshcfg SSHCFG"
printf " path to sshcfg file\n"
echo
# :flag.usage
echo " --options, -o OPTIONS"
printf " rdiff options\n"
echo
# :flag.usage
echo " --include_file, -i OPTIONS"
printf " rdiff options\n"
echo
# :flag.usage
echo " --exclude_file, -e OPTIONS"
printf " rdiff options\n"
echo
# :flag.usage
echo " --mirror, -m"
printf " make a mirror copy instead of a differential snapshot\n"
echo
# :flag.usage
echo " --sudo, -s"
printf " run the backup as sudo\n"
echo
# :flag.usage
echo " --no-dir, -n"
printf " don't make a directory of same name within the target, merge sub directories\n"
echo
# :command.usage_args
printf "Arguments:\n"
# :argument.usage
echo " SOURCE"
printf " source directory to be backed up, default is $PWD\n"
echo
# :argument.usage
echo " TARGET"
printf " target directory for backup\n"
echo
# :command.usage_environment_variables
printf "Environment Variables:\n"
# :environment_variable.usage
echo " BACKUP_EXCLUDE"
printf " path to file of excludes\n"
echo
# :environment_variable.usage
echo " BACKUP_INCLUDE"
printf " path to directory of includes\n"
echo
# :command.usage_examples
printf "Examples:\n"
printf " backup -m -n -h thost --shost shost -u tuser --suser suser . /target/dir\n"
echo
fi
}
# :command.inspect_args
inspect_args() {
echo args:
for k in "${!args[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
}
# :command.command_functions
# :command.parse_requirements
parse_requirements() {
# :command.fixed_flag_filter
case "$1" in
--version | -v )
version_command
exit
;;
--help )
long_usage=yes
backup_usage
exit 1
;;
esac
# :command.environment_variables_filter
# :command.dependencies_filter
# :command.command_filter
action="root"
# :command.required_args_filter
# :command.required_flags_filter
# :command.parse_requirements_while
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
# :flag.case
--host | -h )
if [[ $2 && $2 != -* ]]; then
args[--host]="$2"
shift
shift
else
printf "%s\n" "--host requires an argument: --host, -h THOST"
exit 1
fi
;;
# :flag.case
--shost )
if [[ $2 && $2 != -* ]]; then
args[--shost]="$2"
shift
shift
else
printf "%s\n" "--shost requires an argument: --shost SHOST"
exit 1
fi
;;
# :flag.case
--user | -u )
if [[ $2 && $2 != -* ]]; then
args[--user]="$2"
shift
shift
else
printf "%s\n" "--user requires an argument: --user, -u TUSER"
exit 1
fi
;;
# :flag.case
--suser )
if [[ $2 && $2 != -* ]]; then
args[--suser]="$2"
shift
shift
else
printf "%s\n" "--suser requires an argument: --suser SUSER"
exit 1
fi
;;
# :flag.case
--sshcfg )
if [[ $2 && $2 != -* ]]; then
args[--sshcfg]="$2"
shift
shift
else
printf "%s\n" "--sshcfg requires an argument: --sshcfg SSHCFG"
exit 1
fi
;;
# :flag.case
--options | -o )
if [[ $2 && $2 != -* ]]; then
args[--options]="$2"
shift
shift
else
printf "%s\n" "--options requires an argument: --options, -o OPTIONS"
exit 1
fi
;;
# :flag.case
--include_file | -i )
if [[ $2 && $2 != -* ]]; then
args[--include_file]="$2"
shift
shift
else
printf "%s\n" "--include_file requires an argument: --include_file, -i OPTIONS"
exit 1
fi
;;
# :flag.case
--exclude_file | -e )
if [[ $2 && $2 != -* ]]; then
args[--exclude_file]="$2"
shift
shift
else
printf "%s\n" "--exclude_file requires an argument: --exclude_file, -e OPTIONS"
exit 1
fi
;;
# :flag.case
--mirror | -m )
args[--mirror]=1
shift
;;
# :flag.case
--sudo | -s )
args[--sudo]=1
shift
;;
# :flag.case
--no-dir | -n )
args[--no-dir]=1
shift
;;
-* )
printf "invalid option: %s\n" "$key"
exit 1
;;
* )
# :command.parse_requirements_case
if [[ ! ${args[source]} ]]; then
args[source]=$1
shift
elif [[ ! ${args[target]} ]]; then
args[target]=$1
shift
else
printf "invalid argument: %s\n" "$key"
exit 1
fi
;;
esac
done
# :command.default_assignments
}
# :command.initialize
initialize() {
version="0.1.0"
long_usage=''
set -e
# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
}
# :command.run
run() {
declare -A args
parse_requirements "$@"
if [[ ${args[--version]} ]]; then
version_command
elif [[ ${args[--help]} ]]; then
long_usage=yes
backup_usage
elif [[ $action == "root" ]]; then
root_command
fi
}
initialize
run "$@"

View File

@ -0,0 +1,59 @@
name: backup
help: backup/mirror a directory using rdiff or rsync
version: 0.1.0
environment_variables:
- name: BACKUP_EXCLUDE
help: path to file of excludes
- name: BACKUP_INCLUDE
help: path to directory of includes
args:
- name: source
# required: 1
help: source directory to be backed up, default is $PWD
- name: target
help: "target directory for backup"
flags:
- long: --host
short: -h
arg: thost
help: host on remote to target to receive backup
- long: --shost
arg: shost
help: remote to host of source
- long: --user
short: -u
arg: tuser
help: user on remote host
- long: --suser
arg: suser
help: remote user on source host
- long: --sshcfg
arg: sshcfg
help: path to sshcfg file
- long: --options
short : -o
arg: options
help: rdiff options
- long: --include_file
short : -i
arg: options
help: rdiff options
- long: --exclude_file
short : -e
arg: options
help: rdiff options
- long: --mirror
short: -m
help: make a mirror copy instead of a differential snapshot
- long: --sudo
short: -s
help: run the backup as sudo
- long: --no-dir
short: -n
help: don't make a directory of same name within the target, merge sub directories
examples:
- backup -m -n -h thost --shost shost -u tuser --suser suser . /target/dir

View File

@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.

View File

@ -0,0 +1,35 @@
echo Running Backup Command
inspect_args
# module_load ssh
module_load confirm
local source=${args[source]}
local target=${args[target]}
local shost=$([[ ${args[--shost]} ]] && echo ${args[--shost]}::)
local suser=$([[ ${args[--suser]} ]] && echo ${args[--suser]}@)
local thost=$([[ ${args[--host]} ]] && echo ${args[--host]}::)
local tuser=$([[ ${args[--user]} ]] && echo ${args[--user]}@)
local mirror=${args[--mirror]}
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
local sudo=$([[ ${args[--sudo]} ]] && echo sudo)
local exclude=${args[--exclude_file]}
if [[ ! $exclude ]]; then
echo checking local excludes
[[ -f $source/exclude.bac ]] && exclude="$source/exclude.bac"
# ls $source
# [[ $EXCLUDE_BACKUP ]] && exclude="$BACKUP_EXCLUDE"
fi
exclude=$([[ $exclude ]] && echo --exclude-globbing-filelist $exclude)
echo exclude file: $exclude
# local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\""
cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target"
echo $cmd
confirm run this command? || return 1
eval $cmd

4
all/dev/backup/test Executable file
View File

@ -0,0 +1,4 @@
shopt -s expand_aliases
source ../../app/bashly
bashly generate
./backup "$@"

View File

@ -14,7 +14,6 @@ alias npms="npm start"
alias npmlag="npm la --silent --depth=0 --global"
alias npmla="npm la --silent --depth=0"
alias npmlaf="npm la --silent | grep"
alias npmlsg="npm ls --silent --depth=0 --global"
alias npmlsf="npm ls --silent grep"
alias npmlsa="npm ls --silent"
alias npmls="npm ls --silent --depth=0"
@ -26,13 +25,17 @@ alias npmro="npm uninstall --save-optional"
alias npmidv="npm install --save-dev"
alias npmidvnd="npm install --save-dev --package-lock-only --no-package-lock"
alias npmrdv="npm uninstall --save-dev"
# global for nodejs apps, will be alt directory if npmrc prefix is set
alias npmlsg="npm ls --silent --depth=0 --global"
alias npmig="npm install -g"
alias snpmig="sudo npm install -g"
alias npmrg="npm uninstall -g"
alias snpmrg="npm uninstall -g"
alias npmunpm="echo npm installed version && npm --version && echo npm latest version available && npm view npm@latest version && echo any key to continue npm upgrade or break && read && npm install -g npm@latest"
# global forced in sudo system location /usr
alias snpmig="sudo npm install -g --prefix /usr"
alias snpmlsg="sudo npm ls --silent --depth=0 --global --prefix /usr"
alias snpmrg="sudo npm uninstall -g --prefix /usr"
alias npmunpm="echo npm installed version && npm --version && echo npm latest version available && npm view npm@latest version && echo any key to continue npm upgrade or break && read && sudo npm install -g npm@latest"
alias npmua="npm --depth=9999 update"
alias npmug="npm-check -g -u"
alias npmug="npm update -g"
alias npmu="npm-check -u"
alias npmcc="ncu -p -a -u"
alias npmcdvc="ncu -d -a -u"
@ -47,6 +50,9 @@ alias npmnpub="npm publish --registry https://npm.kebler.net --access restricted
alias npmjspub="npm publish --registry https://registry.npmjs.org --access public"
alias yalcpush="nodemon -x 'yalc push'"
module_load node
# else
# echo "node not installed, npm aliases not loaded"
fi

View File

@ -14,6 +14,8 @@ alias pipi="pipx install"
alias pipl="pipx list"
alias piplv="pipx list --verbose"
if command -v pyenv >/dev/null 2>&1; then
# pyenv environment
path_append "/opt/python/bin"
@ -29,6 +31,7 @@ path_append "/opt/python/apps/bin"
export PIPX_HOME=/opt/python/apps
export PIPX_BIN_DIR=$PIPX_HOME/bin
fi
spipua () {
module_load confirm

17
all/modules/node.sh Normal file
View File

@ -0,0 +1,17 @@
module_load confirm
rm_node_modules () {
parent=${1:-$PWD}
echo finding node_modules folders within $parent
if command find . -name 'node_modules' -type d -prune 2>/dev/null;then
confirm continue with deleting? || return 1
command find . -name 'node_modules' -type d -prune -exec rm -r '{}' +
else
echo no folders to delete
fi
}
# if script was executed then call the function
(return 0 2>/dev/null) || rm_node_modules $@