OSDN Git Service

[disable] : Disabled snap.
[alterlinux/LUBS.git] / lubs
diff --git a/lubs b/lubs
index 381638d..a497c30 100755 (executable)
--- a/lubs
+++ b/lubs
@@ -31,11 +31,32 @@ debug=false
 cache_only=false
 
 
+start_time="$(date +%s)"
+
+_msg_common() {
+    if [[ "${debug}" = true ]]; then
+        local _current_time="$(date +%s)"
+        local _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]")"
+        else
+            echo "[00:00.$(date -d @${_time} +%S)] $("${script_path}/echo_color" -t 6 "[LUBS Core]")"
+        fi
+    else
+        "${script_path}/echo_color" -t 6 "[LUBS Core]"
+    fi
+}
+
 # Show an INFO message
 # _msg_info <message>
 _msg_info() {
     local _msg="${@}"
-    echo "$("${script_path}/echo_color" -t 6 "[LUBS Core]")  $("${script_path}/echo_color" -t 2 "Info:") ${_msg}"
+    echo "$(_msg_common)  $("${script_path}/echo_color" -t 2 "Info:") ${_msg}"
 }
 
 # Show an debug message
@@ -43,7 +64,7 @@ _msg_info() {
 _msg_debug() {
     if [[ "${debug}" = true ]]; then
         local _msg="${@}"
-        echo "$("${script_path}/echo_color" -t 6 "[LUBS Core]")  $("${script_path}/echo_color" -t 3 "Debug:") ${_msg}"
+        echo "$(_msg_common)  $("${script_path}/echo_color" -t 3 "Debug:") ${_msg}"
     fi
 }
 
@@ -52,7 +73,7 @@ _msg_debug() {
 _msg_error() {
     local _msg="${1}"
     local _error=${2}
-    echo "$("${script_path}/echo_color" -t 6 "[LUBS Core]")  $("${script_path}/echo_color" -t 1 "Error:") ${_msg}"
+    echo "$(_msg_common)  $("${script_path}/echo_color" -t 1 "Error:") ${_msg}"
     if [[ ! ${_error} = 0 ]]; then
         exit ${_error}
     fi
@@ -63,7 +84,7 @@ umount_chroot () {
     local mount
     for mount in $(mount | awk '{print $3}' | grep $(realpath ${work_dir})); do
         _msg_info "Unmounting ${mount}"
-        umount "${mount}"
+        umount -fl "${mount}"
     done
 }
 
@@ -235,18 +256,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
 
@@ -300,6 +321,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"
@@ -544,13 +566,41 @@ done
 
 bootfiles_dir="${work_dir}/bootfiles"
 
+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
 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