Skip to content

Instantly share code, notes, and snippets.

@UnixSage
UnixSage / CertBotNearlyFreeSpeechAuthHook.sh
Last active March 16, 2024 15:04
Drop in script for CertBot's --manual-auth-hook switch for DNS Hosted at NearlyFreeSpeech.com
#!/bin/bash
API_KEY="##NFS-API-KEY##"
LOGIN="##NFS-USER##"
updatedns() {
OLDDATA=`dig @${NAMESERVER} -t txt +noall +answer ${DNSRECORD}.${CERTBOT_DOMAIN} | awk '{gsub("\"",""); print $5}'`
for FUNCTION in removeRR addRR ; do
echo "Running ${FUNCTION}"
@UnixSage
UnixSage / GetBitBucketRepos.sh
Last active January 22, 2024 17:13
Simple Script to get a list of BitBucket repos for a given team
#!/bin/bash
USER="##USER_NAME_NOT_EMAIL##"
SECRET="##SECRET##"
TEAM="##TEAMNAME##"
CACHE="/tmp/repolist.$$"
REPOFILE="/tmp/repolist.txt"
URL="https://api.bitbucket.org/2.0/repositories/${TEAM}?pagelen=100"
@UnixSage
UnixSage / CertBotGoDaddyAuthHook.sh
Last active May 20, 2023 14:27
Script to use with CertBot's --manual-auth-hook switch
#!/bin/bash
KEY="GoDaddyAuthKey"
SECRET="GoDaddySecret"
APISITE="api.godaddy.com"
BASEDOMAIN=`echo ${CERTBOT_DOMAIN} | awk -F. '{OFS="."; print $(NF-1),$(NF)}'`
SUBDOMAIN=`echo ${CERTBOT_DOMAIN} | sed -e 's/'${BASEDOMAIN}'//' -e 's/\.$//'`
@UnixSage
UnixSage / ssh-agent.sh
Created September 7, 2022 13:41
Snipit to add to bash_profile that will find an existing ssh-agent or start a new one. Also complains if it finds more than one for a user.
# Attach to a running ssh-agent or start a new one
if [ `find /tmp -maxdepth 1 -name "ssh-*" -user ${USER} | wc -l` == 1 ] ; then
echo "Found ssh-agent, attaching.."
SSHDIR=`find /tmp -maxdepth 1 -name "ssh-*" -user ${USER}`
SSH_AUTH_SOCK=`ls ${SSHDIR}/agent*` ; export SSH_AUTH_SOCK
SSH_AGENT_PID=`echo ${SSH_AUTH_SOCK} | awk -F"." '{print $2+1}'` ; export SSH_AGENT_PID
echo "Agent pid ${SSH_AGENT_PID}"
elif [ `find /tmp -maxdepth 1 -name "ssh-*" -user ${USER} | wc -l` == 0 ] ; then
echo "no ssh-agent found, starting.."
eval `ssh-agent -t 86400`
@UnixSage
UnixSage / CertBotManualAuthHook.sh
Last active January 28, 2022 22:58
Manual Script for CertBot for manual DNS Changes...
#!/bin/sh
echo "Domain: _acme-challenge.${CERTBOT_DOMAIN}" > /tmp/Manual.log
echo "Secret: ${CERTBOT_VALIDATION}" >> /tmp/Manual.log
echo "Looking for /tmp/done.$$" >> /tmp/Manual.log
while [ ! -f /tmp/done.$$ ]
do
sleep 2
@UnixSage
UnixSage / selectiveDump.sh
Created July 30, 2021 14:27
Shell script that calls dump with an exclude list
#!/bin/sh
if [ $# = 2 ] ; then
NODENAME=$1
LEVEL=$2
elif [ $# = 1 ] ; then
NODENAME=$HOSTNAME
LEVEL=$1
else
NODENAME=$HOSTNAME
@UnixSage
UnixSage / PurgeOrphanedPacker.py
Created April 15, 2021 21:03
AWS Lambda function that will stop and eventually terminate instances that have packer keys attached to them .
#!/usr/bin/env python3
import datetime
import pytz
import boto3
def lambda_handler(event, context):
TerminateDelayDays = 3
StopDelayDays = 1
@UnixSage
UnixSage / send2s3.sh
Last active March 5, 2021 01:58
Simple shell script that uses curl to send a file to s3. Useful when you do not want to load the awscli for a simple job. May have to adjust mime types according to need.
#!/bin/sh
if [ $# -ne 1 ] ; then
echo "Need File Name"
exit
fi
s3AccessKey="##ACCESS##"
s3SecretKey="##SECRET##"
s3Bucket="data.example.com"
@UnixSage
UnixSage / genpass.py
Last active March 3, 2021 20:23
SysAdmin Password Tool
#!/usr/bin/env python3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@UnixSage
UnixSage / RotateAwsCreds.py
Created March 2, 2021 19:33
Handy of you have multiple aws accounts, utility that interrogates your aws config and generates aws-vault command lines and passwords to facilitate secret rotation.
#!/usr/bin/env python3
import configparser
import re
import string
from random import choice
from os.path import expanduser
PasswordLength = 32
SpecialCount = 4