55
66from ugrd .initramfs_dict import InitramfsConfigDict
77
8- from importlib .metadata import version
9-
108from .generator_helpers import GeneratorHelpers
119
12- __version__ = version (__package__ )
1310__author__ = "desultory"
1411
1512
1613@loggify
1714class InitramfsGenerator (GeneratorHelpers ):
1815 def __init__ (self , config = '/etc/ugrd/config.toml' , * args , ** kwargs ):
1916 self .config_filename = config
20- self .config_dict = InitramfsConfigDict (logger = self .logger )
17+ self .config_dict = InitramfsConfigDict (NO_BASE = kwargs . pop ( 'NO_BASE' , False ), logger = self .logger )
2118
2219 # Used for functions that are added to the bash source file
2320 self .included_functions = {}
@@ -28,8 +25,11 @@ def __init__(self, config='/etc/ugrd/config.toml', *args, **kwargs):
2825 # init_pre and init_final are run as part of generate_initramfs_main
2926 self .init_types = ['init_debug' , 'init_early' , 'init_main' , 'init_late' , 'init_premount' , 'init_mount' , 'init_mount_late' , 'init_cleanup' ]
3027
31- self .load_config ()
3228 self .config_dict .import_args (kwargs )
29+ if config :
30+ self .load_config ()
31+ else :
32+ self .logger .warning ("No config file specified, using the base config" )
3333 self .config_dict .validate ()
3434
3535 def load_config (self ) -> None :
@@ -127,11 +127,14 @@ def run_init_hook(self, level: str) -> list[str]:
127127 return out
128128 else :
129129 self .logger .debug ("No output for init level: %s" % level )
130+ return []
130131
131132 def generate_profile (self ) -> None :
132133 """ Generates the bash profile file based on self.included_functions. """
133- out = [self ['shebang' ],
134- f"#\n # Generated by UGRD v{ __version__ } " ]
134+ from importlib .metadata import version
135+ ver = version (__package__ ) or 9999 # Version won't be found unless the package is installed
136+ out = [self ['shebang' ].split (' ' )[0 ], # Don't add arguments to the shebang (for the profile)
137+ f"#\n # Generated by UGRD v{ ver } \n #" ]
135138
136139 # Add the library paths
137140 library_paths = ":" .join (self ['library_paths' ])
@@ -172,7 +175,7 @@ def generate_init(self) -> None:
172175 self .run_hook ('functions' , force_include = True )
173176
174177 init .extend (self .run_init_hook ('init_pre' ))
175- init += [f'einfo "Starting UGRD v { __version__ } "' ]
178+ init += [self . banner ]
176179
177180 if self ['imports' ].get ('custom_init' ) and self .get ('_custom_init_file' ):
178181 init += ["\n # !!custom_init" ]
@@ -191,7 +194,7 @@ def generate_init(self) -> None:
191194 self ._write ('/etc/profile' , self .generate_profile (), 0o755 )
192195 self .logger .info ("Included functions: %s" % ', ' .join (list (self .included_functions .keys ())))
193196 if self ['imports' ].get ('custom_init' ):
194- custom_init .insert (2 , f"einfo 'Starting custom init, UGRD v { __version__ } '" )
197+ custom_init .insert (2 , self . banner )
195198
196199 if self .get ('_custom_init_file' ):
197200 self ._write (self ['_custom_init_file' ], custom_init , 0o755 )
0 commit comments