#!/bin/sh # mkinitcpio - modular tool for building an init ramfs cpio image # # IMPORTANT: We need to keep a common base syntax here # because some of these hooks/scripts need to run under # the klibc shell or even busybox's ash - therefore, the # following constraints should be enforced: # variables should be quoted and bracketed "${SOMEVAR}" # inline execution should be done with $() instead of backticks # use "x${var}" = "x" to test for nulls/empty strings # incase of embedded spaces, quote all path names and string comarpisons # # TODO # hook help: help() function in install script, "-h base" # Settings BASEDIR="" KERNELVERSION="$(uname -r)" FUNCTIONS="functions" #/lib/initramfs/functions CONFIG="mkinitcpio.conf" HOOKDIR="hooks" INSTDIR="install" SAVELIST="" GENIMG="" APPEND="" QUIET="n" APPNAME=$(basename "${0}") usage () { echo "${APPNAME}: usage" echo " -c CONFIG Use CONFIG file. default: /etc/mkinitcpio.conf" echo " -k KERNELVERSION Use KERNELVERSION. default: $(uname -r)" echo " -s Save filelist. default: no" echo " -b BASEDIR Use BASEDIR. default: /" echo " -g IMAGE Generate a cpio image as IMAGE. default: no" echo " -a Append to an existing filelist. default: no" echo " -q Quiet output. Default: no" echo " -h This message." exit 1 } while getopts 'c:k:sb:g:aqh' arg; do case "$arg" in c) CONFIG="$OPTARG" ;; k) KERNELVERSION="$OPTARG" ;; s) SAVELIST="y" ;; b) BASEDIR="$OPTARG" ;; g) GENIMG="$OPTARG" ;; a) APPEND="y" ;; q) QUIET="y" ;; h|?) usage ;; *) echo "invalid argument '$arg'"; usage ;; esac done shift $(($OPTIND - 1)) # append a trailing / if needed if [ "${BASEDIR:${#BASEDIR}}" == "/" ]; then BASEDIR="${BASEDIR:0:${#BASEDIR}-1}" fi MODULEDIR="${BASEDIR}/lib/modules/${KERNELVERSION}" FILELIST=${1:-"initcpio.filelist"} if [ "x${BASEDIR}" != "x" ]; then if [ "${BASEDIR:0:1}" != "/" ]; then echo "base directory '${BASEDIR}' must be an absolute path" exit 1 elif [ ! -d "${BASEDIR}" ]; then echo "base directory '${BASEDIR}' does not exist or is not a directory" exit 1 fi fi if [ ! -f "${CONFIG}" ]; then echo "config file '${CONFIG}' cannot be found, aborting..." exit 1 fi source "${CONFIG}" if [ -f "${FILELIST}" -a "x${APPEND}" == "x" ]; then echo "destination file list '${FILELIST}' exists - remove before running" exit 1 elif [ -f "${DESTIMG}" ]; then echo "destination image '${DESTIMG}' exists - remove before running" exit 1 else touch "${FILELIST}" fi source "${FUNCTIONS}" #parse 'global' hook, as defined in ${CONFIG} parse_hook for hook in $HOOKS; do unset MODULES unset BINARIES unset FILES install () { msg "${hook}: no install function..."; } if grep "install ()" "${INSTDIR}/${hook}" /dev/null 2>&1; then source "${INSTDIR}/${hook}" install parse_hook fi #quick test to check for existance... need a better way... # note, this will only pick up valid run_hooks - a space is required if grep "run_hook ()" "${HOOKDIR}/${hook}" 2>&1>/dev/null; then add_file "${HOOKDIR}/${hook}" "/hooks/${hook}" fi done if [ "${HAS_MODULES}" == "y" ]; then add_file "${MODULEDIR}/modules.dep" add_file "${MODULEDIR}/modules.alias" add_file "${MODULEDIR}/modules.symbols" fi if [ "x$GENIMG" != "x" ]; then if ! gen_init_cpio ${FILELIST} | gzip -9 > "${GENIMG}"; then err "Failed to create '${GENIMG}' image" fi if [ "x${SAVELIST}" == "x" ]; then rm ${FILELIST} fi fi #vim:set ft=sh ts=4 sw=4 noet: