@@ -162,7 +162,9 @@ def generate_profile(self) -> list[str]:
162162 def generate_init_main (self ) -> list [str ]:
163163 """
164164 Generates the main init file.
165- Just runs each hook in self.init_types and returns the output
165+ Just runs each hook in self.init_types and returns the output.
166+ These hooks include all init levels but init_pre and init_final.
167+ If a 'custom_init' function is defined, it will be used instead of this function.
166168 """
167169 out = []
168170 for init_type in self .init_types :
@@ -173,34 +175,34 @@ def generate_init_main(self) -> list[str]:
173175 def generate_init (self ) -> None :
174176 """ Generates the init file. """
175177 self .logger .info ("Running init generator functions" )
176-
177- init = [self ['shebang' ]]
178+ init = [self ['shebang' ]] # Add the shebang to the top of the init file
178179
179180 # Run all included functions, so they get included
180181 self .run_hook ('functions' , force_include = True )
181182
182- init .extend (self .run_init_hook ('init_pre' ))
183+ init .extend (self .run_init_hook ('init_pre' )) # Always run init_pre first
183184
185+ # If custom_init is used, create the init using that
184186 if self ['imports' ].get ('custom_init' ) and self .get ('_custom_init_file' ):
185187 init += ["\n # !!custom_init" ]
186188 init_line , custom_init = self ['imports' ]['custom_init' ](self )
187189 if isinstance (init_line , str ):
188190 init .append (init_line )
189191 else :
190192 init .extend (init_line )
191- else :
193+ else : # Otherwise, use the standard init generator
192194 init .extend (self .generate_init_main ())
193195
194- init .extend (self .run_init_hook ('init_final' ))
196+ init .extend (self .run_init_hook ('init_final' )) # Always run init_final last
195197 init += ["\n \n # END INIT" ]
196198
197- if self .included_functions :
199+ if self .included_functions : # There should always be included functions, if the base config is used
198200 self ._write ('/etc/profile' , self .generate_profile (), 0o755 )
199201 self .logger .info ("Included functions: %s" % ', ' .join (list (self .included_functions .keys ())))
200202 if self ['imports' ].get ('custom_init' ):
201203 custom_init .insert (2 , self .banner )
202204
203- if self .get ('_custom_init_file' ):
205+ if self .get ('_custom_init_file' ): # Write the custom init file if it exists
204206 self ._write (self ['_custom_init_file' ], custom_init , 0o755 )
205207
206208 self ._write ('init' , init , 0o755 )
0 commit comments