Skip to content

Instantly share code, notes, and snippets.

View anapsix's full-sized avatar
😺

Anastas Dancha anapsix

😺
View GitHub Profile
@anapsix
anapsix / export_route53_zone.sh
Created March 5, 2018 12:17
export route53 in BINDish format
#!/bin/bash
case $1 in
--name)
shift
zonename="$1"
hostedzoneid=($(aws route53 list-hosted-zones | jq -r ".HostedZones[] | select(.Name == \"$zonename.\") | .Id" | cut -d'/' -f3))
if [ ${#hostedzoneid[@]} -eq 0 ]; then
echo >&2 "Could not find Route53 zone for \"$zonename\", exiting.."
exit 1
@anapsix
anapsix / check_k8s_certs.sh
Created September 20, 2019 11:06
Check K8s certificates and attempt to renew expired
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
renew_cert() {
local cert="${1:-}"
local renew="n"
if [[ "${cert:-_unset_}" == "_unset_" ]]; then
@anapsix
anapsix / kubectl_with_ssh_jumphost.sh
Last active September 30, 2019 12:09
Wrapper for kubectl to automatically establish SSH connection to jumphost, though which to proxy requests to K8s API
#!/usr/bin/env bash
#
# DEPRECATED
# use k8s-vault instead
# https://gist.github.com/anapsix/b5af204162c866431cd5640aef769610
#
#
# Wrapper for kubectl to establish SSH connection to jumphost,
# though which to proxy requests to K8s API
#
@anapsix
anapsix / kinesis_consumer.php
Created December 15, 2017 17:08
Kinesis Consumer in PHP with AWS SDK
<?php
// if running in Alpine, install the following
// apk -U add php7 php7-mbstring php7-simplexml php7-json php7-phar php7-openssl curl
// curl -sS https://getcomposer.org/installer | php
// php composer.phar require aws/aws-sdk-php
//
// export AWS_ACCESS_KEY_ID=...
// export AWS_SECRET_ACCESS_KEY=...
if (getenv('KINESIS_STREAM')) {
$streamName = getenv('KINESIS_STREAM');
@anapsix
anapsix / generate_firewall_rules.jq
Created May 13, 2020 18:57
Generate Terraform statements for cloudflare_filter, and cloudflare_firewall_rule
##############################################################################
# this JQ script parses Cloudflare API call listing Firewall Rules
# and generates cloudflare_filter_and cloudflare_firewall_rule
##############################################################################
# Copyright (c) 2020 Anastas Dancha (@anapsix)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@anapsix
anapsix / helm_tls_wrapper.sh
Last active October 28, 2020 02:43
Helm CLI wrapper making it easier to work with multiple clusters when using TLS-enabled Tiller
#!/usr/bin/env bash
#
# this script is a helpful wrapper for Helm CLI, when using TLS enabled Tiller
# See https://github.com/helm/helm/blob/master/docs/tiller_ssl.md
#
# === NOTE ===
# It will attempt to download Helm binary to match Helm Server version
# if it's not found locally
#
# === INSTRUCTIONS ===
@anapsix
anapsix / mouse_latlon.py
Last active November 4, 2020 12:45
mouse position on screen in python
#!/usr/bin/env python
# I didn't write this
# many examples exist on StackOverflow, etc..
#
# Note: you'll need python-xlib, python-gtk
# sudo apt-get install python-xlib python-gtk2
#
import sys
import os
@anapsix
anapsix / check_dns.sh
Created April 1, 2018 11:14
Watch for DNS changes and reload NGINX (or do something else)
#!/usr/bin/env bash
#
## example running it from cron
# MAILTO=""
# SHELL=/bin/bash
# VERBOSE=1
# CMD_ON_FAILURE='/etc/init.d/nginx reload'
# * * * * * root timeout -k 2 5 /tmp/check_dns.sh upstream.server.com 2>>/var/log/check_dns.log
# * * * * * root sleep 10 && sed -e :a -e '$q;N;501,$D;ba' -i /var/log/check_dns.log
#
@anapsix
anapsix / rkind.sh
Last active February 23, 2022 18:53
Rancher in KIND (Rancher in Kubernetes-in-Docker)
#!/usr/bin/env bash
#
# RKIND is a naive helper script to start KIND and Rancher Management Server
#
set -u
set -o pipefail
RANCHER_CONTAINER_NAME="rancher-for-kind"
RANCHER_HTTP_HOST_PORT=$[$[RANDOM%9000]+30000]
@anapsix
anapsix / aws_metadata_proxy.md
Created December 13, 2017 16:47
How to proxy EC2 metadata

How to proxy to EC2 Metadata

Sometimes, you need to use your EC2 instance's credentials to access the AWS resources, for testing, development, etc.. This is how you do it.

Step 1

create 169.254.169.254 on loopback interface

linux

sudo ip a add 169.254.169.254 dev lo