OSDN Git Service

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