Skip to content

Instantly share code, notes, and snippets.

@IanSavchenko
Last active September 19, 2019 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanSavchenko/6734cb4ac8422399e60f34d7a68ccd44 to your computer and use it in GitHub Desktop.
Save IanSavchenko/6734cb4ac8422399e60f34d7a68ccd44 to your computer and use it in GitHub Desktop.
Add an alias for loopback interface on startup of MacOS for https://github.com/otm/limes
#!/bin/bash
# This script adds an alias for loopback interface on start of MacOS X.
# This is needed in order for https://github.com/otm/limes to work properly.
#
# Inspired by
# https://apple.stackexchange.com/questions/311188/running-a-sudo-command-on-startup
#
# USAGE (with local cloned version):
# sudo bash add_lo0_alias.sh
#
# USAGE (without cloning - ALWAYS VERIFY WHAT YOU RUN BEFORE YOU RUN IT):
# sudo bash -c "$(curl -fsSL https://gist.githubusercontent.com/IanSavchenko/6734cb4ac8422399e60f34d7a68ccd44/raw/add_lo0_alias.sh)"
#
# Written by Ian Savchenko in 2019 (iansavchenko.com)
set -euo pipefail
DAEMON_NAME=org.limes.ifconfig
DAEMON_FILE_NAME=${DAEMON_NAME}.plist
DAEMON_FILE_PATH=/Library/LaunchDaemons/${DAEMON_FILE_NAME}
touch ${DAEMON_FILE_PATH}
chown root:wheel ${DAEMON_FILE_PATH}
cat > ${DAEMON_FILE_PATH} <<- EOM
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${DAEMON_NAME}</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/${DAEMON_NAME}.err</string>
<key>StandardOutPath</key>
<string>/tmp/${DAEMON_NAME}.out</string>
<key>ProgramArguments</key>
<array>
<string>/sbin/ifconfig</string>
<string>lo0</string>
<string>alias</string>
<string>169.254.169.254</string>
</array>
</dict>
</plist>
EOM
echo Created ${DAEMON_FILE_PATH}!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment