diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-12-26 14:01:40 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-12-26 14:05:52 +0100 |
commit | 8532f668f70c3c0c3f3a6dc5d6cddcd73b7023e1 (patch) | |
tree | f21367d697c541c65b43e5fdb9b25e4cb8302121 /src/migration-scripts/system | |
parent | bc36bb5a9db4143696b96ab74eee40539de3541d (diff) | |
download | vyos-1x-8532f668f70c3c0c3f3a6dc5d6cddcd73b7023e1.tar.gz vyos-1x-8532f668f70c3c0c3f3a6dc5d6cddcd73b7023e1.zip |
time-zone: T1906: migrate unknown timezones to UTC
If - for whatever reason - a timezone specified is invalid ... migrate it to
UTC, just in case!
Diffstat (limited to 'src/migration-scripts/system')
-rwxr-xr-x | src/migration-scripts/system/12-to-13 | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/migration-scripts/system/12-to-13 b/src/migration-scripts/system/12-to-13 index deb17e44a..5f7413d46 100755 --- a/src/migration-scripts/system/12-to-13 +++ b/src/migration-scripts/system/12-to-13 @@ -1,15 +1,23 @@ #!/usr/bin/env python3 -# Fixup non existent time-zones. Some systems have time-zone set to: -# - Los* (Los_Angeles) -# - Den* (Denver) -# ... but thos are no real IANA assigned time zones. In the past the have been -# silently remapped. Time to clean it up! +# Fixup non existent time-zones. Some systems have time-zone set to: Los* +# (Los_Angeles), Den* (Denver), New* (New_York) ... but those are no real IANA +# assigned time zones. In the past they have been silently remapped. +# +# Time to clean it up! +# +# Migrate all configured timezones to real IANA assigned timezones! import re import sys from vyos.configtree import ConfigTree +from subprocess import Popen, PIPE, STDOUT + +def _cmd(cmd): + p = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True) + tmp = p.communicate()[0].strip() + return tmp.decode() if (len(sys.argv) < 1): print("Must specify file name!") @@ -28,6 +36,10 @@ if not config.exists(tz_base): else: tz = config.return_value(tz_base) + # retrieve all valid timezones + tz_data = _cmd('find /usr/share/zoneinfo/posix -type f -or -type l | sed -e s:/usr/share/zoneinfo/posix/::') + tz_data = tz_data.split('\n') + if re.match(r'[Ll][Oo][Ss].+', tz): tz = 'America/Los_Angeles' elif re.match(r'[Dd][Ee][Nn].+', tz): @@ -44,6 +56,9 @@ else: tz = 'America/Phoenix' elif re.match(r'GMT(.+)?', tz): tz = 'Etc/' + tz + elif tz not in tz_data: + # assign default UTC timezone + tz = 'UTC' # replace timezone data is required config.set(tz_base, value=tz) |