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=http://cygwin.mirror.constant.com
set BASH=%ROOT%\bin\bash --login -c
set PACKAGEDIR=%ROOT%\packages
echo INSTALL CYGWIN...
@mikeslattery
mikeslattery / runimage.sh
Last active January 13, 2022 16:51
Run containers as if they are locally installed tools
#!/bin/bash
# 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
mikeslattery / docker-over-ssh.inc.sh
Last active May 24, 2021 15:33
Run docker over ssh.
#!/bin/sh
#Usage (local use): docker-over-ssh <server>
#Usage (expose): endpoint=0.0.0.0 docker-over-ssh <server>
endpoint="${endpoint:-localhost}"
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
mikeslattery / x-platform.sh
Last active January 30, 2023 15:44
Cross Platform Bash Snippet for Linux, WSL 1, Cygwin, Msys, and GitBash.
#!/bin/bash
# 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 USERNAME="${USERNAME:-$USER}"
export HOSTNAME="${HOSTNAME:-${MACHINENAME:-$(hostname)}}"
@mikeslattery
mikeslattery / template.inc.sh
Last active October 28, 2019 20:31
An empty Bash script as a template. See #TODO for places to change.
#!/bin/bash
usage() { sed 's/^ //' >&2 <<<USAGETEXT
#TODO: Description of script here.
Usage:
$(sed -r 's/^#@@ (.*)$/ \1/p' < "${BASH_SOURCE[0]}")
Variables:
$(sed -r 's/^#@# (.*)$/ \1/p' < "${BASH_SOURCE[0]}")
USAGETEXT
@mikeslattery
mikeslattery / template.sh
Last active May 15, 2019 21:44
Template engine for Bash
#!/bin/bash
# Interpolates variables in a text file
# $1 = template filename
templatefile="$1"
shift
eval "$(echo -e "cat <<HEREX\n$(cat "$templatefile")\nHEREX\n")"
#!/bin/bash
# Workaround docker wrapper for git-bash/Msys/Cygwin quirks
# Copy this to ~/bin/docker or /usr/local/bin/docker
set -euo pipefail
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL='*'
os="$(uname -o)"
#!/bin/bash
# Wrapper over docker-compose to run on remote server.
# Usage:
# Takes same arguments as docker-compose.
# Typical usage:
# remote-compose server down
#!/bin/bash
# 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; }
export MSYS_NO_PATHCONV=1
USER="$(whoami)"
docker run \