Skip to content

Instantly share code, notes, and snippets.

@kntyskw
kntyskw / install_registry_image.sh
Last active August 29, 2015 14:01
Downloads docker registry container image archive from the bucket specified by environment variable DOCKER_REGISTRY_BUCKET and import it to docker.
#!/bin/sh
# Check if the registry image is already installed
IS_INSTALLED=`docker images | grep -E 'registry\s*latest' | wc -l`
if [ $IS_INSTALLED == 0 ]; then
. /opt/elasticbeanstalk/hooks/common.sh
# Load ElasticBeanstalk environment variables
touch /tmp/env.sh
@kntyskw
kntyskw / gist:40d144e47ed0067e125b
Created December 13, 2015 17:29
UPnP-MQTT Gateway connecting via SORACOM Beam to AWS IoT
var ssdp = require('node-upnp-ssdp');
var UPnPDeviceClient = require('upnp-device-client');
var mqtt = require('mqtt');
var clientId = 'kenta-upnp-gateway';
var mqttOptions = { clientId: clientId };
var mqttEndpoint = 'mqtt://beam.soracom.io';
var mqttClient = mqtt.connect(mqttEndpoint, mqttOptions);
$ npm install node-upnp-ssdp upnp-device-client
@kntyskw
kntyskw / gist:5394696
Created April 16, 2013 09:42
Add a routing table and iptables rule to route specified packets via LVS
#!/bin/sh
LVS_IP=172.31.24.1
TABLE=1
ip route flush table $TABLE
ip route show | grep -Ev ^default | while read ROUTE; do
ip route add table $TABLE $ROUTE
done
ip route add table $TABLE default via $LVS_IP
ip rule del from all fwmark 1
@kntyskw
kntyskw / assign_EIPs.rb
Last active December 20, 2015 22:58
Assign EIPs given from the standard input to ENIs assigned to the instance
#!/bin/env ruby
require 'rubygems'
require 'aws-sdk'
@ec2 = AWS::EC2.new({:region => ENV['AWS_DEFAULT_REGION']})
@eips_to_assign = ARGV # [EIP1 EIP2 EIP3 EIP4 ...]
DEBUG=false
def self.main
@kntyskw
kntyskw / start_docker_registry_on_eb.sh
Last active January 3, 2016 13:40
Starts private docker repository backed by S3 on ElasticBeanstalk environment. It is supposed to launch before the application container is launched so that the application container image can be pulled from the local private repository.
#!/bin/bash
. /opt/elasticbeanstalk/hooks/common.sh
# Load ElasticBeanstalk environment variables
touch /tmp/env.sh
chmod 600 /tmp/env.sh
jq .docker.env[] $EB_CONFIG_FILE | tr -d \" > /tmp/env.sh
@kntyskw
kntyskw / App.java
Created June 26, 2018 22:36
DLNA対応TVをSORACOM Inventoryに登録してWebコンソールから操作する ref: https://qiita.com/kntyskw/items/bae6ef159ebd6af5c6e4
import org.fourthline.cling.UpnpService;
import org.fourthline.cling.UpnpServiceImpl;
import org.fourthline.cling.model.message.header.STAllHeader;
import org.yasukawa.inventory.upnp.InventoryUpnpRegistryListener;
import org.yasukawa.inventory.upnp.UpnpController;
public class App {
public static void main(String[] args) throws Exception {
#!/usr/bin/ruby
require 'rubygems'
require 'packetfu'
dev = ARGV[0]
mac=`ip link show #{dev} | awk '/ether/ {print $2}'`
ARGV.shift
dests = ARGV
cap = PacketFu::Capture.new(
@kntyskw
kntyskw / ec2_multicast.sh
Last active June 8, 2021 14:18
Script to enable IP multicast without using Ethernet broadcast. It uses tc mirred and pedit actions to copy and edit an IP multicast packet to send over multiple Ethernet unicast frames. It requires two network interfaces to work. One is the interface to grab original multicast packets from and the other is to send out modified packets. This is …
#!/bin/sh
[[ -n "$1" && -n "$2" ]] || { echo "Usage: $0 <interface to grab multicast packets from> <interface to send modified packets to> [target MAC address 1] [target MAC address 2] ..."; exit 0 ; }
IIF=$1
OIF=$2
shift
shift
SRC_MACADDR=`ip link show $OIF | awk '/ether/ {print $2}' | tr -d :`
#!/bin/sh
VIP=$1
IF=$2
# Determine the interface's MAC address
MAC=`ip link show $IF | awk '/ether/ {print $2}'`
# Determine ENI ID of the interface
ENI_ID=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/interface-id`