Skip to content

Commit

Permalink
evo host file
Browse files Browse the repository at this point in the history
  • Loading branch information
sphen13 committed May 19, 2020
1 parent 58e9935 commit 8bfc6a0
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
5 changes: 5 additions & 0 deletions evo host file/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# .DS_Store files!
.DS_Store

# our build directory
build/
22 changes: 22 additions & 0 deletions evo host file/build-info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>distribution_style</key>
<false/>
<key>identifier</key>
<string>com.github.sphen13.evo_host_file</string>
<key>install_location</key>
<string>/</string>
<key>name</key>
<string>evo_switch-${version}.pkg</string>
<key>ownership</key>
<string>recommended</string>
<key>postinstall_action</key>
<string>none</string>
<key>suppress_bundle_relocation</key>
<true/>
<key>version</key>
<string>1.0</string>
</dict>
</plist>
23 changes: 23 additions & 0 deletions evo host file/payload/Library/LaunchDaemons/evo-host.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>Disabled</key>
<false/>
<key>Label</key>
<string>evo-host</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Scripts/evo-host.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/etc/resolv.conf</string>
<string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist</string>
<string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
51 changes: 51 additions & 0 deletions evo host file/payload/Library/Scripts/evo-host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

ETC_HOSTS=/etc/hosts

SUBNET=192.168.40
IP=192.168.40.2
HOSTNAME=EVO

#--------

removehost() {
echo "removing host";
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
then
echo "$HOSTNAME Found in your $ETC_HOSTS, Removing now...";
sudo sed -i".bak" "/$HOSTNAME/d" $ETC_HOSTS
else
echo "$HOSTNAME was not found in your $ETC_HOSTS";
fi
}

addhost() {
echo "adding host";
HOSTS_LINE="$IP\t$HOSTNAME"
if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
then
echo "$HOSTNAME already exists : $(grep $HOSTNAME $ETC_HOSTS)"
else
echo "Adding $HOSTNAME to your $ETC_HOSTS";
sudo -- sh -c -e "echo '$HOSTS_LINE' >> /etc/hosts";

if [ -n "$(grep $HOSTNAME /etc/hosts)" ]
then
echo "$HOSTNAME was added succesfully \n $(grep $HOSTNAME /etc/hosts)";
else
echo "Failed to Add $HOSTNAME, Try again!";
fi
fi
}

subnetCheck=$(ifconfig | grep $SUBNET)

if [[ -z $subnetCheck || $subnetCheck == "" ]]; then
# not on edit network - remove host entry if present
removehost
else
# on edit network - make sure host entry is present
addhost
fi

exit 0
7 changes: 7 additions & 0 deletions evo host file/scripts/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# reload
launchctl unload -w /Library/LaunchDaemons/evo-host.plist
launchctl load -w /Library/LaunchDaemons/evo-host.plist

exit 0

0 comments on commit 8bfc6a0

Please sign in to comment.