Skip to content

Instantly share code, notes, and snippets.

View cpswan's full-sized avatar
🏡

Chris Swan cpswan

🏡
View GitHub Profile
@cpswan
cpswan / trusty-kernel.sh
Created June 2, 2014 09:48
Trusty kernel on 12.04
sudo apt-get install -y linux-image-generic-lts-trusty linux-headers-generic-lts-trusty

Keybase proof

I hereby claim:

  • I am cpswan on github.
  • I am cpswan (https://keybase.io/cpswan) on keybase.
  • I have a public key whose fingerprint is B8F4 CBA3 EE20 D98C A9C0 DF60 9A17 F5CF B083 31FE

To claim this, I am signing this object:

@cpswan
cpswan / fixapt.sh
Created December 11, 2014 16:21
Fix apt on Ubuntu 12.04.5 to prevent hash mismatch errors
#!/bin/bash
sudo cp -arf /var/lib/dpkg /var/lib/dpkg.backup
sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status
sudo cp /var/lib/dpkg/available-old /var/lib/dpkg/available
sudo rm -rf /var/lib/dpkg/updates/*
sudo rm -rf /var/lib/apt/lists
sudo mkdir /var/lib/apt/lists
sudo mkdir /var/lib/apt/lists/partial
sudo apt-get clean
sudo apt-get update
@cpswan
cpswan / snapshot.sh
Created March 18, 2015 13:36
Create and retrieve a snapshot from a VNS3 manager
#!/bin/bash
command -v curl >/dev/null 2>&1 || { echo "This script requires curl, but it's not installed. Aborting." >&2; exit 1; }
MGRIP=10.0.0.10
APIPW=pa55Word
SNAPSHOTJSON=`curl -k -X POST -u api:$APIPW https://$MGRIP:8000/api/snapshots`
SNAPSHOTNAME=$(echo $SNAPSHOTJSON | grep -Po '"response":{.*?[^\\]"' | awk '{split($0,a,"{"); print a[2]}' )
curl -k -X GET -H 'Content-Type: application/json' https://api:$APIPW@$MGRIP:8000/api/snapshots/${SNAPSHOTNAME//\"} -o ${SNAPSHOTNAME//\"}
echo "Created and retrieved $SNAPSHOTNAME"
@cpswan
cpswan / nginx_mod_security.sh
Last active August 29, 2015 14:17
Configure Nginx similarly to Ubuntu setup but with mod_security module added
./configure --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/root/modsecurity-2.9.0/nginx/modsecurity
@cpswan
cpswan / show-ip-address.sh
Created March 21, 2015 18:02
Show IP address prior to login
#!/bin/sh
if [ "$METHOD" = loopback ]; then
exit 0
fi
# Only run from ifup.
if [ "$MODE" != start ]; then
exit 0
fi
@cpswan
cpswan / .bash_aliases
Last active August 29, 2015 14:17
Bash aliases for Docker
alias ds='sudo docker start'
alias dt='sudo docker stop'
alias dps='sudo docker ps'
alias da='sudo docker attach'
alias di='sudo docker inspect'
@cpswan
cpswan / vns3.sh
Last active August 29, 2015 14:19
Launch and configure VNS3 from a single script
#!/bin/bash
VNS3_AMI=ami-ea084f82
VNS3_TYPE=t2.small
VNS3_SUBNET=subnet-b123b456
VNS3_GROUP=sg-ea123456
VNS3_NAME=myVNS3
VNS3_PW=pa55Word
VNS3_LIC=license.gpg
VNS3_TK=MyS3cret
@cpswan
cpswan / upgrade-docker.sh
Last active August 29, 2015 14:23
Upgrade Docker and restart running containers
#!/bin/bash
datenow=$(date +%s)
sudo docker ps > /tmp/docker."$datenow"
sudo apt-get update && sudo apt-get install -y lxc-docker
sudo docker start $(tail -n +2 /tmp/docker."$datenow" | cut -c1-12)
@cpswan
cpswan / linkit.sh
Last active October 17, 2015 11:28
Attempt to create symlinks for best quality music from mix of wav and mp3
while read -u 3 outerdir
do
cd "${outerdir}"
ls -1 ../../wav/"${outerdir}" > list
while read -u 4 innerdir
do
ln -s ../../wav/"${outerdir}"/"${innerdir}" "${innerdir}"
done 4< list
done 3< test