OSDN Git Service

[update] : Added --loopmod
[alterlinux/alterlinux.git] / build.sh
index 434f700..ae461a1 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -30,6 +30,8 @@ DEFAULT_ARGUMENT=""
 ARGUMENT=("${@}")
 alteriso_version="3.1"
 norepopkg=()
+legacy_mode=false
+rerun=false
 
 # Load config file
 [[ ! -f "${defaultconfig}" ]] && "${tools_dir}/msg.sh" -a 'build.sh' error "${defaultconfig} was not found." && exit 1
@@ -42,8 +44,7 @@ umask 0022
 # Message common function
 # msg_common [type] [-n] [string]
 msg_common(){
-    local _msg_opts=("-a" "build.sh") _type="${1}"
-    shift 1
+    local _msg_opts=("-a" "build.sh") _type="${1}" && shift 1
     [[ "${1}" = "-n" ]] && _msg_opts+=("-o" "-n") && shift 1
     [[ "${msgdebug}" = true ]] && _msg_opts+=("-x")
     [[ "${nocolor}"  = true ]] && _msg_opts+=("-n")
@@ -83,28 +84,7 @@ getclm() { cut -d " " -f "${1}"; }
 echo_blank(){ yes " " 2> /dev/null  | head -n "${1}" | tr -d "\n"; }
 
 _usage () {
-    echo "usage ${0} [options] [channel]"
-    echo
-    echo "A channel is a profile of AlterISO settings."
-    echo
-    echo " General options:"
-    echo "    -b | --boot-splash           Enable boot splash"
-    echo "    -e | --cleanup | --cleaning  Enable post-build cleaning"
-    echo "    -r |  --tarball               Build rootfs in tar.xz format"
-    echo "    -h | --help                  This help message and exit"
-    echo
-    echo "    -a | --arch <arch>           Set iso architecture"
-    echo "    -c | --comp-type <comp_type> Set SquashFS compression type (gzip, lzma, lzo, xz, zstd)"
-    echo "    -g | --gpgkey <key>          Set gpg key"
-    echo "    -l | --lang <lang>           Specifies the default language for the live environment"
-    echo "    -k | --kernel <kernel>       Set special kernel type. See below for available kernels"
-    echo "    -o | --out <out_dir>         Set the output directory"
-    echo "    -p | --password <password>   Set a live user password"
-    echo "    -t | --comp-opts <options>   Set compressor-specific options."
-    echo "    -u | --user <username>       Set user name"
-    echo "    -w | --work <work_dir>       Set the working directory"
-    echo
-
+    cat "${script_path}/docs/build.sh/help.1"
     local blank="29" _arch _dirname _type _output _first
     for _type in "locale" "kernel"; do
         echo " ${_type} for each architecture:"
@@ -124,36 +104,7 @@ _usage () {
             _first=false
         done
     done
-
-    echo
-    echo " Debug options: Please use at your own risk."
-    echo "    -d | --debug                 Enable debug messages"
-    echo "    -x | --bash-debug            Enable bash debug mode(set -xv)"
-    echo "         --channellist           Output the channel list and exit"
-    echo "         --config                Load additional config file"
-    echo "         --[no]gitversion        Add Git commit hash to image file version"
-    echo "         --logpath <file>        Set log file path (use with --log)"
-    echo "         --[no]log               (No) log ;re-run script with tee"
-    echo "         --msgdebug              Enables output debugging"
-    echo "         --noaur                 Ignore aur packages (Use only for debugging)"
-    echo "         --nocolor               No output colored output"
-    echo "         --[no]confirm           (No) check the settings before building"
-    echo "         --nochkver              No check the version of the channel"
-    echo "         --nodebug               Disable all debug messages"
-    echo "         --noefi                 No efi boot (Use only for debugging)"
-    echo "         --noloopmod             No check and load kernel module automatically"
-    echo "         --nodepend              No check package dependencies before building"
-    echo "         --noiso                 No build iso image (Use with --tarball)"
-    echo "         --nosigcheck            No pacman signature check"
-    echo "         --pacman-debug          Enable pacman debug mode"
-    echo "         --normwork              No remove working dir"
-    echo "         --nopkgbuild            Ignore PKGBUILD (Use only for debugging)"
-    echo "         --tar-type <comp_type>  Set compression type (gzip, lzma, lzo, xz, zstd)"
-    echo "         --tar-opts <option>     Set tar command argument (Use with --tarball)"
-    echo "         --add-module <module>   Load additional modules (Separated by \",\")"
-    echo
-    echo " Many packages are installed from AUR, so specifying --noaur can cause problems."
-    echo
+    cat "${script_path}/docs/build.sh/help.2"
     [[ -n "${1:-}" ]] && exit "${1}"
 }
 
@@ -298,7 +249,8 @@ check_bool() {
     for _variable in "${@}"; do
         msg_debug -n "Checking ${_variable}..."
         eval ": \${${_variable}:=''}"
-        _value="$(eval echo "\$${_variable}")"
+        _value="$(eval echo "\${${_variable},,}")"
+        eval "${_variable}=${_value}"
         if [[ ! -v "${1}" ]] || [[ "${_value}"  = "" ]]; then
             [[ "${debug}" = true ]] && echo ; msg_error "The variable name ${_variable} is empty." "1"
         elif [[ ! "${_value}" = "true" ]] && [[ ! "${_value}" = "false" ]]; then
@@ -414,6 +366,7 @@ prepare_build() {
     if [[ "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" ver "${channel_name}")" = "3.0" ]]; then
         msg_warn "The module cannot be used because it works with Alter ISO3.0 compatibility."
         modules=("legacy")
+        legacy_mode=true
         [[ "${include_extra-"unset"}" = true ]] && modules=("legacy-extra")
     fi
 
@@ -425,8 +378,8 @@ prepare_build() {
 
     # Check modules
     module_check(){
-        msg_debug "Checking ${1} module ..."
-        bash "${tools_dir}/module.sh" check "${1}" || msg_error "Module ${1} is not available." "1";
+        msg_debug -n "Checking ${1} module ... "
+        bash "${tools_dir}/module.sh" check "${1}" || msg_error "Module ${1} is not available." "1" && echo "${module_dir}/${1}"
     }
     readarray -t modules < <(printf "%s\n" "${modules[@]}" | awk '!a[$0]++')
     for_module "module_check {}"
@@ -478,8 +431,8 @@ prepare_build() {
     if [[ ! "${logging}" = false ]]; then
         [[ "${customized_logpath}" = false ]] && logging="${out_dir}/${iso_filename%.iso}.log"
         mkdir -p "$(dirname "${logging}")" && touch "${logging}"
-        msg_warn "Re-run sudo ${0} ${ARGUMENT[*]} --nodepend --nolog --nocolor 2>&1 | tee ${logging}"
-        sudo "${0}" "${ARGUMENT[@]}" --nolog --nocolor --nodepend 2>&1 | tee "${logging}"
+        msg_warn "Re-run sudo ${0} ${ARGUMENT[*]} --nodepend --nolog --nocolor --rerun 2>&1 | tee ${logging}"
+        sudo "${0}" "${ARGUMENT[@]}" --nolog --nocolor --nodepend --rerun 2>&1 | tee "${logging}"
         exit "${?}"
     fi
 
@@ -549,18 +502,20 @@ make_packages_repo() {
     readarray -t _pkglist_install < <("${tools_dir}/pkglist.sh" "${pkglist_args[@]}")
 
     # Package check
-    #readarray -t _pkglist < <("${tools_dir}/pkglist.sh" "${pkglist_args[@]}")
-    #readarray -t repopkgs < <(pacman-conf -c "${build_pacman_conf}" -l | xargs -I{} pacman -Sql --config "${build_pacman_conf}" --color=never {} && pacman -Sg)
-    #local _pkg
-    #for _pkg in "${_pkglist[@]}"; do
-    #    msg_info "Checking ${_pkg}..."
-    #    if printf "%s\n" "${repopkgs[@]}" | grep -qx "${_pkg}"; then
-    #        _pkglist_install+=("${_pkg}")
-    #    else
-    #        msg_info "${_pkg} was not found. Install it with yay from AUR"
-    #        norepopkg+=("${_pkg}")
-    #    fi
-    #done
+    if [[ "${legacy_mode}" = true ]]; then
+        readarray -t _pkglist < <("${tools_dir}/pkglist.sh" "${pkglist_args[@]}")
+        readarray -t repopkgs < <(pacman-conf -c "${build_pacman_conf}" -l | xargs -I{} pacman -Sql --config "${build_pacman_conf}" --color=never {} && pacman -Sg)
+        local _pkg
+        for _pkg in "${_pkglist[@]}"; do
+            msg_info "Checking ${_pkg}..."
+            if printf "%s\n" "${repopkgs[@]}" | grep -qx "${_pkg}"; then
+                _pkglist_install+=("${_pkg}")
+            else
+                msg_info "${_pkg} was not found. Install it with yay from AUR"
+                norepopkg+=("${_pkg}")
+            fi
+        done
+    fi
 
     # Create a list of packages to be finally installed as packages.list directly under the working directory.
     echo -e "# The list of packages that is installed in live cd.\n#\n" > "${build_dir}/packages.list"
@@ -704,9 +659,10 @@ make_setup_mkinitcpio() {
         cp "${script_path}/system/initcpio/install/${_hook}" "${airootfs_dir}/etc/initcpio/install"
     done
 
+    sed -i "s|%COWSPACE%|${cowspace}|g" "${airootfs_dir}/etc/initcpio/hooks/archiso"
     sed -i "s|/usr/lib/initcpio/|/etc/initcpio/|g" "${airootfs_dir}/etc/initcpio/install/archiso_shutdown"
     cp "${script_path}/system/initcpio/install/archiso_kms" "${airootfs_dir}/etc/initcpio/install"
-    cp "${script_path}/system/initcpio/archiso_shutdown" "${airootfs_dir}/etc/initcpio"
+    cp "${script_path}/system/initcpio/script/archiso_shutdown" "${airootfs_dir}/etc/initcpio"
     cp "${script_path}/mkinitcpio/mkinitcpio-archiso.conf" "${airootfs_dir}/etc/mkinitcpio-archiso.conf"
     [[ "${boot_splash}" = true ]] && cp "${script_path}/mkinitcpio/mkinitcpio-archiso-plymouth.conf" "${airootfs_dir}/etc/mkinitcpio-archiso.conf"
 
@@ -993,9 +949,9 @@ make_alteriso_info(){
     # iso version info
     if [[ "${include_info}" = true ]]; then
         local _info_file="${isofs_dir}/alteriso-info" _version="${iso_version}"
-        #remove "${_info_file}"; touch "${_info_file}"
+        remove "${_info_file}"; touch "${_info_file}"
         [[ -d "${script_path}/.git" ]] && [[ "${gitversion}" = false ]] && _version="${iso_version}-${gitrev}"
-        "${tools_dir}/alteriso-info.sh" -a "${arch}" -b "${boot_splash}" -c "${channel_name%.add}" -d "${iso_publisher}" -k "${kernel}" -o "${os_name}" -p "${password}" -u "${username}" -v "${_version}" -m "$(printf "%s," "${modules[@]}")"
+        "${tools_dir}/alteriso-info.sh" -a "${arch}" -b "${boot_splash}" -c "${channel_name%.add}" -d "${iso_publisher}" -k "${kernel}" -o "${os_name}" -p "${password}" -u "${username}" -v "${_version}" -m "$(printf "%s," "${modules[@]}")" > "${_info_file}"
     fi
 
     return 0
@@ -1005,9 +961,9 @@ make_alteriso_info(){
 make_overisofs() {
     local _over_isofs_list _isofs
     _over_isofs_list=("${channel_dir}/over_isofs.any""${channel_dir}/over_isofs.${arch}")
-    for_module '_over_isofs_list+=("${module_dir}/{}/over_isofs.any""${module_dir}/{}/over_isofs.${arch}")'
+    for_module '_over_isofs_list+=("${module_dir}/{}/over_isofs.any" "${module_dir}/{}/over_isofs.${arch}")'
     for _isofs in "${_over_isofs_list[@]}"; do
-        [[ -d "${_isofs}" ]] && cp -af "${_isofs}"/* "${isofs_dir}"
+        [[ -d "${_isofs}" ]] && [[ -n "$(find "${_isofs}" -mindepth 1 -maxdepth 2)" ]] &&  cp -af "${_isofs}"/* "${isofs_dir}"
     done
 
     return 0
@@ -1048,7 +1004,7 @@ make_iso() {
 
 
 # Parse options
-ARGUMENT=("${DEFAULT_ARGUMENT[@]}" "${@}") OPTS=("a:" "b" "c:" "d" "e" "g:" "h" "j" "k:" "l:" "o:" "p:" "r" "t:" "u:" "w:" "x") 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" "tar-type:" "tar-opts:" "add-module:" "nogitversion")
+ARGUMENT=("${DEFAULT_ARGUMENT[@]}" "${@}") OPTS=("a:" "b" "c:" "d" "e" "g:" "h" "j" "k:" "l:" "o:" "p:" "r" "t:" "u:" "w:" "x") 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" "tar-type:" "tar-opts:" "add-module:" "nogitversion" "cowspace:" "rerun" "depend" "loopmod")
 GETOPT=(-o "$(printf "%s," "${OPTS[@]}")" -l "$(printf "%s," "${OPTL[@]}")" -- "${ARGUMENT[@]}")
 getopt -Q "${GETOPT[@]}" || exit 1 # 引数エラー判定
 readarray -t OPT < <(getopt "${GETOPT[@]}") # 配列に代入
@@ -1141,8 +1097,8 @@ while true; do
         --noaur                     ) noaur=true         && shift 1 ;;
         --nochkver                  ) nochkver=true      && shift 1 ;;
         --noefi                     ) noefi=true         && shift 1 ;;
-        --channellist               ) show_channel_list  && exit  ;;
-        --config                    ) source "${2}"      && shift 2 ;;
+        --channellist               ) show_channel_list  && exit  0 ;;
+        --config                    ) source "${2}"       shift 2 ;;
         --pacman-debug              ) pacman_debug=true  && shift 1 ;;
         --nosigcheck                ) nosigcheck=true    && shift 1 ;;
         --normwork                  ) normwork=true      && shift 1 ;;
@@ -1150,6 +1106,10 @@ while true; do
         --nolog                     ) logging=false      && shift 1 ;;
         --nopkgbuild                ) nopkgbuild=true    && shift 1 ;;
         --nogitversion              ) gitversion=false   && shift 1 ;;
+        --cowspace                  ) cowspace="${2}"    && shift 2 ;;
+        --rerun                     ) rerun=true         && shift 1 ;;
+        --depend                    ) nodepend=false     && shift 1 ;;
+        --loopmod                   ) noloopmod=false    && shift 1 ;;
         --                          ) shift 1            && break   ;;
         *)
             msg_error "Argument exception error '${1}'"
@@ -1162,7 +1122,7 @@ done
 if (( ! "${EUID}" == 0 )); then
     msg_warn "This script must be run as root." >&2
     msg_warn "Re-run 'sudo ${0} ${ARGUMENT[*]}'"
-    sudo "${0}" "${ARGUMENT[@]}"
+    sudo "${0}" "${ARGUMENT[@]}" --rerun
     exit "${?}"
 fi