Skip to content

Instantly share code, notes, and snippets.

View bwmorales's full-sized avatar

Benjamin Morales bwmorales

  • Madison, WI
View GitHub Profile
@bwmorales
bwmorales / printlog.sh
Last active December 11, 2017 01:43
(macOS) Redirect output to printlog function to have printlog generate logger output and stdout
# Redirect output to printlog function to have printlog generate logger output and stdout
# Finish script with finalizelog to append cat of TEMP_LOG to LOG_FILE and remove TEMP_LOG
# Example Usage:
# printf "Current working directory: %s" "$(pwd)" | printlog
# ...
# finalizelog; exit 0
export LOG_FILE=""
export TEMP_LOG="/private/tmp/$(basename ${LOG_FILE})"
export LOG_TAG=""
@bwmorales
bwmorales / userIteration.sh
Last active February 9, 2018 19:15
(macOS) Iterate through users, performing some task.
# Iterate through users and perform some tasks.
# Variables and functions that need to be accesible in subshells must be exported (duh).
# Enclose arguments in single-quotes to preserve bash internal variables, etc.
# Example Usage:
# userIteration 'remove "$HOME/Library/Containers/com.microsoft.Excel"'
userIteration() {
for ITERATED_USER in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do
su $ITERATED_USER -c "$*"
done
@bwmorales
bwmorales / backup.sh
Last active December 11, 2017 10:47
(macOS) Rsync a file, check that backup was successful, and send a message to the printlog function
# Rsync a file, check that backup was successful, and send a message to the printlog function
# Printlog function is available at https://gist.github.com/bwmorales/86a1a8c4ec51c9e2ffba1499a2c211e0
# Example Usage:
# backup $HOME/Documents/myfile.txt
export TODAY=$(date +"%Y-%m-%d")
backup() {
if [[ -e "${1}" ]]; then
rsync -aE "${1}" "${1}.${TODAY}.bak"
@bwmorales
bwmorales / appToPkg.sh
Last active March 8, 2019 14:09
(Addigy) Create PKGs from bundled apps, PNG of App icon, and text file of metadata for Addigy.
#!/usr/bin/env bash
###############################################################################
# Copyright 2017 Benjamin Moralez #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
@bwmorales
bwmorales / fileKiller.sh
Last active July 10, 2018 22:31
List files that you want to assasinate in every user's home directory, as well as some system files, on macOS.
#!/bin/bash
USER_FILES=(
'~/Library/Caches/Google/Chrome'
'/Library/Application Support/Google/Chrome/Default/Application Cache'
'Library/Application Support/Google/Chrome/Default/Cookies'
' '
)
SYSTEM_FILES=(
#!/usr/bin/env bash
#
# Remove Microsoft Office 2016 from macOS
# Store file in a place that is readable by all users
export LOG_FILE="/Library/Logs/Microsoft/uninstall.log"
export TODAY=$(date +"%Y-%m-%d")
export RED='\033[0;31m'
export GREEN='\033[0;32m'
export YELLOW='\033[0;33m'
/usr/bin/say "This test worked."
@bwmorales
bwmorales / rmSMB_Illegals.sh
Last active June 29, 2018 18:10
Swap out those pesty SMB illegals with benign characters!
#!/bin/bash
# USAGE: ./rmSMB_Illegals.sh path
# Find searches through each file on a filesystem and passes the filenames to a
# function that tests for the presence of illegal characters and remediates.
# Bad characters are either removed or replaced with a ``-''.
# This has been tested on APFS on macOS 10.13.5. It'd be pretty safe to run this
# on a mounted volume, but it'd be nicer to test on Synology Linux and have it
/sbin/route get 1.1.1.1 | /usr/bin/grep 'interface: ' | /usr/bin/sed 's/.*interface: //'
#!/bin/bash
# Example given with Wireshark. Script tests ping times for Wireshark's mirrors and selects the fastest.
MIRRORS=(
'1.as.dl.wireshark.org'
'1.eu.dl.wireshark.org'
'1.na.dl.wireshark.org'
'2.na.dl.wireshark.org'
# 'www.wireshark.org'