From 85d243ff5836fc17416c65dca8a9e8b4e9d915bc Mon Sep 17 00:00:00 2001 From: Gerardo Exequiel Pozzi Date: Sat, 18 Jun 2011 18:38:58 -0300 Subject: [archiso] Use dm-snapshot instead of aufs2 (A.K.A. "The Big Commit") * Use device mapper + snapshot module, instead union layer filesystem. * A block-level approach vs vfs-level. * No more unofficial (Linux) things. * More memory is needed. * Refactor mkarchiso. * Refactor hooks/archiso. * Fix install/archiso_pxe_nbd (due recent change in mkinitcpio-0.6.15 on checked_modules()/all_modules()) [Thanks Dave for the improved workaround] * New configs/releng to build official images. * Works with a Bash script instead of Makefile. (better control and easy to maintain) * Remove configs/syslinux-iso. * Remove archiso2dual script. Integrate functionality in configs/releng. * New configs/baseline to build the most basic live medium or use as template. * New README (draft). [Thanks Dieter for fixing english grammar] Signed-off-by: Gerardo Exequiel Pozzi --- archiso/mkarchiso | 559 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 372 insertions(+), 187 deletions(-) (limited to 'archiso/mkarchiso') diff --git a/archiso/mkarchiso b/archiso/mkarchiso index a165d03..92b2a26 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -1,254 +1,439 @@ #!/bin/bash -PKGLIST="" -QUIET="y" -FORCE="n" -PACCONFIG="/etc/pacman.conf" -export LABEL="ARCH_$(date +%Y%m)" -PUBLISHER="Arch Linux " -APPLICATION="Arch Linux Live/Rescue CD" -COMPRESSION="xz" -CREATE_DEFAULT="n" -INSTALL_DIR="arch" - -APPNAME=$(basename "${0}") -ARCH=$(uname -m) - -# usage: usage -usage () +set -e -u + +app_name=${0##*/} +arch=$(uname -m) +pkg_list="" +quiet="y" +pacman_conf="/etc/pacman.conf" +export iso_label="ARCH_$(date +%Y%m)" +iso_publisher="Arch Linux " +iso_application="Arch Linux Live/Rescue CD" +install_dir="arch" + +# Show an INFO message +# $1: message string +_msg_info() { + local _msg="${1}" + echo "[mkarchiso] INFO: ${_msg}" +} + +# Show an ERROR message then exit with status +# $1: message string +# $2: exit code number (with 0 does not exit) +_msg_error() { + local _msg="${1}" + local _error=${2} + echo + echo "[mkarchiso] ERROR: ${_msg}" + echo + if [[ ${_error} -gt 0 ]]; then + exit ${_error} + fi +} + +# Show space usage similar to df, but better formatted. +# $1: mount-point or mounted device. +_show_space_usage () { + local _where="${1}" + local _fs _total _used _avail _pct_u=0 _mnt + read _fs _total _used _avail _pct_u _mnt < <(df -m "${_where}" | tail -1) &> /dev/null + _msg_info "Total: ${_total} MiB (100%) | Used: ${_used} MiB (${_pct_u}) | Avail: ${_avail} MiB ($((100 - ${_pct_u%\%}))%)" +} + +# Mount a filesystem (trap signals in case of error for unmounting it +# $1: source image +# $2: mount-point +_mount_fs() { + local _src="${1}" + local _dst="${2}" + trap "_umount_fs ${_src}" EXIT HUP INT TERM + mkdir -p "${_dst}" + _msg_info "Mounting '${_src}' on '${_dst}'" + mount "${_src}" "${_dst}" + _show_space_usage "${_dst}" +} + +# Unmount a filesystem (and untrap signals) +# $1: mount-point or device/image +_umount_fs() { + local _dst="${1}" + _show_space_usage "${_dst}" + _msg_info "Unmounting '${_dst}'" + umount "${_dst}" + rmdir "${_dst}" + trap - EXIT HUP INT TERM +} + +# Compare if a file/directory (source) is newer than other file (target) +# $1: source file/directory +# $2: target file +# return: 0 if target does not exists or if target is older than source. +# 1 if target is newer than source +_is_directory_changed() { + local _src="${1}" + local _dst="${2}" + + if [ -e "${_dst}" ]; then + if [[ $(find ${_src} -newer ${_dst} | wc -l) -gt 0 ]]; then + _msg_info "Target '${_dst}' is older than '${_src}', updating." + rm -f "${_dst}" + return 0 + else + _msg_info "Target '${_dst}' is up to date with '${_src}', skipping." + return 1 + fi + else + _msg_info "Target '${_dst}' does not exist, making it from '${_src}'" + return 0 + fi +} + +# Show help usage, with an exit status. +# $1: exit status number. +_usage () { - echo "usage ${APPNAME} [options] command " + echo "usage ${app_name} [options] command " echo " general options:" - echo " -f Force overwrite of working files/squashfs image/bootable image" - echo " -p PACKAGE(S) Additional package(s) to install, can be used multiple times" - echo " -C Config file for pacman. Default $PACCONFIG" + echo " -p PACKAGE(S) Package(s) to install, can be used multiple times" + echo " -C Config file for pacman. Default ${pacman_conf}" echo " -L