scwrypts/run

354 lines
9.7 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/zsh
export EXECUTION_DIR=$(pwd)
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
source "${0:a:h}/zsh/lib/import.driver.zsh" || exit 42
#####################################################################
__RUN() {
local USAGE='
2023-12-12 00:07:09 +00:00
usage: scwrypts [... options ...] [patterns] -- [...script options...]
options:
selection
-m, --name <scwrypt-name> only run the script if there is an exact match
(requires type and group)
-g, --group <group-name> only use scripts from the indicated group
-t, --type <type-name> only use scripts of the indicated type
runtime
-y, --yes auto-accept all [yn] prompts through current scwrypt
-e, --env <env-name> set environment; overwrites SCWRYPTS_ENV
-q, --quiet run in quiet mode
-n, --no-log skip the log file and run in quiet mode
-v, --verbose override quiet mode settings and print all debug dialogue
alternate commands
-h, --help display this message and exit
-l, --list print out command list and exit
--list-envs print out environment list and exit
--update update scwrypts library to latest version
--version print out scwrypts version and exit
patterns:
- a list of glob patterns to loose-match a scwrypt by name
script options:
- everything after "--" is forwarded to the scwrypt you run
(usually "-- --help" will provide more information)
'
cd "$SCWRYPTS_ROOT"
local ENV_NAME="$SCWRYPTS_ENV"
local SEARCH_PATTERNS=()
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
local VARSPLIT SEARCH_GROUP SEARCH_TYPE SEARCH_NAME
2023-12-12 00:07:09 +00:00
local ALLOW_LOGFILE=1
local VERBOSE=1
[ $CI ] && [ ! $SCWRYPTS_CI_FORCE_NON_VERBOSE ] && VERBOSE=2
local ERROR=0
while [[ $# -gt 0 ]]
do
case $1 in
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
-[a-z][a-z]* )
VARSPLIT=$(echo "$1 " | sed 's/^\(-.\)\(.*\) /\1 -\2/')
set -- $(echo " $VARSPLIT ") ${@:2}
;;
2023-12-12 00:07:09 +00:00
-h | --help ) USAGE; return 0 ;;
-l | --list ) SCWRYPTS__GET_AVAILABLE_SCWRYPTS; return 0 ;;
--list-envs ) SCWRYPTS__GET_ENV_NAMES; return 0 ;;
--version )
echo scwrypts $(git -C "$SCWRYPTS__ROOT__scwrypts" describe --tags)
return 0
;;
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
--update )
cd "$SCWRYPTS__ROOT__scwrypts"
git fetch --quiet origin main
git fetch --quiet origin main --tags
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
local SYNC_STATUS=$?
git diff --exit-code origin/main -- . >&2
local DIFF_STATUS=$?
[[ $SYNC_STATUS -eq 0 ]] && [[ $DIFF_STATUS -eq 0 ]] && {
SUCCESS 'already up-to-date with origin/main'
} || {
git rebase --autostash origin/main \
&& SUCCESS 'up-to-date with origin/main' \
|| {
git rebase --abort
ERROR 'unable to update scwrypts; please try manual upgrade'
REMINDER "installation in '$(pwd)'"
}
}
return 0
;;
2023-12-12 00:07:09 +00:00
-m | --name )
[ ! $2 ] && ERROR "missing value for argument $1" && break
SEARCH_NAME=$2
shift 1
;;
2023-12-12 00:07:09 +00:00
-g | --group )
[ ! $2 ] && ERROR "missing value for argument $1" && break
SEARCH_GROUP=$2
shift 1
;;
2023-12-12 00:07:09 +00:00
-t | --type )
[ ! $2 ] && ERROR "missing value for argument $1" && break
SEARCH_TYPE=$2
shift 1
;;
2023-12-12 00:07:09 +00:00
-y | --yes ) export __SCWRYPTS_YES=1 ;;
-q | --quiet ) VERBOSE=0 ;;
-n | --no-log ) VERBOSE=0 ; [ ! $SUBSCWRYPT ] && SUBSCWRYPT=0 ;;
-v | --verbose ) VERBOSE=2 ;;
-e | --env )
[ ! $2 ] && ERROR "missing value for argument $1" && break
[ ! $SUBSCWRYPTS ] \
&& [ $ENV_NAME ] \
&& WARNING 'overwriting session environment' \
;
ENV_NAME="$2"
STATUS "using CLI environment '$ENV_NAME'"
shift 1
;;
-- ) shift 1; break ;; # pass arguments after '--' to the scwrypt
--* ) ERROR "unrecognized argument '$1'" ;;
* ) SEARCH_PATTERNS+=($1) ;;
esac
2023-12-12 00:07:09 +00:00
shift 1
done
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
[ $SEARCH_NAME ] && {
2023-12-12 00:07:09 +00:00
[ $SEARCH_TYPE ] || ERROR '--name requires --type argument'
[ $SEARCH_GROUP ] || ERROR '--name requires --group argument'
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
}
CHECK_ERRORS
##########################################
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
local SCWRYPTS_AVAILABLE
local POTENTIAL_ERROR="no such scwrypt exists:"
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
SCWRYPTS_AVAILABLE=$(SCWRYPTS__GET_AVAILABLE_SCWRYPTS)
[ $SEARCH_NAME ] && {
POTENTIAL_ERROR+="\n NAME : '$SEARCH_NAME'"
POTENTIAL_ERROR+="\n TYPE : '$SEARCH_TYPE'"
POTENTIAL_ERROR+="\n GROUP : '$SEARCH_GROUP'"
SCWRYPTS_AVAILABLE=$({
echo $SCWRYPTS_AVAILABLE | head -n1
echo $SCWRYPTS_AVAILABLE | sed -e 's/\x1b\[[0-9;]*m//g' | grep "^$SEARCH_NAME *$SEARCH_TYPE *$SEARCH_GROUP\$"
})
}
[ ! $SEARCH_NAME ] && {
[ $SEARCH_TYPE ] && {
POTENTIAL_ERROR+="\n TYPE : '$SEARCH_TYPE'"
SCWRYPTS_AVAILABLE=$(\
{
echo $SCWRYPTS_AVAILABLE | head -n1
echo $SCWRYPTS_AVAILABLE | grep ' [^/]*'$SEARCH_TYPE'[^/]* '
} \
| awk '{$2=""; print $0;}' \
| sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \
| column -ts '^'
)
}
[ $SEARCH_GROUP ] && {
POTENTIAL_ERROR+="\n GROUP : '$SEARCH_GROUP'"
SCWRYPTS_AVAILABLE=$(
{
echo $SCWRYPTS_AVAILABLE | head -n1
echo $SCWRYPTS_AVAILABLE | grep "$SEARCH_GROUP"'[^/]*$'
} \
| awk '{$NF=""; print $0;}' \
| sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \
| column -ts '^'
)
}
[[ ${#SEARCH_PATTERNS[@]} -gt 0 ]] && {
POTENTIAL_ERROR+="\n PATTERNS : $SEARCH_PATTERNS"
local P
for P in ${SEARCH_PATTERNS[@]}
do
SCWRYPTS_AVAILABLE=$(
{
echo $SCWRYPTS_AVAILABLE | head -n1
echo $SCWRYPTS_AVAILABLE | grep $P
}
)
done
}
}
[[ $(echo $SCWRYPTS_AVAILABLE | wc -l) -lt 2 ]] && ERROR "$POTENTIAL_ERROR"
CHECK_ERRORS
##########################################
local NAME="$SEARCH_NAME"
local TYPE="$SEARCH_TYPE"
local GROUP="$SEARCH_GROUP"
2023-12-12 00:07:09 +00:00
[[ $(echo $SCWRYPTS_AVAILABLE | wc -l) -eq 2 ]] && {
SCWRYPT_SELECTION=$(echo $SCWRYPTS_AVAILABLE | tail -n1)
[[ $VERBOSE -eq 2 ]] || VERBOSE=0
} || {
SCWRYPT_SELECTION=$(echo $SCWRYPTS_AVAILABLE | FZF "select a script to run" --header-lines 1)
}
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
[ $SCWRYPT_SELECTION ] || exit 2
SCWRYPTS__SEPARATE_SCWRYPT_SELECTION $SCWRYPT_SELECTION
export SCWRYPT_NAME=$NAME
export SCWRYPT_TYPE=$TYPE
export SCWRYPT_GROUP=$GROUP
##########################################
local ENV_REQUIRED=$(__CHECK_ENV_REQUIRED && echo 1 || echo 0)
local REQUIRED_ENVIRONMENT_REGEX=$(eval echo '$SCWRYPTS_REQUIRED_ENVIRONMENT_REGEX__'$SCWRYPT_GROUP)
[ $REQUIRED_ENVIRONMENT_REGEX ] && {
[[ $ENV_NAME =~ $REQUIRED_ENVIRONMENT_REGEX ]] \
|| FAIL 5 "group '$SCWRYPT_GROUP' requires current environment to match '$REQUIRED_ENVIRONMENT_REGEX' (currently $ENV_NAME)"
}
[[ $ENV_REQUIRED -eq 1 ]] && {
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
[ ! $ENV_NAME ] && ENV_NAME=$(SCWRYPTS__SELECT_ENV)
for GROUP in ${SCWRYPTS_GROUPS[@]}
do
local ENV_FILE=$(SCWRYPTS__GET_ENV_FILE "$ENV_NAME" "$GROUP")
source "$ENV_FILE" || FAIL 5 "missing or invalid environment '$GROUP/$ENV_NAME'"
for f in $(eval 'echo $SCWRYPTS_STATIC_CONFIG__'$GROUP)
do
source "$f" || FAIL 5 "invalid static config '$f'"
done
done
export ENV_NAME
}
[ $REQUIRED_ENVIRONMENT_REGEX ] && {
[[ $ENV_NAME =~ $REQUIRED_ENVIRONMENT_REGEX ]] \
|| FAIL 5 "group '$SCWRYPT_GROUP' requires current environment to match '$REQUIRED_ENVIRONMENT_REGEX' (currently $ENV_NAME)"
}
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
##########################################
2023-12-12 00:07:09 +00:00
: \
&& [ ! $SUBSCWRYPT ] \
&& [[ $ENV_NAME =~ prod ]] \
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
&& { __VALIDATE_UPSTREAM_TIMELINE || ABORT; }
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
##########################################
local RUN_STRING=$(SCWRYPTS__GET_RUNSTRING $SCWRYPT_NAME $SCWRYPT_TYPE $SCWRYPT_GROUP)
[ ! $RUN_STRING ] && exit 3
##########################################
local LOGFILE=$(__GET_LOGFILE)
local HEADER=$(
2023-12-12 00:07:09 +00:00
[[ $VERBOSE -gt 0 ]] || return 0
[ $SUBSCWRYPT ] && return 0
echo '====================================================================='
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
echo "script : $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME"
echo "run at : $(date)"
echo "config : $ENV_NAME"
[ ! $LOGFILE ] && echo '\033[1;33m------------------------------------------\033[0m'
)
[ ! $LOGFILE ] && {
[ $HEADER ] && echo $HEADER
[ $SUBSCWRYPT ] && {
eval "$RUN_STRING $(printf "%q " "$@")"
exit $?
} || {
eval "$RUN_STRING $(printf "%q " "$@")" </dev/tty >/dev/tty 2>&1
exit $?
}
}
{
[ $HEADER ] && echo $HEADER
2023-12-12 00:07:09 +00:00
[[ $VERBOSE -gt 0 ]] && echo '\033[1;33m--- BEGIN OUTPUT -------------------------\033[0m'
(eval "$RUN_STRING $(printf "%q " "$@")")
EXIT_CODE=$?
2023-12-12 00:07:09 +00:00
[[ $VERBOSE -gt 0 ]] && echo '\033[1;33m--- END OUTPUT ---------------------------\033[0m'
[[ $EXIT_CODE -eq 0 ]] && EXIT_COLOR='32m' || EXIT_COLOR='31m'
2023-12-12 00:07:09 +00:00
[[ $VERBOSE -gt 0 ]] && echo "terminated with\\033[1;$EXIT_COLOR code $EXIT_CODE\\033[0m"
} 2>&1 | tee --append "$LOGFILE"
exit $(\
sed -n 's/^terminated with.*code \([0-9]*\).*$/\1/p' $LOGFILE \
| tail -n1
)
}
#####################################################################
__CHECK_ENV_REQUIRED() {
[ $CI ] && return 1
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
echo $SCWRYPT_NAME | grep -q 'scwrypts/logs/' && return 1
echo $SCWRYPT_NAME | grep -q 'scwrypts/environment/' && return 1
return 0
}
__VALIDATE_UPSTREAM_TIMELINE() {
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
STATUS "on '$ENV_NAME'; checking diff against origin/main"
git fetch --quiet origin main
local SYNC_STATUS=$?
git diff --exit-code origin/main -- . >&2
local DIFF_STATUS=$?
[[ $SYNC_STATUS -eq 0 ]] && [[ $DIFF_STATUS -eq 0 ]] && {
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
SUCCESS 'up-to-date with origin/main'
} || {
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
WARNING
[[ $SYNC_STATUS -ne 0 ]] && WARNING 'unable to synchronize with origin/main'
[[ $DIFF_STATUS -ne 0 ]] && WARNING 'your branch differs from origin/main (diff listed above)'
WARNING
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
yN 'continue?' || return 1
}
}
__GET_LOGFILE() {
2023-12-12 00:07:09 +00:00
[ $SUBSCWRYPT ] && return 0
[[ $SCWRYPT_NAME =~ scwrypts/logs ]] && return 0
[[ $SCWRYPT_NAME =~ interactive ]] && return 0
v3.0.0 "The Great Overhaul" ===================================================================== Notice the major version change which comes with breaking changes to 2.x! Reconstructs "library" functions for both python and zsh scwrypts, with changes to virtualenv naming conventions (you'll need to refresh all virtualenv with the appropriate scwrypt). --- Changes ------------------------------ - changed a naming convention across zsh scripts, particularly removing underscores where there is no need to avoid naming clash (e.g. 'zsh/lib/utils/io.zsh' renames '__STATUS' to 'STATUS') - moved clients reliant on py.lib.http to the py.lib.http module - python scripts now rely on py.lib.scwrypts.execute - updated package.json in zx scripts to include `type = module` - 'scwrypts --list' commandline argument now includes additional relevant data for each scwrypt - environment variables no longer add themselves to be staged in the '.env.template' --- New Features ------------------------- - new 'use' syntax for disjoint import within zsh scripts; took me a very long time to convince myself this would be necessary - introduced scwrypt "groups" to allow portable module creation; (i.e. ability add your own scripts from another repo!) - py.lib.scwrypts.io provides a combined IO stream for quick, hybrid use of input/output files and stdin/stdout - py.lib.fzf provides a wrapper to provide similar functionality to zsh/utils/io.zsh including fzf_(head|tail) - improved efficiency of various scwrypts; notably reducing runtime of scwrypts/environment sync - improved scwrypts CLI by adding new options for exact scwrypt matching, better filtering, and prettier/more-detailed interfaces --- New Scripts -------------------------- - py/twilio ) basic SMS integration with twilio - send-sms - py/directus ) interactive directus GET query - get-items - py/discord ) post message to discord channel or webhook - post-message
2023-02-22 01:44:27 +00:00
echo "$SCWRYPTS_LOG_PATH/$(echo $GROUP/$TYPE/$NAME | sed 's/^\.\///; s/\//\%/g').log"
}
#####################################################################
__RUN $@