Check-in [6de4ee9075]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

SHA1 Hash:6de4ee9075be8dd1204cc26ad46f9bef13906f44
Date: 2012-06-29 01:09:10
User: BarryK
Comment:if no hw clock, set date to something reasonable, also save at shutdown

Tags And Properties
Changes

Changes to woof-code/rootfs-skeleton/etc/rc.d/rc.country

@@ -1,10 +1,11 @@
 #!/bin/sh
 #(c) Copyright 2012 Barry Kauler
 #2012 GPL licence v3 (refer: /usr/share/doc/legal)
 #120328 rewrite script.
 #120627 use keymaps from kbd pkg if present.
+#120629 raspberry pi does not have a hw clock, set date to reasonable value.
 
 . /etc/rc.d/PUPSTATE
 . /etc/DISTRO_SPECS #has DISTRO_XORG_AUTO
 STATUS=0
 . /etc/clock
@@ -166,30 +167,43 @@
  fi
 fi
 ######end locale section######
 
 ######clock section######
-if [ "$ASKCLOCK" = "yes" ];then
- /usr/sbin/timezone-set cli > /dev/console
- #choose hardware clock set to local or UTC...
- dialog --title "Set hardware-clock type" --yes-label "Local" --no-label "UTC" --yesno "Is the hardware clock on the computer set to the local time, or to UTC? Note, most PCs with Windows installed have the hardware clock set to the local time, so if in doubt choose that..." 0 0 > /dev/console
- if [ $? -eq 1 ];then #UTC
-  HWCLOCKTIME='utc'
-  hwPATTERN="s/^HWCLOCKTIME=[^#]*/HWCLOCKTIME='utc'/"
-  sed -i "$hwPATTERN" /etc/clock #note, it is default 'localtime'.
+#120629 raspberry pi does not have a hw clock, set date to reasonable value...
+HWDATE="`hwclock --show 2>/dev/null`" #ex: "Fri 29 Jun 2012 07:45:28 AM WST  -0.725833 seconds"
+if [ "$HWDATE" = "" ];then
+ if [ -f /var/local/shutdown_date_saved ];then #see /etc/rc.d/rc.shutdown
+  date -s "`cat /var/local/shutdown_date_saved`"
+ else
+  #either of these formats can set the date: "29 JUN 2012 10:00:00" "2012-06-28 16:20:08"
+  HWDATE="`stat --format=%z /etc/DISTRO_SPECS | cut -f 1 -d '.' | cut -f 1,2 -d ' '`" #creation date of build. ex: "2012-06-28 16:20:08"
+  date -s "$HWDATE"
+  [ ! -e /etc/localtime ] && ln -s /usr/share/zoneinfo/Australia/Perth /etc/localtime
+ fi
+else
+ if [ "$ASKCLOCK" = "yes" ];then
+  /usr/sbin/timezone-set cli > /dev/console
+  #choose hardware clock set to local or UTC...
+  dialog --title "Set hardware-clock type" --yes-label "Local" --no-label "UTC" --yesno "Is the hardware clock on the computer set to the local time, or to UTC? Note, most PCs with Windows installed have the hardware clock set to the local time, so if in doubt choose that..." 0 0 > /dev/console
+  if [ $? -eq 1 ];then #UTC
+   HWCLOCKTIME='utc'
+   hwPATTERN="s/^HWCLOCKTIME=[^#]*/HWCLOCKTIME='utc'/"
+   sed -i "$hwPATTERN" /etc/clock #note, it is default 'localtime'.
+  fi
  fi
-fi
-[ ! -e /etc/localtime ] && ln -s /usr/share/zoneinfo/Australia/Perth /etc/localtime
-#Ref: http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html
-TZ=$(readlink /etc/localtime|sed -e 's,/usr/share/zoneinfo/,,' -e 's,Etc/,,') #shinobar
-export TZ
-HWCLOCKTIME="localtime"
-[ -s /etc/clock ] && grep -qw '^[^#]*utc' /etc/clock && HWCLOCKTIME="utc" #shinobar
-#need to set Linux system time/date, from hardware clock...
-#hwclock --hctosys --localtime
-hwclock --hctosys --${HWCLOCKTIME}
-#...--hctosys reads cmos clock to system.
-#...--localtime means that cmos clock is set to local-time.
+ [ ! -e /etc/localtime ] && ln -s /usr/share/zoneinfo/Australia/Perth /etc/localtime
+ #Ref: http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html
+ TZ=$(readlink /etc/localtime|sed -e 's,/usr/share/zoneinfo/,,' -e 's,Etc/,,') #shinobar
+ export TZ
+ HWCLOCKTIME="localtime"
+ [ -s /etc/clock ] && grep -qw '^[^#]*utc' /etc/clock && HWCLOCKTIME="utc" #shinobar
+ #need to set Linux system time/date, from hardware clock...
+ #hwclock --hctosys --localtime
+ hwclock --hctosys --${HWCLOCKTIME}
+ #...--hctosys reads cmos clock to system.
+ #...--localtime means that cmos clock is set to local-time.
+fi
 ######end clock section######
 
 exit $STATUS
 ###END###

Changes to woof-code/rootfs-skeleton/etc/rc.d/rc.shutdown

@@ -68,10 +68,11 @@
 #120427 01micko: support ext4 save-file.
 #120514 WARNING: i don't have this problem, as no longer deleting /tmp/* (120409), however Karl Godt reported that 'fuser -k -m' may kill rc.shutdown then if no /tmp/bootcnt.txt then X restarts, ref: http://bkhome.org/blog/?viewDetailed=02827
 #120514 Karl Godt: 1st shutdown: test save-file mounted rw, not ro. 120522 removed.
 #120514 shinobar: avoid killing this script.
 #120522 precise puppy with aufs, have two dirs .wh..wh.orph, .wh..wh.plnk, in /initrd/pup_rw, filter out.
+#120629 raspberry pi does not have a hw clock. save date here, read at bootup (see rc.country).
 
 #110923
 . /usr/bin/gettext.sh # enables use of eval_gettext (several named variables) and ngettext (plurals)
 export TEXTDOMAIN=rc.shutdown
 export OUTPUT_CHARSET=UTF-8
@@ -507,10 +508,13 @@
   ;;
 esac
 
 
 cp -f /etc/profile /var/local/etc_profile_at_shutdown #110217 bad hack, see /etc/rc.d/rc.update.
+#120629 raspberry pi does not have a hw clock. save here, read at bootup (see rc.country)...
+DATESAVE="`date -R | cut -f 2-5 -d ' ' | cut -f 1 -d '.' | tr '[a-z]' '[A-Z]'`" #ex: 29 JUN 2012 08:39:07
+echo -n "$DATESAVE" > /var/local/shutdown_date_saved
 
 #when the working files run in tmpfs in ram, they are saved above and /tmp and /var
 #are screened out. however, some PUPMODES mount ${DISTRO_FILE_PREFIX}save.2fs directly on /initrd/pup_rw,
 #the top unionfs layer, meaning that there is no intermediary tmpfs in ram for working
 #files, hence everything is saved directly, ditto for PUPMODE=2 a full h.d. install.