#!/bin/bash set -e -u export LANG=C app_name=${0##*/} arch=$(uname -m) pkg_list="" run_cmd="" 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" sfs_comp="xz" # 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 } _chroot_init() { if [[ -f "${work_dir}/mkarchiso.init" ]]; then _msg_info "Initial enviroment already installed, skipping." else mkdir -p ${work_dir}/airootfs _pacman "base syslinux" : > "${work_dir}/mkarchiso.init" fi } _chroot_run() { eval arch-chroot ${work_dir}/airootfs "${run_cmd}" } _mount_airootfs() { trap "_umount_airootfs" EXIT HUP INT TERM mkdir -p "${work_dir}/mnt/airootfs" _msg_info "Mounting '${work_dir}/airootfs.img' on '${work_dir}/mnt/airootfs'" mount "${work_dir}/airootfs.img" "${work_dir}/mnt/airootfs" _msg_info "Done!" } _umount_airootfs() { _msg_info "Unmounting '${work_dir}/mnt/airootfs'" umount "${work_dir}/mnt/airootfs" _msg_info "Done!" rmdir "${work_dir}/mnt/airootfs" 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 " -r Run inside airootfs" echo " -C Config file for pacman." echo " Default: '${pacman_conf}'" echo " -L