Skip to content

Instantly share code, notes, and snippets.

@efrecon
efrecon / run.tpl
Last active May 30, 2024 03:12
`docker inspect` template to regenerate the `docker run` command that created a container
docker run \
--name {{printf "%q" .Name}} \
{{- with .HostConfig}}
{{- if .Privileged}}
--privileged \
{{- end}}
{{- if .AutoRemove}}
--rm \
{{- end}}
{{- if .Runtime}}
@efrecon
efrecon / docker-cleanup.sh
Last active September 15, 2017 19:58
Entirely clean away docker from a Ubuntu system
sudo apt-get purge -y docker-ce
sudo apt-get autoremove -y --purge docker-ce
sudo apt-get autoclean
sudo rm -rf /var/lib/docker
sudo find /var -name '*docker*' -print -exec rm -rf \{\} \;
sudo find /etc -name '*docker*' -print -exec rm -rf \{\} \;
sudo find /run -name '*docker*' -print -exec rm -rf \{\} \;
echo "Done!"
@efrecon
efrecon / reindent.tcl
Created September 22, 2017 11:31
Reindent the tcl files passed on the command line, automatically make backups.
#!/usr/bin/env tclsh
# From https://gist.githubusercontent.com/yyamasak/af250f7ca74e18526734/raw/563fe0adc00b841cda1ecc4324827684872eb6ab/reformat.tcl
proc reformat {tclcode {pad 4}} {
set lines [split $tclcode \n]
set out ""
set continued no
set oddquotes 0
@efrecon
efrecon / autocomment.tcl
Created September 22, 2017 12:25
Automatically insert commenting skeletons for procedures that lack documentation
#!/usr/bin/env tclsh
set usage "autocomment.tcl filename..."
proc count {str chars} {
set count 0
foreach c [split $str ""] {
foreach d [split $chars ""] {
if { $d eq $c } {
incr count
@efrecon
efrecon / ufw-dynamic-host-update.sh
Last active December 11, 2017 11:39
Allow incoming traffic on specific ports from specific (dynamic) hosts. Should run from crontab.
#!/bin/bash
VERBOSE=0
QUIET=0
SERVER=
while getopts "vqs:" opt; do
case $opt in
v)
VERBOSE=1
;;
@efrecon
efrecon / automount.md
Last active June 18, 2019 09:50
Automounts using sshfs

SSHFS Auto Mounter

The purpose of this project is to facilitate SSHFS mounting at the command-line. In short, this script will read a configuration file to mount remote locations onto the local filesystem using SSHFS. The script supposes that you have ensured that your local account is able to access the remote filesystem using the specified user.

The script is tuned to minimise command-line entry and get you going as quickly as possible, automatically mounting a specific directory, at a specific host

@efrecon
efrecon / openwrt-restart.tcl
Created January 13, 2018 12:49
Restart LuCI-based OpenWRT router from internal host
#!/usr/bin/env tclsh
package require http
array set options {
-root "http://192.168.1.1/"
-user "user"
-password ""
}
@efrecon
efrecon / wait-for-files.sh
Created February 22, 2018 07:17
Wait for a number of files to be present (including 0, the use case!) and start a command
#!/bin/sh
# Number of files to wait for, 0 is usually what you want
TARGET=$1
# Pattern to match path
PATTERN=$2
# Command to execute once target has been reached
COMMAND=$3
@efrecon
efrecon / wait-for.sh
Last active April 7, 2024 00:33
Wait for a port at remote site to be opened. Same as https://github.com/Eficode/wait-for but with options to be silent and an exponential backoff when waiting.
#!/bin/sh
# This comes from : https://github.com/Eficode/wait-for
# The MIT License (MIT)
#
# Copyright (c) 2017 Eficode Oy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@efrecon
efrecon / hub-tags.sh
Last active April 16, 2018 08:15
List all the tags for a given image at the Docker hub
#!/bin/sh
# Inspired by: https://stackoverflow.com/a/43262086, tested on Ubuntu and Alpine
if [ -z "$1" ]; then
echo "You have to provide an image name!"
exit
fi
if [ -z "$(echo "$1" | grep -o '/')" ]; then