<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def install_genome(name, provider, version=None, genome_dir=None, localname=None, mask="soft", regex=None, invert_match=False, annotation=False):
 """ Install a genome. Parameters name : str Genome name provider : str Provider name version : str Version (only for Ensembl) genome_dir : str , optional Where to store the fasta files localname : str , optional Custom name for this genome. mask : str , optional Default is 'soft', specify 'hard' for hard masking. regex : str , optional Regular expression to select specific chromosome / scaffold names. invert_match : bool , optional Set to True to select all chromosomes that don't match the regex. annotation : bool , optional If set to True, download gene annotation in BED and GTF format. """

    if not genome_dir:
        genome_dir = config.get("genome_dir", None)
    if not genome_dir:
        raise norns.exceptions.ConfigError("Please provide or configure a genome_dir")
   
    genome_dir = os.path.expanduser(genome_dir)
    localname = get_localname(name, localname)
    
    # Download genome from provider
    p = ProviderBase.create(provider)
    p.download_genome(
        name, 
        genome_dir, 
        version=version,
        mask=mask, 
        localname=localname, 
        regex=regex, 
        invert_match=invert_match)

    if annotation:
        # Download annotation from provider
        p.download_annotation(name, genome_dir, localname=localname, version=version)

    g = Genome(localname, genome_dir=genome_dir)
    for plugin in get_active_plugins():
        plugin.after_genome_download(g)

    generate_env()