5 # Email : hayao@fascode.net
7 # (c) 2019-2020 Fascode Network.
11 # The main script that runs the build
17 # Do not change these values.
18 script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && pwd )"
19 defaultconfig="${script_path}/default.conf"
21 customized_username=false
25 if [[ -f "${defaultconfig}" ]]; then
26 source "${defaultconfig}"
28 echo "${defaultconfig} was not found."
35 # usage: echo_color -b <backcolor> -t <textcolor> -d <decoration> [Text]
58 # You can specify multiple decorations with ;.
59 # 0 => All attributs off (ノーマル)
61 # 4 => Underscore (下線)
63 # 7 => Reverse video on (色反転)
67 local backcolor textcolor decotypes echo_opts arg OPTIND OPT
69 while getopts 'b:t:d:n' arg; do
71 b) backcolor="${OPTARG}" ;;
72 t) textcolor="${OPTARG}" ;;
73 d) decotypes="${OPTARG}" ;;
74 n) echo_opts="-n -e" ;;
78 if [[ "${nocolor}" = false ]]; then
79 echo ${echo_opts} "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${*}\e[m"
81 echo ${echo_opts} "${@}"
86 # Show an INFO message
89 if [[ "${msgdebug}" = false ]]; then
94 local echo_opts="-e" arg OPTIND OPT
95 while getopts 'n' arg; do
97 n) echo_opts="${echo_opts} -n" ;;
100 shift $((OPTIND - 1))
101 echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '32' 'Info') ${*}"
102 if [[ "${bash_debug}" = true ]]; then
110 # Show an Warning message
113 if [[ "${msgdebug}" = false ]]; then
118 local echo_opts="-e" arg OPTIND OPT
119 while getopts 'n' arg; do
121 n) echo_opts="${echo_opts} -n" ;;
124 shift $((OPTIND - 1))
125 echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '33' 'Warning') ${*}" >&2
126 if [[ "${bash_debug}" = true ]]; then
134 # Show an debug message
137 if [[ "${msgdebug}" = false ]]; then
142 local echo_opts="-e" arg OPTIND OPT
143 while getopts 'n' arg; do
145 n) echo_opts="${echo_opts} -n" ;;
148 shift $((OPTIND - 1))
149 if [[ ${debug} = true ]]; then
150 echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '35' 'Debug') ${*}"
152 if [[ "${bash_debug}" = true ]]; then
160 # Show an ERROR message then exit with status
162 # $2: exit code number (with 0 does not exit)
164 if [[ "${msgdebug}" = false ]]; then
169 local echo_opts="-e" arg OPTIND OPT
170 while getopts 'n' arg; do
172 n) echo_opts="${echo_opts} -n" ;;
175 shift $((OPTIND - 1))
176 echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '31' 'Error') ${1}" >&2
177 if [[ -n "${2:-}" ]]; then
180 if [[ "${bash_debug}" = true ]]; then
189 echo "usage ${0} [options] [channel]"
191 echo "A channel is a profile of AlterISO settings."
193 echo " General options:"
195 echo " -b | --boot-splash Enable boot splash"
196 echo " -e | --cleanup Enable post-build cleaning."
197 echo " -h | --help This help message and exit."
199 echo " -a | --arch <arch> Set iso architecture."
200 echo " Default: ${arch}"
201 echo " -c | --comp-type <comp_type> Set SquashFS compression type (gzip, lzma, lzo, xz, zstd)"
202 echo " Default: ${sfs_comp}"
203 echo " -g | --gpgkey <key> Set gpg key"
204 echo " Default: ${gpg_key}"
205 echo " -l | --lang <lang> Specifies the default language for the live environment."
206 echo " Default: ${locale_name}"
207 echo " -k | --kernel <kernel> Set special kernel type.See below for available kernels."
208 echo " Default: ${kernel}"
209 echo " -o | --out <out_dir> Set the output directory"
210 echo " Default: ${out_dir}"
211 echo " -p | --password <password> Set a live user password"
212 echo " Default: ${password}"
213 echo " -t | --comp-opts <options> Set compressor-specific options."
214 echo " Default: empty"
215 echo " -u | --user <username> Set user name."
216 echo " Default: ${username}"
217 echo " -w | --work <work_dir> Set the working directory"
218 echo " Default: ${work_dir}"
221 local blank="33" arch lang list _locale_name_list kernel
223 echo " Language for each architecture:"
224 for list in ${script_path}/system/locale-* ; do
225 arch="${list#${script_path}/system/locale-}"
227 for i in $( seq 1 $(( ${blank} - 4 - ${#arch} )) ); do
230 _locale_name_list=$(cat ${list} | grep -h -v ^'#' | awk '{print $1}')
231 for lang in ${_locale_name_list[@]};do
238 echo " Kernel for each architecture:"
239 for list in ${script_path}/system/kernel-* ; do
240 arch="${list#${script_path}/system/kernel-}"
242 for i in $( seq 1 $(( ${blank} - 5 - ${#arch} )) ); do
245 for kernel in $(grep -h -v ^'#' ${list} | awk '{print $1}'); do
253 for i in $(ls -l "${script_path}"/channels/ | awk '$1 ~ /d/ {print $9}'); do
254 if [[ -n $(ls "${script_path}"/channels/${i}) ]] && [[ ! ${i} = "share" ]] && [[ "$(cat "${script_path}/channels/${i}/alteriso" 2> /dev/null)" = "alteriso=3" ]]; then
255 if [[ $(echo "${i}" | sed 's/^.*\.\([^\.]*\)$/\1/') = "add" ]]; then
256 channel_list="${channel_list[@]} ${i}"
257 elif [[ ! -d "${script_path}/channels/${i}.add" ]]; then
258 channel_list="${channel_list[@]} ${i}"
262 channel_list="${channel_list[@]} rebuild"
263 for _channel in ${channel_list[@]}; do
264 if [[ -f "${script_path}/channels/${_channel}/description.txt" ]]; then
265 description=$(cat "${script_path}/channels/${_channel}/description.txt")
266 elif [[ ${_channel} = "rebuild" ]]; then
267 description="Build from the point where it left off using the previous build settings."
269 description="This channel does not have a description.txt."
271 if [[ $(echo "${_channel}" | sed 's/^.*\.\([^\.]*\)$/\1/') = "add" ]]; then
272 echo -ne " $(echo ${_channel} | sed 's/\.[^\.]*$//')"
273 for i in $( seq 1 $(( ${blank} - ${#_channel} )) ); do
277 echo -ne " ${_channel}"
278 for i in $( seq 1 $(( ${blank} - 4 - ${#_channel} )) ); do
282 echo -ne "${description}\n"
286 echo " Debug options: Please use at your own risk."
287 echo " -d | --debug Enable debug messages."
288 echo " -x | --bash-debug Enable bash debug mode.(set -xv)"
289 echo " --gitversion Add Git commit hash to image file version"
290 echo " --msgdebug Enables output debugging."
291 echo " --noaur No build and install AUR packages."
292 echo " --nocolor No output colored output."
293 echo " --noconfirm No check the settings before building."
294 echo " --nochkver NO check the version of the channel."
295 echo " --noloopmod No check and load kernel module automatically."
296 echo " --nodepend No check package dependencies before building."
297 echo " --noiso No build iso image. (Use with --tarball)"
298 echo " --shmkalteriso Use the shell script version of mkalteriso."
299 if [[ -n "${1:-}" ]]; then
308 for _mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir}) | tac); do
309 msg_info "Unmounting ${_mount}"
310 umount -lf "${_mount}"
314 # Helper function to run make_*() only one time.
316 if [[ ! -e "${work_dir}/build.${1}_${arch}" ]]; then
317 msg_debug "Running $1 ..."
319 touch "${work_dir}/build.${1}_${arch}"
322 msg_debug "Skipped because ${1} has already been executed."
327 # Delete the file if it exists.
328 # For directories, rm -rf is used.
329 # If the file does not exist, skip it.
330 # remove <file> <file> ...
332 local _list=($(echo "$@")) _file
333 for _file in "${_list[@]}"; do
334 if [[ -f ${_file} ]]; then
335 msg_debug "Removeing ${_file}"
337 elif [[ -d ${_file} ]]; then
338 msg_debug "Removeing ${_file}"
348 msg_error "It was killed by the user."
349 msg_error "The process may not have completed successfully."
354 # load_config [file1] [file2] ...
357 for _file in ${@}; do
358 if [[ -f "${_file}" ]]; then
360 msg_debug "The settings have been overwritten by the ${_file}"
370 # Display channel list
371 show_channel_list() {
373 for _channel in $(ls -l "${script_path}"/channels/ | awk '$1 ~ /d/ {print $9 }'); do
374 if [[ -n "$(ls "${script_path}"/channels/${_channel})" ]] && [[ ! "${_channel}" == "share" ]]; then
375 if [[ ! "$(echo "${_channel}" | sed 's/^.*\.\([^\.]*\)$/\1/')" == "add" ]]; then
376 if [[ ! -d "${script_path}/channels/${_channel}.add" ]]; then
377 echo -n "${_channel} "
380 echo -n "${_channel} "
388 # Check the value of a variable that can only be set to true or false.
390 local _value="$(eval echo '$'${1})"
391 msg_debug -n "Checking ${1}..."
392 if [[ "${debug}" = true ]]; then
395 if [[ ! -v "${1}" ]]; then
396 echo; msg_error "The variable name ${1} is empty." "1"
397 elif [[ ! "${_value}" = "true" ]] && [[ ! "${_value}" = "false" ]]; then
398 echo; msg_error "The variable name ${1} is not of bool type." "1"
403 # Preparation for build
405 # Create a working directory.
406 [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
409 if [[ -n $(ls -a "${work_dir}" 2> /dev/null | grep -xv ".." | grep -xv ".") ]] && [[ ! "${rebuild}" = true ]]; then
411 msg_info "Deleting the contents of ${work_dir}..."
412 remove "${work_dir%/}"/*
416 # 強制終了時に作業ディレクトリを削除する
417 local _trap_remove_work
418 _trap_remove_work() {
424 trap '_trap_remove_work' 1 2 3 15
426 if [[ "${rebuild}" == false ]]; then
427 # If there is pacman.conf for each channel, use that for building
428 if [[ -f "${script_path}/channels/${channel_name}/pacman-${arch}.conf" ]]; then
429 build_pacman_conf="${script_path}/channels/${channel_name}/pacman-${arch}.conf"
433 # If there is config for share channel. load that.
434 load_config "${script_path}/channels/share/config.any"
435 load_config "${script_path}/channels/share/config.${arch}"
438 # If there is config for each channel. load that.
439 load_config "${script_path}/channels/${channel_name}/config.any"
440 load_config "${script_path}/channels/${channel_name}/config.${arch}"
444 if [[ "${customized_username}" = false ]]; then
445 username="${defaultusername}"
450 if [[ "${gitversion}" = true ]]; then
452 iso_version=${iso_version}-$(git rev-parse --short HEAD)
453 cd - > /dev/null 2>&1
457 # Generate iso file name.
459 if [[ $(echo "${channel_name}" | sed 's/^.*\.\([^\.]*\)$/\1/') = "add" ]]; then
460 _channel_name="$(echo ${channel_name} | sed 's/\.[^\.]*$//')-${locale_version}"
462 _channel_name="${channel_name}-${locale_version}"
464 if [[ "${nochname}" = true ]]; then
465 iso_filename="${iso_name}-${iso_version}-${arch}.iso"
467 iso_filename="${iso_name}-${_channel_name}-${iso_version}-${arch}.iso"
469 msg_debug "Iso filename is ${iso_filename}"
473 local _write_rebuild_file
474 _write_rebuild_file() {
475 local out_file="${rebuildfile}"
476 echo -e "${@}" >> "${out_file}"
481 local out_file="${rebuildfile}" i
483 echo -n "${i}=" >> "${out_file}"
484 echo -n '"' >> "${out_file}"
485 eval echo -n '$'{${i}} >> "${out_file}"
486 echo '"' >> "${out_file}"
490 # Save the value of the variable for use in rebuild.
491 remove "${rebuildfile}"
492 _write_rebuild_file "#!/usr/bin/env bash"
493 _write_rebuild_file "# Build options are stored here."
495 _write_rebuild_file "\n# OS Info"
500 _save_var iso_publisher
501 _save_var iso_application
502 _save_var iso_version
503 _save_var iso_filename
504 _save_var channel_name
506 _write_rebuild_file "\n# Environment Info"
507 _save_var install_dir
512 _write_rebuild_file "\n# Live User Info"
517 _write_rebuild_file "\n# Plymouth Info"
518 _save_var boot_splash
522 _write_rebuild_file "\n# Language Info"
523 _save_var locale_name
524 _save_var locale_gen_name
525 _save_var locale_version
526 _save_var locale_time
527 _save_var locale_fullname
529 _write_rebuild_file "\n# Kernel Info"
531 _save_var kernel_package
532 _save_var kernel_headers_packages
533 _save_var kernel_filename
534 _save_var kernel_mkinitcpio_profile
536 _write_rebuild_file "\n# Squashfs Info"
538 _save_var sfs_comp_opt
540 _write_rebuild_file "\n# Debug Info"
545 _write_rebuild_file "\n# Channel Info"
546 _save_var build_pacman_conf
547 _save_var defaultconfig
548 _save_var defaultusername
549 _save_var customized_username
551 _write_rebuild_file "\n# mkalteriso Info"
552 if [[ "${shmkalteriso}" = false ]]; then
553 mkalteriso="${script_path}/system/mkalteriso"
555 mkalteriso="${script_path}/system/mkalteriso.sh"
559 _save_var shmkalteriso
560 _save_var mkalteriso_option
564 load_config "${rebuildfile}"
565 msg_debug "Iso filename is ${iso_filename}"
570 check_bool boot_splash
574 check_bool shmkalteriso
575 check_bool customized_username
583 # Check architecture for each channel
584 if [[ -z $(cat "${script_path}/channels/${channel_name}/architecture" | grep -h -v ^'#' | grep -x "${arch}") ]]; then
585 msg_error "${channel_name} channel does not support current architecture (${arch})." "1"
589 # Check kernel for each channel
590 if [[ -f "${script_path}/channels/${channel_name}/kernel_list-${arch}" ]] && [[ -z $(cat "${script_path}/channels/${channel_name}/kernel_list-${arch}" | grep -h -v ^'#' | grep -x "${kernel}" 2> /dev/null) ]]; then
591 msg_error "This kernel is currently not supported on this channel." "1"
595 # Show alteriso version
596 if [[ -d "${script_path}/.git" ]]; then
598 msg_debug "The version of alteriso is $(git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')."
599 cd - > /dev/null 2>&1
605 for _mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir})); do
606 msg_info "Unmounting ${_mount}"
613 if [[ "${nodepend}" = false ]] && [[ "${arch}" = $(uname -m) ]] ; then
614 local _check_pkg _check_failed=false _pkg
615 local _installed_pkg=($(pacman -Q | awk '{print $1}')) _installed_ver=($(pacman -Q | awk '{print $2}'))
619 for __pkg in $(seq 0 $(( ${#_installed_pkg[@]} - 1 ))); do
620 if [[ "${_installed_pkg[${__pkg}]}" = ${1} ]]; then
621 __ver=$(pacman -Sp --print-format '%v' --config ${build_pacman_conf} ${1} 2> /dev/null)
622 if [[ "${_installed_ver[${__pkg}]}" = "${__ver}" ]]; then
625 elif [[ -z ${__ver} ]]; then
638 msg_info "Checking dependencies ..."
640 for _pkg in ${dependence[@]}; do
641 msg_debug -n "Checking ${_pkg} ..."
642 case $(_check_pkg ${_pkg}) in
644 [[ "${debug}" = true ]] && echo -ne " $(pacman -Q ${_pkg} | awk '{print $2}')\n"
645 msg_warn "${_pkg} is not the latest package."
646 msg_warn "Local: $(pacman -Q ${_pkg} 2> /dev/null | awk '{print $2}') Latest: $(pacman -Sp --print-format '%v' --config ${build_pacman_conf} ${_pkg} 2> /dev/null)"
649 [[ "${debug}" = true ]] && echo
650 msg_error "${_pkg} is not installed." ; _check_failed=true
653 [[ "${debug}" = true ]] && echo
654 msg_warn "${_pkg} is not a repository package."
656 "installed") [[ ${debug} = true ]] && echo -ne " $(pacman -Q ${_pkg} | awk '{print $2}')\n" ;;
660 if [[ "${_check_failed}" = true ]]; then
667 if [[ "${shmkalteriso}" = false ]]; then
668 mkalteriso="${script_path}/system/mkalteriso"
670 msg_info "Building mkalteriso..."
671 if [[ "${debug}" = true ]]; then
675 make mkalteriso > /dev/null 2>&1
677 cd - > /dev/null 2>&1
679 mkalteriso="${script_path}/system/mkalteriso.sh"
683 # Load loop kernel module
684 if [[ "${noloopmod}" = false ]]; then
685 if [[ ! -d "/usr/lib/modules/$(uname -r)" ]]; then
686 msg_error "The currently running kernel module could not be found."
687 msg_error "Probably the system kernel has been updated."
688 msg_error "Reboot your system to run the latest kernel." "1"
690 if [[ -z $(lsmod | awk '{print $1}' | grep -x "loop") ]]; then
699 msg_info "mkalteriso path is ${mkalteriso}"
701 if [[ "${boot_splash}" = true ]]; then
702 msg_info "Boot splash is enabled."
703 msg_info "Theme is used ${theme_name}."
705 msg_info "Language is ${locale_fullname}."
706 msg_info "Use the ${kernel} kernel."
707 msg_info "Live username is ${username}."
708 msg_info "Live user password is ${password}."
709 msg_info "The compression method of squashfs is ${sfs_comp}."
710 if [[ $(echo "${channel_name}" | sed 's/^.*\.\([^\.]*\)$/\1/') = "add" ]]; then
711 msg_info "Use the $(echo ${channel_name} | sed 's/\.[^\.]*$//') channel."
713 msg_info "Use the ${channel_name} channel."
715 msg_info "Build with architecture ${arch}."
716 if [[ ${noconfirm} = false ]]; then
718 echo "Press Enter to continue or Ctrl + C to cancel."
722 trap 'umount_trap' 1 2 3 15
726 # Setup custom pacman.conf with current cache directories.
728 msg_debug "Use ${build_pacman_conf}"
729 local _cache_dirs=($(pacman -v 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
730 sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${_cache_dirs[@]})|g" ${build_pacman_conf} > "${work_dir}/pacman-${arch}.conf"
733 # Base installation (airootfs)
735 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" init
738 if [[ "${boot_splash}" = true ]]; then
739 if [[ -n "${theme_pkg}" ]]; then
740 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "plymouth ${theme_pkg}" install
742 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "plymouth" install
747 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "${kernel_package} ${kernel_headers_packages}" install
749 if [[ "${kernel_package}" = "linux" ]]; then
750 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "broadcom-wl" install
752 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "broadcom-wl-dkms" install
756 # Additional packages (airootfs)
759 local _loadfilelist _pkg _file _excludefile _excludelist _pkglist
761 #-- Detect package list to load --#
762 # Add the files for each channel to the list of files to read.
764 $(ls "${script_path}"/channels/${channel_name}/packages.${arch}/*.${arch} 2> /dev/null)
765 "${script_path}"/channels/${channel_name}/packages.${arch}/lang/${locale_name}.${arch}
766 $(ls "${script_path}"/channels/share/packages.${arch}/*.${arch} 2> /dev/null)
767 "${script_path}"/channels/share/packages.${arch}/lang/${locale_name}.${arch}
771 #-- Read package list --#
772 # Read the file and remove comments starting with # and add it to the list of packages to install.
773 for _file in ${_loadfilelist[@]}; do
774 if [[ -f "${_file}" ]]; then
775 msg_debug "Loaded package file ${_file}."
776 _pkglist=( ${_pkglist[@]} "$(grep -h -v ^'#' ${_file})" )
780 #-- Read exclude list --#
781 # Exclude packages from the share exclusion list
783 "${script_path}/channels/share/packages.${arch}/exclude"
784 "${script_path}/channels/${channel_name}/packages.${arch}/exclude"
787 for _file in ${_excludefile[@]}; do
788 if [[ -f "${_file}" ]]; then
789 _excludelist=( ${_excludelist[@]} $(grep -h -v ^'#' "${_file}") )
793 #-- excludeに記述されたパッケージを除外 --#
794 # _pkglistを_subpkglistにコピーしexcludeのパッケージを除外し再代入
795 local _subpkglist=(${_pkglist[@]})
797 for _pkg in ${_subpkglist[@]}; do
798 # もし変数_pkgの値が配列_excludelistに含まれていなかったらpkglistに追加する
799 if [[ ! $(printf '%s\n' "${_excludelist[@]}" | grep -qx "${_pkg}"; echo -n ${?} ) = 0 ]]; then
800 _pkglist=(${_pkglist[@]} "${_pkg}")
805 #-- excludeされたパッケージを表示 --#
806 if [[ -n "${_excludelist[*]}" ]]; then
807 msg_debug "The following packages have been removed from the installation list."
808 msg_debug "Excluded packages:" "${_excludelist[@]}"
811 # Sort the list of packages in abc order.
812 _pkglist=("$(for _pkg in ${_pkglist[@]}; do echo "${_pkg}"; done | sort)")
816 # Create a list of packages to be finally installed as packages.list directly under the working directory.
817 echo -e "# The list of packages that is installed in live cd.\n#\n\n" > "${work_dir}/packages.list"
818 for _pkg in ${_pkglist[@]}; do
819 echo ${_pkg} >> "${work_dir}/packages.list"
822 # Install packages on airootfs
823 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "${_pkglist[@]}" install
827 make_packages_aur() {
830 local _loadfilelist _pkg _file _excludefile _excludelist _pkglist
832 #-- Detect package list to load --#
833 # Add the files for each channel to the list of files to read.
835 $(ls "${script_path}"/channels/${channel_name}/packages_aur.${arch}/*.${arch} 2> /dev/null)
836 "${script_path}"/channels/${channel_name}/packages_aur.${arch}/lang/${locale_name}.${arch}
837 $(ls "${script_path}"/channels/share/packages_aur.${arch}/*.${arch} 2> /dev/null)
838 "${script_path}"/channels/share/packages_aur.${arch}/lang/${locale_name}.${arch}
841 if [[ ! -d "${script_path}/channels/${channel_name}/packages_aur.${arch}/" ]] && [[ ! -d "${script_path}/channels/share/packages_aur.${arch}/" ]]; then
845 #-- Read package list --#
846 # Read the file and remove comments starting with # and add it to the list of packages to install.
847 for _file in ${_loadfilelist[@]}; do
848 if [[ -f "${_file}" ]]; then
849 msg_debug "Loaded aur package file ${_file}."
850 pkglist_aur=( ${pkglist_aur[@]} "$(grep -h -v ^'#' ${_file})" )
854 #-- Read exclude list --#
855 # Exclude packages from the share exclusion list
857 "${script_path}/channels/share/packages_aur.${arch}/exclude"
858 "${script_path}/channels/${channel_name}/packages_aur.${arch}/exclude"
861 for _file in ${_excludefile[@]}; do
862 [[ -f "${_file}" ]] && _excludelist=( ${_excludelist[@]} $(grep -h -v ^'#' "${_file}") )
866 _pkglist=(${pkglist[@]})
868 for _pkg in ${_pkglist[@]}; do
869 # もし変数_pkgの値が配列excludelistに含まれていなかったらpkglistに追加する
870 if [[ ! $(printf '%s\n' "${_excludelist[@]}" | grep -qx "${_pkg}"; echo -n ${?} ) = 0 ]]; then
871 pkglist=(${pkglist[@]} "${_pkg}")
875 if [[ -n "${_excludelist[*]}" ]]; then
876 msg_debug "The following packages have been removed from the aur list."
877 msg_debug "Excluded packages:" "${_excludelist[@]}"
880 # Sort the list of packages in abc order.
881 pkglist_aur=("$( for _pkg in ${pkglist_aur[@]}; do echo "${_pkg}"; done | sort)")
885 # Create a list of packages to be finally installed as packages.list directly under the working directory.
886 echo -e "\n\n# AUR packages.\n#\n\n" >> "${work_dir}/packages.list"
887 for _pkg in ${pkglist_aur[@]}; do echo ${_pkg} >> "${work_dir}/packages.list"; done
889 # Build aur packages on airootfs
890 local _aur_pkg _copy_aur_scripts
891 _copy_aur_scripts() {
892 for _file in ${@}; do
893 cp -r "${script_path}/system/aur_scripts/${_file}.sh" "${work_dir}/${arch}/airootfs/root/${_file}.sh"
894 chmod 755 "${work_dir}/${arch}/airootfs/root/${_file}.sh"
898 _copy_aur_scripts aur_install aur_prepare aur_remove pacls_gen_new pacls_gen_old
900 local _aur_packages_ls_str=""
901 for _pkg in ${pkglist_aur[@]}; do
902 _aur_packages_ls_str="${_aur_packages_ls_str} ${_pkg}"
905 # Create user to build AUR
906 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -D "${install_dir}" -r "/root/aur_prepare.sh ${_aur_packages_ls_str}" run
909 for _pkg in ${pkglist_aur[@]}; do
910 if [[ ! -f "${work_dir}/${arch}/airootfs/aurbuild_temp/${_pkg}/PKGBUILD" ]]; then
911 msg_error "PKGBUILD is missing. Please check if the package name ( ${_pkg} ) of AUR is correct." "1"
916 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -D "${install_dir}" -r "/root/pacls_gen_old.sh" run
918 # Install dependent packages.
919 local dependent_packages
920 for _aur_pkg in ${pkglist_aur[@]}; do
921 dependent_packages="$("${script_path}/system/aur_scripts/PKGBUILD_DEPENDS_SANDBOX.sh" "${script_path}/system/arch-pkgbuild-parser" "$(realpath "${work_dir}/${arch}/airootfs/aurbuild_temp/${_aur_pkg}/PKGBUILD")")"
922 if [[ -n "${dependent_packages}" ]]; then
923 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "${dependent_packages}" install
928 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -D "${install_dir}" -r "/root/pacls_gen_new.sh" run
930 # Build the package using makepkg.
931 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -D "${install_dir}" -r "/root/aur_install.sh ${_aur_packages_ls_str}" run
933 # Install the built package file.
934 for _pkg in ${pkglist_aur[@]}; do
935 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "${work_dir}/${arch}/airootfs/aurbuild_temp/${_pkg}/*.pkg.tar.*" install_file
939 delete_pkg_list=(`comm -13 --nocheck-order "${work_dir}/${arch}/airootfs/paclist_old" "${work_dir}/${arch}/airootfs/paclist_new" |xargs`)
940 for _dlpkg in ${delete_pkg_list[@]}; do
941 unshare --fork --pid pacman -r "${work_dir}/${arch}/airootfs" -R --noconfirm ${_dlpkg}
944 # Remove the user created for the build.
945 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -D "${install_dir}" -r "/root/aur_remove.sh" run
948 remove "${work_dir}/${arch}/airootfs/root/"{"aur_install","aur_prepare","aur_remove","pacls_gen_new","pacls_gen_old"}".sh"
951 # Customize installation (airootfs)
952 make_customize_airootfs() {
953 # Overwrite airootfs with customize_airootfs.
958 if [[ -d "${_dir}" ]]; then
959 cp -af "${_dir}"/* "${work_dir}/${arch}/airootfs"
963 _copy_airootfs "${script_path}/channels/share/airootfs.any"
964 _copy_airootfs "${script_path}/channels/share/airootfs.${arch}"
965 _copy_airootfs "${script_path}/channels/${channel_name}/airootfs.any"
966 _copy_airootfs "${script_path}/channels/${channel_name}/airootfs.${arch}"
968 # Replace /etc/mkinitcpio.conf if Plymouth is enabled.
969 if [[ "${boot_splash}" = true ]]; then
970 cp "${script_path}/mkinitcpio/mkinitcpio-plymouth.conf" "${work_dir}/${arch}/airootfs/etc/mkinitcpio.conf"
973 # customize_airootfs options
974 # -b : Enable boot splash.
975 # -d : Enable debug mode.
976 # -g <locale_gen_name> : Set locale-gen.
977 # -i <inst_dir> : Set install dir
978 # -k <kernel config line> : Set kernel name.
979 # -o <os name> : Set os name.
980 # -p <password> : Set password.
981 # -s <shell> : Set user shell.
982 # -t : Set plymouth theme.
983 # -u <username> : Set live user name.
984 # -x : Enable bash debug mode.
985 # -r : Enable rebuild.
986 # -z <locale_time> : Set the time zone.
987 # -l <locale_name> : Set language.
989 # -j is obsolete in AlterISO3 and cannot be used.
990 # -k changed in AlterISO3 from passing kernel name to passing kernel configuration.
993 # Generate options of customize_airootfs.sh.
994 local _airootfs_script_options
995 _airootfs_script_options="-p '${password}' -k '${kernel} ${kernel_package} ${kernel_headers_packages} ${kernel_filename} ${kernel_mkinitcpio_profile}' -u '${username}' -o '${os_name}' -i '${install_dir}' -s '${usershell}' -a '${arch}' -g '${locale_gen_name}' -l '${locale_name}' -z '${locale_time}' -t ${theme_name}"
996 [[ ${boot_splash} = true ]] && _airootfs_script_options="${_airootfs_script_options} -b"
997 [[ ${debug} = true ]] && _airootfs_script_options="${_airootfs_script_options} -d"
998 [[ ${bash_debug} = true ]] && _airootfs_script_options="${_airootfs_script_options} -x"
999 [[ ${rebuild} = true ]] && _airootfs_script_options="${_airootfs_script_options} -r"
1004 for _file in ${@}; do
1005 [[ -f "$_file" ]] &&chmod 755 "${_file}"
1009 chmod_755 "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh" "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh" "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh" "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh"
1011 # Execute customize_airootfs.sh.
1012 ${mkalteriso} ${mkalteriso_option} \
1013 -w "${work_dir}/${arch}" \
1014 -C "${work_dir}/pacman-${arch}.conf" \
1015 -D "${install_dir}" \
1016 -r "/root/customize_airootfs.sh ${_airootfs_script_options}" \
1019 if [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh" ]]; then
1020 ${mkalteriso} ${mkalteriso_option} \
1021 -w "${work_dir}/${arch}" \
1022 -C "${work_dir}/pacman-${arch}.conf" \
1023 -D "${install_dir}" \
1024 -r "/root/customize_airootfs_${channel_name}.sh ${_airootfs_script_options}" \
1026 elif [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh" ]]; then
1027 ${mkalteriso} ${mkalteriso_option} \
1028 -w "${work_dir}/${arch}" \
1029 -C "${work_dir}/pacman-${arch}.conf" \
1030 -D "${install_dir}" \
1031 -r "/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh ${_airootfs_script_options}" \
1035 # Delete customize_airootfs.sh.
1036 remove "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh"
1037 remove "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh"
1040 # https://github.com/archlinux/archiso/commit/d39e2ba41bf556674501062742190c29ee11cd59
1041 chmod -f 750 "${work_dir}/x86_64/airootfs/root"
1044 # Copy mkinitcpio archiso hooks and build initramfs (airootfs)
1045 make_setup_mkinitcpio() {
1047 mkdir -p "${work_dir}/${arch}/airootfs/etc/initcpio/hooks"
1048 mkdir -p "${work_dir}/${arch}/airootfs/etc/initcpio/install"
1049 for _hook in "archiso" "archiso_shutdown" "archiso_pxe_common" "archiso_pxe_nbd" "archiso_pxe_http" "archiso_pxe_nfs" "archiso_loop_mnt"; do
1050 cp "${script_path}/system/initcpio/hooks/${_hook}" "${work_dir}/${arch}/airootfs/etc/initcpio/hooks"
1051 cp "${script_path}/system/initcpio/install/${_hook}" "${work_dir}/${arch}/airootfs/etc/initcpio/install"
1053 sed -i "s|/usr/lib/initcpio/|/etc/initcpio/|g" "${work_dir}/${arch}/airootfs/etc/initcpio/install/archiso_shutdown"
1054 cp "${script_path}/system/initcpio/install/archiso_kms" "${work_dir}/${arch}/airootfs/etc/initcpio/install"
1055 cp "${script_path}/system/initcpio/archiso_shutdown" "${work_dir}/${arch}/airootfs/etc/initcpio"
1056 if [[ "${boot_splash}" = true ]]; then
1057 cp "${script_path}/mkinitcpio/mkinitcpio-archiso-plymouth.conf" "${work_dir}/${arch}/airootfs/etc/mkinitcpio-archiso.conf"
1059 cp "${script_path}/mkinitcpio/mkinitcpio-archiso.conf" "${work_dir}/${arch}/airootfs/etc/mkinitcpio-archiso.conf"
1062 if [[ "${gpg_key}" ]]; then
1063 gpg --export "${gpg_key}" >"${work_dir}/gpgkey"
1064 exec 17<>"${work_dir}/gpgkey"
1067 ARCHISO_GNUPG_FD=${gpg_key:+17} ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -r "mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/${kernel_filename} -g /boot/archiso.img" run
1069 if [[ "${gpg_key}" ]]; then
1074 # Prepare kernel/initramfs ${install_dir}/boot/
1076 mkdir -p "${work_dir}/iso/${install_dir}/boot/${arch}"
1077 cp "${work_dir}/${arch}/airootfs/boot/archiso.img" "${work_dir}/iso/${install_dir}/boot/${arch}/archiso.img"
1078 cp "${work_dir}/${arch}/airootfs/boot/${kernel_filename}" "${work_dir}/iso/${install_dir}/boot/${arch}/${kernel_filename}"
1081 # Add other aditional/extra files to ${install_dir}/boot/
1083 if [[ -e "${work_dir}/${arch}/airootfs/boot/memtest86+/memtest.bin" ]]; then
1084 cp "${work_dir}/${arch}/airootfs/boot/memtest86+/memtest.bin" "${work_dir}/iso/${install_dir}/boot/memtest"
1085 cp "${work_dir}/${arch}/airootfs/usr/share/licenses/common/GPL2/license.txt" "${work_dir}/iso/${install_dir}/boot/memtest.COPYING"
1087 if [[ -e "${work_dir}/${arch}/airootfs/boot/intel-ucode.img" ]]; then
1088 cp "${work_dir}/${arch}/airootfs/boot/intel-ucode.img" "${work_dir}/iso/${install_dir}/boot/intel_ucode.img"
1089 cp "${work_dir}/${arch}/airootfs/usr/share/licenses/intel-ucode/LICENSE" "${work_dir}/iso/${install_dir}/boot/intel_ucode.LICENSE"
1091 if [[ -e "${work_dir}/${arch}/airootfs/boot/amd-ucode.img" ]]; then
1092 cp "${work_dir}/${arch}/airootfs/boot/amd-ucode.img" "${work_dir}/iso/${install_dir}/boot/amd_ucode.img"
1093 cp "${work_dir}/${arch}/airootfs/usr/share/licenses/amd-ucode/LICENSE.amd-ucode" "${work_dir}/iso/${install_dir}/boot/amd_ucode.LICENSE"
1097 # Prepare /${install_dir}/boot/syslinux
1099 _uname_r="$(file -b ${work_dir}/${arch}/airootfs/boot/${kernel_filename} | awk 'f{print;f=0} /version/{f=1}' RS=' ')"
1100 mkdir -p "${work_dir}/iso/${install_dir}/boot/syslinux"
1102 # copy all syslinux config to work dir
1103 for _cfg in ${script_path}/syslinux/${arch}/*.cfg; do
1104 sed "s|%ARCHISO_LABEL%|${iso_label}|g;
1105 s|%OS_NAME%|${os_name}|g;
1106 s|%KERNEL_FILENAME%|${kernel_filename}|g;
1107 s|%INSTALL_DIR%|${install_dir}|g" "${_cfg}" > "${work_dir}/iso/${install_dir}/boot/syslinux/${_cfg##*/}"
1110 # Replace the SYSLINUX configuration file with or without boot splash.
1111 local _use_config_name _no_use_config_name _pxe_or_sys
1112 if [[ "${boot_splash}" = true ]]; then
1113 _use_config_name=splash
1114 _no_use_config_name=nosplash
1116 _use_config_name=nosplash
1117 _no_use_config_name=splash
1119 for _pxe_or_sys in "sys" "pxe"; do
1120 remove "${work_dir}/iso/${install_dir}/boot/syslinux/archiso_${_pxe_or_sys}_${_no_use_config_name}.cfg"
1121 mv "${work_dir}/iso/${install_dir}/boot/syslinux/archiso_${_pxe_or_sys}_${_use_config_name}.cfg" "${work_dir}/iso/${install_dir}/boot/syslinux/archiso_${_pxe_or_sys}.cfg"
1124 # Set syslinux wallpaper
1125 if [[ -f "${script_path}/channels/${channel_name}/splash.png" ]]; then
1126 cp "${script_path}/channels/${channel_name}/splash.png" "${work_dir}/iso/${install_dir}/boot/syslinux"
1128 cp "${script_path}/syslinux/${arch}/splash.png" "${work_dir}/iso/${install_dir}/boot/syslinux"
1132 cp "${work_dir}"/${arch}/airootfs/usr/lib/syslinux/bios/*.c32 "${work_dir}/iso/${install_dir}/boot/syslinux"
1133 cp "${work_dir}/${arch}/airootfs/usr/lib/syslinux/bios/lpxelinux.0" "${work_dir}/iso/${install_dir}/boot/syslinux"
1134 cp "${work_dir}/${arch}/airootfs/usr/lib/syslinux/bios/memdisk" "${work_dir}/iso/${install_dir}/boot/syslinux"
1135 mkdir -p "${work_dir}/iso/${install_dir}/boot/syslinux/hdt"
1136 gzip -c -9 "${work_dir}/${arch}/airootfs/usr/share/hwdata/pci.ids" > "${work_dir}/iso/${install_dir}/boot/syslinux/hdt/pciids.gz"
1137 gzip -c -9 "${work_dir}/${arch}/airootfs/usr/lib/modules/${_uname_r}/modules.alias" > "${work_dir}/iso/${install_dir}/boot/syslinux/hdt/modalias.gz"
1142 mkdir -p "${work_dir}/iso/isolinux"
1144 sed "s|%INSTALL_DIR%|${install_dir}|g" \
1145 "${script_path}/system/isolinux.cfg" > "${work_dir}/iso/isolinux/isolinux.cfg"
1146 cp "${work_dir}/${arch}/airootfs/usr/lib/syslinux/bios/isolinux.bin" "${work_dir}/iso/isolinux/"
1147 cp "${work_dir}/${arch}/airootfs/usr/lib/syslinux/bios/isohdpfx.bin" "${work_dir}/iso/isolinux/"
1148 cp "${work_dir}/${arch}/airootfs/usr/lib/syslinux/bios/ldlinux.c32" "${work_dir}/iso/isolinux/"
1153 mkdir -p "${work_dir}/iso/EFI/boot"
1154 cp "${work_dir}/${arch}/airootfs/usr/lib/systemd/boot/efi/systemd-bootx64.efi" "${work_dir}/iso/EFI/boot/bootx64.efi"
1156 mkdir -p "${work_dir}/iso/loader/entries"
1157 cp "${script_path}/efiboot/loader/loader.conf" "${work_dir}/iso/loader/"
1159 sed "s|%ARCHISO_LABEL%|${iso_label}|g;
1160 s|%OS_NAME%|${os_name}|g;
1161 s|%KERNEL_FILENAME%|${kernel_filename}|g;
1162 s|%INSTALL_DIR%|${install_dir}|g" \
1163 "${script_path}/efiboot/loader/entries/archiso-x86_64-usb.conf" > "${work_dir}/iso/loader/entries/archiso-x86_64.conf"
1165 # edk2-shell based UEFI shell
1166 # shellx64.efi is picked up automatically when on /
1167 cp "${work_dir}/x86_64/airootfs/usr/share/edk2-shell/x64/Shell_Full.efi" "${work_dir}/iso/shellx64.efi"
1170 # Prepare efiboot.img::/EFI for "El Torito" EFI boot mode
1172 mkdir -p "${work_dir}/iso/EFI/archiso"
1173 truncate -s 64M "${work_dir}/iso/EFI/archiso/efiboot.img"
1174 mkfs.fat -n ARCHISO_EFI "${work_dir}/iso/EFI/archiso/efiboot.img"
1176 mkdir -p "${work_dir}/efiboot"
1177 mount "${work_dir}/iso/EFI/archiso/efiboot.img" "${work_dir}/efiboot"
1179 mkdir -p "${work_dir}/efiboot/EFI/archiso"
1181 cp "${work_dir}/iso/${install_dir}/boot/${arch}/${kernel_filename}" "${work_dir}/efiboot/EFI/archiso/${kernel_filename}.efi"
1182 cp "${work_dir}/iso/${install_dir}/boot/${arch}/archiso.img" "${work_dir}/efiboot/EFI/archiso/archiso.img"
1184 cp "${work_dir}/iso/${install_dir}/boot/intel_ucode.img" "${work_dir}/efiboot/EFI/archiso/intel_ucode.img"
1185 cp "${work_dir}/iso/${install_dir}/boot/amd_ucode.img" "${work_dir}/efiboot/EFI/archiso/amd_ucode.img"
1187 mkdir -p "${work_dir}/efiboot/EFI/boot"
1188 cp "${work_dir}/${arch}/airootfs/usr/lib/systemd/boot/efi/systemd-bootx64.efi" "${work_dir}/efiboot/EFI/boot/bootx64.efi"
1190 mkdir -p "${work_dir}/efiboot/loader/entries"
1191 cp "${script_path}/efiboot/loader/loader.conf" "${work_dir}/efiboot/loader/"
1194 sed "s|%ARCHISO_LABEL%|${iso_label}|g;
1195 s|%OS_NAME%|${os_name}|g;
1196 s|%KERNEL_FILENAME%|${kernel_filename}|g;
1197 s|%INSTALL_DIR%|${install_dir}|g" \
1198 "${script_path}/efiboot/loader/entries/archiso-x86_64-cd.conf" > "${work_dir}/efiboot/loader/entries/archiso-x86_64.conf"
1200 # shellx64.efi is picked up automatically when on /
1201 cp "${work_dir}/iso/shellx64.efi" "${work_dir}/efiboot/"
1203 umount -d "${work_dir}/efiboot"
1208 cp -a -l -f "${work_dir}/${arch}/airootfs" "${work_dir}"
1210 if [[ -f "${work_dir}/${arch}/airootfs/root/optimize_for_tarball.sh" ]]; then
1211 chmod 755 "${work_dir}/${arch}/airootfs/root/optimize_for_tarball.sh"
1212 # Execute optimize_for_tarball.sh.
1213 ${mkalteriso} ${mkalteriso_option} \
1214 -w "${work_dir}/${arch}" \
1215 -C "${work_dir}/pacman-${arch}.conf" \
1216 -D "${install_dir}" \
1217 -r "/root/optimize_for_tarball.sh" \
1221 ARCHISO_GNUPG_FD=${gpg_key:+17} ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -r "mkinitcpio -p ${kernel_mkinitcpio_profile}" run
1223 remove "${work_dir}/${arch}/airootfs/root/optimize_for_tarball.sh"
1225 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}" -D "${install_dir}" -L "${iso_label}" -P "${iso_publisher}" -A "${iso_application}" -o "${out_dir}" tarball "$(echo ${iso_filename} | sed 's/\.[^\.]*$//').tar.xz"
1227 remove "${work_dir}/airootfs"
1228 if [[ "${noiso}" = true ]]; then
1229 msg_info "The password for the live user and root is ${password}."
1233 # Build airootfs filesystem image
1235 cp -a -l -f "${work_dir}/${arch}/airootfs" "${work_dir}"
1236 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}" -D "${install_dir}" pkglist
1237 pacman -Q --sysroot "${work_dir}/airootfs" > "${work_dir}/packages-full.list"
1238 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}" -D "${install_dir}" ${gpg_key:+-g ${gpg_key}} -c "${sfs_comp}" -t "${sfs_comp_opt}" prepare
1239 remove "${work_dir}/airootfs"
1241 if [[ "${cleaning}" = true ]]; then
1242 remove "${work_dir}/${arch}/airootfs"
1246 local _write_info_file _info_file="${work_dir}/iso/alteriso-info"
1247 _write_info_file () {
1248 echo "${@}" >> "${_info_file}"
1250 rm -rf "${_info_file}"; touch "${_info_file}"
1251 if [[ -d "${script_path}/.git" ]]; then
1252 _write_info_file "${iso_application} ${arch} ${iso_version}-$(git rev-parse --short HEAD)"
1254 _write_info_file "${iso_application} ${arch} ${iso_version}"
1256 _write_info_file "Created by ${iso_publisher}"
1257 _write_info_file "Live user name: ${username}"
1258 _write_info_file "Live user pass: ${password}"
1263 ${mkalteriso} ${mkalteriso_option} -w "${work_dir}" -D "${install_dir}" -L "${iso_label}" -P "${iso_publisher}" -A "${iso_application}" -o "${out_dir}" iso "${iso_filename}"
1264 msg_info "The password for the live user and root is ${password}."
1270 local _get_locale_line_number _locale_config_file _locale_name_list _locale_line_number _locale_config_line
1272 # 選択されたロケールの設定が描かれた行番号を取得
1273 _locale_config_file="${script_path}/system/locale-${arch}"
1274 _locale_name_list=($(cat "${_locale_config_file}" | grep -h -v ^'#' | awk '{print $1}'))
1275 _get_locale_line_number() {
1277 for _lang in ${_locale_name_list[@]}; do
1278 count=$(( count + 1 ))
1279 if [[ "${_lang}" == "${locale_name}" ]]; then
1287 _locale_line_number="$(_get_locale_line_number)"
1290 [[ "${_locale_line_number}" == "failed" ]] && msg_error "${locale_name} is not a valid language." "1"
1292 # ロケール設定ファイルから該当の行を抽出
1293 _locale_config_line="$(cat "${_locale_config_file}" | grep -h -v ^'#' | grep -v ^$ | head -n "${_locale_line_number}" | tail -n 1)"
1295 # 抽出された行に書かれた設定をそれぞれの変数に代入
1296 # ここで定義された変数のみがグローバル変数
1297 locale_name=$(echo ${_locale_config_line} | awk '{print $1}')
1298 locale_gen_name=$(echo ${_locale_config_line} | awk '{print $2}')
1299 locale_version=$(echo ${_locale_config_line} | awk '{print $3}')
1300 locale_time=$(echo ${_locale_config_line} | awk '{print $4}')
1301 locale_fullname=$(echo ${_locale_config_line} | awk '{print $5}')
1305 local _kernel_config_file _kernel_name_list _kernel_line _get_kernel_line _kernel_config_line
1307 # 選択されたカーネルの設定が描かれた行番号を取得
1308 _kernel_config_file="${script_path}/system/kernel-${arch}"
1309 _kernel_name_list=($(cat "${_kernel_config_file}" | grep -h -v ^'#' | awk '{print $1}'))
1310 _get_kernel_line() {
1314 for _kernel in ${_kernel_name_list[@]}; do
1315 count=$(( count + 1 ))
1316 if [[ "${_kernel}" == "${kernel}" ]]; then
1324 _kernel_line="$(_get_kernel_line)"
1327 [[ "${_kernel_line}" == "failed" ]] && msg_error "Invalid kernel ${kernel}" "1"
1329 # カーネル設定ファイルから該当の行を抽出
1330 _kernel_config_line="$(cat "${_kernel_config_file}" | grep -h -v ^'#' | grep -v ^$ | head -n "${_kernel_line}" | tail -n 1)"
1332 # 抽出された行に書かれた設定をそれぞれの変数に代入
1333 # ここで定義された変数のみがグローバル変数
1334 kernel=$(echo ${_kernel_config_line} | awk '{print $1}')
1335 kernel_package=$(echo ${_kernel_config_line} | awk '{print $2}')
1336 kernel_headers_packages=$(echo ${_kernel_config_line} | awk '{print $3}')
1337 kernel_filename=$(echo ${_kernel_config_line} | awk '{print $4}')
1338 kernel_mkinitcpio_profile=$(echo ${_kernel_config_line} | awk '{print $5}')
1344 _opt_short="a:bc:deg:hjk:l:o:p:rt:u:w:x"
1345 _opt_long="arch:,boot-splash,comp-type:,debug,cleaning,gpgkey:,help,lang:,japanese,kernel:,out:,password:,comp-opts:,user:,work:,bash-debug,nocolor,noconfirm,nodepend,gitversion,shmkalteriso,msgdebug,noloopmod,tarball,noiso,noaur,nochkver,channellist"
1346 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${DEFAULT_ARGUMENT} ${ARGUMENT})
1347 [[ ${?} != 0 ]] && exit 1
1349 eval set -- "${OPT}"
1350 unset OPT _opt_short _opt_long
1364 "gzip" | "lzma" | "lzo" | "lz4" | "xz" | "zstd") sfs_comp="${2}" ;;
1365 *) msg_error "Invaild compressors '${2}'" '1' ;;
1386 msg_error "This option is obsolete in AlterISO 3."
1387 msg_error "To use Japanese, use \"-g ja\"." '1'
1414 customized_username=true
1415 username="$(echo -n "${2}" | sed 's/ //g' |tr '[A-Z]' '[a-z]')"
1440 if [[ -d "${script_path}/.git" ]]; then
1443 msg_error "There is no git directory. You need to use git clone to use this feature." "1"
1480 msg_error "Invalid argument '${1}'"
1488 if [[ ${EUID} -ne 0 ]]; then
1489 msg_warn "This script must be run as root." >&2
1490 # echo "Use -h to display script details." >&2
1492 msg_warn "Re-run 'sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT}'"
1493 sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT}
1497 unset DEFAULT_ARGUMENT ARGUMENT
1499 # Show config message
1500 [[ -f "${defaultconfig}" ]] && msg_debug "Use the default configuration file (${defaultconfig})."
1503 mkalteriso_option="-a ${arch} -v"
1504 if [[ "${bash_debug}" = true ]]; then
1506 mkalteriso_option="${mkalteriso_option} -x"
1509 # Pacman configuration file used only when building
1510 build_pacman_conf="${script_path}/system/pacman-${arch}.conf"
1512 # Set rebuild config file
1513 rebuildfile="${work_dir}/alteriso_config"
1517 [[ -n "${1}" ]] && channel_name="${1}"
1519 # check_channel <channel name>
1521 local channel_list i
1523 for i in $(ls -l "${script_path}"/channels/ | awk '$1 ~ /d/ {print $9 }'); do
1524 if [[ -n $(ls "${script_path}"/channels/${i}) ]] && [[ ! ${i} = "share" ]]; then
1525 if [[ $(echo "${i}" | sed 's/^.*\.\([^\.]*\)$/\1/') = "add" ]]; then
1526 channel_list="${channel_list[@]} ${i}"
1527 elif [[ ! -d "${script_path}/channels/${i}.add" ]]; then
1528 channel_list="${channel_list[@]} ${i}"
1532 for i in ${channel_list[@]}; do
1533 if [[ $(echo "${i}" | sed 's/^.*\.\([^\.]*\)$/\1/') = "add" ]]; then
1534 if [[ $(echo ${i} | sed 's/\.[^\.]*$//') = ${1} ]] ; then
1538 elif [[ "${i}" == "${1}" ]] || [[ "${channel_name}" = "rebuild" ]] || [[ "${channel_name}" = "clean" ]]; then
1548 # Check for a valid channel name
1549 [[ $(check_channel "${channel_name}") = false ]] && msg_error "Invalid channel ${channel_name}" "1"
1551 # Set for special channels
1552 if [[ -d "${script_path}"/channels/${channel_name}.add ]]; then
1553 channel_name="${channel_name}.add"
1554 elif [[ "${channel_name}" = "rebuild" ]]; then
1555 if [[ -f "${rebuildfile}" ]]; then
1558 msg_error "The previous build information is not in the working directory." "1"
1560 elif [[ "${channel_name}" = "clean" ]]; then
1562 remove "${script_path}/menuconfig/build"
1563 remove "${script_path}/system/cpp-src/mkalteriso/build"
1564 remove "${script_path}/menuconfig-script/kernel_choice"
1565 remove "${work_dir%/}"/*
1566 remove "${work_dir}"
1567 remove "${rebuildfile}"
1571 # Check channel version
1572 if [[ ! "${channel_name}" == "rebuild" ]]; then
1573 msg_debug "channel path is ${script_path}/channels/${channel_name}"
1574 if [[ ! "$(cat "${script_path}/channels/${channel_name}/alteriso" 2> /dev/null)" = "alteriso=3" ]] && [[ "${nochkver}" = false ]]; then
1575 msg_error "This channel does not support AlterISO 3." "1"
1581 check_bool bash_debug
1591 run_once make_pacman_conf
1592 run_once make_basefs
1593 run_once make_packages
1594 [[ "${noaur}" = false ]] && run_once make_packages_aur
1595 run_once make_customize_airootfs
1596 run_once make_setup_mkinitcpio
1598 run_once make_boot_extra
1599 run_once make_syslinux
1600 run_once make_isolinux
1602 run_once make_efiboot
1603 [[ "${tarball}" = true ]] && run_once make_tarball
1604 [[ "${noiso}" = false ]] && run_once make_prepare
1605 [[ "${noiso}" = false ]] && run_once make_iso
1606 [[ "${cleaning}" = true ]] && remove_work