Skip to content

Instantly share code, notes, and snippets.

@dstrctrng
dstrctrng / gist:5314483
Created April 4, 2013 21:22
Mirror Ubuntu packages installed on the local system
#!/bin/bash
mkdir -p ubuntu/{dists,pool}
meh=$(
rsync -iaO --exclude ubuntu --exclude pool --exclude dists rsync://archive.ubuntu.com/ubuntu/. ubuntu/
for a in dists/{lucid,precise}{,-{backports,security,updates}}; do
rsync -iaO --exclude 'installer-*' rsync://archive.ubuntu.com/ubuntu/$a/. ubuntu/$a/
done
@dstrctrng
dstrctrng / gist:5315149
Last active December 15, 2015 19:59
Running a docker with runsvdir, ssh in, then destroy it
function d {
did=$(docker run -d precise runsvdir /etc/service)
ip=$(docker inspect $did | grep IpAddress | cut -d'"' -f4)
nc -z $ip 22 && ssh -oStrictHostKeyChecking=no root@$ip
docker kill $did
}
cat ec2din.txt | \
perl -pe ' \
s{us-east-\S+}{us-east-xx}g;
s{i-[0-9a-f]{8}}{i-xxxxxxxx}g;
s{vol-[0-9a-f]{8}}{vol-xxxxxxxx}g;
s{\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\dZ}{dddd-dd-ddTdd:dd:dd.dddZ}g;
s{(arn:aws:cloudformation):\S+}{$1:xxxxxx}g;
s{/dev/sd\S+}{/dev/sdxxx}g;;
s{(\w)-[0-9a-f]{8}(,?)}{$1-xxxxxxxx$2}g;
s{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-fx]{12}_\S+}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_xxxx}g;
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["",[
"#!/bin/bash -ex","\n",
"yum -y install gcc-c++ make","\n",
"yum -y install mysql-devel sqlite-devel","\n",
Bringing machine 'default' up with 'docker' provider...
[default] Launching an instance with the following settings...
[default] -- Image: 9014505bebb4
[default] Waiting for instance to become "ready"...
[default] Waiting for SSH to become available...
[default] Machine is booted and ready for use!
env BOX=precise-base vagrant ssh -- -A
Welcome to Ubuntu 12.04.3 LTS (GNU/Linux 3.8.0-30-generic x86_64)
* Documentation: https://help.ubuntu.com/
> ssh bastion
root@8cb2ee8bb517:/# ps axuf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.3 0.0 18156 2072 ? S 23:03 0:00 bash
root 10 0.0 0.0 15280 1056 ? R+ 23:03 0:00 ps axuf
root@8cb2ee8bb517:/# exit
> ssh bastion
root@adf50ae964a3:/# ps axuf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
> ssh bastion
root@8cb2ee8bb517:/# ps axuf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.3 0.0 18156 2072 ? S 23:03 0:00 bash
root 10 0.0 0.0 15280 1056 ? R+ 23:03 0:00 ps axuf
root@8cb2ee8bb517:/# exit
> ssh bastion
root@adf50ae964a3:/# ps axuf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
curl http://curl.haxx.se/ca/cacert.pem | while read -r a; do
[[ "$a" = "-----BEGIN CERTIFICATE-----" ]] && { echo "$a" > cert; continue; }
[[ "$a" = "-----END CERTIFICATE-----" ]] && { echo "$a" >> cert; mv cert $(openssl x509 -hash -noout -in cert).0; }
[[ -f cert ]] && echo "$a" >> cert
done
@dstrctrng
dstrctrng / gpkg.sh
Last active December 26, 2015 02:09
Gist as version control, packaging for simple scripts.
#!/usr/bin/env bash
#/ NAME
#/ gpkg -- manages gist packages
#/
#/ SYNOPSIS
#/ gpkg install [gist_id | archive]
#/ gpkg update [gist_id | archive]
#/ gpkg package [gist_id]
#/ gpkg exec [name]
have_func: checking for rb_str_set_len() in ruby.h... -------------------- no
"gcc -o conftest -I../../.ext/include/x86_64-linux -I../.././include -I../.././ext/openssl -I/opt/br/br-admin/pkg/include/db4 -I/usr/include -I/opt/br/br-admin/pkg/include -I/opt/br/br-admin/pkg/include/db4 -I/usr/include -I/opt/br/br-admin/pkg/include -O2 -Wno-error -pthread -I/opt/br/br-admin/pkg/include/db4 -I/usr/include -I/opt/br/br-admin/pkg/include -fPIC conftest.c -L. -L../.. -L. -L/opt/br/br-admin/pkg/lib -Wl,-R/opt/br/br-admin/pkg/lib -pthread -rdynamic -Wl,-export-dynamic -L/usr/lib64 -lssl -lcrypto -Wl,-R -Wl,/opt/br/br-admin/pkg/lib -L/opt/br/br-admin/pkg/lib -lruby193-static -lssl -lcrypto -lpthread -lrt -ldl -lcrypt -lm -lpthread -lrt -lc"
../../libruby193-static.a(string.o): In function `rb_str_crypt':
string.c:(.text+0xa510): undefined reference to `crypt'
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: