Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script was designed to keep time for Laptop's running *NIX systems with dead CMOS batteries
- # Specfically Mac OSX but it can be adapted to other *NIX Systems, use a launch daemon to run on osx
- #Written By:
- #Geofferey A. Eakins
- #Set up directories & create .conf file
- if [ $(find /usr/share/fixes | wc -l ) -eq 0 ]; then
- echo "";
- echo "Setting up directories & creating .conf file...";
- sleep 1;
- mkdir -p /usr/share/fixes/time;
- cp ./set-time /usr/share/fixes/time;
- cp ./com.geofferey.keeptime.plist /Library/LaunchDaemons/com.geofferey.keeptime.plist;
- chmod 0755 /usr/share/fixes/time/set-time;
- ln -s /usr/share/fixes/time/set-time /usr/bin/set-time;
- chmod 0644 /Library/LaunchDaemons/com.geofferey.keeptime.plist;
- fi
- if [ $(find /usr/share/fixes/time -name time.conf | wc -l) -eq 0 ]; then
- touch /usr/share/fixes/time/time.conf;
- echo "SAVEDTIME=" >> /usr/share/fixes/time/time.conf
- fi
- #Use variables from .conf file
- . /usr/share/fixes/time/time.conf
- #Variables
- DATE=$(date +%m%d%H%M%Y)
- YEAR=$(date +%Y)
- #Check year & set time from variable in .conf file
- echo ""
- echo "Checking year and setting date/time if reset..."
- sleep 1
- [ $YEAR -lt 2014 ] && date $SAVEDTIME
- #Check for active connection to internet & continue script if pass or fails
- echo ""
- echo "Checking for active internet connection before continuing..."
- sleep 1
- for i in {1..1000};
- do ping -c1 www.google.com > /dev/null 2> /dev/null && break;
- done
- #Update time via ntp server
- echo ""
- echo "Updating time via ntp server..."
- sleep 1
- ntpdate -u $(systemsetup -getnetworktimeserver|awk '{print $4}') > /dev/null 2> /dev/null
- #Save time to variable in .conf file if year is greater than 2001
- echo ""
- echo "Saving date & time to file..."
- sleep 1
- if [ $YEAR -gt 2001 ] ; then
- sed -i -e "s/^SAVEDTIME=.*/SAVEDTIME=$DATE/" /usr/share/fixes/time/time.conf &&
- rm /usr/share/fixes/time/time.conf-e
- fi
- echo ""
- sleep 1
- echo "Done!"
- echo ""
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement