Skip to content

Commit ceb7c9e

Browse files
committed
Merge branch 'dev' into dev-stable
2 parents 81b8bf5 + 4d87d37 commit ceb7c9e

File tree

8 files changed

+201
-672
lines changed

8 files changed

+201
-672
lines changed

build.sh

Lines changed: 50 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ customized_username=false
2323
customized_password=false
2424
customized_kernel=false
2525
customized_logpath=false
26-
pkglist_args=""
26+
pkglist_args=()
2727
DEFAULT_ARGUMENT=""
2828
alteriso_version="3.1"
2929

@@ -103,9 +103,7 @@ msg_error() {
103103

104104
# Usage: getclm <number>
105105
# 標準入力から値を受けとり、引数で指定された列を抽出します。
106-
getclm() {
107-
echo "$(cat -)" | cut -d " " -f "${1}"
108-
}
106+
getclm() { cat - | cut -d " " -f "${1}"; }
109107

110108
# Usage: echo_blank <number>
111109
# 指定されたぶんの半角空白文字を出力します
@@ -199,11 +197,9 @@ _mount() { if ! mountpoint -q "${2}" && [[ -f "${1}" ]] && [[ -d "${2}" ]]; then
199197
# Unmount chroot dir
200198
umount_chroot () {
201199
local _mount
202-
for _mount in $(cat /proc/mounts | getclm 2 | grep $(realpath ${work_dir}) | tac); do
203-
if [[ ! "${_mount}" = "$(realpath ${work_dir})/${arch}/airootfs" ]]; then
204-
msg_info "Unmounting ${_mount}"
205-
_umount "${_mount}" 2> /dev/null
206-
fi
200+
for _mount in $(cat /proc/mounts | getclm 2 | grep "$(realpath ${work_dir})" | tac | grep -xv "$(realpath ${work_dir})/${arch}/airootfs"); do
201+
msg_info "Unmounting ${_mount}"
202+
_umount "${_mount}" 2> /dev/null
207203
done
208204
}
209205

@@ -255,7 +251,7 @@ umount_trap() {
255251
# load_config [file1] [file2] ...
256252
load_config() {
257253
local _file
258-
for _file in ${@}; do if [[ -f "${_file}" ]] ; then source "${_file}" && msg_debug "The settings have been overwritten by the ${_file}"; fi; done
254+
for _file in "${@}"; do if [[ -f "${_file}" ]] ; then source "${_file}" && msg_debug "The settings have been overwritten by the ${_file}"; fi; done
259255
}
260256

261257
# Display channel list
@@ -271,7 +267,7 @@ show_channel_list() {
271267
# for_module <command>
272268
for_module(){
273269
local module
274-
for module in ${modules[@]}; do eval $(echo ${@} | sed "s|{}|${module}|g"); done
270+
for module in "${modules[@]}"; do eval "$(echo "${@}" | sed "s|{}|${module}|g")"; done
275271
}
276272

277273
# パッケージをインストールする
@@ -284,7 +280,7 @@ _pacman(){
284280
# コマンドをchrootで実行する
285281
_chroot_run() {
286282
msg_debug "Run command in chroot\nCommand: ${*}"
287-
eval -- arch-chroot "${airootfs_dir}" ${@}
283+
eval -- arch-chroot "${airootfs_dir}" "${@}"
288284
}
289285

290286
_cleanup_common () {
@@ -328,7 +324,7 @@ _mkchecksum() {
328324
# Check the value of a variable that can only be set to true or false.
329325
check_bool() {
330326
local _value _variable
331-
for _variable in ${@}; do
327+
for _variable in "${@}"; do
332328
msg_debug -n "Checking ${_variable}..."
333329
eval ': ${'${_variable}':=""}'
334330
_value="$(eval echo '$'${_variable})"
@@ -349,8 +345,8 @@ prepare_env() {
349345
if [[ "${nodepend}" = false ]]; then
350346
local _check_failed=false _pkg _result=0
351347
msg_info "Checking dependencies ..."
352-
for _pkg in ${dependence[@]}; do
353-
eval "${tools_dir}/package.py" "${_pkg}" $( [[ "${debug}" = false ]] && echo "> /dev/null") || _result="${?}"
348+
for _pkg in "${dependence[@]}"; do
349+
eval "${tools_dir}/package.py" "${_pkg}" "$( [[ "${debug}" = false ]] && echo "> /dev/null")" || _result="${?}"
354350
case "${_result}" in
355351
"3")
356352
_check_failed=true
@@ -378,15 +374,15 @@ prepare_env() {
378374
if [[ -n $(ls -a "${work_dir}" 2> /dev/null | grep -xv ".." | grep -xv ".") ]] && [[ "${normwork}" = false ]]; then
379375
umount_chroot_advance
380376
msg_info "Deleting the contents of ${work_dir}..."
381-
"${tools_dir}/clean.sh" -o -w $(realpath "${work_dir}") $([[ "${debug}" = true ]] && echo -n "-d")
377+
"${tools_dir}/clean.sh" -o -w "$(realpath "${work_dir}")" "$([[ "${debug}" = true ]] && echo -n "-d")"
382378
fi
383379

384380
# 強制終了時に作業ディレクトリを削除する
385381
local _trap_remove_work
386382
_trap_remove_work() {
387383
local status=${?}
388384
if [[ "${normwork}" = false ]]; then
389-
echo; "${tools_dir}/clean.sh" -o -w $(realpath "${work_dir}") $([[ "${debug}" = true ]] && echo -n "-d")
385+
echo; "${tools_dir}/clean.sh" -o -w "$(realpath "${work_dir}")" "$([[ "${debug}" = true ]] && echo -n "-d")"
390386
fi
391387
exit ${status}
392388
}
@@ -422,7 +418,7 @@ prepare_build() {
422418
if [[ -d "${script_path}/.git" ]]; then
423419
cd "${script_path}"
424420
msg_debug "The version of alteriso is $(git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')."
425-
cd "${OLDPWD}" > /dev/null 2>&1
421+
cd "${OLDPWD}"
426422
fi
427423

428424
# Set dirs
@@ -473,8 +469,8 @@ prepare_build() {
473469
fi
474470

475471
# Parse files
476-
eval $(bash "${tools_dir}/locale.sh" -s -a "${arch}" get "${locale_name}")
477-
eval $(bash "${tools_dir}/kernel.sh" -s -c "${channel_name}" -a "${arch}" get "${kernel}")
472+
eval "$(bash "${tools_dir}/locale.sh" -s -a "${arch}" get "${locale_name}")"
473+
eval "$(bash "${tools_dir}/kernel.sh" -s -c "${channel_name}" -a "${arch}" get "${kernel}")"
478474

479475
# Set username
480476
if [[ "${customized_username}" = false ]]; then
@@ -489,7 +485,7 @@ prepare_build() {
489485
# gitversion
490486
if [[ "${gitversion}" = true ]]; then
491487
cd "${script_path}"
492-
iso_version=${iso_version}-$(git rev-parse --short HEAD)
488+
iso_version="${iso_version}-$(git rev-parse --short HEAD)"
493489
cd "${OLDPWD}"
494490
fi
495491

@@ -512,6 +508,19 @@ prepare_build() {
512508
msg_error "${channel_name} channel does not support current architecture (${arch})." "1"
513509
fi
514510

511+
# Run with tee
512+
if [[ ! "${logging}" = false ]]; then
513+
if [[ "${customized_logpath}" = false ]]; then
514+
logging="${out_dir}/${iso_filename%.iso}.log"
515+
fi
516+
mkdir -p "$(dirname "${logging}")"; touch "${logging}"
517+
msg_warn "Re-run sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT[*]} --nolog 2>&1 | tee ${logging}"
518+
sudo ${0} ${DEFAULT_ARGUMENT} "${ARGUMENT[@]}" --nolog 2>&1 | tee "${logging}"
519+
exit "${?}"
520+
else
521+
unset DEFAULT_ARGUMENT ARGUMENT
522+
fi
523+
515524
# Set argument of pkglist.sh
516525
pkglist_args=("-a" "${arch}" "-k" "${kernel}" "-c" "${channel_dir}" "-l" "${locale_name}")
517526
if [[ "${boot_splash}" = true ]]; then pkglist_args+=("-b"); fi
@@ -538,7 +547,7 @@ make_pacman_conf() {
538547
msg_debug "Use ${build_pacman_conf}"
539548

540549
if [[ "${nosigcheck}" = true ]]; then
541-
sed -r "s|^#?\\s*SigLevel.+|SigLevel = Never|g" ${build_pacman_conf} > "${work_dir}/pacman-${arch}.conf"
550+
sed -r "s|^#?\\s*SigLevel.+|SigLevel = Never|g" "${build_pacman_conf}" > "${work_dir}/pacman-${arch}.conf"
542551
else
543552
cp "${build_pacman_conf}" "${work_dir}/pacman-${arch}.conf"
544553
fi
@@ -594,7 +603,7 @@ make_pkgbuild() {
594603
for_module '_pkgbuild_dirs+=("${module_dir}/{}/pkgbuild.any" "${module_dir}/{}/pkgbuild.${arch}")'
595604

596605
#-- PKGBUILDが入ったディレクトリを作業ディレクトリにコピー --#
597-
for _dir in $(find "${_pkgbuild_dirs[@]}" -type f -name "PKGBUILD" 2>/dev/null | xargs -If realpath f | xargs -If dirname f); do
606+
for _dir in $(find "${_pkgbuild_dirs[@]}" -type f -name "PKGBUILD" -print0 2>/dev/null | xargs -0 -I{} realpath {} | xargs -I{} dirname {}); do
598607
mkdir -p "${airootfs_dir}/pkgbuilds/"
599608
cp -r "${_dir}" "${airootfs_dir}/pkgbuilds/"
600609
done
@@ -618,7 +627,7 @@ make_customize_airootfs() {
618627
_airootfs_list=("${channel_dir}/airootfs.any" "${channel_dir}/airootfs.${arch}")
619628
for_module '_airootfs_list=("${module_dir}/{}/airootfs.any" "${module_dir}/{}/airootfs.${arch}" ${_airootfs_list[@]})'
620629

621-
for _airootfs in ${_airootfs_list[@]};do
630+
for _airootfs in "${_airootfs_list[@]}";do
622631
if [[ -d "${_airootfs}" ]]; then
623632
msg_debug "Copying airootfs ${_airootfs} ..."
624633
cp -af "${_airootfs}"/* "${airootfs_dir}"
@@ -667,10 +676,9 @@ make_customize_airootfs() {
667676
for_module '_script_list+=("${airootfs_dir}/root/customize_airootfs_{}.sh")'
668677

669678
# Create script
670-
for _script in ${_script_list[@]}; do
679+
for _script in "${_script_list[@]}"; do
671680
if [[ -f "${_script}" ]]; then
672-
echo -e "\n" >> "${airootfs_dir}/${_main_script}"
673-
cat "${_script}" >> "${airootfs_dir}/${_main_script}"
681+
echo -e "\n$(cat "${_script}")" >> "${airootfs_dir}/${_main_script}"
674682
remove "${_script}"
675683
else
676684
msg_debug "${_script} was not found."
@@ -689,12 +697,13 @@ make_customize_airootfs() {
689697
# Copy mkinitcpio archiso hooks and build initramfs (airootfs)
690698
make_setup_mkinitcpio() {
691699
local _hook
692-
mkdir -p "${airootfs_dir}/etc/initcpio/hooks"
693-
mkdir -p "${airootfs_dir}/etc/initcpio/install"
700+
mkdir -p "${airootfs_dir}/etc/initcpio/hooks" "${airootfs_dir}/etc/initcpio/install"
701+
694702
for _hook in "archiso" "archiso_shutdown" "archiso_pxe_common" "archiso_pxe_nbd" "archiso_pxe_http" "archiso_pxe_nfs" "archiso_loop_mnt"; do
695703
cp "${script_path}/system/initcpio/hooks/${_hook}" "${airootfs_dir}/etc/initcpio/hooks"
696704
cp "${script_path}/system/initcpio/install/${_hook}" "${airootfs_dir}/etc/initcpio/install"
697705
done
706+
698707
sed -i "s|/usr/lib/initcpio/|/etc/initcpio/|g" "${airootfs_dir}/etc/initcpio/install/archiso_shutdown"
699708
cp "${script_path}/system/initcpio/install/archiso_kms" "${airootfs_dir}/etc/initcpio/install"
700709
cp "${script_path}/system/initcpio/archiso_shutdown" "${airootfs_dir}/etc/initcpio"
@@ -843,7 +852,7 @@ make_efi() {
843852
_efi_config_list+=($(ls "${script_path}/efiboot/${_use_config_name}/archiso-usb"*".conf" | grep -v "rescue"))
844853
fi
845854

846-
for _efi_config in ${_efi_config_list[@]}; do
855+
for _efi_config in "${_efi_config_list[@]}"; do
847856
sed "s|%ARCHISO_LABEL%|${iso_label}|g;
848857
s|%OS_NAME%|${os_name}|g;
849858
s|%KERNEL_FILENAME%|${kernel_filename}|g;
@@ -888,10 +897,6 @@ make_efiboot() {
888897

889898
mkdir -p "${work_dir}/efiboot/EFI/boot"
890899

891-
# PreLoader.efiがefitoolsのi686版に存在しません。この行を有効化するとi686ビルドに失敗します
892-
# PreLoader.efiの役割がわかりません誰かたすけてください(archiso v43で使用されていた)
893-
#cp "${airootfs_dir}/usr/share/efitools/efi/PreLoader.efi" "${work_dir}/efiboot/EFI/boot/bootx64.efi"
894-
895900
cp "${airootfs_dir}/usr/share/efitools/efi/HashTool.efi" "${work_dir}/efiboot/EFI/boot/"
896901

897902
local _bootfile="$(basename "$(ls "${airootfs_dir}/usr/lib/systemd/boot/efi/systemd-boot"*".efi" )")"
@@ -908,14 +913,13 @@ make_efiboot() {
908913
sed "s|%ARCH%|${arch}|g;" "${script_path}/efiboot/${_use_config_name}/loader.conf" > "${work_dir}/efiboot/loader/loader.conf"
909914
cp "${isofs_dir}/loader/entries/uefi-shell"* "${work_dir}/efiboot/loader/entries/"
910915

911-
local _efi_config_list=() _efi_config
912-
_efi_config_list+=($(ls "${script_path}/efiboot/${_use_config_name}/archiso-cd"*".conf" | grep -v "rescue"))
916+
local _efi_config _efi_config_list=($(ls "${script_path}/efiboot/${_use_config_name}/archiso-cd"*".conf"))
913917

914918
if [[ "${norescue_entry}" = false ]]; then
915-
_efi_config_list+=($(ls "${script_path}/efiboot/${_use_config_name}/archiso-cd"*".conf" | grep -v "rescue"))
919+
_efi_config_list=($(printf "%s\n" "${_efi_config_list[@]}" | grep -v "rescue"))
916920
fi
917921

918-
for _efi_config in ${_efi_config_list[@]}; do
922+
for _efi_config in "${_efi_config_list[@]}"; do
919923
sed "s|%ARCHISO_LABEL%|${iso_label}|g;
920924
s|%OS_NAME%|${os_name}|g;
921925
s|%KERNEL_FILENAME%|${kernel_filename}|g;
@@ -1024,7 +1028,7 @@ make_overisofs() {
10241028
local _over_isofs_list _isofs
10251029
_over_isofs_list=("${channel_dir}/over_isofs.any""${channel_dir}/over_isofs.${arch}")
10261030
for_module '_over_isofs_list+=("${module_dir}/{}/over_isofs.any""${module_dir}/{}/over_isofs.${arch}")'
1027-
for _isofs in ${_over_isofs_list[@]}; do
1031+
for _isofs in "${_over_isofs_list[@]}"; do
10281032
if [[ -d "${_isofs}" ]]; then cp -af "${_isofs}"/* "${isofs_dir}"; fi
10291033
done
10301034
}
@@ -1064,18 +1068,18 @@ make_iso() {
10641068

10651069

10661070
# Parse options
1067-
ARGUMENT="${@}"
1071+
ARGUMENT=("${@}")
10681072
OPTS="a:bc:deg:hjk:l:o:p:rt:u:w:x"
10691073
OPTL="arch:,boot-splash,comp-type:,debug,cleaning,cleanup,gpgkey:,help,lang:,japanese,kernel:,out:,password:,comp-opts:,user:,work:,bash-debug,nocolor,noconfirm,nodepend,gitversion,msgdebug,noloopmod,tarball,noiso,noaur,nochkver,channellist,config:,noefi,nodebug,nosigcheck,normwork,log,logpath:,nolog,nopkgbuild"
1070-
if ! OPT=$(getopt -o ${OPTS} -l ${OPTL} -- ${DEFAULT_ARGUMENT} ${ARGUMENT}); then
1074+
if ! OPT=$(getopt -o ${OPTS} -l ${OPTL} -- ${DEFAULT_ARGUMENT} "${ARGUMENT[@]}"); then
10711075
exit 1
10721076
fi
10731077

10741078
eval set -- "${OPT}"
10751079
msg_debug "Argument: ${OPT}"
10761080
unset OPT OPTS OPTL
10771081

1078-
while :; do
1082+
while true; do
10791083
case "${1}" in
10801084
-a | --arch)
10811085
arch="${2}"
@@ -1252,8 +1256,8 @@ done
12521256
# Check root.
12531257
if (( ! "${EUID}" == 0 )); then
12541258
msg_warn "This script must be run as root." >&2
1255-
msg_warn "Re-run 'sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT}'"
1256-
sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT}
1259+
msg_warn "Re-run 'sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT[*]}'"
1260+
sudo ${0} ${DEFAULT_ARGUMENT} "${ARGUMENT[@]}"
12571261
exit "${?}"
12581262
fi
12591263

@@ -1288,7 +1292,7 @@ if [[ -d "${channel_dir}.add" ]]; then
12881292
channel_name="${1}"
12891293
channel_dir="${channel_dir}.add"
12901294
elif [[ "${channel_name}" = "clean" ]]; then
1291-
"${tools_dir}/clean.sh" -w "$(realpath "${work_dir}")" $([[ "${debug}" = true ]] && echo -n "-d")
1295+
"${tools_dir}/clean.sh" -w "$(realpath "${work_dir}")" "$([[ "${debug}" = true ]] && echo -n "-d")"
12921296
exit 0
12931297
fi
12941298

@@ -1303,23 +1307,6 @@ if [[ ! "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" ver "$
13031307
fi
13041308
fi
13051309

1306-
# Run with tee
1307-
if [[ ! "${logging}" = false ]]; then
1308-
if [[ "${customized_logpath}" = false ]]; then
1309-
if [[ "${gitversion}" = true ]]; then
1310-
logging="${out_dir}/${iso_name}-${channel_name%.add}-${locale_name}-$(date +%Y.%m.%d)-$(git rev-parse --short HEAD)-${arch}.log"
1311-
else
1312-
logging="${out_dir}/${iso_name}-${channel_name%.add}-${locale_name}-$(date +%Y.%m.%d)-${arch}.log"
1313-
fi
1314-
fi
1315-
mkdir -p "$(dirname "${logging}")"; touch "${logging}"
1316-
msg_warn "Re-run 'sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT} --nolog 2>&1 | tee ${logging}'"
1317-
eval "sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT} --nolog 2>&1 | tee ${logging}"
1318-
exit "${?}"
1319-
fi
1320-
1321-
unset DEFAULT_ARGUMENT ARGUMENT
1322-
13231310
set -eu
13241311

13251312
prepare_env
@@ -1348,6 +1335,6 @@ if [[ "${noiso}" = false ]]; then
13481335
run_once make_iso
13491336
fi
13501337

1351-
[[ "${cleaning}" = true ]] && "${tools_dir}/clean.sh" -o -w "$(realpath "${work_dir}")" $([[ "${debug}" = true ]] && echo -n "-d")
1338+
[[ "${cleaning}" = true ]] && "${tools_dir}/clean.sh" -o -w "$(realpath "${work_dir}")" "$([[ "${debug}" = true ]] && echo -n "-d")"
13521339

13531340
exit 0

0 commit comments

Comments
 (0)