OSDN Git Service

[update] : Use array to getopt
[alterlinux/dmc.git] / dmc
1 #!/usr/bin/env bash
2 #
3 # Yamada Hayao
4 # Twitter: @Hayao0819
5 # GitHub : @Hayao0819
6 # Email  : hayao@fascode.net
7 #
8 # (c) 2019-2021 Fascode Network.
9 #
10 # dmc - display manager config tool
11 #
12 # Tool to change display manager settings
13 # It supports various display managers.
14 #
15 # LICENSE: THE SUSHI-WARE LICENSE
16 # https://github.com/MakeNowJust/sushi-ware
17 #
18 #
19 # 参考資料
20 # https://qiita.com/laikuaut/items/4bc07eabce56ee30812d
21 # https://qiita.com/t_nakayama0714/items/80b4c94de43643f4be51
22
23 SCRIPT_PATH="$( cd -P "$( dirname "$(readlink -f "${0}")" )" && pwd )"
24
25 script_usage(){
26     echo "usage: dmc [options] [command]"
27     echo
28     echo "Tool to change display manager settings"
29     echo
30     echo " General command:"
31     echo "    dm [display manager]              Set display manager"
32     echo "    [mode] [command]                  You can specify the mode as a command"
33     echo "    gtk-list                          Show a list of GTK theme"
34     echo "    help                              Show this help document"
35     echo
36     echo " LightDM command:"
37     echo "    autologin [username] [session]    Set up automatic login (with blank username to disable)"
38     echo "    greeter                           Run greeter setup wizard"
39     echo "    greeter-create [file]             Set the specified executable file as Greeter"
40     echo "    greeter-change [greeter]          Specify the greeter to use"
41     echo "    greeter-edit [greeter]            Edit the greeter configs"
42     echo "    greeter-list                      Show a list of currently installed Greeters"
43     echo "    remove                            Removes all changes made by this command"
44     echo "    edit                              Edit lightdm config"
45     echo "    show-config                       Show current settings"
46     echo
47     echo " GDM command:"
48     echo "    autologin [username] [session]    Set up automatic login (with blank username to disable)"
49     echo "    cursor                            Run cursor selection wizard"
50     echo "    cursor-change [cursor]            Specify the cursor theme"
51     echo "    cursor-list                       Show a list of cursor theme"
52     echo "    edit                              Edit config file"
53     echo "    sound [true or false]             Toggle the sound when an event occurs"
54     echo "    logo [image]                      Specify the logo of the login screen"
55     echo "    tap [true or false]               Toggle whether to recognize the tap as a click"
56     echo "    accessibility [true or false]     Toggle whether to show accessibility menu"
57     echo "    root-login [true or false]        Toggle whether to enable root login"
58     echo "    remove                            Removes all settings"
59     echo
60     echo " GTKG command: (lightdm-gtk-greeter)"
61     echo "    gtk                               Run gtk theme selection wizard"
62     echo "    gtk-change [theme]                Specify gtk theme"
63     echo "    icon                              Run icon theme selection wizard"
64     echo "    icon-change [icon]                Specify the icon theme"
65     echo
66     echo " Webkit2 command: (lightdm-webkit2-greeter)"
67     echo "    theme                             Run theme selection wizard"
68     echo "    theme-change [theme]              Specify the theme"
69     echo "    remove                            Removes all settings"
70     echo "    debug [true or false]             Toggle debug mode"
71     echo
72     echo " Qtquick command: (lightdm-qtquick-greeter)"
73     echo "    back                              Specify the background image"
74     echo "    remove                            Removes all settings"
75     echo
76     echo " Slick command: (lightdm-slick-greeter)"
77     echo "    back [image]                      Specify the background image"
78     echo "    grid [true or false]              Toggle whether to show grid"
79     echo "    icon                              Run icon theme selection wizard"
80     echo "    icon-change [icon]                Specify the icon theme"
81     echo "    gtk                               Run gtk theme selection wizard"
82     echo "    gtk-change [theme]                Specify gtk theme"
83     echo
84     echo " SDDM command:"
85     echo "    autologin [username] [session]    Set up automatic login (with blank username to disable)"
86     echo "    cursor                            Run cursor selection wizard"
87     echo "    cursor-change [cursor]            Specify the cursor theme"
88     echo "    numlock [true or false]           Toggle whether to enable Numlock force"
89     echo "    tty [int number]                  The lowest virtual terminal number that will be used"
90     echo "    theme                             Run theme selection wizard"
91     echo "    theme-change [theme]              Specify the theme"
92     echo
93     echo " LXDM command:"
94     echo "    autologin [username] [session]    Set up automatic login (with blank username to disable)"
95     echo "    back [image]                      Specify the background image"
96     echo "    session                           Run default session selection wizard"
97     echo "    session-change [session]          Specify the default session"
98     echo "    remove-last                       Remove last selected setting"
99     echo "    edit-script                       Edit the script"
100     echo "    gtk                               Run gtk theme selection wizard"
101     echo "    gtk-change [theme]                Specify gtk theme"
102     echo
103     echo " General option:"
104     echo "    -G | --lightdm-greeter            Automatically get the current greeter and set as mode (Only LightDM)"
105     echo "    -m | --mode [mode name]           Specifiy the target you want to set"
106     echo "    -e | --editer [editor path]       Specifiy the editor to use for editing"
107     echo "    -h | --help                       This help message and exit"
108     echo "    --non-interactive                 Run in non-interactive mode"
109     echo "    --no-check-target                 No check the target for the selected mode"
110     echo "    --noroot                          No check root permission"
111     echo "    --write-all-files                 Allows rewriting of all configuration files"
112     echo "    --remove                          Remove the file instead of renaming it with the remove command"
113     echo
114     echo " Supported modes:"
115     echo "    Display managers: lightdm, gdm, sddm, lxdm"
116     echo "    LightDM greeters: webkit2, qtquick, slick, gtkg"
117     echo
118     echo " Default mode: ${MODE}"
119     echo
120     echo " This tool is incomplete and still under development."
121     echo " If you find a bug, please report it on GitHub."
122     echo " https://github.com/FascodeNet/dmc"
123     echo
124 }
125
126 set -eu
127
128 # エラー
129 msg_error() {
130     echo "${@}" 1>&2
131 }
132
133 # 警告
134 msg_warn() {
135     echo "${@}" 1>&2
136 }
137
138 # rootチェック
139 check_root(){
140     if [[ "${NOROOT}" = false ]] && (( "${UID}" != 0 )); then
141         msg_error "You have to run as root"
142         exit 1
143     fi
144 }
145
146 # 数値チェック
147 check_int(){
148     if printf "%s" "${1}" | grep -E "^[0-9]+$" 1>/dev/null 2>&1; then
149         return 0
150     else
151         return 1
152     fi
153 }
154
155 check_bool(){
156     if [[ -n "${1}" ]] && { [[ "${1}" = "true" ]] ||[[ "${1}" = "false" ]]; }; then
157         return 0
158     else
159         return 1
160     fi
161 }
162
163 # コマンドラッパー
164 wrapper(){
165     local _command="${1}"
166     shift 1
167     if which "${_command}" >/dev/null 2>&1; then
168         $(which "${_command}") "${@}"
169     else
170         msg_error "${_command} was not found"
171         exit 1
172     fi
173 }
174
175 # crudini ラッパー
176 crudini(){
177     wrapper crudini "${@}"
178 }
179
180 # jq ラッパー
181 jq(){
182     wrapper jq "${@}"
183 }
184
185 # 指定されたコマンドが現在のモードで実行可能かどうかを判定する
186 check_command_dm(){
187     if ! printf "%s\n" "${@}" | grep -xE "${MODE}" >/dev/null 2>&1; then
188         msg_error "This command (${COMMAND}) is not available in the current mode (${MODE})."
189         exit 1
190     fi
191 }
192
193 # 現在のモードのメインバイナリが存在しているかどうか確認する
194 check_main_binary(){
195     if [[ -z "${MAIN_BINARY["${MODE}"]+SET}" ]]; then
196         msg_warn "The main binary for the selected mode is not set."
197     elif [[ ! -f "${MAIN_BINARY["${MODE}"]}" ]]; then
198         msg_error "The target for the selected mode is not installed."
199         exit 1
200     fi
201 }
202
203 # カーソルテーマの一覧を取得
204 get_cursor_theme(){
205     # カーソルテーマの一覧を取得
206     # 参考: https://wiki.archlinux.jp/index.php/%E3%82%AB%E3%83%BC%E3%82%BD%E3%83%AB%E3%83%86%E3%83%BC%E3%83%9E
207     # 参考: https://wiki.archlinux.jp/index.php/GDM
208     #echo "Searching cursor themes..." 1>&2
209     local _dir _cursor_theme_dir_list _find_cursor_dir_list=("/usr/share/icons" "${HOME}/.local/share/icons" "${HOME}/.icons")
210     for _dir in "${_find_cursor_dir_list[@]}"; do
211         if [[ -d "${_dir}" ]]; then
212             while read -r line; do
213                 _cursor_theme_dir_list+=("${line}")
214             done < <(find "${_dir}" -type d -name "cursors" -print0 | xargs -0 -I{} dirname {} | sort)
215         fi
216     done
217     unset _dir _find_cursor_dir_list
218     
219     local _cursor_theme _cursor_theme_name _name
220     for _cursor_theme in "${_cursor_theme_dir_list[@]}"; do
221         _name="$(grep -E "^Name=" "${_cursor_theme}/cursor.theme" 2> /dev/null | sed "s|^Name=||g")"
222         if [[ -z "${_name}" ]]; then
223             _name="$(basename "${_cursor_theme}")"
224         fi
225         _cursor_theme_name+=("${_name}")
226     done
227     printf "%s\n" "${_cursor_theme_name[@]}"
228 }
229
230 # GTKテーマの一覧を取得
231 get_gtk_theme(){
232     echo "Loading GTK themes..." >&2
233     local _dir _find_theme_dir_list=("/usr/share/themes" "${HOME}/.local/share/themes" "${HOME}/.themes")
234     for _dir in "${_find_theme_dir_list[@]}"; do
235         if [[ -d "${_dir}" ]]; then
236             while read -r line; do
237                 _gtk_theme_dir_list+=("${line}")
238             done < <(find "${_dir}" -type d -name "gtk-*" -print0 | xargs -0 -I{} dirname {} | tr " " "\n" | sort | uniq)
239         fi
240     done
241
242     local _theme_name
243     for _dir in "${_gtk_theme_dir_list[@]}"; do
244         _theme_name="$(crudini --get "${_dir}/index.theme" 'Desktop Entry' "Name" 2> /dev/null ;:)"
245         if [[ -z "${_theme_name}" ]]; then
246             continue
247         else
248             _gtk_theme_name_list+=("${_theme_name}")
249         fi
250     done
251     
252     printf "%s\n" "${_gtk_theme_name_list[@]}" | sort | uniq
253 }
254
255 get_icon_theme(){
256     echo "Loading icons..." >&2
257     local _dir _find_theme_dir_list=("/usr/share/icons" "${HOME}/.local/share/icons" "${HOME}/.icons")
258     for _dir in "${_find_theme_dir_list[@]}"; do
259         if [[ -d "${_dir}" ]]; then
260             while read -r line; do
261                 _icon_theme_dir_list+=("${line}")
262             done < <(find "${_dir}" -type f -name "index.theme" -print0 | xargs -0 -I{} dirname {} | tr " " "\n" | sort | uniq)
263         fi
264     done
265
266     local _theme_name
267     for _dir in "${_icon_theme_dir_list[@]}"; do
268         _theme_name="$(crudini --get "${_dir}/index.theme" 'Icon Theme' "Name" 2> /dev/null ;:)"
269         if [[ -z "${_theme_name}" ]]; then
270             continue
271         else
272             _gtk_theme_name_list+=("${_theme_name}")
273         fi
274     done
275     
276     printf "%s\n" "${_gtk_theme_name_list[@]}" | sort | uniq
277 }
278
279 get_xorg_session(){
280     find "/usr/share/xsessions" -type f -print0 -name "*.desktop" | xargs -0 -I{} bash -c 'basename {} | sed "s|.desktop||g"'
281 }
282
283 get_wayland_session(){
284     find "/usr/share/wayland-sessions" -type f  -print0 -name "*.desktop" | xargs -0 -I{} bash -c 'basename {} | sed "s|.desktop||g"'
285 }
286
287 # 質問を行う関数
288 # Returns only the selected result to standard output
289 # ask_question -d <デフォルト値> -p <質問文> <選択肢1> <選択肢2> ...
290 ask_question(){
291     local arg OPTARG OPTIND _default="" _choice_list _count _choice _question
292     while getopts "d:p:" arg; do
293         case "${arg}" in
294             d) _default="${OPTARG}" ;;
295             p) _question="${OPTARG}" ;;
296             *) exit 1 ;;
297         esac
298     done
299     shift "$((OPTIND - 1))"
300     _choice_list=("${@}")
301     _digit="${##}"
302
303     # 選択肢に関するエラー
304     if (( ${#_choice_list[@]} < 0 )); then
305         msg_error "An exception error has occurred."
306         exit 1
307     fi
308
309     # 選択肢が1つしか無いならばそのまま値を返す
310     if (( ${#_choice_list[@]} <= 1 )); then
311         echo "${_choice_list[*]}"
312         return 0
313     fi
314
315     if [[ -v _question ]] && [[ ! "${_question}" = "" ]]; then
316         echo -e "${_question}" >&2
317     fi
318
319     for (( _count=1; _count<=${#_choice_list[@]}; _count++)); do
320         _choice="${_choice_list[$(( _count - 1 ))]}"
321         if [[ ! "${_default}" = "" ]] && [[ "${_choice}" = "${_default}" ]]; then
322             printf " * %${_digit}d: ${_choice}\n" "${_count}" >&2
323         else
324             printf "   %${_digit}d: ${_choice}\n" "${_count}" >&2
325         fi
326         unset _choice
327     done
328     echo -n "(1 ~ ${#_choice_list[@]}) > " >&2
329     read -r _input
330
331     # 回答を解析
332     if check_int "${_input}"; then
333         # 数字が入力された
334         if (( 1 <= _input)) && (( _input <= ${#_choice_list[@]} )); then
335             _choice="${_choice_list[$(( _input - 1 ))]}"
336         else
337             return 1
338         fi
339     else
340         # 文字が入力された
341         if printf "%s\n" "${_choice_list[@]}" | grep -x "${_input}" 1>/dev/null 2>&1; then
342             _choice="${_input}"
343         else
344             return 1
345         fi
346     fi
347     echo "${_choice}"
348     return 0
349 }
350
351 # デスクトップセッションを聞く
352 ask_session(){
353     local _session
354     if (( $(get_xorg_session | wc -l) <= 1 )); then
355         _session="$(get_xorg_session)"
356     elif [[ "${NON_INTERACTIVE}" = true ]]; then
357         # 非対話モード
358         # ~/.dmrcの値を設定します
359         _session="$(grep -E '^Session=' "${HOME}/.dmrc" 2> /dev/null | cut -d '=' -f 2)"
360         if [[ -z "${autologin_session}" ]]; then
361             msg_error "Failed to set the session."
362             msg_error "Not specified and ~/.dmrc does not exist either."
363             exit 1
364         fi
365     else
366         readarray -t _session_list < <(get_xorg_session)
367         if ! session="$(ask_question -p "Select the desktop session to autologin" "${_session_list[@]}")"; then
368             msg_error "Please enter the correct session name."
369             exit 1
370         fi
371         if [[ -f "/usr/share/xsessions/${session}.desktop" ]]; then
372             _session="${session}"
373         else
374             msg_error "Please enter the correct session name."
375             exit 1
376         fi
377     fi
378     echo "${_session}"
379 }
380
381 # GTKテーマを聞く
382 ask_gtk_theme(){
383     local gtk_themes _theme
384     readarray -t gtk_themes < <(get_gtk_theme)
385
386     # 質問する
387     if ! _theme="$(ask_question -p "Please select the theme to use" "${gtk_themes[@]}")"; then
388         msg_error "Please select the correct theme"
389         exit 1
390     fi
391     echo "${_theme}"
392 }
393
394 # セッションが利用可能かどうか確認する
395 # check_session <session>
396 check_session(){
397     if [[ ! -f "/usr/share/xsessions/${1}.desktop" ]]; then
398         # 存在しないセッションが指定された場合
399         msg_error "This is a session (${1}) that does not exist."
400         exit 1
401     fi
402 }
403
404 # セッションのバイナリを取得する
405 # get_session <session name>
406 get_session(){
407     check_session "${1}"
408     local session_exec="$(crudini --get "/usr/share/xsessions/${1}.desktop" "Desktop Entry" "Exec")"
409     if [[ ! -f "${session_exec}" ]]; then
410         session_exec="$(type -p "${session_exec}")"
411     fi
412     echo -n "${session_exec}"
413     return 0
414 }
415
416 # ユーザーをグループに追加する
417 # add_user_to_group <user> <group>
418 add_user_to_group(){
419     if ! getent passwd "${1}" 1> /dev/null 2>&1; then
420         echo "${1} is a non-existent user."
421         exit 1
422     fi
423
424     if ! getent group "${2}" 1> /dev/null 2>&1; then
425         LANG=C groupadd -r "${2}"
426     fi
427     LANG=C gpasswd -a "${1}" "${2}"
428 }
429
430 # MIMEファイルタイプを返す
431 # get_filetype <file>
432 get_filetype(){
433     file -inb "${1}" | cut -d ";" -f 1
434 }
435
436 # MIMEファイルタイプを判別する
437
438 # check_filetype <ファイルタイプ> <ファイルパス>
439 check_filetype(){
440     local _type="${1}" _path="${2}"
441
442     # ファイルタイプに/が含まれているかどうか
443     if echo "${_type}" | grep -E "^.+/.+$" >/dev/null 2<&1; then
444         # 含まれていたらファイルタイプを完全一致で判定する\
445         if [[ "${_type}" = "$(get_filetype "${_path}")" ]]; then
446             return 0
447         fi
448     else
449         # 含まれていなかったらファイルタイプをメインタイプのみで判定する
450         if [[ "${_type}" = "$(get_filetype "${_path}" | cut -d "/" -f 1 )" ]]; then
451             return 0
452         fi
453     fi
454     # 正常終了しなかったので異常終了
455     return 1
456 }
457
458 # systemdのunitが存在しているか確認
459 check_systemd_unit(){
460     if [[ ! -v 1 ]]; then
461         return 1
462     elif systemctl cat "${1}" 1> /dev/null 2>&1; then
463         return 0
464     fi
465     return 1
466 }
467
468 # removeコマンドの共通処理
469 # 引数に削除したいファイルへのパス
470 common_remove_command(){
471     local _file _yes_or_no
472     for _file in "${@}"; do
473         if [[ -f "${_file}" ]]; then
474             if [[ "${NON_INTERACTIVE}" = true ]]; then
475                 _yes_or_no="y"
476             else
477                 echo -e "Remove ${_file} ? It is irreversible"
478                 echo -ne "(y or n) > "
479                 read -r -n 1 _yes_or_no
480                 echo
481             fi
482             if [[ "${_yes_or_no}" = "y" ]]; then
483                 if [[ "${REMOVE_FILES}" = true ]]; then
484                     echo "Removed ${_file}"
485                     rm -rf "${_file}"
486                 else
487                     echo "Moved ${_file} ${_file}.disabled"
488                     mv "${_file}" "${_file}.disabled"
489                 fi
490             fi
491         else
492             continue
493         fi
494     done
495 }
496
497 #== すべてのモード用コマンド ==#
498 command_general_dm(){
499     if [[ -z "${1}" ]] || [[ "${1}" = "" ]]; then
500         msg_error "Please specify display manager"
501         exit 1
502     fi
503
504     # 現在のディスプレイマネージャを無効化
505     if [[ -n "${CURRENT_DM+SET}" ]]; then
506         systemctl disable "${CURRENT_DM}.service"
507     fi
508
509     # 指定されたディスプレイマネージャを有効化
510     if check_systemd_unit "${1}"; then
511         systemctl enable "${1}.service"
512     else
513         msg_error "Wrong display manager name"
514     fi
515 }
516
517 # モードをコマンドとして扱い自身を再実行する
518 # command_mode <mode> <command> <args>
519 command_mode(){
520     if [[ -z "${2+SET}" ]] || [[ "${2}" = "" ]]; then
521         msg_error "Please specify command"
522         exit 1
523     fi
524
525     local _mode="${1}" _command="${2}"
526     local _dmc_args="-e ${USE_EDITOR} -m ${_mode}"
527     shift 2
528
529     # 基本的な変数を設定
530     local _command_args="${*}"
531     : "${_command_args-""}" # サブコマンドの引数が何も指定されなかった場合に空文字を代入
532
533
534     # オプション設定
535     if [[ "${NON_INTERACTIVE}" = true ]]; then
536         _dmc_args+=" --non-interactive"
537     fi
538     if [[ "${NOROOT}" = true ]]; then
539         _dmc_args+=" --noroot"
540     fi
541     if [[ "${NO_CHECK_TARGET}" = true ]]; then
542         _dmc_args+=" --no-check-target"
543     fi
544     if [[ "${WRITE_ALL_FILES}" = true ]]; then
545         _dmc_args+=" --write-all-files"
546     fi
547
548     bash -c "${SCRIPT_PATH}/$(basename "${0}") ${_dmc_args} ${_command} ${_command_args}"
549 }
550
551
552
553 #== LightDM用の汎用関数 ==#
554 # キーが設定されている設定ファイル
555 lightdm_get_source_file(){
556     local key="${1}"
557     local source_name="$(lightdm --show-config 2>&1 | grep -E "^[A-Z]  ${key}=" | cut -d ' ' -f 1)"
558     local source_path="$(lightdm --show-config 2>&1 | grep -x -A "$(lightdm --show-config 2>&1 | wc -l)" "Sources:" | grep -xv "Sources" | grep -E "^${source_name}  " | sed "s|^${source_name}  ||g")"
559     if [[ -n "${source_path}" ]]; then
560         echo -n "${source_path}"
561     else
562         echo -n ""
563     fi
564 }
565
566
567 # 設定ファイルの値を変更する
568 lightdm_set_config(){
569     local key="${1}" value="${2}" file=${3-${MODE_CONFIG["lightdm"]}}
570     if [[ "${WRITE_ALL_FILES}" = true ]] && [[ -n "$(lightdm_get_source_file "${1}")" ]]; then
571         crudini --set "$(lightdm_get_source_file "${1}")" 'Seat:*' "${key}" "${value}"
572     else
573         crudini --set "${file}" 'Seat:*' "${key}" "${value}"
574     fi
575
576     if [[ ! "$(lightdm_get_value "${key}")" = "${value}" ]]; then
577         msg_error "Failed to change the setting value. A value has already been set for $(lightdm_get_source_file "${1}")"
578         msg_error "lightdm-config does not manipulate other configuration files for safety. Comment out the settings in that file."
579     fi
580 }
581
582 # 設定ファイルのキーを削除する
583 lightdm_remove_key(){
584     local key="${1}" _config
585     if grep -E "^ ?${key}.+" "${MODE_CONFIG["lightdm"]}" 1>/dev/null 2>&1; then
586         sed -i -r "s|^ ?${key} ?=.+||g" "${MODE_CONFIG["lightdm"]}"
587         sed -i '/^$/d' "${MODE_CONFIG["lightdm"]}"
588     fi
589 }
590
591 # 設定ファイルを作成
592 lightdm_init_configs(){
593     check_root
594     if [[ ! -f "${MODE_CONFIG["lightdm"]}" ]]; then
595         mkdir -p "$(dirname "${MODE_CONFIG["lightdm"]}")"
596         touch "${MODE_CONFIG["lightdm"]}"
597         echo "[Seat:*]" > "${MODE_CONFIG["lightdm"]}"
598     fi
599 }
600
601 # 現在設定されている値を取得する
602 lightdm_get_value(){
603     local _current_value="$(lightdm --show-config 2>&1 | grep -E "^[A-Z]  ${1}=" | sed "s|^[A-Z]  ||g" | cut -d "=" -f "2")"
604     if [[ "${_current_value}" ]]; then
605         echo -n "${_current_value}"
606         return 0
607     else
608         echo -n ""
609         return 0
610     fi
611 }
612
613 lightdm_greeter_list(){
614     local greeter_list
615     readarray -t greeter_list < <( (find "${LIGHTDM_GREETERS_DIR}" -print0 -type f | xargs -0 -I{} basename {} | grep -E ".desktop$" | sed "s|.desktop$||g" | grep -xv "xgreeters") 2> /dev/null )
616     printf "%s\n" "${greeter_list[@]}" | sort | uniq
617 }
618
619 #== LightDM用コマンド ==#
620 # greeter-changeコマンド
621 command_lightdm_greeter_change() {
622     # 引数チェック
623     if [[ -z "${1}" ]] || [[ "${1}" = "" ]]; then
624         msg_error "Please specify Greeter."
625         exit 1
626     fi
627
628     # 指定されたGreeterが正しいか確認
629     if ! lightdm_greeter_list | grep -x "${1}" > /dev/null 2>&2; then
630         msg_error "The greeter (${1}) doesn't exist."
631         exit 1
632     else
633         lightdm_set_config "greeter-session" "${1}"
634     fi
635 }
636
637 # greeter-createコマンド
638 command_lightdm_greeter_create(){
639     if [[ -z "${1}" ]] || [[ "${1}" = "" ]]; then
640         msg_error "Please specify Greeter."
641         exit 1
642     fi
643     if [[ ! -f "${1}" ]]; then
644         msg_error "${1} does not exist."
645         exit 1
646     fi
647     if [[ ! -x "${1}" ]]; then
648         msg_error "hoge is not an executable file."
649         exit 1
650     fi
651
652     local path="${1}"
653     local filename="$(basename "${1}")"
654
655     if [[ -f "/usr/share/xgreeters/${filename}.desktop" ]]; then
656         msg_error "Greeter with the same name already exists."
657         exit 1
658     fi
659     cat > "/usr/share/xgreeters/${filename}.desktop"  <<EOF
660 [Desktop Entry]
661 Name=LightDM custom Greeter ${filename}
662 Comment=LightDM Greeter
663 Exec=${path}
664 Type=Application
665 EOF
666 }
667
668 # greeter-listコマンド
669 command_lightdm_greeter_list() {
670     echo "Available Lightdm greeter list:"
671     local _greeter
672     for _greeter in $(lightdm_greeter_list); do
673         if [[ "${_greeter}" = "${LIGHTDM_CURRENT_GREETER}" ]]; then
674             echo " * ${_greeter}"
675         else
676             echo "   ${_greeter}"
677         fi
678     done
679 }
680
681 # greeterコマンド
682 command_lightdm_greeter_wizard(){
683     # グリーターの数を確認
684     if (( $(lightdm_greeter_list | wc -l) < 1 )); then
685         msg_error "LightDM Greeter was not found."
686         exit 1
687     fi
688
689     # 質問する
690     local _greeter
691     # shellcheck disable=SC2046
692     if ! _greeter="$(ask_question -p "Please select the greeter to use." -d "${LIGHTDM_CURRENT_GREETER}" $(lightdm_greeter_list))"; then
693         command_lightdm_greeter_wizard
694         exit 0
695     fi
696
697     # 結果に応じて処理を実行
698     if [[ -n "${_greeter}" ]]; then
699         command_lightdm_greeter_change "${_greeter}"
700     else
701         command_lightdm_greeter_wizard
702         exit 0
703     fi
704
705     if [[ ! "${LIGHTDM_CURRENT_GREETER}" = "${_greeter}" ]]; then
706         echo "Changed greeter to ${_greeter}"
707     fi
708 }
709
710 # removeコマンド
711 command_lightdm_remove(){
712     common_remove_command "${MODE_CONFIG["lightdm"]}"
713 }
714
715 # greeter-edit
716 command_lightdm_greeter_edit(){
717     if [[ "${NON_INTERACTIVE}" = true ]]; then
718         msg_error "You cannot use this command in non-interactive mode."
719         exit 1
720     fi
721     local _greeter="${1:-${LIGHTDM_CURRENT_GREETER}}"
722     if [[ -z "${MODE_CONFIG[${GREETER_MODE["${_greeter}"]}]+SET}" ]]; then
723         msg_error "This Greeter is not currently supported."
724         msg_error "Please report the problem here."
725         msg_error "https://github.com/FascodeNet/lightdm-config/issues"
726         exit 1
727     else
728         if [[ -z "${1}" ]] || [[ "${1}" = "" ]]; then
729             msg_warn "Greeter was not specified. Open the currently configured Greeter configuration file."
730             echo -n "(Enter to continue) > "
731             read -r
732         fi
733         set -u
734         bash -c "${USE_EDITOR} ${MODE_CONFIG[${GREETER_MODE["${_greeter}"]}]}"
735         exit
736     fi
737 }
738
739 # edit
740 command_lightdm_edit(){
741     if [[ "${NON_INTERACTIVE}" = true ]]; then
742         msg_error "You cannot use this command in non-interactive mode."
743         exit 1
744     fi
745     local loaded_config_list
746     readarray -t loaded_config_list < <(printf "%s\n" "$(lightdm --show-config 2>&1 | grep -x -A "$(lightdm --show-config 2>&1 | wc -l)" "Sources:" | grep -v "Sources" | sed 's|^[A-Z]  ||g')"  | tr -d " ")
747     for _config in "${loaded_config_list[@]}"; do
748         echo -ne "Edit ${_config} ? (y or n)> "
749         read -r -n 1 _yes_or_no
750         echo
751         if [[ "${_yes_or_no}" = "y" ]]; then
752             bash -c "${USE_EDITOR} ${_config}"
753         fi
754     done
755 }
756
757 # autologin
758 command_lightdm_auto_login(){
759     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
760         # 既に自動ログインが設定されているかを確認
761         local autologin_user="$(lightdm_get_value autologin-user)"
762         if [[ -n "${autologin_user}" ]]; then
763             # autologinを無効化
764             for _autologin in "autologin-guest" "autologin-user" "autologin-user-timeout" "autologin-in-background" "autologin-session"; do
765                 lightdm_remove_key "${_autologin}"
766             done
767             echo "Canceled automatic login of ${autologin_user}"
768         fi
769     else
770         local autologin_user="${1}" autologin_session
771         if [[ -v 2 ]]; then
772             autologin_session="${2}"
773         fi
774
775         # セッションを設定 (WayLandのセッションは現在サポートされていません)
776         if [[ -z "${autologin_session+SET}" ]]; then
777             autologin_session="$(ask_session)"
778         else
779             # 既に値が設定済み
780             check_session "${autologin_session}"
781         fi
782
783         # autologin グループを設定
784         add_user_to_group "${autologin_user}" "autologin"
785
786         # 設定を書き込み
787         lightdm_set_config "autologin-guest" "false"
788         lightdm_set_config "autologin-user" "${autologin_user}"
789         lightdm_set_config "autologin-user-timeout" "0"
790         lightdm_set_config "autologin-in-background" "false"
791         lightdm_set_config "autologin-session" "${autologin_session}"
792
793         echo "${autologin_user} will automatically log in with ${autologin_session}"
794     fi
795
796 }
797
798 # show-config
799 command_lightdm_show_config(){
800    lightdm --show-config 2>&1 
801 }
802
803 #== GDM用の汎用関数 ==#
804 gdm_init_configs(){
805     check_root
806     if [[ ! -f "/etc/dconf/profile/gdm" ]]; then
807         mkdir -p "/etc/dconf/profile"
808         touch "/etc/dconf/profile/gdm"
809         echo -e "user-db:user\nsystem-db:gdm\nfile-db:/usr/share/gdm/greeter-dconf-defaults" > "/etc/dconf/profile/gdm"
810     fi
811
812     local _file
813     for _file in "${MODE_CONFIG["gdm-dconf"]}" "${MODE_CONFIG["gdm-custom"]}"; do
814         if [[ ! -f "${_file}" ]]; then
815             mkdir -p "$(dirname "${_file}")"
816             touch "${_file}"
817         fi
818     done
819 }
820
821 # gdm_dconf_set_config <dconf path> <key> <value>
822 gdm_dconf_set_config(){
823     if check_int "${3}" || check_bool "${3}"; then
824         crudini --set "${MODE_CONFIG["gdm-dconf"]}" "${1}" "${2}" "${3}"
825     else
826         crudini --set "${MODE_CONFIG["gdm-dconf"]}" "${1}" "${2}" "\"${3}\""
827     fi
828     gdm_update
829 }
830
831 # gdm_dconf_get_value <dconf path> <key>
832 gdm_dconf_get_value(){
833     find "/etc/dconf/db/gdm.d/" -type f -print0 | xargs -0 -I{} cat {} | crudini --get - "${1}" "${2}" | sed "s|^[\"\']||g" | sed "s|[\"\']$||g"
834 }
835
836 # gdm_custom_get_value <section> <key>
837 gdm_custom_get_value(){
838     crudini --get "${MODE_CONFIG["gdm-custom"]}" "${1}" "${2}"
839 }
840
841 # gdm_custom_set_config <section> <key> <value>
842 gdm_custom_set_config(){
843     if check_int "${3}" || check_bool "${3}"; then
844         crudini --set "${MODE_CONFIG["gdm-custom"]}" "${1}" "${2}" "${3}"
845     else
846         crudini --set "${MODE_CONFIG["gdm-custom"]}" "${1}" "${2}" "\"${3}\""
847     fi
848     gdm_update
849 }
850
851 gdm_update(){
852     dconf update
853 }
854
855
856 #== GDM用コマンド ==#
857 command_gdm_logo(){
858     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
859         msg_error "Please specify the image of background"
860         exit 1
861     fi
862     if [[ ! -f "${1}" ]]; then
863         msg_error "${1} was not found."
864         exit 1
865     fi
866
867     local _backgrounf_file="${BACKGROUND_DIR}/gdm/background"
868     mkdir -p "$(dirname "${_backgrounf_file}")"
869     cp "${1}" "${_backgrounf_file}"
870     chmod 644 "${_backgrounf_file}"
871     
872     gdm_dconf_set_config "org/gnome/login-screen" "logo" "${_backgrounf_file}"
873 }
874
875 command_gdm_cursor_wizard(){
876     # カーソル一覧を取得
877     local cursor_themes _current_theme="$(gdm_dconf_get_value "org/gnome/desktop/interface" "cursor-theme")"
878     readarray -t cursor_themes < <(get_cursor_theme)
879
880     # 一覧を生成
881     if ! _cursor_theme="$(ask_question -d "${_current_theme}" -p "Please select the cursor theme to use." "${cursor_themes[@]}")"; then
882         command_gdm_cursor_wizard
883         exit 0
884     fi
885
886     if [[ -n "${_cursor_theme}" ]]; then
887         command_gdm_cursor_change "${_cursor_theme}"
888     else
889         command_gdm_cursor_wizard
890         exit 0
891     fi
892
893     if [[ ! "${_current_theme}" = "${_cursor_theme}" ]]; then
894         echo "Changed cursor to ${_cursor_theme}"
895     fi
896 }
897
898 command_gdm_cursor_change(){
899     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
900         msg_error "Please specify the cursor theme"
901         exit 1
902     fi
903     local cursor_themes
904     readarray -t cursor_themes < <(get_cursor_theme)
905     if ! printf "%s\n" "${cursor_themes[@]}" | grep -x "${1}" 1>/dev/null 2>&1; then
906         msg_error "The cursor theme (${1}) was not found"
907         exit 1
908     fi
909     gdm_dconf_set_config "org/gnome/desktop/interface" "cursor-theme" "${1}"
910 }
911
912 command_gdm_sound(){
913     local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
914     if ! check_bool "${_arg}"; then
915         msg_error "Please specify true or false"
916         exit 1
917     fi
918     gdm_dconf_set_config "org/gnome/desktop/sound" "event-sounds" "${_arg}"
919 }
920
921 command_gdm_tap(){
922     local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
923     if ! check_bool "${_arg}"; then
924         msg_error "Please specify true or false"
925         exit 1
926     fi
927     gdm_dconf_set_config "org/gnome/desktop/peripherals/touchpad" "tap-to-click" "${_arg}"
928 }
929
930 command_gdm_edit(){
931     if [[ "${NON_INTERACTIVE}" = true ]]; then
932         msg_error "You cannot use this command in non-interactive mode."
933         exit 1
934     fi
935     bash -c "${USE_EDITOR} ${MODE_CONFIG["gdm-custom"]}"
936 }
937
938 command_gdm_remove(){
939     common_remove_command "${MODE_CONFIG["gdm-custom"]}"
940 }
941
942 # autologin
943 command_gdm_auto_login(){
944     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
945         # 既に自動ログインが設定されているかを確認
946         local autologin="$(gdm_custom_get_value daemon AutomaticLoginEnable)"
947         if [[ "${autologin}" = "True" ]]; then
948             gdm_custom_set_config "daemon" "AutomaticLoginEnable" "False"
949             echo "Canceled automatic login of $(gdm_custom_get_value "daemon" "AutomaticLogin")"
950         fi
951     else
952         local autologin_user="${1}" autologin_session
953         if [[ -v 2 ]]; then
954             autologin_session="${2}"
955         fi
956
957         # セッションを設定 (WayLandのセッションは現在サポートされていません)
958         if [[ -z "${autologin_session+SET}" ]]; then
959             autologin_session="$(ask_session)"
960         else
961             # 既に値が設定済み
962             check_session "${autologin_session}"
963         fi
964
965         # autologin グループを設定
966         add_user_to_group "${autologin_user}" "autologin"
967
968         # 設定を書き込み
969         gdm_custom_set_config "daemon" "AutomaticLoginEnable" "True"
970         gdm_custom_set_config "daemon" "AutomaticLogin" "${autologin_user}"
971         
972         # セッションを指定
973         crudini --set "/var/lib/AccountsService/users/${autologin_user}" "User" "Session" "${autologin_session}"
974         crudini --set "/var/lib/AccountsService/users/${autologin_user}" "User" "XSession" "${autologin_session}"
975
976         echo "${autologin_user} will automatically log in with ${autologin_session}"
977     fi
978
979 }
980
981 # accessibility コマンド
982 command_gdm_accessibility(){
983     local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
984     if ! check_bool "${_arg}"; then
985         msg_error "Please specify true or false"
986         exit 1
987     fi
988     gdm_dconf_set_config "org/gnome/desktop/interface" "toolkit-accessibility" "${_arg}"
989 }
990
991 # root-login コマンド
992 command_gdm_root_login(){
993     local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
994     if ! check_bool "${_arg}"; then
995         msg_error "Please specify true or false"
996         exit 1
997     fi
998     gdm_custom_set_config "daemon" "AllowRoot" "${_arg}"
999 }
1000
1001 #== Webkit2用の汎用関数 ==#
1002 webkit2_init_configs(){
1003     check_root
1004     if [[ ! -f "${MODE_CONFIG["webkit2"]}" ]]; then
1005         mkdir -p "$(dirname "${MODE_CONFIG["webkit2"]}")"
1006         touch "${MODE_CONFIG["webkit2"]}"
1007     fi
1008 }
1009
1010 # webkit2_get_value <section> <key>
1011 webkit2_get_value(){
1012     crudini --get "${MODE_CONFIG["webkit2"]}" "${1}" "${2}"
1013 }
1014
1015 # webkit2_set_config <section> <key> <value>
1016 webkit2_set_config(){
1017     crudini --set "${MODE_CONFIG["webkit2"]}" "${1}" "${2}" "${3}"
1018 }
1019
1020 #== webkit2用コマンド ==#
1021 command_webkit2_theme_wizard(){
1022     local _theme_list
1023     readarray -t _theme_list < <(ls /usr/share/lightdm-webkit/themes)
1024
1025     local _current_theme=$(webkit2_get_value greeter webkit_theme | sed "s|\"||g")
1026     local _theme
1027     if ! _theme="$(ask_question -d "${_current_theme}" -p "Please select the theme to use." "${_theme_list[@]}")"; then
1028         command_webkit2_theme_wizard
1029         exit 0
1030     fi
1031     if [[ -n "${_theme}" ]]; then
1032         command_webkit2_theme_change "${_theme}"
1033         echo "Changed the theme to ${_theme}"
1034     else
1035         command_webkit2_theme_wizard
1036         exit 0
1037     fi
1038     
1039 }
1040
1041 command_webkit2_theme_change(){
1042     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1043         msg_error "Please specify the theme name"
1044         exit 1
1045     fi
1046     if [[ ! -d "/usr/share/lightdm-webkit/themes/${1}" ]]; then
1047         msg_error "The specified theme (${1}) does not exist"
1048         exit 1
1049     fi
1050
1051     webkit2_set_config "greeter" "webkit_theme" "${1}"
1052 }
1053
1054 command_webkit2_remove(){
1055     common_remove_command "${MODE_CONFIG["webkit2"]}"
1056 }
1057
1058 command_webkit2_debug(){
1059     local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
1060     if ! check_bool "${_arg}"; then
1061         msg_error "Please specify true or false"
1062         exit 1
1063     fi
1064     webkit2_set_config "greeter" "debug_mode" "${_arg}"
1065 }
1066
1067 #== Qtquick用の汎用関数 ==#
1068 qtquick_init_configs(){
1069     check_root
1070     if [[ ! -f "${MODE_CONFIG["qtquick"]}" ]] || [[ -z "$(cat "${MODE_CONFIG["qtquick"]}")" ]]; then
1071         mkdir -p "$(dirname "${MODE_CONFIG["qtquick"]}")"
1072         touch "${MODE_CONFIG["qtquick"]}"
1073         #echo -e "{\n\n}\n" > "${MODE_CONFIG["qtquick"]}"
1074         qtquick_set_config background_path "file:///hoge/fuga.png"
1075         qtquick_set_config theme "qrc:/Login.qml"
1076     fi
1077 }
1078
1079 #qtquick_get_value <key>
1080 qtquick_get_value(){
1081     jq ".${1}" < "${MODE_CONFIG["qtquick"]}"
1082 }
1083
1084 # command_qtquick_back <key> <value>
1085 qtquick_set_config(){
1086     local _tempfile="/tmp/$(basename "${MODE_CONFIG["qtquick"]}")-$(base64 < "/dev/urandom" | fold -w 10 | head -n 1)"
1087     cp "${MODE_CONFIG["qtquick"]}" "${_tempfile}"
1088     #cat "${_tempfile}" | jq -r ".${1}|=\"${2}\"" > "${MODE_CONFIG["qtquick"]}"
1089     jq -r ".${1}|=\"${2}\"" < "${_tempfile}" > "${MODE_CONFIG["qtquick"]}"
1090     chmod 644 "${MODE_CONFIG["qtquick"]}"
1091 }
1092
1093 qtquick_command_remove(){
1094     common_remove_command "${MODE_CONFIG["qtquick"]}"
1095 }
1096
1097 #== Qtquick用コマンド ==#
1098 command_qtquick_back(){
1099     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1100         msg_error "Please specify the image of background"
1101         exit 1
1102     fi
1103     if [[ ! -f "${1}" ]]; then
1104         msg_error "${1} was not found."
1105         exit 1
1106     fi
1107
1108     local _backgrounf_file="${BACKGROUND_DIR}/lightdm/qtquick-greeter"
1109     mkdir -p "$(dirname "${_backgrounf_file}")"
1110     cp "${1}" "${_backgrounf_file}"
1111     chmod 644 "${_backgrounf_file}"
1112     
1113     qtquick_set_config "background_path" "file://${_backgrounf_file}"
1114 }
1115
1116 #== slick用の汎用関数 ==#
1117 slick_get_value(){
1118     crudini --get "${MODE_CONFIG["slick"]}" "Greeter" "${1}"
1119 }
1120
1121 slick_set_config(){
1122     crudini --set "${MODE_CONFIG["slick"]}" "Greeter" "${1}" "${2}"
1123 }
1124
1125 slick_init_configs(){
1126     check_root
1127     if [[ ! -f "${MODE_CONFIG["slick"]}" ]]; then
1128         mkdir -p "$(dirname "${MODE_CONFIG["slick"]}")"
1129         touch "${MODE_CONFIG["slick"]}"
1130         echo "[Greeter]" > "${MODE_CONFIG["slick"]}"
1131     fi
1132 }
1133
1134 #== Slick用コマンド ==#
1135 command_slick_grid(){
1136     local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
1137     if ! check_bool "${_arg}"; then
1138         msg_error "Please specify true or false"
1139         exit 1
1140     fi
1141     slick_set_config "draw-grid" "${_arg}"
1142 }
1143
1144 command_slick_back(){
1145     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1146         msg_error "Please specify the image of background"
1147         exit 1
1148     fi
1149     if [[ ! -f "${1}" ]]; then
1150         msg_error "${1} was not found."
1151         exit 1
1152     fi
1153
1154     local _backgrounf_file="${BACKGROUND_DIR}/lightdm/slick-greeter"
1155     mkdir -p "$(dirname "${_backgrounf_file}")"
1156     cp "${1}" "${_backgrounf_file}"
1157     chmod 644 "${_backgrounf_file}"
1158     
1159     slick_set_config "background" "${_backgrounf_file}"
1160 }
1161
1162 command_slick_gtk_wizard(){
1163     local _theme="$(ask_gtk_theme)"
1164
1165     # 結果に応じて処理を実行
1166     if [[ -n "${_theme}" ]]; then
1167         command_slick_gtk_change "${_theme}"
1168     else
1169         exit 1
1170     fi
1171     echo "Changed theme to ${_theme}"
1172 }
1173
1174 command_slick_gtk_change(){
1175     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1176         msg_error "Please specify the theme"
1177         exit 1
1178     fi
1179     if [[ ! -d "/usr/share/themes/${1}" ]]; then
1180         msg_error "${1} was not found."
1181         exit 1
1182     fi
1183     slick_set_config "theme-name" "${1}"
1184 }
1185
1186 command_slick_icon_wizard(){
1187     local icons
1188     readarray -t icons < <(get_icon_theme)
1189
1190     local _icon
1191     echo "Please select the icon theme to use."
1192     if ! _icon="$(ask_question "${icons[@]}")"; then
1193         command_slick_icon_wizard
1194         exit 0
1195     fi
1196
1197     if [[ -n "${_icon}" ]]; then
1198         slick_set_config "icon-theme-name" "${_icon}"
1199     else
1200         command_slick_icon_wizard
1201         exit 0
1202     fi
1203     echo "Changed icon theme to ${_icon}"
1204 }
1205
1206 command_slick_icon_chenge(){
1207     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1208         msg_error "Please specify the icon theme to use."
1209         exit 1
1210     fi
1211     if ! printf "%s\n" "$(get_icon_theme)" | grep -x "${1}" 1> /dev/null 2>&1; then
1212         msg_error "${1} was not found."
1213         exit 1
1214     fi
1215     slick_set_config "icon-theme-name" "${1}"
1216 }
1217
1218 command_slick_remove(){
1219     common_remove_command "${MODE_CONFIG["slick"]}"
1220 }
1221
1222
1223 #== SDDM用の汎用関数 ==#
1224 # sddm_get_value <section> <key> <valye>
1225 sddm_get_value(){
1226     crudini --set "${MODE_CONFIG["sddm"]}" "${1}" "${2}"
1227 }
1228
1229 # sddm_set_config <section> <key> <value>
1230 sddm_set_config(){
1231     crudini --set "${MODE_CONFIG["sddm"]}" "${1}" "${2}" "${3}"
1232 }
1233
1234 # sddm_remove_key <section> <key>
1235 sddm_remove_key(){
1236     crudini --del "${MODE_CONFIG["sddm"]}" "${1}" "${2}"
1237 }
1238
1239
1240 sddm_init_configs(){
1241     check_root
1242     if [[ ! -f "${MODE_CONFIG["sddm"]}" ]]; then
1243         mkdir -p "$(dirname "${MODE_CONFIG["sddm"]}")"
1244         sddm --example-config > "${MODE_CONFIG["sddm"]}"
1245     fi
1246 }
1247
1248 #== SDDM用コマンド ==#
1249 command_sddm_auto_login(){
1250     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1251         # 既に自動ログインが設定されているかを確認
1252         local autologin_user="$(sddm_get_value Autologin User)"
1253         if [[ -n "${autologin_user}" ]]; then
1254             sddm_remove_key "Autologin" "User"
1255             echo "Canceled automatic login of ${autologin_user}"
1256         fi
1257     else
1258         local autologin_user="${1}" autologin_session
1259         if [[ -v 2 ]]; then
1260             autologin_session="${2}"
1261         fi
1262
1263         # セッションを設定 (WayLandのセッションは現在サポートされていません)
1264         if [[ -z "${autologin_session+SET}" ]]; then
1265             autologin_session="$(ask_session)"
1266         else
1267             # 既に値が設定済み
1268             check_session "${autologin_session}"
1269         fi
1270
1271         # autologin グループを設定
1272         add_user_to_group "${autologin_user}" "autologin"
1273
1274         # 設定を書き込み
1275         sddm_set_config "Autologin" "User" "${autologin_user}"
1276         sddm_set_config "Autologin" "Session" "${autologin_session}"
1277
1278         echo "${autologin_user} will automatically log in with ${autologin_session}"
1279     fi
1280 }
1281
1282 command_sddm_cursor_wizard(){
1283     # カーソル一覧を取得
1284     local cursor_themes _current_theme="$(sddm_get_value "Theme" "CursorTheme")"
1285     readarray -t cursor_themes < <(get_cursor_theme)
1286
1287     # 一覧を生成
1288     if ! _cursor_theme="$(ask_question -d "${_current_theme}" -p "Please select the cursor theme to use." "${cursor_themes[@]}")"; then
1289         command_sddm_cursor_wizard
1290         exit 0
1291     fi
1292
1293     if [[ -n "${_cursor_theme}" ]]; then
1294         command_sddm_cursor_change "${_cursor_theme}"
1295     else
1296         command_sddm_cursor_change
1297         exit 0
1298     fi
1299
1300     if [[ ! "${_current_theme}" = "${_cursor_theme}" ]]; then
1301         echo "Changed cursor to ${_cursor_theme}"
1302     fi
1303 }
1304
1305 command_sddm_cursor_change(){
1306     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1307         msg_error "Please specify the cursor theme"
1308         exit 1
1309     fi
1310     local cursor_themes
1311     readarray -t cursor_themes < <(get_cursor_theme)
1312     if ! printf "%s\n" "${cursor_themes[@]}" | grep -x "${1}" 1>/dev/null 2>&1; then
1313         msg_error "The cursor theme (${1}) was not found"
1314         exit 1
1315     fi
1316     sddm_set_config "Theme" "CursorTheme" "${1}"
1317 }
1318
1319 command_sddm_numlock(){
1320     local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
1321     if ! check_bool "${_arg}"; then
1322         msg_error "Please specify true or false"
1323         exit 1
1324     fi
1325     local _value
1326     if [[ "${_arg}" = true ]]; then
1327         _value="on"
1328     else
1329         _value="none"
1330     fi
1331     sddm_set_config "General" "Numlock" "${_value}"
1332 }
1333
1334 command_sddm_tty(){
1335     if ! check_int "${1}" || (( "${1}" < 1 )); then
1336         msg_error "Please enter an integer greater than 1"
1337         exit 1
1338     fi
1339     sddm_set_config "X11" "MinimumVT" "${1}"
1340 }
1341
1342 command_sddm_theme_wizard(){
1343     local _theme_list
1344     readarray -t _theme_list < <(find "/usr/share/sddm/themes/" -maxdepth 1 -mindepth 1 -type d -print0 | xargs -0 -I{} basename {})
1345
1346     local _theme _current_theme=$(sddm_get_value "Theme" "Current")
1347     if ! _theme="$(ask_question -d "${_current_theme}" -p "Please select the theme to use." "${_theme_list[@]}")"; then
1348         command_sddm_theme_wizard
1349         exit 0
1350     fi
1351     if [[ -n "${_theme}" ]]; then
1352         command_sddm_theme_change "${_theme}"
1353         echo "Changed the theme to ${_theme}"
1354     else
1355         command_sddm_theme_wizard
1356         exit 0
1357     fi
1358     
1359 }
1360
1361 command_sddm_theme_change(){
1362     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1363         msg_error "Please specify the theme name"
1364         exit 1
1365     fi
1366     if [[ ! -d "/usr/share/sddm/themes/${1}" ]]; then
1367         msg_error "The specified theme (${1}) does not exist"
1368         exit 1
1369     fi
1370
1371     sddm_set_config "Theme" "Current" "${1}"
1372 }
1373
1374 #== LXDM用の汎用関数 ==#
1375 # sddm_get_value <section> <key> <valye>
1376 lxdm_get_value(){
1377     crudini --set "${MODE_CONFIG["lxdm"]}" "${1}" "${2}"
1378 }
1379
1380 # sddm_set_config <section> <key> <value>
1381 lxdm_set_config(){
1382     crudini --set "${MODE_CONFIG["lxdm"]}" "${1}" "${2}" "${3}"
1383 }
1384
1385 # sddm_remove_key <section> <key>
1386 lxdm_remove_key(){
1387     crudini --del "${MODE_CONFIG["lxdm"]}" "${1}" "${2}"
1388 }
1389
1390
1391 lxdm_init_configs(){
1392     check_root
1393     if [[ ! -f "${MODE_CONFIG["lxdm"]}" ]]; then
1394         mkdir -p "$(dirname "${MODE_CONFIG["lxdm"]}")"
1395         touch "${MODE_CONFIG["lxdm"]}"
1396     fi
1397 }
1398
1399 #== LXDM用コマンド ==#
1400 command_lxdm_auto_login(){
1401     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1402         # 既に自動ログインが設定されているかを確認
1403         local autologin_user="$(lxdm_get_value "base" "autologin")"
1404         if [[ -n "${autologin_user}" ]]; then
1405             sddm_remove_key "base" "autologin"
1406             echo "Canceled automatic login of ${autologin_user}"
1407         fi
1408     else
1409         local autologin_user="${1}" autologin_session
1410         if [[ -v 2 ]]; then
1411             autologin_session="${2}"
1412         fi
1413
1414         # セッションを設定 (WayLandのセッションは現在サポートされていません)
1415         if [[ -z "${autologin_session+SET}" ]]; then
1416             autologin_session="$(ask_session)"
1417         else
1418             # 既に値が設定済み
1419             check_session "${autologin_session}"
1420         fi
1421
1422         # autologin グループを設定
1423         add_user_to_group "${autologin_user}" "autologin"
1424
1425         # 自動ログインするユーザーを書き込み
1426         sddm_set_config "base" "autologin" "${autologin_user}"
1427
1428         # デフォルトセッションを設定
1429         command_lxdm_session_change "${autologin_session}"
1430
1431         echo "${autologin_user} will automatically log in with ${autologin_session}"
1432     fi
1433 }
1434
1435 command_lxdm_session_wizard(){
1436     command_lxdm_session_change "$(ask_session)"
1437 }
1438
1439 command_lxdm_session_change(){
1440     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1441         msg_error "Please specify the session name"
1442         exit 1
1443     fi
1444     local session="${1}"
1445     check_session "${session}"
1446     local session_exec="$(get_session "${session}")"
1447     lxdm_set_config "base" "session" "${session_exec}"
1448 }
1449
1450 command_lxdm_remove_last(){
1451     rm -rf "/var/lib/lxdm/lxdm.conf"
1452     echo "Removed last configs"
1453 }
1454
1455 comamnd_lxdm_edit_script(){
1456     local _filelist=(
1457         "LoginReady : executed with root privileges when LXDM is ready to show the login window"
1458         "PreLogin   : run as root before logging a user in"
1459         "PostLogin  : run as the logged-in user right after they have logged in"
1460         "PostLogout : run as the logged-in user right after they have logged out"
1461         "PreReboot  : run as root before rebooting with LXDM"
1462         "PreShutdown: run as root before poweroff with LXDM"
1463     )
1464     if ! file=$(ask_question -p "Select the script you want to edit" "${_filelist[@]}" | cut -d ":" -f 1 | tr -d " "); then
1465         comamnd_lxdm_edit_script
1466         exit 0
1467     fi
1468     bash -c "${USE_EDITOR} ${file}"
1469 }
1470
1471 command_lxdm_back(){
1472     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1473         msg_error "Please specify the image of background"
1474         exit 1
1475     fi
1476     if [[ ! -f "${1}" ]]; then
1477         msg_error "${1} was not found."
1478         exit 1
1479     fi
1480
1481     local _backgrounf_file="${BACKGROUND_DIR}/lxdm/background"
1482     mkdir -p "$(dirname "${_backgrounf_file}")"
1483     cp "${1}" "${_backgrounf_file}"
1484     chmod 644 "${_backgrounf_file}"
1485     
1486     lxdm_set_config "display" "bg" "file://${_backgrounf_file}"
1487 }
1488
1489 command_lxdm_gtk_wizard(){
1490     local _theme="$(ask_gtk_theme)"
1491
1492     # 結果に応じて処理を実行
1493     if [[ -n "${_theme}" ]]; then
1494         command_lxdm_gtk_change "${_theme}"
1495     else
1496         exit 1
1497     fi
1498     echo "Changed theme to ${_theme}"
1499 }
1500
1501 command_lxdm_gtk_change(){
1502     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1503         msg_error "Please specify the theme"
1504         exit 1
1505     fi
1506     if [[ ! -d "/usr/share/themes/${1}" ]]; then
1507         msg_error "${1} was not found."
1508         exit 1
1509     fi
1510     lxdm_set_config "display" "gtk_theme" "${1}"
1511 }
1512
1513 #== GTk Greeter用の汎用関数 ==#
1514 # gtk_greeter_get_value <section> <key>
1515 gtk_greeter_get_value(){
1516     crudini --set "${MODE_CONFIG["gtkg"]}" "${1}" "${2}"
1517 }
1518
1519 # gtk_greeter_set_config <section> <key> <value>
1520 gtk_greeter_set_config(){
1521     crudini --set "${MODE_CONFIG["gtkg"]}" "${1}" "${2}" "${3}"
1522 }
1523
1524 # gtk_greeter_remove_key <section> <key>
1525 gtk_greeter_remove_key(){
1526     crudini --del "${MODE_CONFIG["gtkg"]}" "${1}" "${2}"
1527 }
1528
1529 gtk_greeter_init_configs(){
1530     check_root
1531     if [[ ! -f "${MODE_CONFIG["gtkg"]}" ]]; then
1532         mkdir -p "$(dirname "${MODE_CONFIG["gtkg"]}")"
1533         touch "${MODE_CONFIG["gtkg"]}"
1534     fi
1535 }
1536
1537 #== GTk Greeter用のコマンド==#
1538 command_gtk_greeter_gtk_wizard(){
1539     local _theme="$(ask_gtk_theme)"
1540
1541     # 結果に応じて処理を実行
1542     if [[ -n "${_theme}" ]]; then
1543         gtk_greeter_set_config "greeter" "theme-name" "${_theme}"
1544     else
1545         exit 1
1546     fi
1547     echo "Changed theme to ${_theme}"
1548 }
1549
1550 command_gtk_greeter_gtk_change(){
1551     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1552         msg_error "Please specify the theme"
1553         exit 1
1554     fi
1555     if ! printf "%s\n" "$(get_gtk_theme)" | grep -x "${1}" 1> /dev/null 2>&1; then
1556         msg_error "${1} was not found."
1557         exit 1
1558     fi
1559     gtk_greeter_set_config "greeter" "theme-name" "${1}"
1560 }
1561
1562 command_gtk_greeter_icon_wizard(){
1563     local icons
1564     readarray -t icons < <(get_icon_theme)
1565
1566     local _icon
1567     echo "Please select the icon theme to use."
1568     if ! _icon="$(ask_question "${icons[@]}")"; then
1569         command_gtk_greeter_icon_wizard
1570         exit 0
1571     fi
1572
1573     if [[ -n "${_icon}" ]]; then
1574         gtk_greeter_set_config "greeter" "icon-theme-name" "${_icon}"
1575     else
1576         command_gtk_greeter_icon_wizard
1577         exit 0
1578     fi
1579     echo "Changed icon theme to ${_icon}"
1580 }
1581
1582 command_gtk_greeter_icon_chenge(){
1583     if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
1584         msg_error "Please specify the icon theme to use."
1585         exit 1
1586     fi
1587     if ! printf "%s\n" "$(get_icon_theme)" | grep -x "${1}" 1> /dev/null 2>&1; then
1588         msg_error "${1} was not found."
1589         exit 1
1590     fi
1591     gtk_greeter_set_config "greeter" "icon-theme-name" "${_icon}"
1592 }
1593
1594
1595 #== 設定ファイルのパス ==#
1596 declare -A MODE_CONFIG=(
1597     ["lightdm"]="/etc/lightdm/lightdm.conf.d/00-dmc-lightdm.conf"
1598     ["gdm-dconf"]="/etc/dconf/db/gdm.d/00-dmc-gdm"
1599     ["gdm-custom"]="/etc/gdm/custom.conf"
1600     ["sddm"]="/etc/sddm.conf.d/sddm.conf"
1601     ["lxdm"]="/etc/lxdm/lxdm.conf"
1602     ["webkit2"]="/etc/lightdm/lightdm-webkit2-greeter.conf"
1603     ["slick"]="/etc/lightdm/slick-greeter.conf"
1604     ["gtkg"]="/etc/lightdm/lightdm-gtk-greeter.conf"
1605     ["elementary"]="/etc/lightdm/io.elementary.greeter.conf"
1606     ["mini"]="/etc/lightdm/lightdm-mini-greeter.conf"
1607     ["qtquick"]="/etc/lightdm/lightdm-qtquick-greeter.json"
1608 )
1609
1610 declare -A MAIN_BINARY=(
1611     ["lightdm"]="/usr/bin/lightdm"
1612     ["gdm"]="/usr/bin/gdm"
1613     ["sddm"]="/usr/bin/sddm"
1614     ["webkit2"]="/usr/bin/lightdm-webkit2-greeter"
1615     ["slick"]="/usr/bin/slick-greeter"
1616     ["gtkg"]="/usr/bin/lightdm-gtk-greeter"
1617     ["elementary"]="/usr/bin/io.elementary.greeter"
1618     ["mini"]="/usr/bin/lightdm-mini-greeter"
1619     ["qtquick"]="/usr/bin/lightdm-qtquick-greeter"
1620     ["lxdm"]="/usr/bin/lxdm"
1621 )
1622
1623 declare -A GREETER_MODE=(
1624     ["lightdm-webkit2-greeter"]="webkit2"
1625     ["lightdm-slick-greeter"]="slick"
1626     ["io.elementary.greeter"]="elementary"
1627     ["lightdm-mini-greeter"]="mini"
1628     ["lightdm-qtquick-greeter"]="qtquick"
1629     ["lightdm-gtk-greeter"]="gtkg"
1630 )
1631
1632
1633 #== CONFIGS ==#
1634 # LightDM - Greeterのディレクトリ
1635 LIGHTDM_GREETERS_DIR="$(lightdm_get_value "greeters-directory")"
1636 : "${LIGHTDM_GREETERS_DIR:="/usr/share/xgreeters"}"
1637
1638 # LightDM - 現在設定されているGreeter
1639 LIGHTDM_CURRENT_GREETER="$(lightdm --show-config 2>&1 | grep "greeter-session" | cut -d "=" -f 2)"
1640 : "${LIGHTDM_CURRENT_GREETER:="lightdm-gtk-greeter"}"
1641
1642 # Global - エディタ
1643 USE_EDITOR="${EDITOR:-vi}"
1644
1645 # Global - 背景画像をコピーするディレクトリ
1646 BACKGROUND_DIR="/usr/share/backgrounds"
1647
1648 # Global - 現在のディスプレイマネージャ名
1649 if [[ -f "/etc/systemd/system/display-manager.service" ]]; then
1650     CURRENT_DM="$(basename "$(readlink "/etc/systemd/system/display-manager.service")" | sed "s|.service$||g")"
1651 else
1652     CURRENT_DM=""
1653 fi
1654
1655 # モード
1656 MODE="${CURRENT_DM}"
1657 : "${MODE:="lightdm"}"
1658
1659 # dmc config
1660 NON_INTERACTIVE=false
1661 WRITE_ALL_FILES=false
1662 NOROOT=false
1663 NO_CHECK_TARGET=false
1664 REMOVE_FILES=false
1665
1666 #== 引数解析 ==#
1667 ARGUMENT=("${@}")
1668 OPTS=("m:" "e:" "h" "G")
1669 OPTL=("mode:" "editor:" "help" "non-interactive" "noroot" "write-all-files" "no-check-target" "lightdm-greeter" "remove")
1670 if ! OPT=$(getopt -o "$(printf "%s," "${OPTS[@]}")" -l "$(printf "%s," "${OPTL[@]}")" -- "${ARGUMENT[@]}"); then
1671     exit 1
1672 fi
1673
1674 eval set -- "${OPT}"
1675 unset OPT OPTS OPTL
1676
1677 while true; do
1678     case "${1}" in
1679         -m | --mode)
1680             MODE="${2}"
1681             shift 2
1682             ;;
1683         -e | --editor)
1684             USE_EDITOR="${2}"
1685             shift 2
1686             ;;
1687         -h | --help)
1688             script_usage
1689             exit 0
1690             ;;
1691         -G | --lightdm-greeter)
1692             if [[ -n "${LIGHTDM_CURRENT_GREETER+SET}" ]]; then
1693                 MODE="${GREETER_MODE["${LIGHTDM_CURRENT_GREETER}"]}"
1694             else
1695                 msg_error "Failed to get the currently running Greeter."
1696                 exit 1
1697             fi
1698             shift 1
1699             ;;
1700         --non-interactive)
1701             NON_INTERACTIVE=true
1702             shift 1
1703             ;;
1704         --noroot)
1705             NOROOT=true
1706             shift 1
1707             ;;
1708         --no-check-target)
1709             NO_CHECK_TARGET=true
1710             shift 1
1711             ;;
1712         --write-all-files)
1713             WRITE_ALL_FILES=true
1714             shift 1
1715             ;;
1716         --remove)
1717             REMOVE_FILES=true
1718             shift 1
1719             ;;
1720         --)
1721             shift 1
1722             break
1723             ;;
1724     esac
1725 done
1726
1727 # コマンドの引数を解析
1728 COMMAND="${1:-null}"
1729 if (( "${#}" >= 1 )); then
1730     shift 1
1731 fi
1732 COMMAND_ARGS=("${@}")
1733 : "${COMMAND_ARGS=""}" # サブコマンドの引数が何も指定されなかった場合に空文字を代入
1734
1735 if [[ "${COMMAND}" = "null" ]]; then
1736     script_usage
1737     exit 1
1738 fi
1739
1740 # メインバイナリの確認を実行
1741 if [[ "${NO_CHECK_TARGET}" = false ]]; then
1742     check_main_binary
1743 fi
1744
1745 # コマンドとモードに応じて関数を実行する
1746 case "${COMMAND}" in
1747     "accessibility")
1748         check_command_dm "gdm"
1749         gdm_init_configs
1750         command_gdm_accessibility "${COMMAND_ARGS[@]}"
1751         ;;
1752     "autologin")
1753         check_command_dm "lightdm" "gdm" "sddm" "lxdm"
1754         case "${MODE}" in
1755             "lightdm")
1756                 lightdm_init_configs
1757                 command_lightdm_auto_login "${COMMAND_ARGS[@]}"
1758                 ;;
1759             "gdm")
1760                 gdm_init_configs
1761                 command_gdm_auto_login "${COMMAND_ARGS[@]}"
1762                 ;;
1763             "sddm")
1764                 sddm_init_configs
1765                 command_sddm_auto_login "${COMMAND_ARGS[@]}"
1766                 ;;
1767             "lxdm")
1768                 lxdm_init_configs
1769                 command_lxdm_auto_login "${COMMAND_ARGS[@]}"
1770                 ;;
1771         esac
1772         ;;
1773     "back")
1774         check_command_dm "qtquick" "slick" "lxdm"
1775         case "${MODE}" in
1776             "qtquick")
1777                 qtquick_init_configs
1778                 command_qtquick_back "${COMMAND_ARGS[@]}"
1779                 ;;
1780             "slick")
1781                 slick_init_configs
1782                 command_slick_back "${COMMAND_ARGS[@]}"
1783                 ;;
1784             "back")
1785                 lxdm_init_configs
1786                 command_lxdm_back "${COMMAND_ARGS[@]}"
1787                 ;;
1788         esac
1789         ;;
1790     "cursor")
1791         check_command_dm "gdm" "sddm"
1792         case "${MODE}" in
1793             "gdm")
1794                 gdm_init_configs
1795                 command_gdm_cursor_wizard
1796                 ;;
1797             "sddm")
1798                 sddm_init_configs
1799                 command_sddm_cursor_wizard
1800                 ;;
1801         esac
1802         ;;
1803     "cursor-change")
1804         check_command_dm "gdm" "sddm"
1805         case "${MODE}" in
1806             "gdm")
1807                 gdm_init_configs
1808                 command_gdm_cursor_change "${COMMAND_ARGS[@]}"
1809                 ;;
1810             "sddm")
1811                 sddm_init_configs
1812                 command_sddm_cursor_change "${COMMAND_ARGS[@]}"
1813                 ;;
1814         esac
1815         ;;
1816     "debug")
1817         check_comamnd_dm "webkit2"
1818         command_webkit2_debug "${COMMAND_ARGS[@]}"
1819         ;;
1820     "dm")
1821         command_general_dm "${COMMAND_ARGS[@]}"
1822         ;;
1823     "edit")
1824         check_command_dm "lightdm" "gdm"
1825         case "${MODE}" in
1826             "lightdm")
1827                 check_root
1828                 command_lightdm_edit
1829                 ;;
1830             "gdm")
1831                 gdm_init_configs
1832                 command_gdm_edit
1833                 ;;
1834         esac
1835         ;;
1836     "edit-script")
1837         check_command_dm "lxdm"
1838         lxdm_init_configs
1839         comamnd_lxdm_edit_script
1840         ;;
1841     "gtk")
1842         check_command_dm "slick" "lxdm" "gtkg"
1843         case "${MODE}" in
1844             "slick")
1845                 slick_init_configs
1846                 command_slick_gtk_wizard
1847                 ;;
1848             "lxdm")
1849                 lxdm_init_configs
1850                 command_lxdm_gtk_wizard
1851                 ;;
1852             "gtkg")
1853                 gtk_greeter_init_configs
1854                 command_gtk_greeter_gtk_wizard
1855                 ;;
1856         esac
1857         ;;
1858     "greeter")
1859         check_command_dm "lightdm"
1860         lightdm_init_configs
1861         command_lightdm_greeter_wizard
1862         ;;
1863     "greeter-change")
1864         check_command_dm "lightdm"
1865         lightdm_init_configs
1866         command_lightdm_greeter_change "${COMMAND_ARGS[@]}"
1867         ;;
1868     "greeter-create")
1869         check_command_dm "lightdm"
1870         lightdm_init_configs
1871         command_lightdm_greeter_create "${COMMAND_ARGS[@]}"
1872         ;;
1873     "greeter-edit")
1874         check_command_dm "lightdm"
1875         check_root
1876         command_lightdm_greeter_edit "${COMMAND_ARGS[@]}"
1877         ;;
1878     "greeter-list")
1879         check_command_dm "lightdm"
1880         command_lightdm_greeter_list
1881         ;;
1882
1883     "grid")
1884         check_command_dm "slick"
1885         slick_init_configs
1886         command_slick_grid "${COMMAND_ARGS[@]}"
1887         ;;
1888     "gtk-change")
1889         check_command_dm "slick" "lxdm" "gtkg"
1890         case "${MODE}" in
1891             "slick")
1892                 slick_init_configs
1893                 command_slick_gtk_change "${COMMAND_ARGS[@]}"
1894                 ;;
1895             "lxdm")
1896                 command_lxdm_gtk_change "${COMMAND_ARGS[@]}"
1897                 ;;
1898             "gtkg")
1899                 command_gtk_greeter_gtk_change "${COMMAND_ARGS[@]}"
1900                 ;;
1901         esac
1902         ;;
1903     "icon")
1904         check_command_dm "slick" "gtkg"
1905         case "${MODE}" in
1906             "slick")
1907                 slick_init_configs
1908                 command_slick_icon_wizard
1909                 ;;
1910             "gtkg")
1911                 gtk_greeter_init_configs
1912                 command_gtk_greeter_icon_wizard
1913                 ;;
1914         esac
1915         ;;
1916     "icon-change")
1917         check_command_dm "slick" "gtkg"
1918         case "${MODE}" in
1919             "slick")
1920                 slick_init_configs
1921                 command_slick_icon_chenge "${COMMAND_ARGS[@]}"
1922                 ;;
1923             "gtkg")
1924                 gtk_greeter_init_configs
1925                 command_gtk_greeter_icon_chenge "${COMMAND_ARGS[@]}"
1926                 ;;
1927         esac
1928         ;;
1929     "logo")
1930         check_command_dm "gdm" "slick"
1931         case "${MODE}" in
1932             "gdm")
1933                 gdm_init_configs
1934                 command_gdm_logo "${COMMAND_ARGS[@]}"
1935                 ;;
1936             "slick")
1937                 slick_init_configs
1938                 command_slick_logo "${COMMAND_ARGS[@]}"
1939                 ;;
1940         esac
1941         ;;
1942     "numlock")
1943         check_command_dm "sddm"
1944         sddm_init_configs
1945         command_sddm_numlock "${COMMAND_ARGS[@]}"
1946         ;;
1947     "other-monitor")
1948         check_command_dm "slick"
1949         slick_init_configs
1950         command_slick_other_monitor "${COMMAND_ARGS[@]}"
1951         ;;
1952     "remove")
1953         check_command_dm "lightdm" "gdm" "webkit2" "qtquick"
1954         check_root
1955         eval "command_${MODE}_remove"
1956         ;;
1957     "remove-last")
1958         check_command_dm "lxdm"
1959         lxdm_init_configs
1960         command_lxdm_remove_last
1961         ;;
1962     "root-login")
1963         check_command_dm "gdm"
1964         gdm_init_configs
1965         command_gdm_root_login "${COMMAND_ARGS[@]}"
1966         ;;
1967     "session")
1968         check_command_dm "lxdm"
1969         lxdm_init_configs
1970         command_lxdm_session_wizard
1971         ;;
1972     "session-change")
1973         check_command_dm "lxdm"
1974         lxdm_init_configs
1975         command_lxdm_session_change "${COMMAND_ARGS[@]}"
1976         ;;
1977     "show-config")
1978         check_command_dm "lightdm"
1979         command_lightdm_show_config
1980         ;;
1981
1982     "sound")
1983         check_command_dm "gdm"
1984         gdm_init_configs
1985         command_gdm_sound "${COMMAND_ARGS[@]}"
1986         ;;
1987     "tap")
1988         check_command_dm "gdm"
1989         gdm_init_configs
1990         command_gdm_tap "${COMMAND_ARGS[@]}"
1991         ;;
1992     "theme")
1993         check_command_dm "webkit2" "sddm"
1994         case "${MODE}" in
1995             "webkit2")
1996                 webkit2_init_configs
1997                 command_webkit2_theme_wizard
1998                 ;;
1999             "sddm")
2000                 sddm_init_configs
2001                 command_sddm_theme_wizard
2002                 ;;
2003         esac
2004         ;;
2005     "theme-change")
2006         check_command_dm "webkit2" "sddm"
2007         case "${MODE}" in
2008             "webkit2")
2009                 webkit2_init_configs
2010                 command_webkit2_theme_change "${COMMAND_ARGS[@]}"
2011                 ;;
2012             "sddm")
2013                 sddm_init_configs
2014                 command_sddm_theme_change
2015                 ;;
2016         esac
2017         ;;
2018     "tty")
2019         check_command_dm "sddm"
2020         sddm_init_configs
2021         command_sddm_tty "${COMMAND_ARGS[@]}"
2022         ;;
2023     "gtk-list")
2024         get_gtk_theme
2025         exit 0
2026         ;;
2027     "lightdm" | "gdm" | "sddm" | "lxdm" | "webkit2" | "qtquick" | "slick" | "gtkg")
2028         command_mode "${COMMAND}" "${COMMAND_ARGS[@]}"
2029         ;;
2030     "help")
2031         script_usage
2032         exit 0
2033         ;;
2034     *)
2035         msg_error "This command cannot be used in any mode"
2036         exit 1
2037         ;;
2038 esac