* During server startup, if config.c_default_cal_zone is an empty string, run a shell...
authorArt Cancro <ajc@citadel.org>
Sun, 18 Jan 2009 05:35:55 +0000 (05:35 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 18 Jan 2009 05:35:55 +0000 (05:35 +0000)
citadel/citadel_dirs.c
citadel/citadel_dirs.h
citadel/guesstimezone.sh [new file with mode: 0755]
citadel/modules/upgrade/serv_upgrade.c

index b6bfe57627956d1a8471bff74fc20018d024ee40..0b8e4019261ae409fd7415d1a1f5e2d99194caf1 100644 (file)
@@ -66,6 +66,7 @@ char file_crpt_file_csr[PATH_MAX]="";
 char file_crpt_file_cer[PATH_MAX]="";
 char file_chkpwd[PATH_MAX]="";
 char file_base64[PATH_MAX]="";
+char file_guesstimezone[PATH_MAX]="";
 char file_funambol_msg[PATH_MAX] = "";
 char file_dpsam_conf[PATH_MAX] = "";
 char file_dspam_log[PATH_MAX] = "";
@@ -228,6 +229,11 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
                 "%sbase64",
                 ctdl_utilbin_dir);
 
+       snprintf(file_guesstimezone,
+                sizeof file_guesstimezone,
+                "%sguesstimezone.sh",
+                ctdl_utilbin_dir);
+
        snprintf(file_dpsam_conf,
                 sizeof file_dpsam_conf,
                 "%sdspam.conf",
@@ -292,6 +298,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        DBG_PRINT(file_crpt_file_cer);
        DBG_PRINT(file_chkpwd);
        DBG_PRINT(file_base64);
+       DBG_PRINT(file_guesstimezone);
        DBG_PRINT(file_funambol_msg);
 }
 
index d8a9038fa520841ef9cfec7b6d0d3566f85a71c9..cebf4fb9183ed8f1cb78b464843bbbe786fb5c5a 100644 (file)
@@ -48,6 +48,7 @@ extern char file_crpt_file_csr[PATH_MAX];
 extern char file_crpt_file_cer[PATH_MAX];
 extern char file_chkpwd[PATH_MAX];
 extern char file_base64[PATH_MAX];
+extern char file_guesstimezone[PATH_MAX];
 extern char file_dpsam_conf[PATH_MAX];
 extern char file_dspam_log[PATH_MAX];
 
diff --git a/citadel/guesstimezone.sh b/citadel/guesstimezone.sh
new file mode 100755 (executable)
index 0000000..90493fd
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# guesstimezone.sh - an ugly hack of a script to try to guess the time
+# zone currently in use on the host system, and output its name.
+
+# Copyright (c) by Art Cancro
+
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 3 of the License, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 675 Mass Ave, Cambridge, MA 02139, USA. 
+
+md5sum </dev/null >/dev/null 2>/dev/null || exit 1
+       
+LOCALTIMESUM=`md5sum /etc/localtime | awk ' { print $1 } ' 2>/dev/null`
+find /usr/share/zoneinfo -type f -print | while read filename
+do
+       THISTIMESUM=`md5sum $filename | awk ' { print $1 } '`
+       if [ $LOCALTIMESUM = $THISTIMESUM ] ; then
+               echo $filename | cut -c21-
+               exit 0
+       fi
+done 2>/dev/null
+exit 2
index a173024b047e4d2bdb4b84ad59a6b363da081d97..0b09d9f57675f3c896742487db278f0710774bc5 100644 (file)
@@ -195,6 +195,27 @@ void convert_ctdluid_to_minusone(void) {
        return;
 }
 
+
+/*
+ * Attempt to guess the name of the time zone currently in use
+ * on the underlying host system.
+ */
+void guess_time_zone(void) {
+       FILE *fp;
+       char buf[PATH_MAX];
+
+       fp = popen(file_guesstimezone, "r");
+       if (fp) {
+               if (fgets(buf, sizeof buf, fp) && (strlen(buf) > 2)) {
+                       buf[strlen(buf)-1] = 0;
+                       safestrncpy(config.c_default_cal_zone, buf, sizeof config.c_default_cal_zone);
+                       CtdlLogPrintf(CTDL_INFO, "Configuring timezone: %s\n", config.c_default_cal_zone);
+               }
+               fclose(fp);
+       }
+}
+
+
 /*
  * Do various things to our configuration file
  */
@@ -230,6 +251,10 @@ void update_config(void) {
                config.c_xmpp_s2s_port = 5269;
        }
 
+       if (IsEmptyStr(config.c_default_cal_zone)) {
+               guess_time_zone();
+       }
+
        put_config();
 }