Skip to content

Instantly share code, notes, and snippets.

View cam8001's full-sized avatar
💭
lol no

Cameron Tod cam8001

💭
lol no
  • Amazon Web Services
  • Wellington, New Zealand
  • 03:07 (UTC +12:00)
View GitHub Profile
@cam8001
cam8001 / lg-soundbar-network.md
Last active March 21, 2021 07:14
Trying to figure out what a weird device on my network was - turns out it was my FIL's LG soundbar

Trying to figure out what this thing is:

$ nmap -A -T4 -Pn 10.99.98.97 2>/dev/null                                                  

Starting Nmap 7.60 ( https://nmap.org ) at 2020-10-07 16:34 NZDT
Nmap scan report for 10.99.98.97
Host is up (0.0038s latency).
Not shown: 997 filtered ports
PORT      STATE SERVICE         VERSION
8008/tcp  open  http            Google Chromecast httpd
@cam8001
cam8001 / userdata.sh
Created September 30, 2020 21:33
AWS EC2 userdata for Unifi Controller on Ubuntu 16.04. Assumes Correto is installed and Ubiqiuiti repo is added
#!/bin/bash
echo "Updating Unifi..."
systemctl stop unifi
apt update
# Disable interactive prompts for the unifi installer
echo "unifi unifi/has_backup boolean true" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive apt-get install --only-upgrade unifi
# Update the Unifi config for a system using Amazon Corretto instead of OpenJDK
curl https://gist.githubusercontent.com/cam8001/585bc721b25c80e185b83269fdb62e4a/raw/de847624ee14b89814c8c759e2559d7871d6c4ce/correto_unifi.sh > /usr/lib/unifi/bin/unifi.init
@cam8001
cam8001 / filter-iam-roles.sh
Created September 29, 2020 23:57
Filter IAM roles showing trust relationship, conditions, and principal
aws iam list-roles | jq '.Roles | .[] | { role_name: .RoleName, action: .AssumeRolePolicyDocument.Statement | .[] | .Action, principal: .AssumeRolePolicyDocument.Statement | .[] | .Principal, condition: .AssumeRolePolicyDocument.Statement | .[] | .Condition }'
@cam8001
cam8001 / ubuntu-ssm-user-data.sh
Last active September 28, 2020 09:17
Ubuntu 16.04 AMI 20180627 and later user data for SSM session manager
#!/bin/bash
apt update && apt upgrade -y
ln -fs /usr/share/zoneinfo/Pacific/Auckland /etc/localtime
systemctl start snap.amazon-ssm-agent.amazon-ssm-agent.service
systemctl enable snap.amazon-ssm-agent.amazon-ssm-agent.service
@cam8001
cam8001 / init-version-systemd.md
Last active September 19, 2020 00:37
/sbin/init: unrecognized option '--version'

If you get an error in some script or whatever like:

/sbin/init: unrecognized option '--version'

This is probably because:

  • /sbin/init is a symlink to /lib/systemd/systemd
  • systemd supports the --version flag, but not if it is called via a symlink ??

So, if possible, replace calls to /sbin/init with calls to systemd instead. Or something

@cam8001
cam8001 / amazon.url
Created September 9, 2020 23:28
Example .url file, filesystem link which opens in browser
[InternetShortcut]
URL=https://www.amazon.com/
'use strict';
/**
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*/
const AWS = require('aws-sdk');
const url = require('url');
const https = require('https');
@cam8001
cam8001 / acm_arn_regex.ts
Last active May 8, 2020 03:43
Regex to validate an AWS Certificate Manager (ACM) certification ARN
// Standalone utility function for checking whether a certificate ARN is valid.
const isValidCertArn = (arnString: string): boolean => {
return /arn:(aws[a-zA-Z-]*)?:acm:[a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1}:\d{12}:certificate\/[a-zA-Z0-9-_]+/.test(
arnString
);
};
@cam8001
cam8001 / correto_unifi.sh
Last active September 30, 2020 02:26
Corrretto JAVA_HOME on Ubuntu 16.04. Replace /etc/init.d/unifi with this!
#!/bin/bash
#
# /etc/init.d/UniFi -- startup script for Ubiquiti UniFi
#
#
### BEGIN INIT INFO
# Provides: unifi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
@cam8001
cam8001 / ubuntu-allocate-eip-on-launch.sh
Last active March 18, 2020 08:25
EC2 User Data script to allocate an EIP on launch.
#!/bin/bash
#
# Associate a given elastic IP with an instance on boot.
#
# Useful in autoscaling groups with a max-size of 1, where you always want the
# same IP for a given instance.
#
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
AWS_DEFAULT_REGION=ap-southeast-2