# The main script that runs the build
#
-set -e
-set -u
+set -eu
# Internal config
# Do not change these values.
rebuild=false
customized_username=false
-
# Load config file
if [[ -f "${defaultconfig}" ]]; then
source "${defaultconfig}"
exit 1
fi
-
umask 0022
-
# Color echo
# usage: echo_color -b <backcolor> -t <textcolor> -d <decoration> [Text]
#
# 8 => Concealed on
echo_color() {
- local backcolor
- local textcolor
- local decotypes
- local echo_opts
- local arg
- local OPTIND
- local OPT
-
+ local backcolor textcolor decotypes echo_opts arg OPTIND OPT
echo_opts="-e"
-
while getopts 'b:t:d:n' arg; do
case "${arg}" in
b) backcolor="${OPTARG}" ;;
n) echo_opts="-n -e" ;;
esac
done
-
shift $((OPTIND - 1))
-
if [[ "${nocolor}" = false ]]; then
echo ${echo_opts} "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${*}\e[m"
else
else
set -xv
fi
- local echo_opts="-e"
- local arg
- local OPTIND
- local OPT
+ local echo_opts="-e" arg OPTIND OPT
while getopts 'n' arg; do
case "${arg}" in
n) echo_opts="${echo_opts} -n" ;;
else
set -xv
fi
- local echo_opts="-e"
- local arg
- local OPTIND
- local OPT
+ local echo_opts="-e" arg OPTIND OPT
while getopts 'n' arg; do
case "${arg}" in
n) echo_opts="${echo_opts} -n" ;;
else
set -xv
fi
- local echo_opts="-e"
- local arg
- local OPTIND
- local OPT
+ local echo_opts="-e" arg OPTIND OPT
while getopts 'n' arg; do
case "${arg}" in
n) echo_opts="${echo_opts} -n" ;;
else
set -xv
fi
- local echo_opts="-e"
- local arg
- local OPTIND
- local OPT
- local OPTARG
+ local echo_opts="-e" arg OPTIND OPT
while getopts 'n' arg; do
case "${arg}" in
n) echo_opts="${echo_opts} -n" ;;
echo " Default: ${work_dir}"
echo
- local blank="33"
- local arch
- local lang
- local list
- local locale_name_list
- local kernel
+ local blank="33" arch lang list locale_name_list kernel
echo " Language for each architecture:"
for list in ${script_path}/system/locale-* ; do
echo " --nodepend No check package dependencies before building."
echo " --noiso No build iso image. (Use with --tarball)"
echo " --shmkalteriso Use the shell script version of mkalteriso."
-
if [[ -n "${1:-}" ]]; then
exit "${1}"
fi
fi
}
-
# rm helper
# Delete the file if it exists.
# For directories, rm -rf is used.
# If the file does not exist, skip it.
# remove <file> <file> ...
remove() {
- local _list
- local _file
- _list=($(echo "$@"))
+ local _list=($(echo "$@")) _file
for _file in "${_list[@]}"; do
if [[ -f ${_file} ]]; then
_msg_debug "Removeing ${_file}"
done
}
+# Debug line
+debug_line() {
+ if [[ "${debug}" = true ]]; then
+ echo
+ fi
+}
# 強制終了時にアンマウント
umount_trap() {
out_dir="$(realpath -e "${out_dir}")"
work_dir="$(realpath -e "${work_dir}")"
-
# Check work dir
if [[ -n $(ls -a "${work_dir}" 2> /dev/null | grep -xv ".." | grep -xv ".") ]] && [[ ! "${rebuild}" = true ]]&& [[ ! "${rebuild}" = true ]]; then
umount_chroot
remove "${work_dir%/}"/*
fi
-
# 強制終了時に作業ディレクトリを削除する
local trap_remove_work
trap_remove_work() {
load_config "${script_path}/channels/share/config.any"
load_config ${script_path}/channels/share/config.${arch}
-
# If there is config for each channel. load that.
load_config "${script_path}/channels/${channel_name}/config.any"
load_config "${script_path}/channels/${channel_name}/config.${arch}"
-
# Set username
if [[ "${customized_username}" = false ]]; then
username="${defaultusername}"
local save_var
save_var() {
- local out_file="${rebuildfile}"
- local i
+ local out_file="${rebuildfile}" i
for i in ${@}; do
echo -n "${i}=" >> "${out_file}"
echo -n '"' >> "${out_file}"
if [[ "${channel_name}" = "rebuild" ]]; then
# Delete the lock file.
remove "$(ls ${work_dir}/* | grep "build.make")"
-
# reset work
remove_work
fi
mkalteriso="${script_path}/system/mkalteriso.sh"
fi
-
# Show alteriso version
if [[ -d "${script_path}/.git" ]]; then
cd "${script_path}"
cd - > /dev/null 2>&1
fi
-
# Unmount
local mount
for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir})); do
umount "${mount}"
done
-
# Check packages
if [[ "${nodepend}" = false ]] && [[ "${arch}" = $(uname -m) ]] ; then
- local installed_pkg
- local installed_ver
- local check_pkg
- local check_failed=false
- local pkg
-
- installed_pkg=($(pacman -Q | awk '{print $1}'))
- installed_ver=($(pacman -Q | awk '{print $2}'))
-
+ local check_pkg check_failed=false pkg
+ local installed_pkg=($(pacman -Q | awk '{print $1}')) installed_ver=($(pacman -Q | awk '{print $2}'))
+
check_pkg() {
- local i
- local ver
+ local i ver
for i in $(seq 0 $(( ${#installed_pkg[@]} - 1 ))); do
if [[ "${installed_pkg[${i}]}" = ${1} ]]; then
ver=$(pacman -Sp --print-format '%v' --config ${build_pacman_conf} ${1} 2> /dev/null)
if [[ ${noconfirm} = false ]]; then
echo "Press Enter to continue or Ctrl + C to cancel."
read
- else
- :
- #sleep 3
fi
trap 1 2 3 15
trap 'umount_trap' 1 2 3 15
# Base installation, plus needed packages (airootfs)
make_basefs() {
${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" init
- # ${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "haveged intel-ucode amd-ucode memtest86+ mkinitcpio-nfs-utils nbd zsh efitools" install
${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "bash haveged intel-ucode amd-ucode mkinitcpio-nfs-utils nbd efitools" install
# Install plymouth.
make_packages() {
# インストールするパッケージのリストを読み込み、配列pkglistに代入します。
set +e
- local _loadfilelist
- local _pkg
- local _file
- local excludefile
- local excludelist
- local _pkglist
+ local _loadfilelist _pkg _file excludefile excludelist _pkglist
#-- Detect package list to load --#
# Add the files for each channel to the list of files to read.
pkglist=( ${pkglist[@]} "$(grep -h -v ^'#' ${_file})" )
fi
done
- if [[ ${debug} = true ]]; then
- sleep 1
- fi
-
+
#-- Read exclude list --#
# Exclude packages from the share exclusion list
excludefile=(
_msg_debug "Excluded packages:" "${excludelist[@]}"
fi
-
# Sort the list of packages in abc order.
pkglist=(
"$(
)
set -e
- # _msg_debug "${pkglist[@]}"
-
# Create a list of packages to be finally installed as packages.list directly under the working directory.
echo "# The list of packages that is installed in live cd." > "${work_dir}/packages.list"
echo "#" >> "${work_dir}/packages.list"
# Install packages on airootfs
${mkalteriso} ${mkalteriso_option} -w "${work_dir}/${arch}" -C "${work_dir}/pacman-${arch}.conf" -D "${install_dir}" -p "${pkglist[@]}" install
}
+
+
make_packages_aur() {
# インストールするパッケージのリストを読み込み、配列pkglistに代入します。
set +e
- local _loadfilelist
- local _pkg
- local _file
- local excludefile
- local excludelist
- local _pkglist
+
+ local _loadfilelist _pkg _file excludefile excludelist _pkglist
#-- Detect package list to load --#
# Add the files for each channel to the list of files to read.
"${script_path}"/channels/share/packages_aur.${arch}/lang/${language}.${arch}
)
-
#-- Read package list --#
# Read the file and remove comments starting with # and add it to the list of packages to install.
for _file in ${_loadfilelist[@]}; do
pkglist_aur=( ${pkglist_aur[@]} "$(grep -h -v ^'#' ${_file})" )
fi
done
- if [[ ${debug} = true ]]; then
- sleep 1
- fi
#-- Read exclude list --#
# Exclude packages from the share exclusion list
_msg_debug "Excluded packages:" "${excludelist[@]}"
fi
-
# Sort the list of packages in abc order.
pkglist_aur=(
"$(
local copy_airootfs
copy_airootfs() {
- local i
- for i in "${@}"; do
- local _dir="${i%/}"
- if [[ -d "${_dir}" ]]; then
- cp -af "${_dir}"/* "${work_dir}/${arch}/airootfs"
- fi
- done
+ local _dir="${1%/}"
+ if [[ -d "${_dir}" ]]; then
+ cp -af "${_dir}"/* "${work_dir}/${arch}/airootfs"
+ fi
}
-
+
copy_airootfs "${script_path}/channels/share/airootfs.any"
copy_airootfs "${script_path}/channels/share/airootfs.${arch}"
copy_airootfs "${script_path}/channels/${channel_name}/airootfs.any"
if [[ "${boot_splash}" = true ]]; then
cp "${script_path}/mkinitcpio/mkinitcpio-plymouth.conf" "${work_dir}/${arch}/airootfs/etc/mkinitcpio.conf"
fi
-
- # Code to use common pacman.conf in archiso.
- # cp "${script_path}/pacman.conf" "${work_dir}/${arch}/airootfs/etc"
- # cp "${build_pacman_conf}" "${work_dir}/${arch}/airootfs/etc"
-
+
# Get the optimal mirror list.
case "${arch}" in
"x86_64") arch_domain="https://www.archlinux.org/mirrorlist/" ;;
# Generate options of customize_airootfs.sh.
- local addition_options
- local share_options
- addition_options=
+ local customize_airootfs_script_options
+ customize_airootfs_script_options="-p '${password}' -k '${kernel_config_line}' -u '${username}' -o '${os_name}' -i '${install_dir}' -s '${usershell}' -a '${arch}' -g '${localegen}' -l '${language}' -z '${timezone}' -t ${theme_name}"
if [[ ${boot_splash} = true ]]; then
- if [[ -z ${theme_name} ]]; then
- addition_options="${addition_options} -b"
- else
- addition_options="${addition_options} -b -t ${theme_name}"
- fi
+ customize_airootfs_script_options="${customize_airootfs_script_options} -b"
fi
if [[ ${debug} = true ]]; then
- addition_options="${addition_options} -d"
+ customize_airootfs_script_options="${customize_airootfs_script_options} -d"
fi
if [[ ${bash_debug} = true ]]; then
- addition_options="${addition_options} -x"
+ customize_airootfs_script_options="${customize_airootfs_script_options} -x"
fi
if [[ ${rebuild} = true ]]; then
- addition_options="${addition_options} -r"
+ customize_airootfs_script_options="${customize_airootfs_script_options} -r"
fi
-
- share_options="-p '${password}' -k '${kernel_config_line}' -u '${username}' -o '${os_name}' -i '${install_dir}' -s '${usershell}' -a '${arch}' -g '${localegen}' -l '${language}' -z '${timezone}'"
-
-
+
# X permission
- if [[ -f ${work_dir}/${arch}/airootfs/root/customize_airootfs.sh ]]; then
- chmod 755 "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh"
- fi
- if [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh" ]]; then
- chmod 755 "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh"
- fi
- if [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh" ]]; then
- chmod 755 "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh"
- elif [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh" ]]; then
- chmod 755 "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh"
- fi
+ local chmod_755
+ chmod_755() {
+ _file="${1}"
+ if [[ -f "$_file" ]]; then
+ chmod 755 "${_file}"
+ fi
+ }
+
+ chmod_755 "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh"
+ chmod_755 "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh"
+ chmod_755 "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh"
+ chmod_755 "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh"
# Execute customize_airootfs.sh.
- if [[ -z ${addition_options} ]]; then
+ ${mkalteriso} ${mkalteriso_option} \
+ -w "${work_dir}/${arch}" \
+ -C "${work_dir}/pacman-${arch}.conf" \
+ -D "${install_dir}" \
+ -r "/root/customize_airootfs.sh ${customize_airootfs_script_options}" \
+ run
+
+ if [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh" ]]; then
${mkalteriso} ${mkalteriso_option} \
-w "${work_dir}/${arch}" \
-C "${work_dir}/pacman-${arch}.conf" \
-D "${install_dir}" \
- -r "/root/customize_airootfs.sh ${share_options}" \
+ -r "/root/customize_airootfs_${channel_name}.sh ${customize_airootfs_script_options}" \
run
- if [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh" ]]; then
- ${mkalteriso} ${mkalteriso_option} \
- -w "${work_dir}/${arch}" \
- -C "${work_dir}/pacman-${arch}.conf" \
- -D "${install_dir}" \
- -r "/root/customize_airootfs_${channel_name}.sh ${share_options}" \
- run
- elif [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh" ]]; then
- ${mkalteriso} ${mkalteriso_option} \
- -w "${work_dir}/${arch}" \
- -C "${work_dir}/pacman-${arch}.conf" \
- -D "${install_dir}" \
- -r "/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh ${share_options}" \
- run
- fi
- else
+ elif [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh" ]]; then
${mkalteriso} ${mkalteriso_option} \
-w "${work_dir}/${arch}" \
-C "${work_dir}/pacman-${arch}.conf" \
-D "${install_dir}" \
- -r "/root/customize_airootfs.sh ${share_options} ${addition_options}" \
+ -r "/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh ${customize_airootfs_script_options}" \
run
-
- if [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh" ]]; then
- ${mkalteriso} ${mkalteriso_option} \
- -w "${work_dir}/${arch}" \
- -C "${work_dir}/pacman-${arch}.conf" \
- -D "${install_dir}" \
- -r "/root/customize_airootfs_${channel_name}.sh ${share_options} ${addition_options}" \
- run
- elif [[ -f "${work_dir}/${arch}/airootfs/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh" ]]; then
- ${mkalteriso} ${mkalteriso_option} \
- -w "${work_dir}/${arch}" \
- -C "${work_dir}/pacman-${arch}.conf" \
- -D "${install_dir}" \
- -r "/root/customize_airootfs_$(echo ${channel_name} | sed 's/\.[^\.]*$//').sh ${share_options} ${addition_options}" \
- run
- fi
fi
-
# Delete customize_airootfs.sh.
remove "${work_dir}/${arch}/airootfs/root/customize_airootfs.sh"
remove "${work_dir}/${arch}/airootfs/root/customize_airootfs_${channel_name}.sh"
# Add other aditional/extra files to ${install_dir}/boot/
make_boot_extra() {
- # In AlterLinux, memtest has been removed.
- # cp "${work_dir}/${arch}/airootfs/boot/memtest86+/memtest.bin" "${work_dir}/iso/${install_dir}/boot/memtest"
- # cp "${work_dir}/${arch}/airootfs/usr/share/licenses/common/GPL2/license.txt" "${work_dir}/iso/${install_dir}/boot/memtest.COPYING"
cp "${work_dir}/${arch}/airootfs/boot/intel-ucode.img" "${work_dir}/iso/${install_dir}/boot/intel_ucode.img"
cp "${work_dir}/${arch}/airootfs/usr/share/licenses/intel-ucode/LICENSE" "${work_dir}/iso/${install_dir}/boot/intel_ucode.LICENSE"
cp "${work_dir}/${arch}/airootfs/boot/amd-ucode.img" "${work_dir}/iso/${install_dir}/boot/amd_ucode.img"
done
# Replace the SYSLINUX configuration file with or without boot splash.
- local _use_config_name
- local _no_use_config_name
- local _pxe_or_sys
+ local _use_config_name _no_use_config_name _pxe_or_sys
if [[ "${boot_splash}" = true ]]; then
_use_config_name=splash
_no_use_config_name=nosplash
cp "${script_path}/efiboot/loader/entries/uefi-shell-x86_64.conf" "${work_dir}/efiboot/loader/entries/"
cp "${script_path}/efiboot/loader/entries/uefi-shell-full-x86_64.conf" "${work_dir}/efiboot/loader/entries/"
-
sed "s|%ARCHISO_LABEL%|${iso_label}|g;
s|%OS_NAME%|${os_name}|g;
s|%KERNEL_FILENAME%|${kernel_filename}|g;
unset _opt_short
unset _opt_long
-
while :; do
case ${1} in
-a | --arch)
arch="${2}"
shift 2
- ;;
+ ;;
-b | --boot-splash)
boot_splash=true
shift 1
- ;;
+ ;;
-c | --comp-type)
case "${2}" in
"gzip" | "lzma" | "lzo" | "lz4" | "xz" | "zstd") sfs_comp="${2}" ;;
*) _msg_error "Invaild compressors '${2}'" '1' ;;
esac
shift 2
- ;;
+ ;;
-d | --debug)
debug=true
shift 1
- ;;
+ ;;
-g | --lang)
language="${2}"
shift 2
- ;;
+ ;;
-h | --help)
_usage
exit 0
- ;;
+ ;;
-j | --japanese)
_msg_error "This option is obsolete in AlterISO 3."
_msg_error "To use Japanese, use \"-g ja\"." '1'
- ;;
+ ;;
-k | --kernel)
kernel="${2}"
shift 2
- ;;
+ ;;
-l | --cleaning)
cleaning=true
shift 1
- ;;
+ ;;
-o | --out)
out_dir="${2}"
shift 2
- ;;
+ ;;
-p | --password)
password="${2}"
shift 2
- ;;
+ ;;
-t | --comp-opts)
sfs_comp_opt="${2}"
shift 2
- ;;
+ ;;
-u | --user)
customized_username=true
username="$(echo -n "${2}" | sed 's/ //g' |tr '[A-Z]' '[a-z]')"
shift 2
- ;;
+ ;;
-w | --work)
work_dir="${2}"
shift 2
- ;;
+ ;;
-x | --bash-debug)
debug=true
bash_debug=true
shift 1
- ;;
+ ;;
--noconfirm)
noconfirm=true
shift 1
- ;;
+ ;;
--nodepend)
nodepend=true
shift 1
- ;;
+ ;;
--nocolor)
nocolor=true
shift 1
- ;;
+ ;;
--gitversion)
if [[ -d "${script_path}/.git" ]]; then
gitversion=true
_msg_error "There is no git directory. You need to use git clone to use this feature." "1"
fi
shift 1
- ;;
+ ;;
--shmkalteriso)
shmkalteriso=true
shift 1
- ;;
+ ;;
--msgdebug)
msgdebug=true;
shift 1
- ;;
+ ;;
--noloopmod)
noloopmod=true
shift 1
--)
shift
break
- ;;
+ ;;
*)
_msg_error "Invalid argument '${1}'"
_usage 1
- ;;
+ ;;
esac
done
# Show config message
[[ -f "${defaultconfig}" ]] && _msg_debug "The settings have been overwritten by the ${defaultconfig}"
-
# Debug mode
mkalteriso_option="-a ${arch} -v"
if [[ "${bash_debug}" = true ]]; then
mkalteriso_option="${mkalteriso_option} -x"
fi
-
# Pacman configuration file used only when building
build_pacman_conf=${script_path}/system/pacman-${arch}.conf
# Set rebuild config file
rebuildfile="${work_dir}/build_options"
-
# Parse channels
set +eu
if [[ -n "${1}" ]]; then
# check_channel <channel name>
check_channel() {
- local channel_list
- local i
+ local channel_list i
channel_list=()
for i in $(ls -l "${script_path}"/channels/ | awk '$1 ~ /d/ {print $9 }'); do
if [[ -n $(ls "${script_path}"/channels/${i}) ]] && [[ ! ${i} = "share" ]]; then
locale_config_file="${script_path}/system/locale-${arch}"
locale_name_list=($(cat "${locale_config_file}" | grep -h -v ^'#' | awk '{print $1}'))
get_locale_line() {
- local _lang
- local count
- count=0
+ local _lang count=0
for _lang in ${locale_name_list[@]}; do
count=$(( count + 1 ))
if [[ "${_lang}" == "${language}" ]]; then
fi
kernel_config_line="$(cat "${kernel_config_file}" | grep -h -v ^'#' | grep -v ^$ | head -n "${kernel_line}" | tail -n 1)"
-
kernel_package=$(echo ${kernel_config_line} | awk '{print $2}')
kernel_headers_packages=$(echo ${kernel_config_line} | awk '{print $3}')
kernel_filename=$(echo ${kernel_config_line} | awk '{print $4}')
kernel_mkinitcpio_profile=$(echo ${kernel_config_line} | awk '{print $5}')
-kernel_config_line="${kernel} ${kernel_package} ${kernel_headers_packages} ${kernel_filename} ${kernel_mkinitcpio_profile}"
-
# Check the value of a variable that can only be set to true or false.
check_bool() {
fi
}
-if [[ "${debug}" = true ]]; then
- echo
-fi
+debug_line
+
check_bool boot_splash
check_bool debug
check_bool bash_debug
check_bool noiso
check_bool noaur
-if [[ "${debug}" = true ]]; then
- echo
-fi
+debug_line
set -eu