#!/bin/bash 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" work_dir="work" out_dir="out" # 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 ${app_name} [options] command " echo " general options:" echo " -p PACKAGE(S) Package(s) to install, can be used multiple times" echo " -C Config file for pacman. Default ${pacman_conf}" echo " -L