Skip to content

Instantly share code, notes, and snippets.

View rcj4747's full-sized avatar

Robert Jennings rcj4747

View GitHub Profile
@rcj4747
rcj4747 / multiple_github.txt
Created March 24, 2016 15:58
[TIP] manage multiple github accounts
From: http://everythingsysadmin.com/2016/03/two-github-accounts.html
Someone recently commented that with Github it is "a pain if you want to have a work and personal identity."
It is? I've had separate work and personal Github accounts for years. I thought everyone knew this trick.
When I clone a URL like git@github.com:TomOnTime/tomutils.git I simply change github to either github-home or github-work. Then I have my ~/.ssh/config file set with those two names configured to use different keys:
# TomOnTime
Host home-github.com
HostName github.com
#!/bin/bash -e
## Launch the latest daily Ubuntu in AWS, optionally with user-data
## provided in a file and tagged with a name
function usage() {
echo "$0: [-r region] [-V ubuntu_version] [-i instance_type] \\"
echo " [-u user_data_file] [-n instance_name] [-d disk_size] \\"
echo " [-D] to disable termination via the API"
echo " [-I] iam instance profile [-a AMI ID]"
echo " [-P profile] aws cli profile"
@rcj4747
rcj4747 / change_cloudinit_datasource.sh
Last active January 1, 2024 10:16
An example of changing the datasource in cloud-init
# Get the Ubuntu cloud image of your choosing (this example uses the latest Xenial daily)
wget http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
# Set the cloud-init datasource to use explicitly (this example uses the EC2 datasource)
sudo mount-image-callback xenial-server-cloudimg-amd64-disk1.img -- \
sh -c 'echo "datasource: Ec2" > $MOUNTPOINT/etc/cloud/ds-identify.cfg'
# Confirm the current datasource configuration
sudo mount-image-callback xenial-server-cloudimg-amd64-disk1.img -- \
chroot _MOUNTPOINT_ cat /etc/cloud/ds-identify.cfg
@rcj4747
rcj4747 / aws_pricing.py
Created February 10, 2017 20:58
Here is a log (from ipython) from toying with the pricing API for Amazon EC2. Not sure that this is still supported. I played around exploring the data with the intent of using this to derive a list of supported instance types per region. That information is contained within and is quite rich; instance types have properties reflecting features s…
# log from ipython as I played with the pricing api
#index.json from https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json
# Per http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html#download-the-offer-index
# But this may no longer be supported as it (EC2) is not part of the parent index of all services any longer
import json
with open('index.json', 'r') as foo:
data = json.read(foo)
with open('index.json', 'r') as foo:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rcj4747
rcj4747 / aws_killer.sh
Last active November 5, 2020 19:03
Kill AWS instances (run daily from cron)
#!/bin/bash
PATH=$PATH:/snap/bin
EC2KILL_PROFILE=${EC2KILL_PROFILE:-workpersonal}
PROFILE=${EC2KILL_PROFILE:+--profile $EC2KILL_PROFILE}
NOKILL=~/ec2nokill
notify-send --urgency=critical --expire-time 5000 --icon=system-restart \
"EC2" \
"About to kill EC2 instances, touch ${NOKILL} to prevent this."
#!/bin/bash
cat <<EOF > meta-data
instance-id: iid-local01
local-hostname: cloudimg
EOF
cat <<EOF > user-data
#cloud-config
ssh_import_id: [ yourlaunchpadid ]
@rcj4747
rcj4747 / aws_7d_s3_lifecycle.sh
Created November 9, 2017 15:51
AWS Bucket Lifecycle for AMI testing (delete after 7 days)
#!/bin/sh
cat > lifecycle.json <<EOF
{
"Rules": [
{
"Expiration": {
"Days": 7
},
"ID": "Expire, delete, and cancel",
@rcj4747
rcj4747 / gist:53aff2a2f00a8328d28f5829bca1ec61
Last active January 12, 2018 22:25 — forked from tsellers-r7/gist:002b75391a3384326587714561ed8820
Searching Amazon AMIs for the latest images for Ubuntu 16.04
# HVM EBS-SSD
aws ec2 describe-regions --output text --query 'Regions[*].[RegionName]' --region us-east-1 | while read region; do echo -e "$region "; aws --region $region ec2 describe-images --owners 099720109477 --filters Name=root-device-type,Values=ebs Name=architecture,Values=x86_64 Name=name,Values='*hvm-ssd/ubuntu-xenial-16.04*' --query 'sort_by(Images, &Name)[-1].ImageLocation'; done;
# HVM Instance-store
aws ec2 describe-regions --output text --query 'Regions[*].[RegionName]' --region us-east-1 | while read region; do echo -e "$region "; aws --region $region ec2 describe-images --owners 099720109477 --filters Name=root-device-type,Values=instance-store Name=architecture,Values=x86_64 Name=name,Values='*hvm-instance/ubuntu-xenial-16.04*' --query 'sort_by(Images, &Name)[-1].ImageLocation'; done;
# PV EBS-SSD
aws ec2 describe-regions --output text --query 'Regions[*].[RegionName]' --region us-east-1 | while read region; do echo -e "$region "; aws --region $region ec2 describe-images --owners 0997201094
@rcj4747
rcj4747 / private_ppa_addition.sh
Created January 26, 2018 21:43
Add a package from a private PPA to a chroot and strip references to the private PPA
REPO_LINE="deb https://${LP_USER}:${PPA_PASSWORD}@${PRIVATE_PPA_URL} ${SUITE} main"
REPO_KEY_FINGERPRINT=832749327429CADB77842973ED72947203471037
# Add the private ppa to the system
env DEBIAN_FRONTEND=noninteractive chroot "${MOUNTPOINT}" apt-add-repository "${REPO_LINE}"
env DEBIAN_FRONTEND=noninteractive chroot "${MOUNTPOINT}" apt-key adv --keyserver keyserver.ubuntu.com --recv ${REPO_KEY_FINGERPRINT}
env DEBIAN_FRONTEND=noninteractive chroot "${MOUNTPOINT}" apt-get update
# Install from private PPA HERE
env DEBIAN_FRONTEND=noninteractive chroot "${MOUNTPOINT}" apt-get install -qqy awesome_package_but_super_secret