Skip to content

Commit 8d4a012

Browse files
committed
TimeZone API
1 parent 14c5076 commit 8d4a012

File tree

2 files changed

+525
-0
lines changed

2 files changed

+525
-0
lines changed

bin/v-get-sys-timezone

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# info: get system timezone
3+
# options: [FORMAT]
4+
#
5+
# The function to get system timezone
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
18+
19+
#----------------------------------------------------------#
20+
# Action #
21+
#----------------------------------------------------------#
22+
23+
# Checking timesonze on RHEL/CentOS
24+
if [ -f "/etc/sysconfig/clock" ]; then
25+
source /etc/sysconfig/clock
26+
27+
# Checking timezone on Debian/Ubuntu
28+
elif [ -f "/etc/timezone" ]; then
29+
ZONE=$(cat /etc/timezone)
30+
31+
# Checking symlynks
32+
elif [ -h /etc/localtime ]; then
33+
ZONE=$(readlink /etc/localtime | sed "s/\/usr\/share\/zoneinfo\///")
34+
35+
# Parsing zoneinfo (very slow)
36+
else
37+
checksum=$(md5sum /etc/localtime | cut -d' ' -f1)
38+
ZONE=$(find /usr/share/zoneinfo/ -type f -exec md5sum {} \; |\
39+
grep "^$checksum" | sed "s/.*\/usr\/share\/zoneinfo\///" | head -n 1)
40+
fi
41+
42+
echo $ZONE
43+
44+
45+
#----------------------------------------------------------#
46+
# Vesta #
47+
#----------------------------------------------------------#
48+
49+
exit

0 commit comments

Comments
 (0)