diff --git a/bin/avhcd2x264 b/bin/avhcd2x264 new file mode 100644 index 0000000..808b9ab --- /dev/null +++ b/bin/avhcd2x264 @@ -0,0 +1,73 @@ +#!/bin/bash + +# +set -e + +# loglevels: quiet, panic, fatal, error, warning, info, verbose, debug +LOGLEVEL=info + +# set nice level, 20 lowest, -20 highest +NICE="nice -n 19" + +# on pass or two pass encoding +PASSES="2" + +### +### +### + +if ! [ -f "$1" ] +then + echo ""$!" is not a file. Nothing to convert." + exit +fi + +trap cleanup EXIT +cleanup() { + set +e + rm -f "${PASSLOGFILE}-0.log" "${PASSLOGFILE}-0.log.mbtree" "${TEMPFILE}" +} + +# get creation date +TIMESTAMP=$(stat -l -t "%Y-%m-%d %H:%M:%S" "$1" | awk '{ print $6" "$7 }') +# get betrate +BITRATE=$(ffmpeg -i "$1" 2>&1 |grep bitrate | awk '{print $6}') + +# set task priority to low +NICE="nice -n 19" + +EXT="mp4" + +DIRECTORY=$(dirname "$1") +FILENAME=$(basename "$1") +NOW=$(date "+%Y%m%d%-H%M%S") +TEMPFILE="$DIRECTORY/.${FILENAME%.*}_${NOW}_ffmpeg.${EXT}" + +#METADATA="-metadata creation_time=\"$TIMESTAMP\"" + +if [ "$PASSES" == "1" ] +then + # 1 pass encoding + $NICE ffmpeg -i "$1" -threads auto -loglevel "$LOGLEVEL" -vcodec libx264 -b:v "${BITRATE}k" -vf yadif=1 -acodec libfaac -ab 192k -ar 48000 -sn -metadata creation_time="$TIMESTAMP" -f mp4 -y "${TEMPFILE}" +else + # 2 pass encoding + PASSLOGFILE="$DIRECTORY/.${FILENAME%.*}_${NOW}_ffmpeg" + $NICE ffmpeg -i "$1" -threads auto -loglevel "$LOGLEVEL" -vcodec libx264 -b:v "${BITRATE}k" -vf yadif=1 -pass 1 -passlogfile "$PASSLOGFILE" -an -sn -f rawvideo -y /dev/null + $NICE ffmpeg -i "$1" -threads auto -loglevel "$LOGLEVEL" -vcodec libx264 -b:v "${BITRATE}k" -vf yadif=1 -pass 2 -passlogfile "$PASSLOGFILE" -acodec libfaac -ab 192k -ar 48000 -sn -metadata creation_time="$TIMESTAMP" -f mp4 -y "${TEMPFILE}" + rm "${PASSLOGFILE}-0.log" + rm "${PASSLOGFILE}-0.log.mbtree" +fi + +touch -r "$1" "${TEMPFILE}" + +if [ -f "${1%.*}.${EXT}" ] +then + mv -f "${TEMPFILE}" "${1%.*}_${NOW}.${EXT}" + echo + echo "File "${1%.*}.${EXT}" already exist, moved to: "${1%.*}_${NOW}.${EXT}"" + echo +else + mv -i "${TEMPFILE}" "${1%.*}.${EXT}" +fi + +exit diff --git a/bin/backup b/bin/backup new file mode 100755 index 0000000..620062e --- /dev/null +++ b/bin/backup @@ -0,0 +1,14 @@ +#!/bin/bash -e + +if [ -e /Volumes ]; then + SHACHECK="2688057d3ddc1b9b5a5a4309f89a2bcb57cc033b /Volumes/Duplicity/mountcheck" + if ! ( echo "${SHACHECK}" | shasum -cs ); then + echo "/Volumes/Duplicity does not seem to be mounted or wrong volume" + exit 1 + fi +fi + +CMD=${1:-backup} + +exec vault2env /secret/private/duplicity/$(hostname -s) -- \ + duplicity-backup ${CMD} diff --git a/bin/clean-keys b/bin/clean-keys new file mode 100755 index 0000000..ed1fb7b --- /dev/null +++ b/bin/clean-keys @@ -0,0 +1,40 @@ +#!/bin/bash +# clean_keyring.sh - clean up all the excess keys + +# my key should probably be the first secret key listed +mykey=$(gpg --list-secret-keys | grep '^sec' | cut -c 13-20) +if [ -z "$mykey" ]; then + # exit if no key string + echo "Can't get user's key ID" + exit 1 +fi + +# all of the people who have signed my key +mysigners=$(gpg --list-sigs $mykey | grep '^sig' | cut -c 14-21 | sort -u) + +# keep also the keys of persons I'm tracking on keybase.io +keybase_tracks="" +for person in $(keybase list-tracking); do + id=$(keybase id $person 2>&1 | grep "public key fingerprint" | cut -d ':' -f 2 | cut -c 41-50 | sed "s/ //g") + keybase_tracks="$keybase_tracks $id" +done + +# keep all of the signers, plus my key (if I haven't self-signed) +keepers=$(echo $mykey $mysigners $keybase_tracks | tr ' ' '\012' | sort -u) + +# the keepers list in egrep syntax: ^(key|key|…) +keepers_egrep=$(echo $keepers | sed 's/^/^(/; s/$/)/; s/ /|/g;') + +# show all the keepers as a comment so this script's output is shell-able +echo '# Keepers: ' $keepers + +# everyone who isn't on the keepers list is deleted +deleters=$(gpg --list-keys | grep '^pub'| cut -c 13-20 | egrep -v ${keepers_egrep}) + +# echo the command if there are any to delete +# command is interactive +if [ -z "$deleters" ]; then + echo "# Nothing to delete!" +else + echo 'gpg --delete-keys' $deleters +fi diff --git a/bin/cleanup_directories b/bin/cleanup_directories new file mode 100755 index 0000000..53aeb5b --- /dev/null +++ b/bin/cleanup_directories @@ -0,0 +1,4 @@ +#!/bin/bash + +find /Users/luzifer/Downloads ! -name '.*' -mtime +12h -exec mv "{}" /Users/luzifer/.Trash/ \; +find /Users/luzifer/.Trash ! -name '.*' -mtime +2d -exec rm -rf "{}" \; diff --git a/bin/docker-clean b/bin/docker-clean new file mode 100755 index 0000000..7093f9d --- /dev/null +++ b/bin/docker-clean @@ -0,0 +1,3 @@ +#!/bin/bash + +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc spotify/docker-gc diff --git a/bin/edgedist.py b/bin/edgedist.py new file mode 100755 index 0000000..4427f05 --- /dev/null +++ b/bin/edgedist.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import json, sys, urllib + +data = json.loads(open(sys.argv[1], 'r').read()) + +keys = sorted(data.keys()) +last = data[keys[0]] +distsum = 0 + +for key in keys[1:]: + start = '%s,%s' % tuple(last) + end = '%s,%s' % tuple(data[key]) + url = 'http://maps.googleapis.com/maps/api/directions/json?origin=%s&destination=%s&sensor=false' % (start, end) + result = json.loads(urllib.urlopen(url).read()) + dist = result['routes'][0]['legs'][0]['distance']['value'] + distsum = distsum + dist + last = data[key] + +print 'Distance of list: %.2f km' % (float(distsum) / 1000.0) diff --git a/bin/exportstickies b/bin/exportstickies new file mode 100755 index 0000000..db72b39 --- /dev/null +++ b/bin/exportstickies @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import json, subprocess, os, re, HTMLParser + +exportcmd = 'plutil -convert json -o - %s' % os.path.expanduser('~/Library/Preferences/widget-com.apple.widget.stickies.plist') +out = json.loads(subprocess.check_output(exportcmd.split(' '))) + +stickies = [] +htmlparser = HTMLParser.HTMLParser() + +for key in out.keys(): + if not '-data' in key: + continue + + html = out[key] + text = re.sub('\n+', '\n', '\n'.join(re.split(r'<[^>]*div>', html))).strip() + text = '\n'.join(re.split(r']*>\n?', text)) + lines = text.split('\n') + lines = map((lambda parm: htmlparser.unescape(parm).strip()), lines) + text = '\n'.join(lines).strip() + stickies.append(text) + +print '\n\n=====\n\n'.join(stickies) diff --git a/bin/fix-ssh b/bin/fix-ssh new file mode 100755 index 0000000..48e3867 --- /dev/null +++ b/bin/fix-ssh @@ -0,0 +1,5 @@ +#!/bin/bash + +for host in $@; do + grep -v ${host} ~/.ssh/known_hosts > ~/.ssh/known_hosts.tmp && mv ~/.ssh/known_hosts.tmp ~/.ssh/known_hosts +done diff --git a/bin/gen-dockerfile-1.6 b/bin/gen-dockerfile-1.6 new file mode 100755 index 0000000..f937481 --- /dev/null +++ b/bin/gen-dockerfile-1.6 @@ -0,0 +1,77 @@ +#!/bin/bash + +PWD=$(pwd) +PACKAGE=${PWD/${GOPATH}\/src\//} +BINARY=$(basename ${PACKAGE}) + +GIT_NAME=$(git config --get user.name) +GIT_MAIL=$(git config --get user.email) + +if [ -e "${PWD}/Godeps/_workspace/src" ]; then + OVERRIDE_GOPATH="/go:/go/src/${PACKAGE}/Godeps/_workspace" +fi + +EXPOSE="EXPOSE" + +while getopts ":e:t:v:" opt; do + case $opt in + e) + EXPOSE="${EXPOSE} ${OPTARG}" + ;; + t) + TIMEZONE=${OPTARG} + ;; + v) + VOLUME="${VOLUME}, \"${OPTARG}\"" + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +# Header +cat < + +EOF + +# Support old (pre-1.6) Godep style +[ -z "${OVERRIDE_GOPATH}" ] || echo -e "ENV GOPATH ${OVERRIDE_GOPATH}\n" + +# Allow setting timezone using `-t Europe/Berlin` +[ -z "${TIMEZONE}" ] || cat < /etc/timezone \\ + && apk del --purge tzdata + +EOF + +# Build binary +cat < 0: + if argv[0] == "-h" or argv[0] == "--help" or argv[0] == "-?": + self.usageExit() + + elif argv[0] == "-o": + argv.pop(0) + if len(argv) == 0: self.usageExit() + self.outfilename = argv[0] + + elif self.infilename == None: + self.infilename = argv[0] + + argv.pop(0) + + if self.infilename == None: + self.infile = sys.stdin + self.infilename = "" + else: + try: + self.infile = file(self.infilename, "r") + except IOError, (no, str): + self.errorExit("error opening %s: %s" % \ + (self.infilename, str), 2) + + try: + self.dom = xml.dom.minidom.parse(self.infile) + except Exception, (str): + self.errorExit("%s: %s" % (self.infilename, str), 4) + + if self.outfilename == None: + self.outfile = sys.stdout + self.outfilename = "" + else: + try: + self.outfile = file(self.outfilename, "w") + except IOError, (no, str): + self.errorExit("error opening %s: %s" % \ + (self.outfilename, str), 3) + + def __del__(self): + if self.infile != None: self.infile.close() + if self.outfile != None: self.outfile.close() + + def errorExit(self, str, status=1): + sys.stderr.write("%s: %s\n" % (self.scriptname, str)) + sys.exit(status) + + def usageExit(self): + sys.stderr.write("usage: %s [-o outfile] [infile]\n" % self.scriptname) + sys.exit(1) + +def getTextBelow(node, subnodename, handleNone=False): + subnodes = node.getElementsByTagName(subnodename) + if subnodes != []: + return subnodes[0].firstChild.data + + if handleNone: return "" + + return None + +def symTranslate(name): + if not symbolMap.has_key(name): name = "Dot" + return symbolMap[name] + +def main(argv): + ai = AppInfo(argv) + + gpx = ai.dom.firstChild + + waypoints = gpx.getElementsByTagName("wpt") + + ai.outfile.write(""" + + +\t +\t\t +""") + + if waypoints != []: + for wp in waypoints: + lat = wp.getAttribute("lat") + lon = wp.getAttribute("lon") + name = getTextBelow(wp, "name", True) + sym = getTextBelow(wp, "sym") + desc = getTextBelow(wp, "desc") + ele = getTextBelow(wp, "ele") + + ai.outfile.write('\t\t\n') + ai.outfile.write('\t\t\t%s\n' % name) + if desc != '' and desc != None: + ai.outfile.write('\t\t\t%s\n' \ + % desc) + ai.outfile.write("\t\t\t#trackStyle\n") + ai.outfile.write('\t\t\t\n') + ai.outfile.write('\t\t\t\t') + ai.outfile.write('%s,%s\n' % (lon, lat)) + ai.outfile.write('\t\t\t\n') + + ai.outfile.write('\t\t\n') + + tracks = gpx.getElementsByTagName("trk") + + if tracks != []: + for trk in tracks: + + name = getTextBelow(trk, "name", True) + desc = getTextBelow(trk, "desc") + + ai.outfile.write('\t\t\n') + ai.outfile.write('\t\t\t%s\n' % name) + if desc != '' and desc != None: + ai.outfile.write('\t\t\t%s\n' \ + % desc) + ai.outfile.write("\t\t\t#trackStyle\n") + ai.outfile.write("\t\t\t>\n") + ai.outfile.write("\t\t\t\t\n") + + for seg in trk.getElementsByTagName("trkseg"): + for trkpt in seg.getElementsByTagName("trkpt"): + lat = trkpt.getAttribute("lat") + lon = trkpt.getAttribute("lon") + ele = getTextBelow(trkpt, "ele") + + ai.outfile.write("\t\t\t\t\t%s,%s\n" % (lon, lat)) + + ai.outfile.write("\t\t\t\t\n") + ai.outfile.write("\t\t\t>\n") + ai.outfile.write('\t\t\n') + + ai.outfile.write('\t\n') + ai.outfile.write('\n') + + return 0 + +if __name__ == "__main__": sys.exit(main(sys.argv)) diff --git a/bin/habitica b/bin/habitica new file mode 100755 index 0000000..90c6aa1 --- /dev/null +++ b/bin/habitica @@ -0,0 +1,6 @@ +#!/bin/bash + +HABITICA_API_TOKEN=$(vault read -field=api_token /secret/private/habitica) +HABITICA_USER_ID=$(vault read -field=user_id /secret/private/habitica) + +curl -s -H "x-api-key: ${HABITICA_API_TOKEN}" -H "x-api-user: ${HABITICA_USER_ID}" "$@" <&0 diff --git a/bin/instacopy b/bin/instacopy new file mode 100755 index 0000000..78b0c12 --- /dev/null +++ b/bin/instacopy @@ -0,0 +1,56 @@ +#!/opt/local/bin/python2.7 + +# Install: easy_install gdata + +# Config: + +google_email = 'configure@me.com' +google_passwd = 'yoursecretpassword' + +instagram_token = 'some instagram_token' + +# Code: + +import gdata.photos.service, gdata.photos +import gdata.media +import gdata.geo +import json, tempfile, sys, urllib, os + +gd_client = gdata.photos.service.PhotosService() +gd_client.email = google_email +gd_client.password = google_passwd +gd_client.source = 'InstaCopy v0.1' +gd_client.ProgrammaticLogin() + +album = gd_client.InsertAlbum(title='Instagram', summary='EditMe') +album_url = '/data/feed/api/user/default/albumid/%s' % album.gphoto_id.text + +url = 'https://api.instagram.com/v1/users/self/media/recent?access_token=%s&count=100' % (instagram_token) +images = json.loads(urllib.urlopen(url).read()) + +if not 'data' in images: + sys.exit(0) + +i = 0 + +for image in images['data']: + i = i + 1 + if not image['type'] == 'image': + continue + + _, temp_path = tempfile.mkstemp(suffix='.jpg') + f = open(temp_path, 'w') + f.write(urllib.urlopen(image['images']['standard_resolution']['url']).read()) + f.close() + + photo = gd_client.InsertPhotoSimple(album_url, image['link'].split('/')[4], image['caption']['text'], temp_path, content_type='image/jpeg') + photo.timestamp = gdata.photos.Timestamp(text=str(int(image['caption']['created_time']) * 1000)) + try: + gd_client.UpdatePhotoMetadata(photo) + except: + pass + os.unlink(temp_path) + + sys.stdout.write('Transferred %d of %d...\r' % (i, len(images['data']))) + sys.stdout.flush() + diff --git a/bin/issh b/bin/issh new file mode 100755 index 0000000..f4889cf --- /dev/null +++ b/bin/issh @@ -0,0 +1,47 @@ +#!/usr/bin/env python2 + +import os, sys, argparse, boto.ec2 + +def main(): + parser = argparse.ArgumentParser(description='Searches instance IP and connects via SSH') + parser.add_argument('-p', type=int, default=22, metavar='port', help='Port to connect to (default 22)') + parser.add_argument('-u', type=str, default=None, metavar='user', help='User to use for connection (default current username)') + parser.add_argument('instance_id', type=str, help='ID of the instance in format "i-XXXXX"') + args = parser.parse_args() + + if None in [os.getenv('EC2_REGION'), os.getenv('AWS_ACCESS_KEY_ID'), os.getenv('AWS_SECRET_ACCESS_KEY')]: + print 'Please provide these environment variables: EC2_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY' + sys.exit(1) + + if os.getenv('EC2_REGION') not in [r.name for r in boto.ec2.regions()]: + print 'Region "{}" derived from environment variable EC2_REGION is not a valid region.'.format(os.getenv('EC2_REGION')) + sys.exit(1) + + ec2_connection = boto.ec2.connect_to_region(os.getenv('EC2_REGION'), + aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'), + aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY')) + + instances = ec2_connection.get_only_instances([args.instance_id]) + if len(instances) != 1: + print 'Did not found a single instance for ID {}'.format(args.instance_id) + sys.exit(1) + instance = instances[0] + + if instance.private_ip_address is not None: + _call_ssh(instance.private_ip_address, args.u, args.p) + else: + _call_ssh(instance.ip_address, args.u, args.p) + +def _call_ssh(ip, user=None, port=None): + args = ['/usr/bin/ssh'] + if port is not None: + args.append('-p {}'.format(port)) + if user is not None: + args.append('{}@{}'.format(user, ip)) + else: + args.append('{}'.format(ip)) + + os.execv('/usr/bin/ssh', args) + +if __name__ == '__main__': + main() diff --git a/bin/local-vault-auth b/bin/local-vault-auth new file mode 100755 index 0000000..7b71fa7 --- /dev/null +++ b/bin/local-vault-auth @@ -0,0 +1,13 @@ +#!/bin/bash + +if (vault status | grep -q "Sealed: true"); then + echo -n "Vault is sealed, trying to unseal... " + UNSEAL_TOKEN=$(lpass show --field=Passphrase "vault-unseal") + vault unseal "${UNSEAL_TOKEN}" > /dev/null || echo "FAIL" && echo "OK" +fi + +if ! (vault token-lookup 1>/dev/null 2>&1); then + echo -n "Vault is not authenticated, trying to authenticate... " + AUTH_TOKEN=$(lpass show --field=Passphrase "vault-auth") + echo "${AUTH_TOKEN}" | vault auth - > /dev/null || echo "FAIL" && echo "OK" +fi diff --git a/bin/ls-unsafe-ssh b/bin/ls-unsafe-ssh new file mode 100755 index 0000000..4792453 --- /dev/null +++ b/bin/ls-unsafe-ssh @@ -0,0 +1,5 @@ +#!/bin/bash + +for key in $(find . -type f | grep -vE "\.(pub|pem)" | grep -vE '(config|authorized_keys|known_hosts)' | sort); do + grep -q ENCRYPTED ${key} || echo "Key unsafe: ${key}" +done diff --git a/bin/migrate-godeps-1.6 b/bin/migrate-godeps-1.6 new file mode 100755 index 0000000..dd56243 --- /dev/null +++ b/bin/migrate-godeps-1.6 @@ -0,0 +1,22 @@ +#!/bin/bash + +PWD=$(pwd) + +if ! [ -e "${PWD}/Godeps/_workspace/src" ]; then + echo "Path ${PWD}/Godeps/_workspace/src not found, stopping." + exit 1 +fi + +if [ -e "${PWD}/vendor" ]; then + echo "You already have a vendor directory, stopping." + exit 1 +fi + +set -ex + +mv "${PWD}/Godeps/_workspace/src" "${PWD}/vendor" +rm -rf "${PWD}/Godeps/_workspace" +godep update -goversion + +git add vendor +git rm -rf Godeps/_workspace diff --git a/bin/pbfold b/bin/pbfold new file mode 100755 index 0000000..6dedde1 --- /dev/null +++ b/bin/pbfold @@ -0,0 +1,5 @@ +#!/bin/bash + +LEN=${1:-72} + +pbpaste | fold -sw $LEN | pbcopy diff --git a/bin/pdfsort b/bin/pdfsort new file mode 100755 index 0000000..b6ea861 --- /dev/null +++ b/bin/pdfsort @@ -0,0 +1,7 @@ +#!/bin/bash + +for filename in *.pdf; do + target=$(echo ${filename} | sed 's/^\(\([0-9]\{4\}\)\([0-9]\{2\}\).*\)$/\2\/\3\/\1/') + mkdir -p $(dirname ${target}) + mv ${filename} ${target} +done diff --git a/bin/read_timestamp b/bin/read_timestamp new file mode 100755 index 0000000..54b178e --- /dev/null +++ b/bin/read_timestamp @@ -0,0 +1,5 @@ +#!/usr/bin/env python +import sys +from email.Utils import formatdate + +print formatdate(float(sys.argv[1])) diff --git a/bin/short_path b/bin/short_path new file mode 100755 index 0000000..e7bcef0 --- /dev/null +++ b/bin/short_path @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +import os + +path = os.getcwd() +path = path.replace(os.environ["HOME"], "~") + +path_parts = path.split("/") +path = "" +for part in path_parts[:-2]: + if len(part) > 0: + path = "{}/{}".format(path, part[0]) + else: + path = "{}/{}".format(path, part) + +path = "{}/{}".format(path, "/".join(path_parts[-2:])) + +print path[1:] diff --git a/bin/ssh-knownhosts-cleanup.py b/bin/ssh-knownhosts-cleanup.py new file mode 100755 index 0000000..58d98eb --- /dev/null +++ b/bin/ssh-knownhosts-cleanup.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# By Joonas Kuorilehto 2011, MIT license +# https://gist.github.com/joneskoo/1306614 +# +# The script combines .ssh/known_hosts so that each fingerprint is only +# listed once. + +import re +import sys +import os +import shutil + +HOME = os.environ['HOME'] +KNOWN_HOSTS = os.path.join(HOME, '.ssh', 'known_hosts') + +# Backup known hosts file +shutil.copyfile(KNOWN_HOSTS, KNOWN_HOSTS+".old") + +# Read known hosts to memory +with open(KNOWN_HOSTS) as f: + knownhosts = dict() + oldlines = 0 + for line in f: + if line.strip() == "" or line.strip().startswith("#"): + continue + oldlines += 1 + hosts, keytype, fingerprint = line.strip().split(" ") + dictkey = keytype + fingerprint + hosts = hosts.split(",") + if knownhosts.get(dictkey) == None: + knownhosts[dictkey] = dict(hosts=set(), keytype=keytype, + fingerprint=fingerprint) + knownhosts[dictkey]['hosts'].update(hosts) + +lines = [] +for key, host in knownhosts.items(): + host['hosts_joined'] = ",".join(sorted(host['hosts'], reverse=True)) + lines.append("%(hosts_joined)s %(keytype)s %(fingerprint)s" % host) + +# Replace known hosts with a cleaned version +with open(KNOWN_HOSTS, 'w') as f: + f.write("\n".join(sorted(lines))) + f.write("\n") + +print("OK. Cleaned up", KNOWN_HOSTS) +print("Change: from %d lines to %d lines." % (oldlines, len(knownhosts))) diff --git a/bin/sslcert b/bin/sslcert new file mode 100755 index 0000000..94ae89a --- /dev/null +++ b/bin/sslcert @@ -0,0 +1,22 @@ +#!/bin/bash + +selfsigned=false + +while getopts s opt; do + case $opt in + s) + selfsigned=true + ;; + esac +done + +shift $(( OPTIND - 1 )) + +domain=$1 + +openssl genrsa -out ${domain}.key 2048 +openssl req -new -sha256 -key ${domain}.key -out ${domain}.csr + +if $selfsigned; then + openssl x509 -req -days 365 -in ${domain}.csr -signkey ${domain}.key -out ${domain}.crt +fi diff --git a/bin/supervisorctl b/bin/supervisorctl new file mode 100755 index 0000000..56ddfd0 --- /dev/null +++ b/bin/supervisorctl @@ -0,0 +1,3 @@ +#!/bin/bash + +exec /usr/local/bin/supervisorctl -c /Users/luzifer/config/supervisord/supervisord.conf "$@" diff --git a/bin/tmux-reboot-required b/bin/tmux-reboot-required new file mode 100755 index 0000000..618ae38 --- /dev/null +++ b/bin/tmux-reboot-required @@ -0,0 +1,9 @@ +#!/bin/bash + +if ! [ -f /var/run/reboot-required ]; then + exit +fi + +PKG_COUNT=$(wc -l /var/run/reboot-required.pkgs | awk '{ print $1 }') + +echo -n "Reboot required (${PKG_COUNT} pkgs)" diff --git a/bin/traveltime b/bin/traveltime new file mode 100755 index 0000000..935eba0 --- /dev/null +++ b/bin/traveltime @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +import urllib, json, sys + +if len(sys.argv) < 3: + print 'Usage: %s ' % sys.argv[0] + sys.exit(2) + +url = 'http://maps.googleapis.com/maps/api/directions/json?origin=%s&destination=%s&sensor=false' % (sys.argv[1], sys.argv[2]) + +result = json.loads(urllib.urlopen(url).read()) + +duration = result['routes'][0]['legs'][0]['duration']['text'] +distance = result['routes'][0]['legs'][0]['distance']['text'] + +print '%s for %s' % (duration, distance) diff --git a/bin/update-gotools b/bin/update-gotools new file mode 100755 index 0000000..4e7d723 --- /dev/null +++ b/bin/update-gotools @@ -0,0 +1,27 @@ +#!/bin/bash -ex + +export GOPATH="${HOME}/gocode" + +# Re-Install gocode +rm -rf "${GOPATH}/bin/gocode" +go get -u github.com/nsf/gocode + +# Re-Install gometalinter +rm -rf "${GOPATH}/bin/gometalinter" +go get -u github.com/alecthomas/gometalinter +${GOPATH}/bin/gometalinter --install --update + +# Re-Install godebug +rm -rf "${GOPATH}/bin/godebug" +go get -u github.com/mailgun/godebug + +# Re-Install godep +rm -rf "${GOPATH}/bin/godep" +go get -u github.com/tools/godep + +# Re-Install go-bindata +rm -rf "${GOPATH}/bin/go-bindata" +go get -u github.com/jteeuwen/go-bindata/... + +# Ensure vim-go can work +vim +:GoInstallBinaries +:qall diff --git a/bin/vault-awsenv b/bin/vault-awsenv new file mode 100755 index 0000000..de51126 --- /dev/null +++ b/bin/vault-awsenv @@ -0,0 +1,41 @@ +#!/bin/bash + +if ! ( which vault > /dev/null ); then + error "vault is required." + exit 2 +fi + + +# If we can list the environments there is no need to unlock the database +if ( awsenv list > /dev/null 2>&1 ); then + echo "Database already unlocked." + exit 0 +fi + +# Retrieve key from LastPass +PWD=$(vault read -field=passphrase "/secret/private/awsenv") + +# In case Vault exitted non-zero we have no password +if ! [ $? -eq 0 ]; then + echo "Unable to get password. Not trying to unlock." + exit 1 +fi + +# Fill password to ssh-add utility +expect </dev/null +spawn -ignore HUP awsenv unlock +expect "Password: " +send "$PWD\n" +expect "Database unlocked." +expect eof +EOF + +# Check whether awsenv was unlocked +if ( awsenv list > /dev/null 2>&1 ); then + echo "Database unlocked successfully" + exit 0 +else + echo "Found passphrase but could not unlock database." + exit 1 +fi + diff --git a/bin/vault-gpg b/bin/vault-gpg new file mode 100755 index 0000000..38458ec --- /dev/null +++ b/bin/vault-gpg @@ -0,0 +1,32 @@ +#!/bin/bash + +KEY=$1 + +if [ -z "${KEY}" ] || ! (gpg --list-secret-keys | grep -q ${KEY}); then + echo "No key given or no secret key found for '${KEY}'" + exit 2 +fi + +# Read password for this key +PWD=$(vault read --field=passphrase "/secret/gpg-key/${KEY}") + +if [ -z "${PWD}" ]; then + echo "Could not read passphrase from vault." + exit 2 +fi + +HEXPWD=$(python -c "print '${PWD}'.encode('hex')") + +# Get keygrip of secret key +for KEYGRIP in $(gpg2 --with-keygrip -k ${KEY} | grep Keygrip | cut -d '=' -f 2 | xargs); do + + # Set password for keygrip + if ! ( gpg-connect-agent -q "PRESET_PASSPHRASE ${KEYGRIP} -1 ${HEXPWD}" /bye >/dev/null 2>&1 ); then + echo "An error occurred while caching password in GPG agent" + exit 1 + fi + +done + +echo "Successfully cached password in GPG agent" +exit 0 diff --git a/bin/vault-muttpwd b/bin/vault-muttpwd new file mode 100755 index 0000000..057b92d --- /dev/null +++ b/bin/vault-muttpwd @@ -0,0 +1,12 @@ +#!/bin/bash + +USER=$(vault read -field=gmail_user /secret/private/mutt) +PASS=$(vault read -field=gmail_pass /secret/private/mutt) + +cat < /dev/null ); then + error "vault is required." + exit 2 +fi + +# Require something to be passed to this command +if [ $# -eq 0 ]; then + error "You need to specify a key name." + exit 2 +fi + +for KEY_NAME in $@; do + KEYNAME_IN=${KEY_NAME} + + # Try to find the passed key path / name + if ! [ -e "${KEY_NAME}" ]; then + if [ -e "${HOME}/.ssh/${KEY_NAME}" ]; then + KEY_NAME="${HOME}/.ssh/${KEY_NAME}" + else + error "[${KEYNAME_IN}] Could not find key file." + continue + fi + fi + + # If this key is already in the agent we don't need to do anything + if ( ssh-add -l | grep -q "${KEY_NAME}" ); then + info "[${KEYNAME_IN}] Key already present." + continue + fi + + # Retrieve key from LastPass + PWD=$(vault read -field=passphrase "/secret/ssh-key/$(basename ${KEY_NAME})") + + # In case LastPass exitted non-zero we have no password + if ! [ $? -eq 0 ]; then + error "[${KEYNAME_IN}] Unable to get password. Not trying to unlock." + continue + fi + + # Fill password to ssh-add utility + expect </dev/null +spawn ssh-add ${KEY_NAME} +expect "Enter passphrase" +send "$PWD\n" +expect eof +EOF + + # Check whether the key was added to the agent + if ( ssh-add -l | grep -q "${KEY_NAME}" ); then + success "[${KEYNAME_IN}] Key successfully added." + continue + else + error "[${KEYNAME_IN}] Found passphrase but could not add key." + continue + fi + +done diff --git a/bin/zsh-refresh-godirs b/bin/zsh-refresh-godirs new file mode 100755 index 0000000..d722b66 --- /dev/null +++ b/bin/zsh-refresh-godirs @@ -0,0 +1,4 @@ +#!/bin/bash + +find $HOME -type f -name '.gopath' | sed 's!/.gopath$!!' > /tmp/godirs +mv /tmp/godirs $HOME/.config/godirs