OSDN Git Service

[fix] : Fixed remove function
[alterlinux/fascode-live-tools.git] / alterlinux-desktop-file / alterlinux-desktop-file
index 4b3db2f..b8eb7db 100755 (executable)
@@ -12,17 +12,31 @@ alterlive=false
 force=false
 checklive=false
 
+remove () {
+    local _list
+    local _file
+    _list=($(echo "$@"))
+    for _file in "${_list[@]}"; do
+        if [[ -f ${_file} ]]; then
+            rm -f "${_file}"
+        elif [[ -d ${_file} ]]; then
+            rm -rf "${_file}"
+        fi
+    done
+}
+
 _help() {
     echo "usage ${0} [options]"
     echo
     echo " General options:"
     echo "    -f | --force        Force overwriting."
     echo "    -h | --help         This help message and exit."
-    echo "    -l | --live         Opens the page only in a live environment."
+    echo "    -l | --live         Create files only in a live environment."
     echo "                        Whether it is a live environment or not is determined"
     echo "                        by the presence or absence of the installer."
     echo
     echo "         --alterlive    Remove the file for live session"
+    echo "                        If you specify --alterlive, --live is also specified automatically."
 }
 
 # Argument analysis and processing
@@ -56,6 +70,7 @@ while true; do
             ;;
         --alterlive)
             alterlive=true
+            checklive=true
             shift 1
             ;;
         --)
@@ -70,6 +85,9 @@ while true; do
     esac
 done
 
+if [[ "${alterlive}" = true ]]; then
+    remove "${HOME}/.config/autostart/genicon.desktop"
+fi
 
 if [[ "${checklive}" = true ]]; then
     if ! pacman -Qq alterlinux-calamares 1> /dev/null 2> /dev/null; then
@@ -84,10 +102,10 @@ get_desktop_dir() {
     if [[ -v XDG_CONFIG_HOME ]]; then
         _user_config_dir="${XDG_CONFIG_HOME}"
     else
-        _use_config_dir="${HOME}/.config"
+        _user_config_dir="${HOME}/.config"
     fi
-    if [[ -f "${_use_config_dir}/user-dirs.dirs" ]]; then
-        source "${_use_config_dir}/user-dirs.dirs"
+    if [[ -f "${_user_config_dir}/user-dirs.dirs" ]]; then
+        source "${_user_config_dir}/user-dirs.dirs"
     fi
     if [[ -v XDG_DESKTOP_DIR ]]; then
         _desktop_dir="${XDG_DESKTOP_DIR}"
@@ -97,35 +115,26 @@ get_desktop_dir() {
     echo -n "${_desktop_dir}"
 }
 
-remove () {
-    local _list
-    local _file
-    _list=($(echo "$@"))
-    for _file in "${_list[@]}"; do
-        if [[ -f ${_file} ]]; then
-            rm -f "${_file}"
-        elif [[ -d ${_file} ]]; then
-            rm -rf "${_file}"
-        fi
-    done
+#copy <コピー元> <コピー先>
+copy() {
+    if [[ ! -f "${1}" ]]; then
+        echo "${1} was not found" >&2
+        exit 1
+    fi
+    if [[ -f "${2}/$(basename "${1}")" ]] || [[ -f "${2}" ]] && [[ "${force}" = false ]]; then
+        echo "File already exists" >&2
+        exit 1
+    fi
+
+    cp "${1}" "${2}"
 }
 
 desktop_dir="$(get_desktop_dir)"
 
 # calamaresのアイコン
-calamares="/usr/share/alterlinux/desktop-file/calamares.desktop"
-desktop_icon="${desktop_dir}/$(basename "${calamares}")"
-
-if [[ ! -f "${calamares}" ]]; then
-    echo "${calamares} was not found" >&2
-    exit 1
-fi
-
-if [[ -f "${desktop_icon}" ]] && [[ "${force}" = false ]]; then
-    echo "File already exists" >&2
-    exit 1
-fi
-cp "${calamares}" "${desktop_dir}"
+source_file="/usr/share/alterlinux/desktop-file/calamares.desktop"
+desktop_icon="${desktop_dir}/$(basename "${source_file}")"
+copy "${source_file}" "${desktop_dir}"
 os_name="$(
     if [[ -f "/etc/os-release" ]]; then
         source "/etc/os-release"
@@ -137,6 +146,7 @@ os_name="$(
 sed -i "s/%OS_NAME%/${os_name}/g" "${desktop_icon}"
 
 
-if [[ "${alterlive}" = true ]]; then
-    remove ~/.config/autostart/genicon.desktop
-fi
+# welcome-page
+source_file="/usr/share/alterlinux/desktop-file/welcome-to-alter.desktop"
+desktop_icon="${desktop_dir}/$(basename "${source_file}")"
+copy "${source_file}" "${desktop_dir}"