Skip to content

Instantly share code, notes, and snippets.

View Jcpetrucci's full-sized avatar

John C. Petrucci Jcpetrucci

View GitHub Profile
@Jcpetrucci
Jcpetrucci / _.sh
Last active July 31, 2022 01:48
better Bash trace
#!/bin/bash
# Define variables for adjustable verbosity
verbosity=2 #Start counting at 2 so that any increase to this will result in a minimum of file descriptor 3. You should leave this alone.
maxverbosity=5 #The highest verbosity we use / allow to be displayed. Feel free to adjust.
# Parse requested verbosity level and whether we're logging or not
while getopts ":vl" opt; do
case $opt in
v) (( verbosity=verbosity+1 ));;
@Jcpetrucci
Jcpetrucci / acme-nonroot.sh
Last active November 9, 2020 19:43 — forked from Greelan/letsencrypt_notes.sh
Provision certificate via ACME using acme.sh as non-root user
#!/bin/bash
# Run this script once to set up ACME.sh as a non-root user. After this script is done, it can be removed if you want. The script also can be run multiple times safely such that it will not create multiples of anything.
#CFG_ACME_USERNAME='acme' # What do you want to call the user who will fetch certificates?
#CFG_CERT_DOMAIN='tst-server.virtual.example.com' # What fully qualified domain name should the certificate be for?
#CFG_ACME_SERVER='https://acme-v02.api.letsencrypt.org/directory' # What is the ACME server we should get certificates from?
verbosity=2 # Start counting at 2 so that any increase to this will result in a minimum of file descriptor 3. You should leave this alone.
maxverbosity=5 # The highest verbosity we use / allow to be displayed. Feel free to adjust.
while getopts ":vr" opt; do
@Jcpetrucci
Jcpetrucci / dns-response-check.sh
Last active March 8, 2024 17:34
monitor dns response, alert when it changes
#!/bin/bash
declare -A currentAnswer=()
declare -A lastAnswer=()
while getopts ":s" opt; do
case $opt in
s) silent=true ;;
esac
done
shift "$((OPTIND-1))"
query=${1:-"autodiscover.wip.company.com."}
@Jcpetrucci
Jcpetrucci / saml2sts.sh
Created June 14, 2024 19:29
AWS CLI- Exchange SAML for STS
# Drop this function code in your .bashrc, then call `saml2sts` when you want to authenticate.
# This relies on AWS not restricting SAML Assertion re-use. They do not, so let's take advantage.
saml2sts() {
printf ' * %s\n' 'In your browser, authenticate to AWS using SAML.' 'Capture the SAML assertion in base64 format from IdP and copy it to clipboard. Copy the whole b64 encoded payload (NOT THE XML!) from SAML Decoder plugin. Alternatively you can capture the b64 payload with F12 developer tools, which requires no third party browser extensions.'
read -r -e -p 'SAML Assertion in Base64: ' myAssertion
mySts="$(aws sts assume-role-with-saml --output text --role-arn arn:aws:iam::000000000000:role/YourRoleName --principal-arn arn:aws:iam::000000000000:saml-provider/SamlIdpName --saml-assertion \"$myAssertion\" --duration-seconds 28800 --query 'Credentials.[AccessKeyId, SecretAccessKey, SessionToken]')" || return;
while read access secret session; do printf '[default]\naws_access_key_id=%s\naws_secre