]> git.saurik.com Git - apple/system_cmds.git/blob - zic.tproj/generate_zoneinfo.sh
system_cmds-735.tar.gz
[apple/system_cmds.git] / zic.tproj / generate_zoneinfo.sh
1 #!/bin/sh
2 set -e
3 set -x
4
5 printenv | sort
6
7 if [ $# -ne 5 ]; then
8 echo "Usage: $0 SRCROOT OBJROOT BUILT_PRODUCTS_DIR SDKROOT PLATFORM_NAME" 1>&2
9 exit 1
10 fi
11
12 SRCROOT="$1"
13 OBJROOT="$2"
14 BUILT_PRODUCTS_DIR="$3"
15 SDKROOT="$4"
16 PLATFORM_NAME="$5"
17
18 ZICHOST_SYMROOT="${BUILT_PRODUCTS_DIR}/zic_host-sym"
19 ZICHOST_DSTROOT="${BUILT_PRODUCTS_DIR}/zic_host-dst"
20 ZICHOST="${ZICHOST_DSTROOT}/zic_host"
21
22 LOCALTIME="US/Pacific"
23 POSIXRULES="US/Pacific"
24
25 ZONEINFO="${BUILT_PRODUCTS_DIR}/zoneinfo"
26 DATFILES="${BUILT_PRODUCTS_DIR}/datfiles"
27 PRIVATEDIR="${BUILT_PRODUCTS_DIR}/private"
28
29 # ftp://elsie.nci.nih.gov/pub/tzdata*.tar.gz
30 # the tzdata*.tar.gz file is automatically unpacked and a version file created
31 # /usr/local/share/tz/tzdata*.tar.gz is installed by the TimeZoneData project
32 TARBALL="${SDKROOT}"/usr/local/share/tz/latest_tzdata.tar.gz
33 if [ ! -L "$TARBALL" ]; then
34 echo "error: ${TARBALL} is not a symbolic link" 1>&2
35 exit 1
36 fi
37 if [ ! -r "$TARBALL" ]; then
38 echo "error: ${TARBALL} does not point to a valid file" 1>&2
39 exit 1
40 fi
41 DATVERS=`readlink ${TARBALL} | cut -d. -f1 | sed -e 's/^tzdata//'`
42 VERSIONFILE="${ZONEINFO}/+VERSION"
43
44 mkdir -p "${DATFILES}"
45 mkdir -p "${ZONEINFO}"
46 tar zxf "${TARBALL}" -C "${DATFILES}"
47 ZONE_FILES="$("${SRCROOT}"/zic.tproj/generate_zone_file_list.sh "${DATFILES}")"
48 for tz in ${ZONE_FILES}; do
49 if [ ${tz} = "northamerica" ]; then
50 ARG="-p America/New_York"
51 else
52 ARG=""
53 fi
54 "${ZICHOST}" ${ARG} -L /dev/null -d "${ZONEINFO}" \
55 -y "${DATFILES}/yearistype.sh" "${DATFILES}/${tz}" || exit 1
56 done
57
58 if [ $? -ne 0 ]; then
59 exit 1
60 fi
61
62 chmod -R og-w "${ZONEINFO}"
63 for f in "zone.tab" "iso3166.tab"; do
64 install -m 0444 "${DATFILES}/$f" "${ZONEINFO}/$f" || exit 1
65 done
66 if [ $? -ne 0 ]; then
67 exit 1
68 fi
69
70 if [ -n "$RC_BRIDGE" ]; then
71 ACTUAL_PLATFORM_NAME="bridge${PLATFORM_NAME#watch}"
72 else
73 ACTUAL_PLATFORM_NAME="${PLATFORM_NAME}"
74 fi
75
76 case "$ACTUAL_PLATFORM_NAME" in
77 iphone*|appletv*|watch*)
78 mkdir -p "${PRIVATEDIR}/var/db"
79 mkdir -p -m a+rx "${PRIVATEDIR}/var/db/timezone"
80
81 # This link must precisely start with TZDIR followed by a slash. radar:13532660
82 ln -hfs "/var/db/timezone/zoneinfo/${LOCALTIME}" "${PRIVATEDIR}/var/db/timezone/localtime"
83 ;;
84 macosx|bridge*)
85 mkdir -p "${PRIVATEDIR}/etc"
86 ln -hfs "/usr/share/zoneinfo/${LOCALTIME}" "${PRIVATEDIR}/etc/localtime"
87 ;;
88 *)
89 echo "Unsupported platform: $ACTUAL_PLATFORM_NAME"
90 exit 1
91 ;;
92 esac
93
94 rm -f "${VERSIONFILE}"
95 echo ${DATVERS} > "${VERSIONFILE}"
96 chmod 444 "${VERSIONFILE}"
97 touch "${ZONEINFO}"
98 touch "${PRIVATEDIR}"
99