summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-06-07 02:27:27 +0200
committerDave Reisner <d@falconindy.com>2011-06-19 23:33:34 +0200
commit77beaa3018f5cacf8bc51251b50e76041c7eb6cd (patch)
treee27bc2089fc70fcc3fe781db19370a8e047e5033
parentf751758256ca9ab3db2b73e157542a2719296603 (diff)
downloadmkinitcpio-77beaa3018f5cacf8bc51251b50e76041c7eb6cd.tar.gz
mkinitcpio-77beaa3018f5cacf8bc51251b50e76041c7eb6cd.tar.xz
add -t option to specify alternate build directory
This requires some refactoring of how we handle TMPDIR declaration and creation, as well as protecting the way we do cleanup so that we don't error out when cleanup is called prior to TMPDIR being declared. We also add a shortcut to the build root based on the TMPDIR for convenience. Signed-off-by: Dave Reisner <d@falconindy.com>
-rw-r--r--functions10
-rwxr-xr-xmkinitcpio34
-rw-r--r--mkinitcpio.5.txt3
3 files changed, 31 insertions, 16 deletions
diff --git a/functions b/functions
index a4f6c0c..dbbcb3c 100644
--- a/functions
+++ b/functions
@@ -132,9 +132,9 @@ add_dir() {
# Add a directory to the initcpio image.
# $1: absolute path of directory on image
- if [[ ! -e "$TMPDIR/root/$1" ]]; then
+ if [[ ! -e "$BUILDROOT/$1" ]]; then
(( QUIET )) || plain "adding dir: %s" "$1"
- command install -dm755 "$TMPDIR/root/$1"
+ command install -dm755 "$BUILDROOT/$1"
fi
}
@@ -148,7 +148,7 @@ add_symlink() {
add_dir $(get_dirname "$file")
if [[ ! -e "$TMPDIR/root/$dest" ]]; then
(( QUIET )) || plain "adding symlink: $file -> $dest"
- ln -s "$dest" "$TMPDIR/root/$file"
+ ln -s "$dest" "$BUILDROOT/$file"
fi
}
@@ -170,9 +170,9 @@ add_file() {
return
fi
- if [[ ! -e "$TMPDIR/root/$dest" ]]; then
+ if [[ ! -e "$BUILDROOT/$dest" ]]; then
(( QUIET )) || plain "adding file: %s" "$dest"
- command install -Dm$(stat -c '%a' "$file") "$file" "$TMPDIR/root/$dest"
+ command install -Dm$(stat -c '%a' "$file") "$file" "$BUILDROOT/$dest"
fi
else
error "file '$file' does not exist"
diff --git a/mkinitcpio b/mkinitcpio
index 1f4792c..53326f0 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -13,7 +13,6 @@
shopt -s extglob
# Settings
-TMPDIR=$(mktemp -d /tmp/mkinitcpio.XXXXXX)
MESSAGEFILE=$TMPDIR/message
KERNELVERSION=$(uname -r)
FUNCTIONS=functions
@@ -23,7 +22,7 @@ INSTDIR=install
PRESETDIR=mkinitcpio.d
COMPRESSION=gzip
-declare BASEDIR MODULE_FILE SAVELIST GENIMG PRESET MESSAGE COMPRESSION_OPTIONS
+declare TMPDIR BASEDIR MODULE_FILE GENIMG PRESET MESSAGE COMPRESSION_OPTIONS BUILDROOT
declare NC= BOLD= BLUE= GREEN= RED= YELLOW=
declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1
declare -a SKIPHOOKS ADDED_MODULES
@@ -49,6 +48,7 @@ usage ()
echo " -m MESSAGE Print MESSAGE before passing control to init."
echo " -n Disable colorized output messages."
echo " -S SKIPHOOKS Skip SKIPHOOKS (comma-separated) when building the image."
+ echo " -t TMPDIR Use TMPDIR as the temporary build directory."
echo " -v Verbose output. Default: no"
echo " -M Display modules found via autodetection."
echo " -L List all available hooks."
@@ -60,10 +60,12 @@ usage ()
cleanup ()
{
- if (( SAVELIST )); then
- msg "build directory saved in %s" "$TMPDIR"
- else
- rm -rf ${TMPDIR}
+ if [[ $TMPDIR ]]; then
+ if (( $SAVELIST )); then
+ msg "build directory saved in %s" "$TMPDIR"
+ else
+ rm -rf "$TMPDIR"
+ fi
fi
}
@@ -95,7 +97,7 @@ get_kernver() {
trap sighandler TERM INT
-while getopts ':c:k:sb:g:p:m:nvH:LMhS:' arg; do
+while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:' arg; do
case "${arg}" in
c) CONFIG="${OPTARG}" ;;
k) optkver=$OPTARG ;;
@@ -115,14 +117,13 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:' arg; do
H) . "${INSTDIR}/${OPTARG}";
msg "Help for hook '${OPTARG}'"
help
- cleanup
exit 0 ;;
L) msg "Available hooks"
cd "$INSTDIR" >/dev/null
printf ' %s\n' * | column -c$(tput cols)
- cleanup
exit 0 ;;
M) SHOW_AUTOMODS=1 ;;
+ t) TMPDIR=$OPTARG ;;
h|?) usage ;;
:) echo "${OPTARG} requires a value..."; usage ;;
esac
@@ -155,6 +156,17 @@ if [[ $optkver ]]; then
fi
fi
+if [[ $TMPDIR ]]; then
+ if [[ ! -d $TMPDIR ]]; then
+ error "'$TMPDIR' does not exist or is not a directory"
+ unset TMPDIR
+ cleanup
+ exit 1
+ fi
+fi
+TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/mkinitcpio.XXXXXX")
+declare BUILDROOT=$TMPDIR/root
+
# use preset $PRESET
if [[ $PRESET ]]; then
if [[ -f "$PRESETDIR/$PRESET.preset" ]]; then
@@ -285,7 +297,7 @@ done
if (( ${#ADDED_MODULES[*]} )); then
msg "Generating module dependencies"
/sbin/depmod -b "${TMPDIR}/root" "${KERNELVERSION}"
- rm "$TMPDIR/root/lib/modules/$KERNELVERSION"/modules.!(dep.bin|alias.bin|symbols.bin)
+ rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(dep.bin|alias.bin|symbols.bin)
fi
declare -i status=0
@@ -294,7 +306,7 @@ if [[ "${GENIMG}" ]]; then
msg "Creating $COMPRESSION initcpio image: %s" "$GENIMG"
[[ "$COMPRESSION" = xz ]] && COMPRESSION_OPTIONS+=" --check=crc32"
- pushd "$TMPDIR/root" >/dev/null
+ pushd "$BUILDROOT" >/dev/null
find . -print0 | bsdcpio -0oH newc | $COMPRESSION $COMPRESSION_OPTIONS > "$IMGPATH"
pipesave=("${PIPESTATUS[@]}") # save immediately
popd >/dev/null
diff --git a/mkinitcpio.5.txt b/mkinitcpio.5.txt
index 1c96b8e..66bab68 100644
--- a/mkinitcpio.5.txt
+++ b/mkinitcpio.5.txt
@@ -42,6 +42,9 @@ Options
*-S* 'hooks'::
Skip 'hooks' when generating the image. Several hooks should be comma-separated.
+*-t* 'tmpdir'::
+ Use 'tmpdir' as the temporary build directory instead of /tmp. 'tmpdir' must exist.
+
*-v*::
Verbose output. Outputs more information about what's happening during creation of the ramdisk.