Created
April 8, 2013 17:54
-
-
Save abythell/5338916 to your computer and use it in GitHub Desktop.
Use gphoto2 to set the system time from a USB-attached camera. Handy for use on a Raspberry Pi which does not have a real-time clock or network connection for NTP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set system date using gphoto2 camera | |
# | |
# Make sure a root user is running this script | |
# | |
if [[ $EUID -ne 0 ]]; then | |
echo "Must run as root/sudo" | |
exit -1 | |
fi | |
# | |
# Get unix epoch from camera. Note, gphoto2 does not support timezones | |
# or daylight savings. The local system's timezone will be used, assuming | |
# the camera and the system are in the same zone. | |
# | |
DATETIME=`gphoto2 --get-config datetime` | |
if [ $? -ne 0 ]; then | |
exit 1 | |
fi | |
EPOCH=`echo "$DATETIME" | grep Current | awk '{print $2}'` | |
if [[ ! $EPOCH =~ [0-9]{10} ]]; then | |
echo "gphoto2 did not return a usable time." | |
exit 1 | |
fi | |
# | |
# Set current time | |
# | |
date -s @$EPOCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment