Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e -u
- iso_name=fluxar
- iso_label="FLUXAR"
- iso_version=$(date +%Y.%m.%d)
- install_dir=arch
- arch=$(uname -m)
- work_dir=work
- out_dir=out
- verbose=""
- script_path=$(readlink -f ${0%/*})
- # Base installation (root-image)
- make_basefs() {
- mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "base" create
- mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "memtest86+ syslinux" create
- }
- # Additional packages (root-image)
- make_packages() {
- mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -p "$(grep -v ^# ${script_path}/packages.${arch})" create
- }
- # Customize installation (root-image)
- make_customize_root_image() {
- if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
- cp -af ${script_path}/root-image ${work_dir}
- chmod 750 ${work_dir}/root-image/etc/sudoers.d
- chmod 440 ${work_dir}/root-image/etc/sudoers.d/g_wheel
- chroot ${work_dir}/root-image /usr/sbin/locale-gen
- chroot ${work_dir}/root-image /usr/sbin/useradd --create-home --skel /etc/skel --password "" --gid users --groups "storage,optical,audio,video,network,wheel,power,lp,log" --shell /bin/bash live
- chroot ${work_dir}/root-image /bin/chown live /home/live &> /dev/null
- : > ${work_dir}/build.${FUNCNAME}
- fi
- }
- # Copy mkinitcpio archiso hooks (root-image)
- make_setup_mkinitcpio() {
- if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
- local _hook
- for _hook in archiso; do
- cp /lib/initcpio/hooks/${_hook} ${work_dir}/root-image/lib/initcpio/hooks
- cp /lib/initcpio/install/${_hook} ${work_dir}/root-image/lib/initcpio/install
- done
- : > ${work_dir}/build.${FUNCNAME}
- fi
- }
- # Prepare ${install_dir}/boot/
- make_boot() {
- if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
- local _src=${work_dir}/root-image
- local _dst_boot=${work_dir}/iso/${install_dir}/boot
- mkdir -p ${_dst_boot}/${arch}
- mkinitcpio \
- -c ${script_path}/mkinitcpio.conf \
- -b ${_src} \
- -k /boot/vmlinuz-linux \
- -g ${_dst_boot}/${arch}/archiso.img
- mv ${_src}/boot/vmlinuz-linux ${_dst_boot}/${arch}/vmlinuz
- cp ${_src}/boot/memtest86+/memtest.bin ${_dst_boot}/memtest
- cp ${_src}/usr/share/licenses/common/GPL2/license.txt ${_dst_boot}/memtest.COPYING
- : > ${work_dir}/build.${FUNCNAME}
- fi
- }
- # Prepare /${install_dir}/boot/syslinux
- make_syslinux() {
- if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
- local _src_syslinux=${work_dir}/root-image/usr/lib/syslinux
- local _dst_syslinux=${work_dir}/iso/${install_dir}/boot/syslinux
- mkdir -p ${_dst_syslinux}
- sed "s|%ARCHISO_LABEL%|${iso_label}|g;
- s|%INSTALL_DIR%|${install_dir}|g;
- s|%ARCH%|${arch}|g" ${script_path}/syslinux/syslinux.cfg > ${_dst_syslinux}/syslinux.cfg
- cp ${script_path}/syslinux/splash.png ${_dst_syslinux}
- cp ${_src_syslinux}/*.c32 ${_dst_syslinux}
- cp ${_src_syslinux}/*.com ${_dst_syslinux}
- cp ${_src_syslinux}/*.0 ${_dst_syslinux}
- cp ${_src_syslinux}/memdisk ${_dst_syslinux}
- # Remove useless shortcuts
- rm ${work_dir}/root-image/usr/share/applications/avahi* &>/dev/null
- rm ${work_dir}/root-image/usr/share/applications/bvnc* &>/dev/null
- rm ${work_dir}/root-image/usr/share/applications/bssh* &>/dev/null
- rm ${work_dir}/root-image/usr/share/applications/7z* &>/dev/null
- rm ${work_dir}/root-image/usr/share/applications/qv4* &>/dev/null
- rm ${work_dir}/root-image/usr/share/applications/dconf-editor.desktop &>/dev/null
- rm ${work_dir}/root-image/etc/xdg/autostart/nm-applet.desktop &>/dev/null
- # End of removing useless shortcuts
- mkdir -p ${_dst_syslinux}/hdt
- wget -O - http://pciids.sourceforge.net/v2.2/pci.ids | gzip -9 > ${_dst_syslinux}/hdt/pciids.gz
- cat ${work_dir}/root-image/lib/modules/*-ARCH/modules.alias | gzip -9 > ${_dst_syslinux}/hdt/modalias.gz
- : > ${work_dir}/build.${FUNCNAME}
- fi
- }
- # Prepare /isolinux
- make_isolinux() {
- if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
- mkdir -p ${work_dir}/iso/isolinux
- sed "s|%INSTALL_DIR%|${install_dir}|g" ${script_path}/isolinux/isolinux.cfg > ${work_dir}/iso/isolinux/isolinux.cfg
- cp ${work_dir}/root-image/usr/lib/syslinux/isolinux.bin ${work_dir}/iso/isolinux/
- cp ${work_dir}/root-image/usr/lib/syslinux/isohdpfx.bin ${work_dir}/iso/isolinux/
- : > ${work_dir}/build.${FUNCNAME}
- fi
- }
- # Process aitab
- # args: $1 (core | netinstall)
- make_aitab() {
- local _iso_type=${1}
- if [[ ! -e ${work_dir}/build.${FUNCNAME}_${_iso_type} ]]; then
- sed "s|%ARCH%|${arch}|g" ${script_path}/aitab.${_iso_type} > ${work_dir}/iso/${install_dir}/aitab
- : > ${work_dir}/build.${FUNCNAME}_${_iso_type}
- fi
- }
- # Build all filesystem images specified in aitab (.fs .fs.sfs .sfs)
- make_prepare() {
- mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" prepare
- }
- # Build ISO
- # args: $1 (core | netinstall)
- make_iso() {
- local _iso_type=${1}
- mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" checksum
- mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -L "${iso_label}" -o "${out_dir}" iso "${iso_name}-${iso_version}-${arch}.iso"
- }
- purge_single ()
- {
- if [[ -d ${work_dir} ]]; then
- find ${work_dir} -mindepth 1 -maxdepth 1 \
- ! -path ${work_dir}/iso -prune \
- | xargs rm -rf
- fi
- }
- clean_single ()
- {
- rm -rf ${work_dir}
- rm -f ${out_dir}/${iso_name}-${iso_version}-*-${arch}.iso
- }
- make_common_single() {
- make_basefs
- make_packages
- make_customize_root_image
- make_setup_mkinitcpio
- make_boot
- make_syslinux
- make_isolinux
- make_aitab $1
- make_prepare $1
- make_iso $1
- }
- _usage ()
- {
- echo "usage ${0} [options] command <command options>"
- echo
- echo " General options:"
- echo " -N <iso_name> Set an iso filename (prefix)"
- echo " Default: ${iso_name}"
- echo " -V <iso_version> Set an iso version (in filename)"
- echo " Default: ${iso_version}"
- echo " -L <iso_label> Set an iso label (disk label)"
- echo " Default: ${iso_label}"
- echo " -D <install_dir> Set an install_dir (directory inside iso)"
- echo " Default: ${install_dir}"
- echo " -w <work_dir> Set the working directory"
- echo " Default: ${work_dir}"
- echo " -o <out_dir> Set the output directory"
- echo " Default: ${out_dir}"
- echo " -v Enable verbose output"
- echo " -h This help message"
- echo
- echo " Commands:"
- echo " build <mode> <type>"
- echo " Build selected .iso by <mode> and <type>"
- echo " purge <mode>"
- echo " Clean working directory except iso/ directory of build <mode>"
- echo " clean <mode>"
- echo " Clean working directory and .iso file in output directory of build <mode>"
- echo
- echo " Command options:"
- echo " <mode> Valid value 'single'"
- echo " <type> Valid value 'core'"
- exit ${1}
- }
- if [[ ${EUID} -ne 0 ]]; then
- echo "This script must be run as root."
- _usage 1
- fi
- while getopts 'N:V:L:D:w:o:vh' arg; do
- case "${arg}" in
- N) iso_name="${OPTARG}" ;;
- V) iso_version="${OPTARG}" ;;
- L) iso_label="${OPTARG}" ;;
- D) install_dir="${OPTARG}" ;;
- w) work_dir="${OPTARG}" ;;
- o) out_dir="${OPTARG}" ;;
- v) verbose="-v" ;;
- h|?) _usage 0 ;;
- *)
- _msg_error "Invalid argument '${arg}'" 0
- _usage 1
- ;;
- esac
- done
- shift $((OPTIND - 1))
- if [[ $# -lt 1 ]]; then
- echo "No command specified"
- _usage 1
- fi
- command_name="${1}"
- if [[ $# -lt 2 ]]; then
- echo "No command mode specified"
- _usage 1
- fi
- command_mode="${2}"
- if [[ ${command_name} == "build" ]]; then
- if [[ $# -lt 3 ]]; then
- echo "No build type specified"
- _usage 1
- fi
- command_type="${3}"
- fi
- if [[ ${command_mode} == "single" ]]; then
- work_dir=${work_dir}/${arch}
- fi
- case "${command_name}" in
- build)
- case "${command_mode}" in
- single)
- case "${command_type}" in
- core)
- make_common_single core
- ;;
- *)
- echo "Invalid build type '${command_type}'"
- _usage 1
- ;;
- esac
- ;;
- *)
- echo "Invalid build mode '${command_mode}'"
- _usage 1
- ;;
- esac
- ;;
- purge)
- case "${command_mode}" in
- single)
- purge_single
- ;;
- *)
- echo "Invalid purge mode '${command_mode}'"
- _usage 1
- ;;
- esac
- ;;
- clean)
- case "${command_mode}" in
- single)
- clean_single
- ;;
- *)
- echo "Invalid clean mode '${command_mode}'"
- _usage 1
- ;;
- esac
- ;;
- *)
- echo "Invalid command name '${command_name}'"
- _usage 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment