Skip to content

Instantly share code, notes, and snippets.

@hyukishi
hyukishi / floating-ip-gateway.sh
Last active January 12, 2020 17:19 — forked from sparkcodeuk/floating-ip-gateway.sh
Digital Ocean floating IP gateway script (force droplet to use the assigned floating IP for outbound traffic as well as inbound traffic)
#!/bin/bash
# Force outbound traffic through the attached floating IP
# Script must be run as root
NET_INT="eth0"
CURL_TIMEOUT=3
echo -n "Setting floating IP as the default gateway: "
# Check there's a floating IP attached to this droplet
#!/bin/bash
# Created by Jeffery Grantham 1/8/2019
# Usage: piholeimgmount.sh [image]
# This script assumes that you've already made a folder under /mnt called loop
# It will attempt to create the directory if it is not found.
# If it fails, the user account running the script does not have rights to do so.
# This script will not work with berryboot installed images.
# It is only designed to work with raspbian-based images as it has already calculated
# the offset at which your Linux partition begins
#!/bin/bash
# Return gateway settings to default if floating IP is not active
# Script must be run as root
NET_INT="eth0"
CURL_TIMEOUT=3
# Check there's a floating IP attached to this droplet
if [ "$(curl -s --connect-timeout $CURL_TIMEOUT http://169.254.169.254/metadata/v1/floating_ip/ipv4/active)" == "true" ]; then
echo "This droplet has a floating IP assigned to it."
@hyukishi
hyukishi / slack
Created February 6, 2019 17:16
Script for passing stdout to slack messages
#!/bin/bash
# Created by Jeffery Grantham with assistance from Jimmy Burrell on February 5, 2019
# Usage: <command> | slack <channel> <username to display>
# If username is not included, it will default to the username "Admin."
# Designed to pipe stdout in a slack message to any one of the predefined channels
i="$1"
cron="(webhook url here)"
general="(webhook url here)"
random="(webhook url here)"
@hyukishi
hyukishi / 301.sh
Created February 6, 2019 17:20
Add a 301 redirect to point to the https (secure) url
#!/bin/bash
# Created by Jeffery Grantham 01/07/2019
# Purpose: Easily implement 301 redirects into website conf files
# Written for use with apache only
# Usage: 301.sh [.conf file]
FILE=$1
cd /etc/apache2/sites-available/
sed "/CustomLog/a\ \tRedirect 301 / https://$FILE.com/" $FILE.conf> tempfile && mv tempfile $FILE.conf
cat $FILE.conf
@hyukishi
hyukishi / screenresume.sh
Created February 6, 2019 17:22
See comments at the top of the script
#!/bin/bash
# Created by Jeffery Grantham 01/04/2019
# The purpose of this script is to reattach all open screens in sequential order.
# As you exit a screen, you will be automatically attached to the next open screen.
for line in `screen -ls | grep Detached | awk '{print $1}'`
do `screen -r $line`
done
@hyukishi
hyukishi / linuxmaintenance.sh
Last active February 6, 2019 18:12
Perform linux maintenance across multiple boxes with ease using screens
#!/bin/bash
# linuxmaintenance.sh
# Authored Sep 7 2018 by Jim
# Optimized Jan 4 2019 by Jeffery Grantham
# You must have a file named hosts.txt containing each hostname or FDQN for the boxes of which maintenance will be performed
# Hosts/FQDNs must have 1 listed per line for the script to execute properly
# run-updates script must be on target boxes and included in the PATH for the root user
# Checking if screen is installed. If not, apt will install it.
if [[ $(which screen) != "/usr/bin/screen" ]]; then
@hyukishi
hyukishi / run-updates.sh
Last active February 6, 2019 18:07
Updates all packages and autoremoves unneeded. Schedules a restart of the box for 5:00 AM.
#! /bin/bash
# Created by Jeffery Grantham on 2/6/2019
# Checking if "at" is installed. If not, apt-get will install it.
if [[ $(which at) != "/usr/bin/at" ]]; then
apt-get install at -y
fi
# Proceeding to check for updates
@hyukishi
hyukishi / GarageDoor_ESP8266-01.ino
Last active April 5, 2019 01:49
The purpose of this code is to remove the need for yet another automation platform such as HomeAssistant or OpenHAB.
// Setup your sonoff //
// Flash your sonoff switch with tasmota //
// Associate the tasmotized sonoff with your WiFi network //
// Load the webpage for the sonoff and setup your mqtt topics //
// Go into module setup and set GPIO14 to Switch2 //
// Go into the console and type "SwitchMode2 1" (without quotes) //
// Lastly, in the console type "PulseTime 1" (without quotes) //
// Setup credentials in the code //
// Replace asterisks next to ssid & password with WiFi credentials //
#!/bin/bash
DATE=`date +%d-%b-%Y`
/bin/dd bs=4M if=/dev/mmcblk0 iflag=direct of=/media/usb/jgpiholebackup/jgpihole_$DATE.img
if [ $? != 0 ]; then
echo "Image creation failed. $(date)">> /var/log/doimage.log
exit 1
fi
cd /media/usb/jgpiholebackup/