use MODULEDIR as reference for *.(order|builtin) files
mkinitcpio: separate logic to resolve kernel version

Rename get_kernelver -> resolve_kernelver, and ensure that it only does
what it's name advertises. Introduce find_moduledir to locate the
corresponding module directory in /usr/lib or /lib.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
document special kernel cmdline parameters

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
refactor error tracking in build hooks

Rather than catching errors solely from parse_hook via an ERR trap,
implement a RETURN trap which catches all errors from the core add_*
functions.

In the future, this may mean that support for MODULES/FILES/BINARIES
within hooks goes away, and those variables remain only in the config.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
mmc: package as mode 644, not 755

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
functions: remove get_dirname and get_basename

A lot has changed since 643e98eeb42677 when these functions were
implemented, and there is exactly 1 case of get_dirname left, and no
calls to get_basename. Remove these, and use a PE in place of the
remaining call.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
functions: move --try logic into add_module

Allow add_module to detect trailing ? characters for ignoring errors
rather than passing -t or --try to add_module.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
move -g option checking to parseopts loop

Avoid any delay in checking this option, as it only serves to fragment
the logic.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
functions: introduce add_checked_modules and add_all_modules

Instead of returning a list of modules which the caller should then add
themselves or stuff into the MODULES string, call add_module for each
candidate. This is basically a different wrapper around all_modules.

DEPRECATION WARNING: This commit marks checked_modules as deprecated.
Although it is not slated to go away, direct usage of all_modules is
strongly discouraged.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
functions: introduce add_runscript

This function adds a runtime script to the /hooks directory on the
initramfs image. Note that this function will also install hooks with
executable permissions for use by a later change to early init.

With this commit, there are now methods available which can be used in
place of the MODULES, FILES, BINARIES, and SCRIPT variables, as we now
offer error checking on the add_* functions. Usage of the variables is
deprecated, and these will no longer be read in a future version of
mkinitcpio.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
use new API for install hooks

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
init: correct trimming of earlymodules and MODULES

This never worked properly and only "fixed" the stupid bug that found
an edge case when either of these vars contains nothing more than a
single space.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
init_functions: move running hooks to separate func

Abstract this out to the init_functions file, and allow this function
take 2+ parameters -- the hook name to be run, a user friendly short
description, and then the list of hook files to source from. While we're
at it, take advantage of the fact that hooks are now installed with
executable perms. If a hook isn't marked excutable, we skip it, thereby
removing our eval hack.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
init: add support for early, late and cleanup hooks

This adds support for three more rounds of hooks during early userspace.
Users can define a 'run_latehook' in their hook script similar to the
declaration of 'run_hook' (which continue to run at the same point in
execution). These are run in the same order as the original "early"
hooks shortly after root is mounted.

Additionally, 'run_cleanup' hook can be defined which will run right
after the late hooks. These scripts are executed after mounting root in
reverse order of how they're clared in mkinitcpio'c config.

These late running hooks should take care of things such as:

- mounting /usr (possibly encrypted)
- moving config to the real root (mostly for liveCDs)
- shutting down previously started daemons (e.g. udev or dropbear)

Finally, we add run_earlyhook which is run as soon as possible. There
will likely be only a few subscribers to this, but udev will certainly
be one of them, as it needs to be started as early as possible when
present, to avoid problems with firmware loading.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
shutdown: package as 644, install as 755

There's no need to keep this mildly dangerous script executable on the
filesystem.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
shutdown: convert to cleanup hook

Run this later in init where we can delete the modules from the ramfs
before copying the image over to /run/initramfs.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
buildsys: fix clean target

We don't ship compressed manpages, and this never touched lsinitcpio's
generated page.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
lsinitcpio: extract the image to a tempdir

We read the image a number of times. Extract the image to a temp
directory so we can just extract it once and use the filesystem to our
advantage. This requires a temp dir which we can nuke on an EXIT trap,
but the whole operation is sped is a bit, especially for larger images.

The real goal of this is to make examination of the hooks easier. Since
we now have multiple hook sets to contend with, dynamically tally up the
available functions in the hook files so we can iterate over specific
functions of interest in the output.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
lsinitcpio: add support for listing new hooks

The previous patch makes this quite simple, and we can easily catch
instances of run_earlyhook, run_latehook, and run_cleanuphook for
printing in the output.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
lsinitcpio: Always show extraction time

Even for uncompressed images, estimate the work being done to extract to
ramfs.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>