Skip to content

Instantly share code, notes, and snippets.

@toonetown
toonetown / swup
Last active September 1, 2024 03:37
A script which updates brews, cast, software updates, etc
#!/bin/bash
# Script that will update all kinds of stuff (brews, casks, software updates, app store apps, etc)
set -o pipefail
# You can set any of these variables to "no" in your environment if you want to skip that particular portion
: ${SWUP_OS:="yes"}
: ${SWUP_BREW:="yes"}
: ${SWUP_MAS:="yes"}
: ${SWUP_BUNDLE:="yes"}
: ${SWUP_REMOVE_QUARANTINE:="yes"}
@toonetown
toonetown / mate-editor
Last active February 7, 2025 19:32
A script which wraps around `mate -w` or `rmate -w` for use in EDITOR variables
#!/bin/bash
PFX="$(which brew &>/dev/null && brew --prefix || echo "/usr/local")"
if [ -n "${SSH_CONNECTION}" ]; then
exec "$(brew --prefix)/bin/rmate" -w "$@"
else
exec "$(brew --prefix)/bin/mate" -w "$@"
fi
@toonetown
toonetown / check-kext-linkage
Created March 14, 2019 17:46
Checks the linkage of a kext
###########
# Copies a kext to a temporary location and test loading it (to make sure that all
# library linkages are in place). This is a standalone script because in order
# for a kext to be loaded, it must have ownership of root:wheel - which requires
# root to change.
#
# This script will call sudo on itself if it is run as non-root.
#
# In order to prevent this script for prompting for a password (i.e. for use in
# continuous integration or for other cases where you are too lazy to type in
@toonetown
toonetown / git-p4g
Last active May 7, 2019 20:23
Add perforce command line access using git configuration
###########
# Helper script that adds the ability to point to a perforce workspace using git command line
#
#!/bin/bash
PARENT_BRANCH="$(git branch -r -a --merged | sed -nE 's|^[ \*]+remotes/origin/(master\|branches/.*)$|\1|p')"
[ -n "${PARENT_BRANCH}" -a "$(echo "${PARENT_BRANCH}" | wc -l)" -eq 2 ] && {
PARENT_BRANCH="$(echo "${PARENT_BRANCH}" | grep -v '^master$')"
}
[ -n "${PARENT_BRANCH}" -a "$(echo "${PARENT_BRANCH}" | wc -l)" -eq 1 ] || {
@toonetown
toonetown / shimo-sshuttle
Last active September 24, 2020 10:10
Connects to sshuttle tunnel using Shimo
#!/bin/bash
# Function to convert cidr to a mask
cidr2mask () {
# Number of args to shift, 255..255, first non-255 byte, zeroes
set -- $(( 5 - (${1} / 8) )) 255 255 255 255 $(( (255 << (8 - (${1} % 8))) & 255 )) 0 0 0
[ ${1} -gt 1 ] && shift ${1} || shift
echo ${1-0}.${2-0}.${3-0}.${4-0}
}
@toonetown
toonetown / boot-shutdown.sh
Created July 19, 2019 14:32
Startup/Shutdown
#!/bin/bash
function shutdown()
{
# INSERT HERE THE COMMAND YOU WANT EXECUTE AT SHUTDOWN OR SERVICE UNLOAD
exit 0
}
function startup()
{
@toonetown
toonetown / copy-diff
Last active August 10, 2021 16:24
Copies a file if it is different than the target
#!/bin/bash
# Copies a file if and only if it is different
if [ "$(diff -q "${1}" "${2}" 2>&1 | wc -l)" -gt 0 ]; then cp "${1}" "${2}"; fi
@toonetown
toonetown / QuickSetup.sh
Last active January 17, 2020 02:46
A list of steps to perform to quickly set up a machine like I like it.
# Default Settings (run from recovery partition before user creation)
cd "/Volumes/Macintosh HD"
curl -sSL -o data https://gist.githubusercontent.com/toonetown/c5664875177e8253a99814c6184db41b/raw
chroot .
/bin/bash data
exit
rm data
# First-run setup, create user, set auto-login, download folder options, Parallels Tools (if on VM)
@toonetown
toonetown / oc
Last active January 21, 2020 16:58
Openconnect helper script
#!/bin/bash
[ -f "${OC_CONFIG:="${HOME}/.oc-config"}" ] || { echo "Not configured - set up ${OC_CONFIG}" >&2; exit 1; }
if [ "$(id -u)" != "0" ]; then OC_CONFIG="${OC_CONFIG}" sudo "${0}" "$@"; exit $?; fi
OC_PID="/var/run/openconnect.pid"
OC_LOG="/var/log/openconnect.log"
case "${1}" in
connect)
@toonetown
toonetown / ksymbolicate
Last active August 16, 2021 20:24
A script which will help decode macOS kernel panics
#!/bin/bash
###########
# A script which will help to decode macOS kernel panics
###########
# Helper functions
function do_jq {
_J="$(which jq 2>/dev/null)" || {
echo "You must install jq (brew install jq) to use the script" >&2; return 1;
}; "${_J}" "$@"