index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Anton Hvornum <anton.feeds+github@gmail.com> | 2019-11-27 22:16:06 +0000 |
---|---|---|
committer | Anton Hvornum <anton.feeds+github@gmail.com> | 2019-11-27 22:16:06 +0000 |
commit | 198ba06c2749bae8f1e35a6e69a6ddf50708a17d (patch) | |
tree | b02b5b43b3bb617dfaed10d386ea5a4fc4cdaedf /archinstall.py | |
parent | 434daeae6840c123cc8c8c3f6feb6f0e8ea50b8a (diff) |
-rw-r--r-- | archinstall.py | 32 |
diff --git a/archinstall.py b/archinstall.py index 38856973..e2d8f945 100644 --- a/archinstall.py +++ b/archinstall.py @@ -748,12 +748,32 @@ def phone_home(url): request = urllib.request.Request(url, data=payload, headers={'content-type': 'application/json'}) response = urllib.request.urlopen(request) +def get_external_ip(*positionals, **kwargs): + result = urllib.request.urlopen("https://hvornum.se/ip/?f=json").read().decode('UTF-8') + return json.loads(result)['ip'] + +def guess_country(*positionals, **kwargs): + # python-pygeoip + # geoip-database + result = None + GEOIP_DB = '/usr/share/GeoIP/GeoIP.dat' + if os.path.isfile(GEOIP_DB): + try: + import pygeoip + except: + return result + + gi = pygeoip.GeoIP(GEOIP_DB) + result = gi.country_name_by_addr(ip) + else: + log(f'Missing GeoIP database: {GEOIP_DB}', origin='guess_country', level=LOG_LEVELS.ERROR) + return result + def setup_args_defaults(args, interactive=True): if not 'size' in args: args['size'] = '100%' if not 'start' in args: args['start'] = '513MiB' if not 'pwfile' in args: args['pwfile'] = '/tmp/diskpw' if not 'hostname' in args: args['hostname'] = 'Archinstall' - if not 'country' in args: args['country'] = 'SE' # 'all' if we don't want country specific mirrors. if not 'packages' in args: args['packages'] = '' # extra packages other than default if not 'post' in args: args['post'] = 'reboot' if not 'password' in args: args['password'] = '0000' # Default disk passord, can be <STDIN> or a fixed string @@ -764,7 +784,6 @@ def setup_args_defaults(args, interactive=True): if not 'aur-keep' in args: args['aur-keep'] = False if not 'aur-support' in args: args['aur-support'] = True # Support adds yay (https://github.com/Jguer/yay) in installation steps. if not 'ignore-rerun' in args: args['ignore-rerun'] = False - if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now if not 'phone-home' in args: args['phone-home'] = False if not 'drive' in args: if interactive and len(harddrives): @@ -793,6 +812,15 @@ def setup_args_defaults(args, interactive=True): exit(1) args['drive'] = drive + + # Setup locales if we didn't get one. + if not 'country' in args: + country = None + if get_default_gateway_linux(): + country = guess_country(get_external_ip()) + args['country'] = 'all' if not country else country + if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now + return args def load_automatic_instructions(*positionals, **kwargs): |