@@ -748,12 +748,34 @@ def phone_home(url):
748748 request = urllib .request .Request (url , data = payload , headers = {'content-type' : 'application/json' })
749749 response = urllib .request .urlopen (request )
750750
751+ def get_external_ip (* positionals , ** kwargs ):
752+ result = urllib .request .urlopen ("https://hvornum.se/ip/?f=json" ).read ().decode ('UTF-8' )
753+ return json .loads (result )['ip' ]
754+
755+ def guess_country (ip , * positionals , ** kwargs ):
756+ # python-pygeoip
757+ # geoip-database
758+ result = None
759+ GEOIP_DB = '/usr/share/GeoIP/GeoIP.dat'
760+ if os .path .isfile (GEOIP_DB ):
761+ try :
762+ import pygeoip
763+ except :
764+ ## TODO: Do a best-effort-guess based off the hostname given off the IP instead, if GoeIP doesn't exist.
765+ return result
766+
767+ gi = pygeoip .GeoIP (GEOIP_DB )
768+ result = gi .country_code_by_addr (ip )
769+ else :
770+ log (f'Missing GeoIP database: { GEOIP_DB } ' , origin = 'guess_country' , level = LOG_LEVELS .ERROR )
771+ return result
772+
751773def setup_args_defaults (args , interactive = True ):
752774 if not 'size' in args : args ['size' ] = '100%'
775+ if not 'mirrors' in args : args ['mirrors' ] = True
753776 if not 'start' in args : args ['start' ] = '513MiB'
754777 if not 'pwfile' in args : args ['pwfile' ] = '/tmp/diskpw'
755778 if not 'hostname' in args : args ['hostname' ] = 'Archinstall'
756- if not 'country' in args : args ['country' ] = 'SE' # 'all' if we don't want country specific mirrors.
757779 if not 'packages' in args : args ['packages' ] = '' # extra packages other than default
758780 if not 'post' in args : args ['post' ] = 'reboot'
759781 if not 'password' in args : args ['password' ] = '0000' # Default disk passord, can be <STDIN> or a fixed string
@@ -764,7 +786,6 @@ def setup_args_defaults(args, interactive=True):
764786 if not 'aur-keep' in args : args ['aur-keep' ] = False
765787 if not 'aur-support' in args : args ['aur-support' ] = True # Support adds yay (https://github.com/Jguer/yay) in installation steps.
766788 if not 'ignore-rerun' in args : args ['ignore-rerun' ] = False
767- if not 'localtime' in args : args ['localtime' ] = 'Europe/Stockholm' if args ['country' ] == 'SE' else 'GMT+0' # TODO: Arbitrary for now
768789 if not 'phone-home' in args : args ['phone-home' ] = False
769790 if not 'drive' in args :
770791 if interactive and len (harddrives ):
@@ -793,6 +814,16 @@ def setup_args_defaults(args, interactive=True):
793814 exit (1 )
794815
795816 args ['drive' ] = drive
817+
818+ # Setup locales if we didn't get one.
819+ if not 'country' in args :
820+ country = None
821+ if get_default_gateway_linux ():
822+ ip = get_external_ip ()
823+ country = guess_country (ip )
824+ args ['country' ] = 'all' if not country else country
825+ if not 'localtime' in args : args ['localtime' ] = 'Europe/Stockholm' if args ['country' ] == 'SE' else 'GMT+0' # TODO: Arbitrary for now
826+
796827 return args
797828
798829def load_automatic_instructions (* positionals , ** kwargs ):
@@ -1148,7 +1179,7 @@ def run_post_install_steps(*positionals, **kwargs):
11481179 format_disk ('drive' , start = 'start' , end = 'size' )
11491180
11501181 refresh_partition_list ('drive' )
1151- print (f'Partitions: (Boot: { list (args ["partitions" ].keys ())[0 ]} )' )
1182+ print (f'[N] Partitions: { len ( args [ "partitions" ]) } (Boot: { list (args ["partitions" ].keys ())[0 ]} )' )
11521183
11531184 if len (args ['partitions' ]) <= 0 :
11541185 print (f'[E] No partitions were created on { args ["drive" ]} ' , o )
@@ -1180,7 +1211,7 @@ def run_post_install_steps(*positionals, **kwargs):
11801211
11811212 if 'mirrors' in args and args ['mirrors' ] and 'country' in args and get_default_gateway_linux ():
11821213 print ('[N] Reordering mirrors.' )
1183- filter_mirrors_by_country_list ([ args ['country' ] ])
1214+ filter_mirrors_by_country_list (args ['country' ])
11841215
11851216 pre_conf = {}
11861217 if 'pre' in instructions :
0 commit comments