OSDN Git Service

add ubuntuになる問題の修正
[alterlinux/LUBS.git] / lubs
diff --git a/lubs b/lubs
index c19393f..034c400 100755 (executable)
--- a/lubs
+++ b/lubs
@@ -34,17 +34,21 @@ cache_only=false
 start_time="$(date +%s)"
 
 _msg_common() {
-    local _current_time="$(date +%s)"
-    local _time
+    if [[ "${debug}" = true ]]; then
+        local _current_time="$(date +%s)"
+        local _time
 
-    _time="$(("${_current_time}"-"${start_time}"))"
+        _time="$(("${_current_time}"-"${start_time}"))"
 
-    if [[ "${_time}" -ge 3600 ]]; then
-        echo "[$(date -d _time +%H:%M%.S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
-    elif [[ "${_time}" -ge 60 ]]; then
-        echo "[00:$(date -d_time +%M%.S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
+        if [[ "${_time}" -ge 3600 ]]; then
+            echo "[$(date -d @${_time} +%H:%M.%S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
+        elif [[ "${_time}" -ge 60 ]]; then
+            echo "[00:$(date -d @${_time} +%M.%S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
+        else
+            echo "[00:00.$(date -d @${_time} +%S)] $("${script_path}/echo_color" -t 6 "[LUBS Core]")"
+        fi
     else
-        echo "[00:00.$(date -d _time +%S)] $("${script_path}/echo_color" -t 6 "[LUBS Core]")"
+        "${script_path}/echo_color" -t 6 "[LUBS Core]"
     fi
 }
 
@@ -78,9 +82,9 @@ _msg_error() {
 # Unmount chroot dir
 umount_chroot () {
     local mount
-    for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir})); do
-        _msg_info "Unmounting ${mount}"
-        umount "${mount}"
+    for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir}) | sort -r); do
+        [[ "${1}" == debug ]] && _msg_debug "Unmounting ${mount}" || _msg_info "Unmounting ${mount}"
+        umount -fl "${mount}"
     done
 }
 
@@ -110,7 +114,13 @@ run_once() {
 }
 
 run_cmd() {
-    arch-chroot "${work_dir}/airootfs" "${@}"
+    for mount in "dev" "dev/pts" "proc" "sys" "run/systemd/resolve/stub-resolv.conf"; do
+        _msg_debug "Mounting  ${work_dir}/airootfs/${mount}"
+        [[ "${mount}" == "run/systemd/resolve/stub-resolv.conf" ]] && mount --bind /etc/resolv.conf "${work_dir}/airootfs/${mount}" || mount --bind /${mount} "${work_dir}/airootfs/${mount}"
+    done
+
+    chroot "${work_dir}/airootfs" "${@}"
+    umount_chroot debug
 }
 
 run_bootfiles() {
@@ -196,11 +206,7 @@ prepare_build() {
     [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
     [[ ! -d "${out_dir}" ]] && mkdir -p "${out_dir}"
 
-    local mount
-    for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir}) | sort -r); do
-        _msg_info "Unmounting ${mount}"
-        umount "${mount}"
-    done
+    umount_chroot 
 
     # Check codename
     if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then
@@ -252,18 +258,18 @@ make_sourcelist() {
         _apt_install gnupg
 
         for repo in $(find ${channels_dir}/*/repo -name *.list); do
-            key="$(dirname $repo)/$(basename $repo | sed "s/list/key/")"
+            key="$(dirname ${repo})/$(basename ${repo} | sed "s/list/key/")"
             
-            if [[ -f "$key" ]]; then
-                if $(file $key | grep -q "PGP/GPG key"); then
-                    cp $key ${work_dir}/airootfs/$(basename $key)
+            if [[ -f "${key}" ]]; then
+                if $(file ${key} | grep -q "PGP/GPG key"); then
+                    cp ${key} ${work_dir}/airootfs/$(basename ${key})
                 else
-                    wget -q -O ${work_dir}/airootfs/$(basename $key) $(cat $key)
+                    wget -q -O ${work_dir}/airootfs/$(basename ${key}) $(cat ${key})
                 fi
 
-                run_cmd apt-key add $(basename $key)
-                rm ${work_dir}/airootfs/$(basename $key)
-                cp $repo ${work_dir}/airootfs/etc/apt/sources.list.d
+                run_cmd apt-key add $(basename ${key})
+                rm ${work_dir}/airootfs/$(basename ${key})
+                cp ${repo} ${work_dir}/airootfs/etc/apt/sources.list.d
             fi
         done
 
@@ -317,6 +323,7 @@ make_snap_packages() {
         grep -h -v ^'#' "${channels_dir}/${channel_name}/snap-packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/snappkglist"
     fi
     if [[ -n "$(echo $(<"${work_dir}/airootfs/snappkglist"))" ]]; then
+        _apt_install snapd
         run_cmd env -i bash -c 'snap install $(echo $(<snappkglist))'
     fi
     remove "${work_dir}/airootfs/snappkglist"
@@ -370,7 +377,7 @@ make_clean() {
 }
 
 make_bootfiles() {
-    run_cmd update-initramfs -c -k all
+    run_cmd env -i bash -c 'update-initramfs -c -k all'
     _apt_install memtest86+
     [[ -d "${bootfiles_dir}" ]] && rm -r "${bootfiles_dir}"
     mkdir -p ${bootfiles_dir}/{casper,isolinux,install}
@@ -435,6 +442,7 @@ make_isolinux() {
         --modules="linux16 linux normal iso9660 biosdisk search" \
         --locales="" \
         --fonts="" \
+        --themes="" \
         "boot/grub/grub.cfg=isolinux/grub.cfg"
     cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img > isolinux/bios.img
 }
@@ -560,6 +568,35 @@ while :; do
 done
 
 bootfiles_dir="${work_dir}/bootfiles"
+trap  umount_chroot 0 2 15
+
+if [[ -n "${1}" ]]; then
+    channel_name="${1}"
+
+    check_channel() {
+        local channel_list
+        local i
+        channel_list=()
+        for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
+            if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
+                channel_list="${channel_list[@]} ${_channel}"
+            fi
+        done
+        for i in ${channel_list[@]}; do
+            if [[ "${i}" = "${channel_name}" ]]; then
+                echo -n "true"
+                return 0
+            fi
+        done
+        echo -n "false"
+        return 1
+    }
+
+    if [[ $(check_channel ${channel_name}) = false ]]; then
+        _msg_error "Invalid channel ${channel_name}"
+        exit 1
+    fi
+fi
 
 
 prepare_build
@@ -567,7 +604,7 @@ run_once make_basefs
 run_once make_sourcelist
 run_once make_systemd
 run_once make_apt_packages
-# run_once make_snap_packages
+#run_once make_snap_packages
 run_once make_config
 run_once make_customize_airootfs
 run_once make_clean