3 ### Common utilities for rsync-backup scripts
5 ### (c) 2014 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the `rsync-backup' program.
12 ### rsync-backup is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### rsync-backup is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with rsync-backup; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ###--------------------------------------------------------------------------
30 pkgdatadir
=@pkgdatadir@
34 conf
=@sysconfdir@
/rsync-backup.conf
36 INDEXDB
=@pkglocalstatedir@
/index.db
38 SNAPDIR
=$mntbkpdir/snap
39 STOREDIR
=$mntbkpdir/store
40 METADIR
=$mntbkpdir/meta
46 mntbkpdir = $mntbkpdir
47 fshashdir = $fshashdir
52 ###--------------------------------------------------------------------------
57 ## Parse an ISO8601 DATE, and set YEAR, MONTH, DAY appropriately (and
58 ## without leading zeros).
60 ## Extract the components of the date and trim leading zeros (which will
61 ## cause things to be interpreted as octal and fail).
62 year
=${date%%-*} rest
=${date#*-}; month
=${rest%%-*} day
=${rest#*-}
63 year
=${year#0} month
=${month#0} day
=${day#0}
68 ## Convert an ISO8601 DATE to a Julian Day Number.
72 ## The actual calculation: convert a (proleptic) Gregorian calendar date
73 ## into a Julian day number. This is taken from Wikipedia's page
74 ## http://en.wikipedia.org/wiki/Julian_day#Calculation but the commentary
75 ## is mine. The epoch is 4713BC-01-01 (proleptic) Julian, or 4714BC-11-24
76 ## proleptic Gregorian.
78 ## If the MONTH is January or February then set a = 1, otherwise set a = 0.
79 a
=$
(( (14 - $month)/12 ))
81 ## Compute a year offset relative to 4799BC-03-01. This puts the leap day
82 ## as the very last day in a year, which is very convenient. The offset
83 ## here is sufficient to make all y values positive (within the range of
84 ## the JDN calendar), and is a multiple of 400, which is the Gregorian
86 y
=$
(( $year + 4800 - $a ))
88 ## Compute the offset month number in that year. These months count from
90 m
=$
(( $month + 12*$a - 3 ))
92 ## Now for the main event. The (153 m + 2)/5 term is a surprising but
93 ## correct trick for obtaining the number of days in the first m months of
94 ## the (shifted) year). The magic offset 32045 is what you get when you
95 ## plug the proper JDN epoch (year = -4713, month = 11, day = 24) into the
97 jdn
=$
(( $day + (153*$m + 2)/5 + 365*$y + $y/4 - $y/100 + $y/400 - 32045 ))
102 ###----- That's all, folks --------------------------------------------------