summaryrefslogtreecommitdiffstats
path: root/functions
AgeCommit message (Collapse)AuthorFilesLines
2012-10-21function: add a map() utility function0.11.0Dave Reisner1-24/+15
map() runs the first argument (a function) with each of the remaining arguments as $1. The return value of map() is only 0 if all the calls succeeded. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-10-21convert autodetect cache to hashDave Reisner1-4/+4
If mkinitcpio -s is run, we still flush this cache to disk before exiting. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-10-21functions: trim path of resolved symlinkDave Reisner1-1/+1
When reporting that a hook is deprecated, only show the hook name, not the full resolved path. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-10-07commit to some level of style in variable namingDave Reisner1-46/+46
This is an ugly patch, and probably does more than I'd like it to. The idea is that mkinitcpio adopts some sort of consistent style which I'm actually happy with. I define 3 kinds of variables: 1) local variables: all lower case, and scoped within functions. Use freely, as they're well contained. 2) global variables: these are known to mkinitcpio internally, but are global in scope. They mainly carry runtime configuration and collected data during the image generation process. These are always lower case, but carry a leading underscore to denote that they're global. 3) "API" variables: also global in scope, but exist "outside" of mkinitcpio -- either drawn in from the configuration file, or "exported" to the install hooks. These are always all upper case. When introducing new variables, extreme care must be taken to pick names that will not conflict with the environment inherited by mkinitcpio. A HACKING file is introduced with a similar description of the above, and more. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-09-30functions: avoid fully resolving soname symlinksDave Reisner1-4/+2
It's okay to fully resolve the symlink to add the regular file it points to, but avoid mangling the symlink name to try and preserve relative links. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-09-30functions: include image config on image itselfDave Reisner1-7/+6
For the purposes of accounting and debugging, it's nice to have this around. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-09-30functions: always treat ADDED_MODULES as a hashDave Reisner1-4/+4
Overlooked in b8d9c5cd2753e9. This change also assigns a value of "2" to builtin modules which are added to the the ADDED_MODULES array, to distinguish them from actual modules on disk. Using this, we can avoid adding builtins to the image's runtime config. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-09-17declare ADDED_MODULES as associative arrayDave Reisner1-2/+2
Lookups in the hash table are far faster than traversing the entire array, as this grows O(n) and introduces a particularly noticeable slowdown on larger images. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-09-17functions: allow add_symlink to only take a single argDave Reisner1-7/+18
In the case of a single arg, use readlink(1) to resolve the target of the symlink. Document this, and additionally note the lack of guarantee about the target of the symlink. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-09-17install fstab/mtab as part of base layoutDave Reisner1-0/+4
These are low level enough that they should be part of the base layout, similar to the filesystem package in userspace. Later hooks can easily override these, if they really want to. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-08-19functions: avoid creating /usr/sbinDave Reisner1-1/+1
Booo. This broke my boot. Should never have been added in f3638aaa0937. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-08-13functions: symlink /usr/local/sbin -> /usr/binDave Reisner1-1/+2
This was overlooked in 5f81d06e8b87. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-07-28implement --moduleroot optionDave Reisner1-2/+2
This might be useful for creating an initramfs image as part of a kernel package. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-07-24baseroot: add flagfile to indicate we're in an initramfsTom Gundersen1-1/+4
This is used by udev to deal with firmware requests for firmware that is not available until the real root. It will also be used by systemd to detect what to do, if that is ever used. ref: http://www.spinics.net/lists/linux-wireless/msg94522.html Signed-off-by: Tom Gundersen <teg@jklm.no>
2012-07-15initalize buildroot later, and out outside of hooksDave Reisner1-0/+26
mkinitcpio needs to be able to more tightly control the layout of the image. By moving this outside the control of the base hook, it's more reasonable to believe that a drop-in replacement for the base hook could be written, as it now only contains the utilities required for the /init that it provides. Being that initialize_buildroot is outside of a hook, we can make "raw" calls to coreutils that create the directories and symlinks, saving some overhead and forking. This also symlinks /usr/local/{lib,bin} into the common /usr/lib and /usr/bin, respectively, so that there's always a way to override libs and bins, and they're automatically pulled into our strict early init path of /usr/bin. Finally, we lump all this generally a little "later" in the early setup. This addresses an unseen "bug" wherein an extra temp directory that never gets used is created when leveraging a preset. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-12Update module filter to be aware of hyphens in the MODULES arrayBrian Parsons1-1/+1
[dave: fix whitespace and re-add needed quoting] Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-08Use declare -f over type -t to avoid subshellsDave Reisner1-1/+1
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-08functions: avoid adding nonexistant modules to configDave Reisner1-2/+6
If we didn't actually add a module to the image, avoid adding it to the runtime config for probing. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-08functions: style nitsDave Reisner1-3/+11
Avoid using compound commands where one side runs a command group. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-05explicitly unset build function before sourcingDave Reisner1-0/+1
This fixes an unlikely (and likely unseen) regression from 9a20048c6279cd. Without unsetting the build function before sourcing the hook file, we can't guarantee that we're running the build function tied to that specific file. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-02catch errors in ldd ELF dep resolutionDave Reisner1-1/+7
ldd reporting a library to be 'not found' is dangerous, and should be reported. Consider this a build error, which will hopefully prompt the user to reconsider before rebooting. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-01add hookpoints to --hookhelp outputDave Reisner1-6/+24
Generalize the awk program embedded in add_runscript and create a separate function which can be reused to display the specific hooks that a script has. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-01move running of hooks to separate functionDave Reisner1-0/+37
This allows us to declare sourced variables that we want to shield from stomping on our config variables, and without needing to use a subshell. Incidentally, this also fixes FS#29992 in a more permanent way. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-30add_full_dir: properly handle symlinks and empty dirsDave Reisner1-2/+5
Note that we're intentionally very liberal about what we accept for symlinks, and don't actually care if the target exists. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-18mkinitcpio: write image config after install hooksDave Reisner1-0/+20
Break this out of install/base into a separate function. We need to be able to read from the RUNHOOKS array to accurately specify which hooks to execute at runtime. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-18use new API for install hooksDave Reisner1-1/+1
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-18functions: introduce add_runscriptDave Reisner1-4/+44
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. This commit also lays the groundwork for the addition of more early userspace hooks. Runtime hook files are parsed for specific functions and variables (not yet used) are populated. These will eventually be written to the image config so that early userspace knows exactly what to run. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-16functions: introduce add_checked_modules and add_all_modulesDave Reisner1-2/+50
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>
2012-05-16functions: move --try logic into add_moduleDave Reisner1-13/+16
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>
2012-05-16functions: remove get_dirname and get_basenameDave Reisner1-13/+1
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>
2012-05-16refactor error tracking in build hooksDave Reisner1-2/+7
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>
2012-05-12remove unnecessary quoting/bracingDave Reisner1-4/+4
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-12functions: merge _add_symlink into add_symlinkDave Reisner1-19/+11
This frontend/backend split is no longer necessary without the notion of a basedir. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-12functions: merge _add_file into add_fileDave Reisner1-28/+16
This frontend/backend split is no longer necessary without the notion of a basedir. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-12function: merge _add_dir into add_dirDave Reisner1-17/+9
This frontend/backend split is no longer necessary without the notion of a basedir. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-12mkinitcpio: remove --basedir optionDave Reisner1-34/+14
This option is just a bad idea. Initramfs creation is too important to get wrong, and running it from outside the root FS has too many gotchas, the worst of them being: - where do you pull hooks from? - how do you resolve binary dependencies within the root? In general, dealing with the extra luggage of the base directory makes the codebase more complicated than it needs to be (see all the '_' prefixed functions which are called from add functions). In favor of simplifying the code, and making it more maintainable, kill this off and force the sane option of chroot'ing into an install if the need arises. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-03functions: firmware is now in /usr/libMatthew Monaco1-2/+2
2012-04-22functions: align error output with GNU getopt_longDave Reisner1-8/+7
Display the name of the program. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-04-22functions: add missing local for iteratorDave Reisner1-0/+2
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-04-20functions: add parseopts for longopt funDave Reisner1-0/+138
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-03-04add support for HOOKDIR/INSTDIR as arraysDave Reisner1-2/+16
This is a really ugly patch, but allows mkinitcpio to read hooks from multiple locations, namely: /usr/lib/initcpio/{install,hooks} /lib/initcpio/{install,hooks} Preference is given to the first, and all files included with mkinitcpio are moved there. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-01-28function: avoid applying --try to all modulesDave Reisner1-3/+3
An error in logic here would cause the --try flag to be passed to all modules after the first, if a hook added modules ending with a '?'. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-01-05function: suppress errors from modprobeDave Reisner1-1/+1
kmod is a bit noisier about unresolvable aliases, but we don't really care for the purposes of creating the module whitelist. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-12-26functions: display proper name on file not foundDave Reisner1-1/+1
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-12-15functions: don't fail on add_binary adding a non-binaryDave Reisner1-1/+1
The function did its job, it just isn't going to add any deps. This makes add_binary effectively a slightly more costly version of add_file. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-11-29functions: don't allow add_binary to re-add depsDave Reisner1-1/+1
Since we now silently overwrite instead of silently failing on existing files and symlinks, we have a lot of sodeps which are overwritten by various binaries -- udevd and udevadm being one example. Nip this in add_binary by doing our own check and preventing addition of pre-existing files in the $BUILDROOT. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-11-29functions: add verbose output for overwriting filesDave Reisner1-3/+14
This goes in hand with an earlier commit which changed behavior to silenltly overwrite files rather than silently fail. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-11-29add_{file,symlink}: overwrite existing fileTom Gundersen1-3/+1
Now we fail silently if the file exists, which means there is no easy way to overwrite binaries. I think it makes the most sense to do the following: 1) add all the busybox stuff as a basic system; 2) overwrite some of the links with any binaries we add to base hook; 3) allow users to write their own hooks to overwrite even more stuff. This can now be done by this hook. v2: make sure we are able to overwrite a symlink pointing to a directory Signed-off-by: Tom Gundersen <teg@jklm.no>
2011-10-30add_symlink: fix argument ordering and add_dir callTom Gundersen1-2/+2
Two bugs: operands were swapped in call to _add_symlink, and missing operand in call to _add_dir. Signed-off-by: Tom Gundersen <teg@jklm.no>
2011-10-01functions: fix output order in _add_symlinkDave Reisner1-1/+1
Signed-off-by: Dave Reisner <dreisner@archlinux.org>