diff options
author | Thomas Bächler <thomas@archlinux.org> | 2008-03-15 22:14:36 +0100 |
---|---|---|
committer | Thomas Bächler <thomas@archlinux.org> | 2008-03-15 22:14:36 +0100 |
commit | 5ce327f59920366b4f43eec12becf484383643ca (patch) | |
tree | 6cc426c8eecc32b0dba16e54dc858f932473fe94 /mkinitcpio | |
parent | ee858697632359dcf4577132a38d1ce107e84ae3 (diff) | |
download | mkinitcpio-5ce327f59920366b4f43eec12becf484383643ca.tar.gz mkinitcpio-5ce327f59920366b4f43eec12becf484383643ca.tar.xz |
Use a temporary directory instead of several files. trap cleanup
Diffstat (limited to 'mkinitcpio')
-rwxr-xr-x[-rw-r--r--] | mkinitcpio | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/mkinitcpio b/mkinitcpio index 987a882..07fe7f7 100644..100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -10,13 +10,13 @@ # use -z "${var}" to test for nulls/empty strings # incase of embedded spaces, quote all path names and string comarpisons # -#TODO trap and remove FILELIST # Settings +TMPDIR="$(mktemp -d /tmp/mkinitcpio.XXXXXX)" BASEDIR="" -FILELIST="$(mktemp /tmp/.tmpfilelist.XXXX)" -MESSAGEFILE="$(mktemp /tmp/.message.XXXX)" +FILELIST="$(${TMPDIR}/filelist)" +MESSAGEFILE="$(${TMPDIR}/message)" KERNELVERSION="$(uname -r)" FUNCTIONS="functions" CONFIG="mkinitcpio.conf" @@ -59,6 +59,19 @@ usage () exit 1 } +cleanup () +{ + [ -n "${TMPDIR}" -a -d "${TMPDIR}" ] && rm -rf ${TMPDIR} +} + +sighandler() { + cleanup + exit 1 +} + +trap SIGTERM sighandler +trap SIGINT sighandler + while getopts ':c:k:s:b:g:a:p:m:vH:LMhS:' arg; do if [ "${OPTARG:0:1}" = "-" ]; then echo "error: optional argument to '-$arg' begins with a '-'" @@ -228,13 +241,13 @@ if [ "${HAS_MODULES}" == "y" ]; then echo ":: Generating module dependencies" for mod in $(grep "file /lib/modules/${KERNELVERSION}" ${FILELIST} | cut -d' ' -f2); do dir=$(dirname "${mod}") - mkdir -p "/tmp/${dir}" - cp "${BASEDIR}${mod}" "/tmp/${dir}/" + mkdir -p "${TMPDIR}/${dir}" + cp "${BASEDIR}${mod}" "${TMPDIR}/${dir}/" done - /sbin/depmod -b /tmp ${KERNELVERSION} - add_file "/tmp/lib/modules/${KERNELVERSION}/modules.dep" "/lib/modules/${KERNELVERSION}/modules.dep" - add_file "/tmp/lib/modules/${KERNELVERSION}/modules.alias" "/lib/modules/${KERNELVERSION}/modules.alias" - add_file "/tmp/lib/modules/${KERNELVERSION}/modules.symbols" "/lib/modules/${KERNELVERSION}/modules.symbols" + /sbin/depmod -b ${TMPDIR} ${KERNELVERSION} + add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/modules.dep" "/lib/modules/${KERNELVERSION}/modules.dep" + add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/modules.alias" "/lib/modules/${KERNELVERSION}/modules.alias" + add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/modules.symbols" "/lib/modules/${KERNELVERSION}/modules.symbols" fi status=0 @@ -256,13 +269,7 @@ else echo ":: Dry run complete, use -g IMAGE to generate a real image" fi -#cleanup - we should probably trap this... -isempty () { [ $(ls -1 "${1}" | wc -l) -eq 0 ]; } -[ -e "${MODULE_FILE}" ] && rm "${MODULE_FILE}" -if [ -d /tmp/lib/modules/${KERNELVERSION} ]; then - rm -rf /tmp/lib/modules/${KERNELVERSION} - isempty /tmp/lib/modules && rm -rf /tmp/lib/modules - isempty /tmp/lib && rm -rf /tmp/lib -fi +cleanup + exit $status #vim:set ft=sh ts=4 sw=4 noet: |