Skip to content

Instantly share code, notes, and snippets.

View josh-padnick's full-sized avatar

Josh Padnick josh-padnick

View GitHub Profile
@josh-padnick
josh-padnick / fish-agent.sh
Last active April 1, 2024 06:28
Run ssh-agent via fish shell
#!/bin/bash
#
# Convert ssh-agent output to fish shell
#
eval "$(ssh-agent)" >/dev/null
echo "set SSH_AUTH_SOCK \"$SSH_AUTH_SOCK\"; export SSH_AUTH_SOCK"
echo "set SSH_AGENT_PID \"$SSH_AGENT_PID\"; export SSH_AGENT_PID"
@josh-padnick
josh-padnick / README.md
Last active March 16, 2024 15:19
Manually Edit AWS Console "Switch Role" Configuration in Bash

Manually Edit AWS Console "Switch Role" Configuration in Bash

Motivation

At Gruntwork, we work with multiple software teams. That means we have to modify the "Switch Role" history multiple times. But the only way to do that today is to delete your cookie and clear all AWS Console saved settings. That got old after a while, so these instructions enable you to modify the "Switch Roles" configuration directly.

The Big Picture

@josh-padnick
josh-padnick / download.sh
Last active July 21, 2023 11:45
Download a private binary release file from GitHub in bash
#!/usr/bin/env bash
#
# This is an adaptation of code I wrote to download a private binary from GitHub. Such...pain.
# Why can't GitHub just offer a standardized URL you can download a release binary from and attach
# your Github Personal Access Token as a header?
#
# Since this code is an adaptation it hasn't been directly tested, but the code it was adapted from works
# and hopefully you can get the missing piece you're after by looking here.
#
@josh-padnick
josh-padnick / Dockerfile
Created February 17, 2015 02:07
Dockerfile Example
# MINIMAL DOCKER IMAGE FOR RUNNING A MICROSERVICE
FROM ohmygoshjosh/busybox
MAINTAINER Josh Padnick <josh@tinysteps.co>
# MICROSERVICE ENV VARS
# ------------------------------------------------------------------------------
ENV MICROSERVICE_NAME lemon
#!/bin/bash
#
# If there's a new Terraform releases available, delete the current Terraform install and download the new one.
# Must be run from within the directory where terraform binaries should reside
#
LATEST_RELEASE=$(curl https://api.github.com/repos/hashicorp/terraform/releases/latest | jq --raw-output '.tag_name' | cut -c 2-)
if [[ ! -e ${LATEST_RELEASE} ]]; then
echo "Installing Terraform ${LATEST_RELEASE}..."
rm terraform-*
@josh-padnick
josh-padnick / crontab file
Last active June 15, 2022 04:48
Create EC2 AMI from Bash Script; Good for cron jobs
PATH=/bin:/usr/local/bin
# Put this in your crontab file to run the script every day at 01:30 (1:30am). Note the PATH variable above; required for this script.
# m h dom mon dow command
30 01 * * * /bin/bash /home/ubuntu/scripts/ec2-create-image.sh i-8a915682 >> /home/ubuntu/logs/crontab.log 2>&1
@josh-padnick
josh-padnick / get-latest-terraform.sh
Created March 28, 2016 21:50
Auto-update to latest version of Terraform
#!/bin/bash
LATEST_RELEASE=$(curl https://api.github.com/repos/hashicorp/terraform/releases/latest | jq --raw-output '.tag_name' | cut -c 2-)
if [[ ! -e ${LATEST_RELEASE} ]]; then
echo "Installing Terraform ${LATEST_RELEASE}..."
rm terraform-*
rm terraform
wget https://releases.hashicorp.com/terraform/${LATEST_RELEASE}/terraform_${LATEST_RELEASE}_linux_amd64.zip
unzip terraform_${LATEST_RELEASE}_linux_amd64.zip
rm terraform_${LATEST_RELEASE}_linux_amd64.zip
@josh-padnick
josh-padnick / tf-bar.tf
Last active December 15, 2021 17:55
Hack for Terraform Module depends_on
# This file would need to be in its own folder like /tf-bar/main.tf
variable "bar" {
default = "foo"
}
resource "null_resource" "bar" {
triggers {
bar = "${var.bar}"
}
@josh-padnick
josh-padnick / render.js
Created May 7, 2021 18:24
Render images served from localhost in gmail
// Run this in your Chrome WebDev Tools console
// Based on https://stackoverflow.com/questions/20836911/images-not-displayed-for-gmail#comment114947075_20837071
(function(){ while(img = document.evaluate('//img[contains(@src, \'googleusercontent.com\')][contains(@src, \'#\')]', document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){ var src = img.attributes.src.value; src = src.substr(src.indexOf('#')+1); img.attributes.src.value = src; } })();
// NOTE: I have NOT validated this gist as pasted above, though I have validated it manually (or some variant of it before)
@josh-padnick
josh-padnick / gist:a0ae497d19508c9512018d8b2c9e17d8
Last active November 21, 2018 06:42
module-server log output
=== RUN TestOsHardeningXFS
TestOsHardeningXFS 2018-11-21T06:02:13Z region.go:72: Looking up all AWS regions available in this account
TestOsHardeningXFS 2018-11-21T06:02:15Z region.go:57: Using region ap-northeast-2
TestOsHardeningXFS 2018-11-21T06:02:15Z key_pair.go:31: Generating new public/private key of size 2048
TestOsHardeningXFS 2018-11-21T06:02:20Z keypair.go:49: Creating new Key Pair in EC2 region ap-northeast-2 named AAsSgo
TestOsHardeningXFS 2018-11-21T06:03:08Z command.go:52: Running command ./packer-build.sh with args [-var ami_module_security_version_type="branch" -var vpc_id="vpc-32e3025b" -var should_create_keypair="0" -var aws_region="ap-northeast-2" -var ami_builder_source_ami="ami-0076ae0908f382581" -var ami_builder_source_ami_ssh_username="ec2-user" -var ami_ebs_volume_size="25" -var ami_github_oauth_token="<REDACTED>" -var ami_partition_fs_type="xfs" -var ami_module_security_version="master" -var ami_builder_keypair_private_key="-----BEGIN RSA PRIVATE KEY-----\nREDACTED\n-----END RSA PR