Skip to content

Instantly share code, notes, and snippets.

View srinivasmohan's full-sized avatar

Srinivasan Mohan srinivasmohan

View GitHub Profile
@srinivasmohan
srinivasmohan / shellsock2.sh
Created September 25, 2014 22:52
shellsock2.sh
#!/bin/dash
export DEBDIR="/tmp/bashdebs"
[ -d $DEBDIR ] && rm -fr $DEBDIR
rm -f /tmp/bashdebs.tgz
cd /tmp/ && wget --quiet http://s3.amazonaws.com/com.versal.sysops/shellsock/bashdebs.tgz && tar zxvf bashdebs.tgz
cd $DEBDIR && sudo /usr/bin/dpkg -i *.deb 2>&1 1>/dev/null
#Test after update
bashver=`/usr/bin/dpkg -l bash | tail -1 | awk '{print $3}'`
echo "Host `hostname`, post update, with Bash $bashver"
rm -f echo && env -i X='() { (a)=>\' bash -c 'echo id'; cat echo
@srinivasmohan
srinivasmohan / shellsock.sh
Created September 25, 2014 20:01
shellsock.sh
#!/bin/sh
#Patch bash for CVE-2014-6271 - For non-lts distro versions.
mkdir -p /usr/local/src && cd /usr/local/src
wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
tar zxvf bash-4.3.tar.gz
#Get patches
for i in $(seq -f "%03g" 0 25); do wget http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-$i; done
cd bash-4.3
for i in $(seq -f "%03g" 0 25);do patch -p0 < ../bash43-$i; done
./configure && make && make install
@srinivasmohan
srinivasmohan / thumbnail.rb
Created September 4, 2014 19:12
ffmpeg screenshots
#!/usr/bin/ruby
require "streamio-ffmpeg"
class Video
def initialize(f="", outf="./", at=[20, 50, 80])
@video=FFMPEG::Movie.new(f)
@at=at.map { |x| (@video.duration*x/100).to_i}
$stderr.puts "Video #{f} (#{@video.duration} secs) - Screenshots at #{@at.inspect}"
@outf=outf
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@srinivasmohan
srinivasmohan / versal-ubuntu1204lts.sh
Created October 10, 2013 00:02
Prebuild chef ready AMI
#!/bin/bash
#Run this on AMI ami-7e2da54e in us-west-2 (Supply this script as userdata) and build an AMI from the resulting instance.
#VPC Bootstrap User-data script generated at 2013-10-09 16:56:44 -0700
function logmsg {
echo "CHEF-VPC-INIT: $1"
}
CHEF_VERSION=11.6.0
RUBY_GEM_VER=1.8.25
@srinivasmohan
srinivasmohan / uri-encode
Created August 2, 2013 20:18
Add to unsafe characters to force them to be encoded - Ruby 1.9.x URI.
[smohan@dhcpa-111 ~]$ irb
irb(main):001:0> require 'uri'
=> true
irb(main):002:0> p URI::Parser.new.regexp[:UNSAFE]
/[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]/
=> /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]/
irb(main):003:0> p Regexp.union([URI::Parser.new.regexp[:UNSAFE],'~','@'])
/(?-mix:[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]])|~|@/
=> /(?-mix:[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]])|~|@/
irb(main):004:0>
@srinivasmohan
srinivasmohan / awscreds_from_databag.rb
Created May 30, 2013 11:48
Pull config info for a script from a chef data bag (So your script runs via "knife exec" without embedding config info in it)
#This is meant to be run via "knife exec scriptname.rb"
#
require 'fog'
#Make sure you have a data bag called admin/ec2creds containing values 'aws_access_key_id' and 'aws_secret_access_key'
#which point to your AWS access key and secret access key.
DBAG_NAME='admin'
DBAG_KEY='ec2creds'
#Pull AWS credentials from the databag 'admin' with key 'ec2creds'
aws=Chef::DataBagItem.load(DBAG_NAME,DBAG_KEY)
@srinivasmohan
srinivasmohan / hosts.erb
Created December 17, 2012 21:09
Hosts.erb template for updhosts.rb
#Last updated <%= Time.now.to_s %> by '<%= $0.split('/')[-1] %> <%= ARGV[0] %> <%= ARGV[1] %>'
127.0.0.1 localhost
<%= myip_ohai %> my_mgmt_host
#Static entries...
#...
#...
#The following are chef managed instances whose IPs are pulled from knife exec runs.
##All of the below are generated from template entry in /etc/hosts.erb
<% %w{server1 server2 server3}.sort.each do |thissvr| %>
@srinivasmohan
srinivasmohan / updhosts.rb
Created December 17, 2012 21:08
Update /etc/hosts based on a template usinf Knife/Chef provided info.
#Rebuild hosts file from knife node list,
require 'erb'
require 'json'
require 'ohai' #to find my own IP
def myaddress
thissys=Ohai::System.new
thissys.all_plugins
myip=thissys['cloud']['private_ips'][0]
return myip
@srinivasmohan
srinivasmohan / deb_via_dpkg_provider.rb
Created September 1, 2012 00:07
Install local deb via Chef::Provide Dpkg
#Cookbook_file section same as before
package 'glusterfs_3.2.1-1_amd64.deb' do
provider Chef::Provider::Package::Dpkg
source "/var/chef-package-cache/glusterfs_3.2.1-1_amd64.deb"
action :install
end