OSDN Git Service

[fix] : FIxed --alterlive
[alterlinux/fascode-live-tools.git] / alterlinux-desktop-file / alterlinux-desktop-file
1 #!/usr/bin/env bash
2 # Yamada Hayao
3 # Twitter: @Hayao0819
4 # Email  : hayao@fascode.net
5 #
6 # (c) 2019-2020 Fascode Network.
7 #
8
9 set -e
10
11 alterlive=false
12 force=false
13 checklive=false
14
15 _help() {
16     echo "usage ${0} [options]"
17     echo
18     echo " General options:"
19     echo "    -f | --force        Force overwriting."
20     echo "    -h | --help         This help message and exit."
21     echo "    -l | --live         Create files only in a live environment."
22     echo "                        Whether it is a live environment or not is determined"
23     echo "                        by the presence or absence of the installer."
24     echo
25     echo "         --alterlive    Remove the file for live session"
26     echo "                        If you specify --alterlive, --live is also specified automatically."
27 }
28
29 # Argument analysis and processing
30 options="${@}"
31 _opt_short="fhl"
32 _opt_long="force,live,help,alterlive"
33 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
34 if [[ ${?} != 0 ]]; then
35     exit 1
36 fi
37
38 eval set -- "${OPT}"
39 unset OPT
40 unset _opt_short
41 unset _opt_long
42
43 while true; do
44     case ${1} in
45         -f | --force)
46             force=true
47             shift 1
48             ;;
49         -l | --live)
50             checklive=true
51             shift 1
52             ;;
53         -h | --help)
54             _help
55             shift 1
56             exit 0
57             ;;
58         --alterlive)
59             alterlive=true
60             checklive=true
61             shift 1
62             ;;
63         --)
64             shift
65             break
66             ;;
67         *)
68             echo "Invalid argument '${1}'" >&2
69             _help
70             exit 1
71             ;;
72     esac
73 done
74
75 if [[ "${alterlive}" = true ]]; then
76     remove "${HOME}/.config/autostart/genicon.desktop"
77 fi
78
79 if [[ "${checklive}" = true ]]; then
80     if ! pacman -Qq alterlinux-calamares 1> /dev/null 2> /dev/null; then
81         exit 0
82     fi
83 fi
84
85
86 # ~/Desktopに相当するディレクトリを返します
87 get_desktop_dir() {
88     local _user_config_dir _desktop_dir
89     if [[ -v XDG_CONFIG_HOME ]]; then
90         _user_config_dir="${XDG_CONFIG_HOME}"
91     else
92         _user_config_dir="${HOME}/.config"
93     fi
94     if [[ -f "${_user_config_dir}/user-dirs.dirs" ]]; then
95         source "${_user_config_dir}/user-dirs.dirs"
96     fi
97     if [[ -v XDG_DESKTOP_DIR ]]; then
98         _desktop_dir="${XDG_DESKTOP_DIR}"
99     else
100         _desktop_dir="${HOME}/Desktop"
101     fi
102     echo -n "${_desktop_dir}"
103 }
104
105 remove () {
106     local _list
107     local _file
108     _list=($(echo "$@"))
109     for _file in "${_list[@]}"; do
110         if [[ -f ${_file} ]]; then
111             rm -f "${_file}"
112         elif [[ -d ${_file} ]]; then
113             rm -rf "${_file}"
114         fi
115     done
116 }
117
118 #copy <コピー元> <コピー先>
119 copy() {
120     if [[ ! -f "${1}" ]]; then
121         echo "${1} was not found" >&2
122         exit 1
123     fi
124     if [[ -f "${2}/$(basename "${1}")" ]] || [[ -f "${2}" ]] && [[ "${force}" = false ]]; then
125         echo "File already exists" >&2
126         exit 1
127     fi
128
129     cp "${1}" "${2}"
130 }
131
132 desktop_dir="$(get_desktop_dir)"
133
134 # calamaresのアイコン
135 source_file="/usr/share/alterlinux/desktop-file/calamares.desktop"
136 desktop_icon="${desktop_dir}/$(basename "${source_file}")"
137 copy "${source_file}" "${desktop_dir}"
138 os_name="$(
139     if [[ -f "/etc/os-release" ]]; then
140         source "/etc/os-release"
141         echo -n "${NAME}"
142     else
143         echo -n "Alter Linux"
144     fi
145 )"
146 sed -i "s/%OS_NAME%/${os_name}/g" "${desktop_icon}"
147
148
149 # welcome-page
150 source_file="/usr/share/alterlinux/desktop-file/welcome-to-alter.desktop"
151 desktop_icon="${desktop_dir}/$(basename "${source_file}")"
152 copy "${source_file}" "${desktop_dir}"