Skip to content

Instantly share code, notes, and snippets.

@echo off
:: Setup an ssd daemon/server on a Windows server box on the internal network.
set ROOT=C:\cygwin
set PACKAGES=openssh,nc,curl,tmux
set SITE=
set BASH=%ROOT%\bin\bash --login -c
set PACKAGEDIR=%ROOT%\packages
mikeslattery /
Last active January 13, 2022 16:51
Run containers as if they are locally installed tools
# Run containers as if they are locally installed tools.
# This is useful for images such as "python" or "maven".
# Edit the "image" variable and place in your ~/bin directory.
# For "Docker Desktop for Windows" under these environments:
# * WSL: if /c is mounted to C: and run from a dir under /c, but /tmp and $HOME volumes should be removed.
# * Msys/GitBash: but /tmp volume should be removed.
# * Cygwin: Will not work as-is due to path differences.
docker system df
df -h
# Delete builds and workspaces more 6+ months old
find /var/lib/jenkins/jobs -maxdepth 6 -mtime +180 -name build.xml -print0 | xargs -0 -I{} dirname {} | xargs -d '\n' -r rm -rf
find /var/lib/jenkins/jobs -maxdepth 3 -mtime +180 -name workspace -print0 | xargs -0 -r rm -rf
# Stop containers running more than 2 days, except Jenkins
docker ps | grep -E 'days|weeks|months' | grep -Ev "$(hostname)|CONTAINER" | awk '{ print $1; }' | xargs -r docker stop
mikeslattery /
Last active May 24, 2021 15:33
Run docker over ssh.
#Usage (local use): docker-over-ssh <server>
#Usage (expose): endpoint= docker-over-ssh <server>
ssh -nNT -L $endpoint:2375:/var/run/docker.sock "$1" &
export DOCKER_HOST=tcp://$endpoint:2375
echo "Now your docker commands will run on $1"
mikeslattery /
Last active January 30, 2023 15:44
Cross Platform Bash Snippet for Linux, WSL 1, Cygwin, Msys, and GitBash.
# shebang added only to appease shellcheck
# Cross-platform for bash.
# Worry less about when writting a script that must run on Windows and Linux.
# Meant to be used with "source" command in scripts or .bashrc/.zshrc
export USER="${USER:-${USERNAME:-$(whoami)}}"
export HOSTNAME="${HOSTNAME:-${MACHINENAME:-$(hostname)}}"
mikeslattery /
Last active October 28, 2019 20:31
An empty Bash script as a template. See #TODO for places to change.
usage() { sed 's/^ //' >&2 <<<USAGETEXT
#TODO: Description of script here.
$(sed -r 's/^#@@ (.*)$/ \1/p' < "${BASH_SOURCE[0]}")
$(sed -r 's/^#@# (.*)$/ \1/p' < "${BASH_SOURCE[0]}")
mikeslattery /
Last active May 15, 2019 21:44
Template engine for Bash
# Interpolates variables in a text file
# $1 = template filename
eval "$(echo -e "cat <<HEREX\n$(cat "$templatefile")\nHEREX\n")"
# Workaround docker wrapper for git-bash/Msys/Cygwin quirks
# Copy this to ~/bin/docker or /usr/local/bin/docker
set -euo pipefail
export MSYS2_ARG_CONV_EXCL='*'
os="$(uname -o)"
# Wrapper over docker-compose to run on remote server.
# Usage:
# Takes same arguments as docker-compose.
# Typical usage:
# remote-compose server down
# More seemless integration between git-bash/WSL/Cygwin and Docker for Windows
set -euo pipefail
( [ -d 'C:\'] && cygpath . > /dev/null; ) || \
{ echo 'Must be run from GitBash, Msys or Cygwin'; exit 1; }
docker run \