Skip to content

Instantly share code, notes, and snippets.

View darth-veitcher's full-sized avatar

James Veitch darth-veitcher

View GitHub Profile
@darth-veitcher
darth-veitcher / crontab
Created December 28, 2016 12:43
Crontab times example
# MIN HOUR DOM MON DOW CMD
# -----+---------------+-------------
# Field Description Allowed Value
# -----+---------------+-------------
# MIN Minute field 0 to 59
# HOUR Hour field 0 to 23
# DOM Day of Month 1-31
# MON Month field 1-12
# DOW Day Of Week 0-6
# CMD Command Any command to be executed.
@darth-veitcher
darth-veitcher / cloudflare_dyndns.py
Last active December 28, 2016 14:05
Update Cloudflare DNS record for Dynamic IP
#!/usr/bin/env python
# https://github.com/cloudflare/python-cloudflare/blob/master/examples/example_update_dynamic_dns.py
"""CloudFlare API code - example"""
import os
import sys
import re
import json
import requests
@darth-veitcher
darth-veitcher / caddy-server.md
Last active January 7, 2017 21:10
Using Caddy Server as a reverse proxy
# Download saved version from Dropbox and extract
# http://unix.stackexchange.com/a/85195
sudo mkdir -p /data/caddy && sudo chown -R $USER:$USER /data/caddy
wget -qO- "https://db.tt/2coec0FX" | tar xvz -C /data/caddy

# Allow Caddy to bind to 80/443 without needing
# root priveleges
cd /data/caddy
sudo setcap cap_net_bind_service=+ep caddy
@darth-veitcher
darth-veitcher / shellinabox.md
Created January 7, 2017 21:13
Shellinabox reverse proxy and basic auth with Caddy

Install shellinabox

sudo apt-get install shellinabox -y
# Modify the shellinabox settings
# - lock down so only localhost allowed
# - disable ssl as we will use the verified certs provided by Caddy
sudo nano /etc/default/shellinabox
...
SHELLINABOX_ARGS="--no-beep --localhost-only --disable-ssl"
...
@darth-veitcher
darth-veitcher / atlassian-confluence.md
Created January 7, 2017 21:15
self-hosted atlassian confluence with reverse proxy via CaddyServer
@darth-veitcher
darth-veitcher / gitlab.md
Created January 7, 2017 21:18
self-hosted GitLab setup
@darth-veitcher
darth-veitcher / bash-pid.md
Created January 8, 2017 22:13
Bash Script PID file locking

Pattern below allows for a bash script to be called via, say, cron and check to see if it is already running.

Useful for things like rsync tasks.

PIDFILE=/var/run/myscriptname.pid

if [ -f $PIDFILE ]
then
 PID=$(cat $PIDFILE)
@darth-veitcher
darth-veitcher / sources.list
Created January 13, 2017 21:35
OVH Ubuntu apt sources.list
deb http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu/ xenial main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu/ xenial-updates main restricted
deb-src http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu/ xenial-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
@darth-veitcher
darth-veitcher / cryptroot
Created January 13, 2017 22:01
cryptroot unlock via dropbear
#!/bin/sh
# https://chicagolug.org/news/2015-10-09-remotely-unlock-encrypted-server-with-dropbear.html
# Quit the Ubuntu graphical splash screen. This is necessary for cryptroot
# to work right. The server will fall back to a non-graphical unlock
# screen.
plymouth --quit
count=0
# Looping gives us some control over the number of unlock attempts.
while ! ( ls /dev/mapper/ | grep root > /dev/null ); do
if [ $count -gt 0 ]; then