@@ -58,44 +58,35 @@ msg_common(){
5858
5959# Show an INFO message
6060# ${1}: message string
61- msg_info () {
62- msg_common info " ${@ } "
63- }
61+ msg_info () { msg_common info " ${@ } " ; }
6462
6563# Show an Warning message
6664# ${1}: message string
67- msg_warn () {
68- msg_common warn " ${@ } "
69- }
65+ msg_warn () { msg_common warn " ${@ } " ; }
7066
7167# Show an debug message
7268# ${1}: message string
73- msg_debug () {
74- if [[ " ${debug} " = true ]]; then
75- msg_common debug " ${@ } "
76- fi
69+ msg_debug () {
70+ [[ " ${debug} " = true ]] && msg_common debug " ${@ } "
71+ return 0
7772}
7873
7974# Show an ERROR message then exit with status
8075# ${1}: message string
8176# ${2}: exit code number (with 0 does not exit)
8277msg_error () {
8378 msg_common error " ${1} "
84- if [[ -n " ${2:- } " ]]; then
85- exit " ${2} "
86- fi
79+ [[ -n " ${2:- } " ]] && exit " ${2} "
8780}
8881
8982
9083# Usage: getclm <number>
9184# 標準入力から値を受けとり、引数で指定された列を抽出します。
92- getclm () { cat - | cut -d " " -f " ${1} " ; }
85+ getclm () { cut -d " " -f " ${1} " ; }
9386
9487# Usage: echo_blank <number>
9588# 指定されたぶんの半角空白文字を出力します
96- echo_blank (){
97- yes " " 2> /dev/null | head -n " ${1} " | tr -d " \n"
98- }
89+ echo_blank (){ yes " " 2> /dev/null | head -n " ${1} " | tr -d " \n" ; }
9990
10091_usage () {
10192 echo " usage ${0} [options] [channel]"
@@ -153,13 +144,12 @@ _usage () {
153144 echo " -x | --bash-debug Enable bash debug mode(set -xv)"
154145 echo " --channellist Output the channel list and exit"
155146 echo " --gitversion Add Git commit hash to image file version"
156- echo " --log Enable logging (re-run script with tee)"
157147 echo " --logpath <file> Set log file path (use with --log)"
158- echo " --nolog No logging "
148+ echo " --[no]log (No) log ;re-run script with tee "
159149 echo " --msgdebug Enables output debugging"
160150 echo " --noaur Ignore aur packages (Use only for debugging)"
161151 echo " --nocolor No output colored output"
162- echo " --noconfirm No check the settings before building"
152+ echo " --[no]confirm (No) check the settings before building"
163153 echo " --nochkver No check the version of the channel"
164154 echo " --nodebug No debug message"
165155 echo " --noefi No efi boot (Use only for debugging)"
@@ -172,31 +162,20 @@ _usage () {
172162 echo
173163 echo " Many packages are installed from AUR, so specifying --noaur can cause problems."
174164 echo
175- if [[ -n " ${1:- } " ]]; then exit " ${1} " ; fi
165+ [[ -n " ${1:- } " ]] && exit " ${1} "
176166}
177167
178168# Unmount helper Usage: _umount <target>
179169_umount () { if mountpoint -q " ${1} " ; then umount -lf " ${1} " ; fi ; }
180170
181171# Mount helper Usage: _mount <source> <target>
182- _mount () { if ! mountpoint -q " ${2} " && [[ -f " ${1} " ]] && [[ -d " ${2} " ]]; then mount " ${1} " " ${2} " ; fi ; }
172+ _mount () { ! mountpoint -q " ${2} " && [[ -f " ${1} " ]] && [[ -d " ${2} " ]] && mount " ${1} " " ${2} " ; return 0 ; }
183173
184174# Unmount work dir
185175umount_work () {
186- local _mount
187- if [[ ! -v " build_dir" ]] || [[ " ${build_dir} " = " " ]]; then
188- msg_error " Exception error about working directory" 1
189- fi
190- [[ ! -d " ${build_dir} " ]] && return 0
191- # for _mount in $(cat "/proc/mounts" | getclm 2 | grep "$(realpath -s ${build_dir})" | tac | grep -xv "$(realpath -s ${airootfs_dir})"); do
192- for _mount in $( find " ${build_dir} " -mindepth 1 -type d -printf " %p\0" | xargs -0 -I{} bash -c " mountpoint -q {} && echo {}" | tac) ; do
193- if echo " ${_mount} " | grep " ${work_dir} " > /dev/null 2>&1 || echo " ${_mount} " | grep " ${script_path} " > /dev/null 2>&1 || echo " ${_mount} " | grep " ${out_dir} " > /dev/null 2>&1 ; then
194- msg_info " Unmounting ${_mount} "
195- _umount " ${_mount} " 2> /dev/null
196- else
197- msg_error " It is dangerous to unmount a directory that is not managed by the script."
198- fi
199- done
176+ local _args=(" ${build_dir} " )
177+ [[ " ${debug} " = true ]] && _args=(" -d" " ${_args[@]} " )
178+ " ${tools_dir} /umount.sh" " ${_args[@]} "
200179}
201180
202181# Mount airootfs on "${airootfs_dir}"
@@ -239,16 +218,15 @@ umount_trap() {
239218# load_config [file1] [file2] ...
240219load_config () {
241220 local _file
242- for _file in " ${@ } " ; do if [[ -f " ${_file} " ]] ; then source " ${_file} " && msg_debug " The settings have been overwritten by the ${_file} " ; fi ; done
221+ for _file in " ${@ } " ; do [[ -f " ${_file} " ]] && source " ${_file} " && msg_debug " The settings have been overwritten by the ${_file} " ; done
222+ return 0
243223}
244224
245225# Display channel list
246226show_channel_list () {
247- if [[ " ${nochkver} " = true ]]; then
248- bash " ${tools_dir} /channel.sh" -v " ${alteriso_version} " -n show
249- else
250- bash " ${tools_dir} /channel.sh" -v " ${alteriso_version} " show
251- fi
227+ local _args=(" -v" " ${alteriso_version} " show)
228+ [[ " ${nochkver} " = true ]] && _args+=(" -n" )
229+ bash " ${tools_dir} /channel.sh" " ${_args[@]} "
252230}
253231
254232# Execute command for each module. It will be executed with {} replaced with the module name.
@@ -261,19 +239,17 @@ for_module(){
261239# pacstrapを実行
262240_pacstrap (){
263241 msg_info " Installing packages to ${airootfs_dir} /'..."
264- if [[ " ${pacman_debug} " = true ]]; then
265- pacstrap -C " ${build_dir} /pacman.conf" -c -G -M -- " ${airootfs_dir} " --debug " ${@ } "
266- else
267- pacstrap -C " ${build_dir} /pacman.conf" -c -G -M -- " ${airootfs_dir} " " ${@ } "
268- fi
242+ local _args=(" -c" " -G" " -M" " --" " ${airootfs_dir} " " ${@ } " )
243+ [[ " ${pacman_debug} " = true ]] && _args+=(--debug)
244+ pacstrap -C " ${build_dir} /pacman.conf" " ${_args[@]} "
269245 msg_info " Packages installed successfully!"
270246}
271247
272248# chroot環境でpacmanコマンドを実行
273249# /etc/alteriso-pacman.confを準備してコマンドを実行します
274250_run_with_pacmanconf (){
275251 sed " s|^CacheDir =|#CacheDir =|g" " ${build_dir} /pacman.conf" > " ${airootfs_dir} /etc/alteriso-pacman.conf"
276- " ${@ } "
252+ eval -- " ${@ } "
277253 remove " ${airootfs_dir} /etc/alteriso-pacman.conf"
278254}
279255
@@ -334,9 +310,9 @@ check_bool() {
334310 eval ' : ${' ${_variable} ' :=""}'
335311 _value=" $( eval echo ' $' ${_variable} ) "
336312 if [[ ! -v " ${1} " ]] || [[ " ${_value} " = " " ]]; then
337- if [[ " ${debug} " = true ]]; then echo ; fi ; msg_error " The variable name ${_variable} is empty." " 1"
313+ [[ " ${debug} " = true ]] && echo ; msg_error " The variable name ${_variable} is empty." " 1"
338314 elif [[ ! " ${_value} " = " true" ]] && [[ ! " ${_value} " = " false" ]]; then
339- if [[ " ${debug} " = true ]]; then echo ; fi ; msg_error " The variable name ${_variable} is not of bool type. " " 1"
315+ [[ " ${debug} " = true ]] && echo ; msg_error " The variable name ${_variable} is not of bool type ( ${_variable} = ${_value} ) " " 1"
340316 elif [[ " ${debug} " = true ]]; then
341317 echo -e " ${_value} "
342318 fi
@@ -364,13 +340,13 @@ prepare_env() {
364340 fi
365341 _result=0
366342 done
367- if [[ " ${_check_failed} " = true ]]; then exit 1; fi
343+ [[ " ${_check_failed} " = true ]] && exit 1
368344 fi
369345
370346 # Load loop kernel module
371347 if [[ " ${noloopmod} " = false ]]; then
372- if [[ ! -d " /usr/lib/modules/$( uname -r) " ]]; then msg_error " The currently running kernel module could not be found.\nProbably the system kernel has been updated.\nReboot your system to run the latest kernel." " 1" ; fi
373- if [[ -z " $( lsmod | getclm 1 | grep -x " loop" ) " ]]; then modprobe loop; fi
348+ [[ ! -d " /usr/lib/modules/$( uname -r) " ]] && msg_error " The currently running kernel module could not be found.\nProbably the system kernel has been updated.\nReboot your system to run the latest kernel." " 1"
349+ [[ -z " $( lsmod | getclm 1 | grep -x " loop" ) " ]] && modprobe loop
374350 fi
375351
376352 # Check work dir
@@ -495,7 +471,7 @@ prepare_build() {
495471 msg_debug " Iso filename is ${iso_filename} "
496472
497473 # check bool
498- check_bool boot_splash cleaning noconfirm nodepend customized_username customized_password noloopmod nochname tarball noiso noaur customized_syslinux norescue_entry debug bash_debug nocolor msgdebug noefi nosigcheck
474+ check_bool boot_splash cleaning noconfirm nodepend customized_username customized_password noloopmod nochname tarball noiso noaur customized_syslinux norescue_entry debug bash_debug nocolor msgdebug noefi nosigcheck gitversion
499475
500476 # Check architecture for each channel
501477 local _exit=0
@@ -510,11 +486,11 @@ prepare_build() {
510486 logging=" ${out_dir} /${iso_filename% .iso} .log"
511487 fi
512488 mkdir -p " $( dirname " ${logging} " ) " ; touch " ${logging} "
513- msg_warn " Re-run sudo ${0} ${DEFAULT_ARGUMENT} ${ ARGUMENT[*]} --nodepend --nolog 2>&1 | tee ${logging} "
514- sudo ${0} ${DEFAULT_ARGUMENT} " ${ARGUMENT[@]} " --nolog --nodepend 2>&1 | tee " ${logging} "
489+ msg_warn " Re-run sudo ${0} ${ARGUMENT[*]} --nodepend --nolog --nocolor 2>&1 | tee ${logging} "
490+ sudo " ${0} " " ${ARGUMENT[@]} " --nolog --nocolor --nodepend 2>&1 | tee " ${logging} "
515491 exit " ${?} "
516492 else
517- unset DEFAULT_ARGUMENT ARGUMENT
493+ unset ARGUMENT
518494 fi
519495
520496 # Set argument of pkglist.sh
@@ -556,6 +532,13 @@ make_pacman_conf() {
556532 msg_info " Use cached package files in ${cache_dir} "
557533 fi
558534
535+ # Share any architecture packages
536+ # while read -r _pkg; do
537+ # if [[ ! -f "${cache_dir}/$(basename "${_pkg}")" ]]; then
538+ # ln -s "${_pkg}" "${cache_dir}"
539+ # fi
540+ # done < <(find "${cache_dir}/../" -type d -name "$(basename "${cache_dir}")" -prune -o -type f -name "*-any.pkg.tar.*" -printf "%p\n")
541+
559542 return 0
560543}
561544
@@ -575,6 +558,7 @@ make_basefs() {
575558
576559# Additional packages (airootfs)
577560make_packages_repo () {
561+ msg_debug " pkglist.sh ${pkglist_args[*]} "
578562 local _pkglist=($( " ${tools_dir} /pkglist.sh" " ${pkglist_args[@]} " ) )
579563
580564 # Create a list of packages to be finally installed as packages.list directly under the working directory.
@@ -584,9 +568,6 @@ make_packages_repo() {
584568 # Install packages on airootfs
585569 _pacstrap " ${_pkglist[@]} "
586570
587- # Upgrade cached package
588- # _run_with_pacmanconf _chroot_run pacman -Syy --noconfirm --config "/etc/alteriso-pacman.conf"
589-
590571 return 0
591572}
592573
@@ -610,18 +591,17 @@ make_packages_aur() {
610591}
611592
612593make_pkgbuild () {
613- # -- PKGBUILDが入ってるディレクトリの一覧 --#
594+ # Get PKGBUILD List
614595 local _pkgbuild_dirs=(" ${channel_dir} /pkgbuild.any" " ${channel_dir} /pkgbuild.${arch} " )
615596 for_module ' _pkgbuild_dirs+=("${module_dir}/{}/pkgbuild.any" "${module_dir}/{}/pkgbuild.${arch}")'
616597
617- # -- PKGBUILDが入ったディレクトリを作業ディレクトリにコピー --#
598+ # Copy PKGBUILD to work
618599 mkdir -p " ${airootfs_dir} /pkgbuilds/"
619600 for _dir in $( find " ${_pkgbuild_dirs[@]} " -type f -name " PKGBUILD" -print0 2> /dev/null | xargs -0 -I{} realpath {} | xargs -I{} dirname {}) ; do
620601 msg_info " Find $( basename " ${_dir} " ) "
621602 cp -r " ${_dir} " " ${airootfs_dir} /pkgbuilds/"
622603 done
623604
624- # -- ビルドスクリプトの実行 --#
625605 # copy buold script
626606 cp -rf --preserve=mode " ${script_path} /system/pkgbuild.sh" " ${airootfs_dir} /root/pkgbuild.sh"
627607
@@ -827,8 +807,8 @@ make_syslinux() {
827807 sed -i " s|$( cat " ${isofs_dir} /syslinux/archiso_sys_load.cfg" | grep " ${1} " ) ||g" " ${isofs_dir} /syslinux/archiso_sys_load.cfg"
828808 }
829809
830- if [[ " ${norescue_entry} " = true ]]; then _remove_config archiso_sys_rescue.cfg; fi
831- if [[ " ${memtest86} " = false ]]; then _remove_config memtest86.cfg; fi
810+ [[ " ${norescue_entry} " = true ]] && _remove_config archiso_sys_rescue.cfg
811+ [[ " ${memtest86} " = false ]] && _remove_config memtest86.cfg
832812
833813 # copy files
834814 cp " ${airootfs_dir} /usr/lib/syslinux/bios/" * .c32 " ${isofs_dir} /syslinux"
@@ -862,7 +842,6 @@ make_efi() {
862842 install -d -m 0755 -- " ${isofs_dir} /EFI/boot"
863843
864844 local _bootfile=" $( basename " $( ls " ${airootfs_dir} /usr/lib/systemd/boot/efi/systemd-boot" * " .efi" ) " ) "
865- # cp "${airootfs_dir}/usr/lib/systemd/boot/efi/${_bootfile}" "${isofs_dir}/EFI/boot/${_bootfile#systemd-}"
866845 install -m 0644 -- " ${airootfs_dir} /usr/lib/systemd/boot/efi/${_bootfile} " " ${isofs_dir} /EFI/boot/${_bootfile# systemd-} "
867846
868847 local _use_config_name=" nosplash"
@@ -900,11 +879,7 @@ make_efi() {
900879 else
901880 continue
902881 fi
903- cat - > " ${isofs_dir} /loader/entries/uefi-shell-${_efi_shell_arch} .conf" << EOF
904- title UEFI Shell ${_efi_shell_arch}
905- efi /EFI/shell_${_efi_shell_arch} .efi
906-
907- EOF
882+ echo -e " title UEFI Shell ${_efi_shell_arch} \nefi /EFI/shell_${_efi_shell_arch} .efi" > " ${isofs_dir} /loader/entries/uefi-shell-${_efi_shell_arch} .conf"
908883 done
909884 fi
910885
@@ -977,9 +952,7 @@ make_tarball() {
977952 # Run script
978953 mount_airootfs
979954 if [[ -f " ${airootfs_dir} /root/optimize_for_tarball.sh" ]]; then
980- chmod 755 " ${airootfs_dir} /root/optimize_for_tarball.sh"
981- # Execute optimize_for_tarball.sh.
982- _chroot_run " /root/optimize_for_tarball.sh -u ${username} "
955+ _chroot_run " bash /root/optimize_for_tarball.sh -u ${username} "
983956 fi
984957
985958 _cleanup_common
@@ -1042,9 +1015,7 @@ make_prepare() {
10421015
10431016 umount_work
10441017
1045- if [[ " ${cleaning} " = true ]]; then
1046- remove " ${airootfs_dir} " " ${airootfs_dir} .img"
1047- fi
1018+ [[ " ${cleaning} " = true ]] && remove " ${airootfs_dir} " " ${airootfs_dir} .img"
10481019
10491020 return 0
10501021}
@@ -1069,7 +1040,7 @@ make_overisofs() {
10691040 _over_isofs_list=(" ${channel_dir} /over_isofs.any" " ${channel_dir} /over_isofs.${arch} " )
10701041 for_module ' _over_isofs_list+=("${module_dir}/{}/over_isofs.any""${module_dir}/{}/over_isofs.${arch}")'
10711042 for _isofs in " ${_over_isofs_list[@]} " ; do
1072- if [[ -d " ${_isofs} " ]]; then cp -af " ${_isofs} " /* " ${isofs_dir} " ; fi
1043+ [[ -d " ${_isofs} " ]] && cp -af " ${_isofs} " /* " ${isofs_dir} "
10731044 done
10741045
10751046 return 0
@@ -1112,16 +1083,16 @@ make_iso() {
11121083
11131084
11141085# Parse options
1115- ARGUMENT=(" ${@ } " )
1116- OPTS=" a:bc:deg:hjk:l:o:p:rt:u:w:x "
1117- 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, pacman-debug"
1118- if ! OPT=$( getopt -o $ {OPTS} -l $ {OPTL} -- ${DEFAULT_ARGUMENT} " ${ARGUMENT[@]} " ) ; then
1086+ ARGUMENT=(" ${@ } " ${DEFAULT_ARGUMENT} )
1087+ OPTS=( " a:" " b " " c: " " d " " e " " g: " " h " " j " " k: " " l: " " o: " " p: " " r " " t: " " u: " " w: " " x " )
1088+ 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" " pacman-debug" " confirm " )
1089+ if ! OPT=$( getopt -o " $( printf " %s, " " $ {OPTS[@]} " ) " -l " $( printf " %s, " " $ {OPTL[@]} " ) " -- " ${ARGUMENT[@]} " ) ; then
11191090 exit 1
11201091fi
11211092
11221093eval set -- " ${OPT} "
11231094msg_debug " Argument: ${OPT} "
1124- unset OPT OPTS OPTL
1095+ unset OPT OPTS OPTL DEFAULT_ARGUMENT
11251096
11261097while true ; do
11271098 case " ${1} " in
@@ -1207,6 +1178,10 @@ while true; do
12071178 noconfirm=true
12081179 shift 1
12091180 ;;
1181+ --confirm)
1182+ noconfirm=false
1183+ shift 1
1184+ ;;
12101185 --nodepend)
12111186 nodepend=true
12121187 shift 1
@@ -1304,8 +1279,8 @@ done
13041279# Check root.
13051280if (( ! "${EUID} " == 0 )) ; then
13061281 msg_warn " This script must be run as root." >&2
1307- msg_warn " Re-run 'sudo ${0} ${DEFAULT_ARGUMENT} ${ ARGUMENT[*]} '"
1308- sudo ${0} ${DEFAULT_ARGUMENT} " ${ARGUMENT[@]} "
1282+ msg_warn " Re-run 'sudo ${0} ${ARGUMENT[*]} '"
1283+ sudo " ${0} " " ${ARGUMENT[@]} "
13091284 exit " ${?} "
13101285fi
13111286
@@ -1314,7 +1289,7 @@ msg_debug "Use the default configuration file (${defaultconfig})."
13141289[[ -f " ${script_path} /custom.conf" ]] && msg_debug " The default settings have been overridden by custom.conf"
13151290
13161291# Debug mode
1317- if [[ " ${bash_debug} " = true ]]; then set -x -v; fi
1292+ [[ " ${bash_debug} " = true ]] && set -x -v
13181293
13191294# Check for a valid channel name
13201295if [[ -n " ${1+SET} " ]]; then
0 commit comments