5 # Email : hayao@fascode.net
7 # (c) 2019-2021 Fascode Network.
11 # LICENSE: THE SUSHI-WARE LICENSE
12 # https://github.com/MakeNowJust/sushi-ware
16 # https://qiita.com/laikuaut/items/4bc07eabce56ee30812d
17 # https://qiita.com/t_nakayama0714/items/80b4c94de43643f4be51
20 echo "usage: dmc [options] [command]"
22 echo "A simple tool for switching LightDM Greeters"
24 echo " LightDM command:"
25 echo " autologin [username] [session] Set up automatic login (with blank username to disable)"
26 echo " greeter Run greeter setup wizard"
27 echo " greeter-create [file] Set the specified executable file as Greeter"
28 echo " greeter-change [greeter] Specify the greeter to use"
29 echo " greeter-edit [greeter] Edit the greeter configs"
30 echo " greeter-list Show a list of currently installed Greeters"
31 echo " remove Removes all changes made by this command"
32 echo " edit Edit lightdm config"
33 echo " show-config Show current settings"
36 echo " autologin [username] [session] Set up automatic login (with blank username to disable)"
37 echo " cursor Run cursor selection wizard"
38 echo " cursor-change [cursor] Specify the cursor theme"
39 echo " cursor-list Show a list of cursor theme"
40 echo " sound [true or false] Toggle the sound when an event occurs"
41 echo " logo [image] Specify the logo of the login screen"
42 echo " tap [true or false] Toggle whether to recognize the tap as a click"
43 echo " accessibility [true or false] Toggle whether to show accessibility menu"
44 echo " root-login [true or false] Toggle whether to enable root login"
46 echo " Webkit2 command:"
47 echo " theme Run theme selection wizard"
48 echo " theme-change [theme] Specify the theme"
50 echo " Qtquick command:"
51 echo " back Specify the background image"
53 echo " Slick command:"
54 echo " back [image] Specify the background image"
55 echo " grid [true or false] Toggle whether to show grid"
56 echo " icon Run icon theme selection wizard"
57 echo " theme Run gtk theme selection wizard"
59 echo " General option:"
60 echo " -m | --mode [mode name] Specifiy the target you want to set"
61 echo " -e | --editer [editor path] Specifiy the editor to use for editing"
62 echo " -h | --help This help message and exit"
63 echo " --non-interactive Run in non-interactive mode"
64 echo " --noroot No check root permission"
65 echo " --write-all-files Allows rewriting of all configuration files"
67 echo " Supported modes:"
68 echo " Display managers: lightdm, gdm"
69 echo " LightDM greeters: webkit2, qtquick, slick"
71 echo " This tool is incomplete and still under development."
72 echo " If you find a bug, please report it on GitHub."
73 echo " https://github.com/FascodeNet/dmc"
91 if [[ "${NOROOT}" = false ]] && (( "${UID}" != 0 )); then
92 msg_error "You have to run as root"
100 #if (( "$(expr "${1}" + 1 >/dev/null 2>&1; printf "${?}")" < 2 )); then
101 if printf "%s" "${1}" | grep -E "^[0-9]+$" 1>/dev/null 2>&1; then
111 if [[ -n "${1}" ]] && { [[ "${1}" = "true" ]] ||[[ "${1}" = "false" ]]; }; then
120 local _command="${1}"
122 if which "${_command}" >/dev/null 2>&1; then
123 $(which "${_command}") "${@}"
125 msg_error "${_command} was not found"
131 wrapper crudini "${@}"
142 # 参考: 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
143 # 参考: https://wiki.archlinux.jp/index.php/GDM
144 #echo "Searching cursor themes..." 1>&2
145 local _dir _cursor_theme_dir_list _find_cursor_dir_list=("/usr/share/icons" "${HOME}/.local/share/icons" "${HOME}/.icons")
146 for _dir in "${_find_cursor_dir_list[@]}"; do
147 if [[ -d "${_dir}" ]]; then
148 while read -r line; do
149 _cursor_theme_dir_list+=("${line}")
150 done < <(find "${_dir}" -type d -name "cursors" -print0 | xargs -0 -i dirname {} | sort)
153 unset _dir _find_cursor_dir_list
155 local _cursor_theme _cursor_theme_name _name
156 for _cursor_theme in "${_cursor_theme_dir_list[@]}"; do
157 _name="$(grep -E "^Name=" "${_cursor_theme}/cursor.theme" 2> /dev/null | sed "s|^Name=||g")"
158 if [[ -z "${_name}" ]]; then
159 _name="$(basename "${_cursor_theme}")"
161 _cursor_theme_name+=("${_name}")
163 printf "%s\n" "${_cursor_theme_name[@]}"
168 echo "Loading GTK themes..." >&2
169 local _dir _find_theme_dir_list=("/usr/share/themes" "${HOME}/.local/share/themes" "${HOME}/.themes")
170 for _dir in "${_find_theme_dir_list[@]}"; do
171 if [[ -d "${_dir}" ]]; then
172 while read -r line; do
173 _gtk_theme_dir_list+=("${line}")
174 done < <(find "${_dir}" -type d -name "gtk-*" -print0 | xargs -0 -i dirname {} | tr " " "\n" | sort | uniq)
179 for _dir in "${_gtk_theme_dir_list[@]}"; do
180 _theme_name="$(crudini --get "${_dir}/index.theme" 'Desktop Entry' "Name" 2> /dev/null ;:)"
181 if [[ -z "${_theme_name}" ]]; then
184 _gtk_theme_name_list+=("${_theme_name}")
188 printf "%s\n" "${_gtk_theme_name_list[@]}" | sort | uniq
192 echo "Loading icons..." >&2
193 local _dir _find_theme_dir_list=("/usr/share/icons" "${HOME}/.local/share/icons" "${HOME}/.icons")
194 for _dir in "${_find_theme_dir_list[@]}"; do
195 if [[ -d "${_dir}" ]]; then
196 while read -r line; do
197 _icon_theme_dir_list+=("${line}")
198 done < <(find "${_dir}" -type f -name "index.theme" -print0 | xargs -0 -i dirname {} | tr " " "\n" | sort | uniq)
203 for _dir in "${_icon_theme_dir_list[@]}"; do
204 _theme_name="$(crudini --get "${_dir}/index.theme" 'Icon Theme' "Name" 2> /dev/null ;:)"
205 if [[ -z "${_theme_name}" ]]; then
208 _gtk_theme_name_list+=("${_theme_name}")
212 printf "%s\n" "${_gtk_theme_name_list[@]}" | sort | uniq
216 # ask_question -d <デフォルト値> <選択肢1> <選択肢2> ...
218 local arg OPTARG OPTIND
219 local _default="" _choice_list _count _choice
220 while getopts "d:" arg; do
222 d) _default="${OPTARG}" ;;
225 shift $((OPTIND - 1))
226 _choice_list=("${@}")
228 for (( _count=1; _count<=${#_choice_list[@]}; _count++)); do
229 _choice="${_choice_list[$(( _count - 1 ))]}"
230 if [[ ! "${_default}" = "" ]] && [[ "${_choice}" = "${_default}" ]]; then
231 echo " * ${_count}: ${_choice}" >&2
233 echo " ${_count}: ${_choice}" >&2
237 echo -n "(1 ~ ${#_choice_list[@]}) > " >&2
241 if check_int "${_input}"; then
243 if (( 1 <= _input)) && (( _input <= ${#_choice_list[@]} )); then
244 _choice="${_choice_list[$(( _input - 1 ))]}"
250 if printf "%s\n" "${_choice_list[@]}" | grep -x "${_input}" 1>/dev/null 2>&1; then
260 #== LightDM用の汎用関数 ==#
262 lightdm_get_source_file(){
264 local source_name="$(lightdm --show-config 2>&1 | grep -E "^[A-Z] ${key}=" | cut -d ' ' -f 1)"
265 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")"
266 if [[ -n "${source_path}" ]]; then
267 echo -n "${source_path}"
275 lightdm_set_config(){
276 local key="${1}" value="${2}" file=${3-${DISPLAY_MANAGER_CONFIG["lightdm"]}}
277 if [[ "${WRITE_ALL_FILES}" = true ]] && [[ -n "$(lightdm_get_source_file "${1}")" ]]; then
278 crudini --set "$(lightdm_get_source_file "${1}")" 'Seat:*' "${key}" "${value}"
280 crudini --set "${file}" 'Seat:*' "${key}" "${value}"
283 if [[ ! "$(lightdm_get_value "${key}")" = "${value}" ]]; then
284 msg_error "Failed to change the setting value. A value has already been set for $(lightdm_get_source_file "${1}")"
285 msg_error "lightdm-config does not manipulate other configuration files for safety. Comment out the settings in that file."
290 lightdm_remove_key(){
291 local key="${1}" _config
292 if grep -E "^ ?${key}.+" "${DISPLAY_MANAGER_CONFIG["lightdm"]}" 1>/dev/null 2>&1; then
293 sed -i -r "s|^ ?${key} ?=.+||g" "${DISPLAY_MANAGER_CONFIG["lightdm"]}"
294 sed -i '/^$/d' "${DISPLAY_MANAGER_CONFIG["lightdm"]}"
299 lightdm_init_configs(){
301 if [[ ! -f "${DISPLAY_MANAGER_CONFIG["lightdm"]}" ]]; then
302 mkdir -p "$(dirname "${DISPLAY_MANAGER_CONFIG["lightdm"]}")"
303 touch "${DISPLAY_MANAGER_CONFIG["lightdm"]}"
304 echo "[Seat:*]" > "${DISPLAY_MANAGER_CONFIG["lightdm"]}"
310 local _current_value="$(lightdm --show-config 2>&1 | grep -E "^[A-Z] ${1}=" | sed "s|^[A-Z] ||g" | cut -d "=" -f "2")"
311 if [[ "${_current_value}" ]]; then
312 echo -n "${_current_value}"
322 command_lightdm_greeter_change() {
324 if [[ -z "${1}" ]] || [[ "${1}" = "" ]]; then
325 msg_error "Please specify Greeter."
330 # 指定されたGreeterが正しいか確認
331 if ! printf "%s\n" "${LIGHTDM_GREETERS[@]}" | grep -x "${1}" > /dev/null 2>&2; then
332 msg_error "The greeter (${1}) doesn't exist."
335 lightdm_set_config "greeter-session" "${1}"
340 command_lightdm_greeter_create(){
341 if [[ -z "${1}" ]] || [[ "${1}" = "" ]]; then
342 msg_error "Please specify Greeter."
346 if [[ ! -f "${1}" ]]; then
347 msg_error "${1} does not exist."
351 if [[ ! -x "${1}" ]]; then
352 msg_error "hoge is not an executable file."
358 local filename="$(basename "${1}")"
360 if [[ -f "/usr/share/xgreeters/${filename}.desktop" ]]; then
361 msg_error "Greeter with the same name already exists."
364 cat > "/usr/share/xgreeters/${filename}.desktop" <<EOF
366 Name=LightDM custom Greeter ${filename}
367 Comment=LightDM Greeter
374 command_lightdm_greeter_list() {
375 echo "Available Lightdm greeter list:"
377 for _greeter in "${LIGHTDM_GREETERS[@]}"; do
378 if [[ "${_greeter}" = "${LIGHTDM_CURRENT_GREETER}" ]]; then
379 echo " * ${_greeter}"
387 run_greeter_wizard(){
389 if (( ${#LIGHTDM_GREETERS[@]} < 1 )); then
390 msg_error "LightDM Greeter was not found."
396 echo "Please select the greeter to use."
397 if ! _greeter="$(ask_question -d "${LIGHTDM_CURRENT_GREETER}" "${LIGHTDM_GREETERS[@]}")"; then
403 if [[ -n "${_greeter}" ]]; then
404 command_lightdm_greeter_change "${_greeter}"
409 echo "Changed greeter to ${_greeter}"
413 command_lightdm_remove(){
414 if [[ ! -f "${DISPLAY_MANAGER_CONFIG["lightdm"]}" ]]; then
418 echo -ne "Are you sure you want to delete all settings?\nThis change is irreversible.\n (y or n) > "
419 read -r -n 1 _yes_or_no
420 if [[ "${_yes_or_no}" = "y" ]]; then
421 mv "${DISPLAY_MANAGER_CONFIG["lightdm"]}" "${DISPLAY_MANAGER_CONFIG["lightdm"]}.disabled"
427 command_lightdm_greeter_edit(){
428 if [[ "${NON_INTERACTIVE}" = true ]]; then
429 msg_error "You cannot use this command in non-interactive mode."
432 local _greeter="${1:-${LIGHTDM_CURRENT_GREETER}}"
433 if [[ -z "${GREETER_CONFIG["${_greeter}"]+SET}" ]]; then
434 msg_error "This Greeter is not currently supported."
435 msg_error "Please report the problem here."
436 msg_error "https://github.com/FascodeNet/lightdm-config/issues"
439 if [[ -z "${1}" ]] || [[ "${1}" = "" ]]; then
440 msg_warn "Greeter was not specified. Open the currently configured Greeter configuration file."
441 echo -n "(Enter to continue) > "
445 bash -c "${USE_EDITOR} ${GREETER_CONFIG["${_greeter}"]}"
451 command_lightdm_edit(){
452 if [[ "${NON_INTERACTIVE}" = true ]]; then
453 msg_error "You cannot use this command in non-interactive mode."
456 for _config in "${LIGHTDM_LOADED_CONFIG[@]}"; do
457 echo -ne "Edit ${_config} ? (y or n)> "
458 read -r -n 1 _yes_or_no
460 if [[ "${_yes_or_no}" = "y" ]]; then
461 bash -c "${USE_EDITOR} ${_config}"
467 command_lightdm_auto_login(){
468 if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
469 # 既に自動ログインが設定されているかを確認
470 local autologin_user="$(lightdm_get_value autologin-user)"
471 if [[ -n "${autologin_user}" ]]; then
473 for _autologin in "autologin-guest" "autologin-user" "autologin-user-timeout" "autologin-in-background" "autologin-session"; do
474 remove_key "${_autologin}"
476 echo "Canceled automatic login of ${autologin_user}"
479 local autologin_user="${1}" autologin_session
481 autologin_session="${2}"
485 if ! getent passwd "${autologin_user}" 1> /dev/null 2>&1; then
486 echo "${autologin_user} is a non-existent user."
491 if [[ -z "${autologin_session+SET}" ]]; then
492 if (( $(find "/usr/share/xsessions" -print0 -type f 2> /dev/null | xargs -0 -i basename {} | wc -l) <= 1 )); then
493 autologin_session="$(find "/usr/share/xsessions" -print0 -type f 2> /dev/null | xargs -0 -i basename {} | sed 's|.desktop$||g')"
494 elif [[ "${NON_INTERACTIVE}" = true ]]; then
497 autologin_session="$(grep -E '^Session=' "${HOME}/.dmrc" 2> /dev/null | cut -d '=' -f 2)"
498 if [[ -z "${autologin_session}" ]]; then
499 msg_error "Failed to set the session."
500 msg_error "Not specified and ~/.dmrc does not exist either."
504 echo "Select the desktop session to autologin"
506 for session in "/usr/share/xsessions/"*; do
509 echo -n "(session name) > "
511 if [[ -f "/usr/share/xsessions/${session}.desktop" ]]; then
512 autologin_session="${session}"
514 msg_error "Please enter the correct session name."
520 if [[ ! -f "/usr/share/xsessions/${autologin_session}.desktop" ]]; then
522 msg_error "This is a session (${autologin_session}) that does not exist."
528 if ! getent group "autologin" 1> /dev/null 2>&1; then
529 LANG=C groupadd -r "autologin"
531 LANG=C gpasswd -a "${autologin_user}" "autologin"
534 lightdm_set_config "autologin-guest" "false"
535 lightdm_set_config "autologin-user" "${autologin_user}"
536 lightdm_set_config "autologin-user-timeout" "0"
537 lightdm_set_config "autologin-in-background" "false"
538 lightdm_set_config "autologin-session" "${autologin_session}"
540 echo "${autologin_user} will automatically log in with ${autologin_session}"
546 command_lightdm_show_config(){
547 lightdm --show-config 2>&1
553 if [[ ! -f "/etc/dconf/profile/gdm" ]]; then
554 mkdir -p "/etc/dconf/profile"
555 touch "/etc/dconf/profile/gdm"
556 echo -e "user-db:user\nsystem-db:gdm\nfile-db:/usr/share/gdm/greeter-dconf-defaults" > "/etc/dconf/profile/gdm"
560 for _file in "${DISPLAY_MANAGER_CONFIG["gdm-dconf"]}" "${DISPLAY_MANAGER_CONFIG["gdm-custom"]}"; do
561 if [[ ! -f "${_file}" ]]; then
562 mkdir -p "$(dirname "${_file}")"
568 # gdm_dconf_set_config <dconf path> <key> <value>
569 gdm_dconf_set_config(){
570 if check_int "${3}" || check_bool "${3}"; then
571 crudini --set "${DISPLAY_MANAGER_CONFIG["gdm-dconf"]}" "${1}" "${2}" "${3}"
573 crudini --set "${DISPLAY_MANAGER_CONFIG["gdm-dconf"]}" "${1}" "${2}" "\"${3}\""
578 # gdm_dconf_get_value <dconf path> <key>
579 gdm_dconf_get_value(){
580 dconf dump / | crudini --get - "${1}" "${2}"
583 # gdm_custom_get_value <section> <key>
584 gdm_custom_get_value(){
585 crudini --get "${DISPLAY_MANAGER_CONFIG["gdm-custom"]}" "${1}" "${2}"
588 # gdm_custom_set_config <section> <key> <value>
589 gdm_custom_set_config(){
590 if check_int "${3}" || check_bool "${3}"; then
591 crudini --set "${DISPLAY_MANAGER_CONFIG["gdm-custom"]}" "${1}" "${2}" "${3}"
593 crudini --set "${DISPLAY_MANAGER_CONFIG["gdm-custom"]}" "${1}" "${2}" "\"${3}\""
605 if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
606 msg_error "Please specify the image of background"
609 if [[ ! -f "${1}" ]]; then
610 msg_error "${1} was not found."
614 local _backgrounf_file="/usr/share/backgrounds/gdm/background"
615 mkdir -p "$(dirname "${_backgrounf_file}")"
616 cp "${1}" "${_backgrounf_file}"
617 chmod 644 "${_backgrounf_file}"
619 gdm_dconf_set_config "org/gnome/login-screen" "logo" "${_backgrounf_file}"
622 command_gdm_cursor_wizard(){
625 while read -r line; do cursor_themes+=("${line}"); done < <(get_cursor_theme)
630 echo "Please select the cursor theme to use."
631 if ! _cursor_theme="$(ask_question "${cursor_themes[@]}")"; then
636 if [[ -n "${_cursor_theme}" ]]; then
637 command_gdm_cursor_change "${_cursor_theme}"
639 command_gdm_cursor_wizard
642 echo "Changed cursor to ${_cursor_theme}"
645 command_gdm_cursor_change(){
646 if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
647 msg_error "Please specify the cursor theme"
651 while read -r line; do cursor_themes+=("${line}"); done < <(get_cursor_theme)
652 if ! printf "%s\n" "${cursor_themes[@]}" | grep -x "${1}" 1>/dev/null 2>&1; then
653 msg_error "The cursor theme (${1}) was not found"
656 gdm_dconf_set_config "org/gnome/desktop/interface" "cursor-theme" "${1}"
660 local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
661 if ! check_bool "${_arg}"; then
662 msg_error "Please specify true or false"
666 gdm_dconf_set_config "org/gnome/desktop/sound" "event-sounds" "${_arg}"
670 local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
671 if ! check_bool "${_arg}"; then
672 msg_error "Please specify true or false"
676 gdm_dconf_set_config "org/gnome/desktop/peripherals/touchpad" "tap-to-click" "${_arg}"
680 command_gdm_auto_login(){
681 if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
682 # 既に自動ログインが設定されているかを確認
683 local autologin="$(gdm_custom_get_value daemon AutomaticLoginEnable)"
684 if [[ "${autologin}" = "True" ]]; then
685 gdm_custom_set_config "daemon" "AutomaticLoginEnable" "False"
686 echo "Canceled automatic login of $(gdm_custom_get_value "daemon" "AutomaticLogin")"
689 local autologin_user="${1}" autologin_session
691 autologin_session="${2}"
695 if ! getent passwd "${autologin_user}" 1> /dev/null 2>&1; then
696 echo "${autologin_user} is a non-existent user."
700 # セッションを設定 (WayLandのセッションは現在サポートされていません)
701 if [[ -z "${autologin_session+SET}" ]]; then
702 if (( $(find "/usr/share/xsessions" -print0 -type f 2> /dev/null | xargs -0 -i basename {} | wc -l) <= 1 )); then
703 autologin_session="$(find "/usr/share/xsessions" -print0 -type f 2> /dev/null | xargs -0 -i basename {} | sed 's|.desktop$||g')"
704 elif [[ "${NON_INTERACTIVE}" = true ]]; then
707 autologin_session="$(grep -E '^Session=' "${HOME}/.dmrc" 2> /dev/null | cut -d '=' -f 2)"
708 if [[ -z "${autologin_session}" ]]; then
709 msg_error "Failed to set the session."
710 msg_error "Not specified and ~/.dmrc does not exist either."
714 echo "Select the desktop session to autologin"
716 for session in "/usr/share/xsessions/"*; do
717 echo " $(basename "${session}" | sed "s|.desktop$||g")"
719 echo -n "(session name) > "
721 if [[ -f "/usr/share/xsessions/${session}.desktop" ]]; then
722 autologin_session="${session}"
724 msg_error "Please enter the correct session name."
730 if [[ ! -f "/usr/share/xsessions/${autologin_session}.desktop" ]]; then
732 msg_error "This is a session (${autologin_session}) that does not exist."
738 if ! getent group "autologin" 1> /dev/null 2>&1; then
739 LANG=C groupadd -r "autologin"
741 LANG=C gpasswd -a "${autologin_user}" "autologin"
744 gdm_custom_set_config "daemon" "AutomaticLoginEnable" "True"
745 gdm_custom_set_config "daemon" "AutomaticLogin" "${autologin_user}"
748 crudini --set "/var/lib/AccountsService/users/${autologin_user}" "User" "Session" "${autologin_session}"
749 crudini --set "/var/lib/AccountsService/users/${autologin_user}" "User" "XSession" "${autologin_session}"
751 echo "${autologin_user} will automatically log in with ${autologin_session}"
757 command_gdm_accessibility(){
758 local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
759 if ! check_bool "${_arg}"; then
760 msg_error "Please specify true or false"
764 gdm_dconf_set_config "org/gnome/desktop/interface" "toolkit-accessibility" "${_arg}"
768 command_gdm_root_login(){
769 local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
770 if ! check_bool "${_arg}"; then
771 msg_error "Please specify true or false"
775 gdm_custom_set_config "daemon" "AllowRoot" "${_arg}"
778 #== Webkit2用の汎用関数 ==#
779 webkit2_init_configs(){
781 if [[ ! -f "${GREETER_CONFIG["lightdm-webkit2-greeter"]}" ]]; then
782 mkdir -p "$(dirname "${GREETER_CONFIG["lightdm-webkit2-greeter"]}")"
783 touch "${GREETER_CONFIG["lightdm-webkit2-greeter"]}"
787 # webkit2_get_value <section> <key>
789 crudini --get "${GREETER_CONFIG["lightdm-webkit2-greeter"]}" "${1}" "${2}"
792 # webkit2_set_config <section> <key> <value>
793 webkit2_set_config(){
794 crudini --set "${GREETER_CONFIG["lightdm-webkit2-greeter"]}" "${1}" "${2}" "${3}"
798 command_webkit2_theme_wizard(){
800 while read -r line; do
801 _theme_list+=("${line}")
802 done < <(ls /usr/share/lightdm-webkit/themes)
804 local _current_theme=$(webkit2_get_value greeter webkit_theme | sed "s|\"||g")
806 echo "Please select the theme to use." _theme_list
807 if ! _theme="$(ask_question -d "${_current_theme}" "${_theme_list[@]}")"; then
811 if [[ -n "${_theme}" ]]; then
812 command_webkit2_theme_change "${_theme}"
813 echo "Changed the theme to ${_theme}"
815 command_webkit2_theme_wizard
821 command_webkit2_theme_change(){
822 if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
823 msg_error "Please specify the theme name"
826 if [[ ! -d "/usr/share/lightdm-webkit/themes/${1}" ]]; then
827 msg_error "The specified theme (${1}) does not exist"
831 webkit2_set_config "greeter" "webkit_theme" "${1}"
834 #== Qtquick用の汎用関数 ==#
835 qtquick_init_configs(){
837 if [[ ! -f "${GREETER_CONFIG["lightdm-qtquick-greeter"]}" ]] || [[ -z "$(cat "${GREETER_CONFIG["lightdm-qtquick-greeter"]}")" ]]; then
838 mkdir -p "$(dirname "${GREETER_CONFIG["lightdm-qtquick-greeter"]}")"
839 touch "${GREETER_CONFIG["lightdm-qtquick-greeter"]}"
840 #echo -e "{\n\n}\n" > "${GREETER_CONFIG["lightdm-qtquick-greeter"]}"
841 qtquick_set_config background_path "file:///hoge/fuga.png"
842 qtquick_set_config theme "qrc:/Login.qml"
846 #qtquick_get_value <key>
848 jq ".${1}" < "${GREETER_CONFIG["lightdm-qtquick-greeter"]}"
851 # command_qtquick_back <key> <value>
852 qtquick_set_config(){
853 local _tempfile="/tmp/$(basename "${GREETER_CONFIG["lightdm-qtquick-greeter"]}")-$(base64 < "/dev/urandom" | fold -w 10 | head -n 1)"
854 cp "${GREETER_CONFIG["lightdm-qtquick-greeter"]}" "${_tempfile}"
855 #cat "${_tempfile}" | jq -r ".${1}|=\"${2}\"" > "${GREETER_CONFIG["lightdm-qtquick-greeter"]}"
856 jq -r ".${1}|=\"${2}\"" < "${_tempfile}" > "${GREETER_CONFIG["lightdm-qtquick-greeter"]}"
857 chmod 644 "${GREETER_CONFIG["lightdm-qtquick-greeter"]}"
861 command_qtquick_back(){
862 if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
863 msg_error "Please specify the image of background"
866 if [[ ! -f "${1}" ]]; then
867 msg_error "${1} was not found."
871 local _backgrounf_file="/usr/share/backgrounds/lightdm/qtquick-greeter"
872 mkdir -p "$(dirname "${_backgrounf_file}")"
873 cp "${1}" "${_backgrounf_file}"
874 chmod 644 "${_backgrounf_file}"
876 qtquick_set_config "background_path" "file://${_backgrounf_file}"
881 crudini --get "${GREETER_CONFIG["lightdm-slick-greeter"]}" "Greeter" "${1}"
885 crudini --set "${GREETER_CONFIG["lightdm-slick-greeter"]}" "Greeter" "${1}" "${2}"
888 slick_init_configs(){
890 if [[ ! -f "${GREETER_CONFIG["lightdm-slick-greeter"]}" ]]; then
891 mkdir -p "$(dirname "${GREETER_CONFIG["lightdm-slick-greeter"]}")"
892 touch "${GREETER_CONFIG["lightdm-slick-greeter"]}"
893 echo "[Greeter]" > "${GREETER_CONFIG["lightdm-slick-greeter"]}"
897 command_slick_grid(){
898 local _arg="$(echo "${1-""}" | tr "[:upper:]" "[:lower:]")"
899 if ! check_bool "${_arg}"; then
900 msg_error "Please specify true or false"
904 slick_set_config "draw-grid" "${_arg}"
907 command_slick_back(){
908 if [[ -z "${1+SET}" ]] || [[ "${1}" = "" ]]; then
909 msg_error "Please specify the image of background"
912 if [[ ! -f "${1}" ]]; then
913 msg_error "${1} was not found."
917 local _backgrounf_file="/usr/share/backgrounds/lightdm/slick-greeter"
918 mkdir -p "$(dirname "${_backgrounf_file}")"
919 cp "${1}" "${_backgrounf_file}"
920 chmod 644 "${_backgrounf_file}"
922 slick_set_config "background" "${_backgrounf_file}"
926 command_slick_theme_wizard(){
928 while read -r line; do gtk_themes+=("${line}"); done < <(get_gtk_theme)
932 echo "Please select the theme to use."
933 if ! _theme="$(ask_question "${gtk_themes[@]}")"; then
934 command_slick_theme_wizard
939 if [[ -n "${_theme}" ]]; then
940 slick_set_config "theme-name" "${_theme}"
942 command_slick_theme_wizard
945 echo "Changed theme to ${_theme}"
949 command_slick_icon_wizard(){
951 while read -r line; do icons+=("${line}"); done < <(get_icon_theme)
954 echo "Please select the icon theme to use."
955 if ! _icon="$(ask_question "${icons[@]}")"; then
956 command_slick_icon_wizard
960 if [[ -n "${_icon}" ]]; then
961 slick_set_config "icon-theme-name" "${_icon}"
963 command_slick_icon_wizard
966 echo "Changed icon theme to ${_icon}"
971 declare -A GREETER_CONFIG=(
972 ["lightdm-webkit2-greeter"]="/etc/lightdm/lightdm-webkit2-greeter.conf"
973 ["lightdm-slick-greeter"]="/etc/lightdm/slick-greeter.conf"
974 ["lightdm-gtk-greeter"]="/etc/lightdm/lightdm-gtk-greeter.conf"
975 ["io.elementary.greeter"]="/etc/lightdm/io.elementary.greeter.conf"
976 ["lightdm-mini-greeter"]="/etc/lightdm/lightdm-mini-greeter.conf"
977 ["lightdm-qtquick-greeter"]="/etc/lightdm/lightdm-qtquick-greeter.json"
980 declare -A DISPLAY_MANAGER_CONFIG=(
981 ["lightdm"]="/etc/lightdm/lightdm.conf.d/00-dmc-lightdm.conf"
982 ["gdm-dconf"]="/etc/dconf/db/gdm.d/00-dmc-gdm"
983 ["gdm-custom"]="/etc/gdm/custom.conf"
989 # LightDM - Greeterのディレクトリ
990 LIGHTDM_GREETERS_DIR="$(lightdm_get_value "greeters-directory")"
991 : "${LIGHTDM_GREETERS_DIR:="/usr/share/xgreeters"}"
993 # LightDM - Greeter一覧
994 #LIGHTDM_GREETERS=( $( )
995 while read -r line; do
996 LIGHTDM_GREETERS+=("${line}")
997 done < <( (find "${LIGHTDM_GREETERS_DIR}" -print0 -type f | xargs -0 -i basename {} | sed "s|.desktop$||g" | grep -xv "xgreeters") 2> /dev/null )
999 # LightDM - 現在設定されているGreeter
1000 LIGHTDM_CURRENT_GREETER="$(lightdm --show-config 2>&1 | grep "greeter-session" | cut -d "=" -f 2)"
1001 : "${LIGHTDM_CURRENT_GREETER:="lightdm-gtk-greeter"}"
1003 # LightDM - 読み込まれた設定ファイルの一覧
1004 while read -r line; do
1005 LIGHTDM_LOADED_CONFIG+=("${line}")
1006 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 " ")
1009 USE_EDITOR="${EDITOR:-vi}"
1012 DISPLAY_MANAGER="$(basename "$(readlink "/etc/systemd/system/display-manager.service")" | sed "s|.service$||g")"
1013 : "${DISPLAY_MANAGER:="lightdm"}"
1016 NON_INTERACTIVE=false
1017 WRITE_ALL_FILES=false
1024 OPTL="mode:,editor:,help,non-interactive,noroot,write-all-files"
1025 # shellcheck disable=SC2086
1026 if ! OPT="$(getopt -o ${OPTS} -l ${OPTL} -- ${ARGUMENT})"; then
1030 eval set -- "${OPT}"
1036 DISPLAY_MANAGER="${2}"
1048 NON_INTERACTIVE=true
1056 WRITE_ALL_FILES=true
1066 COMMAND="${1:-null}"
1067 if (( "${#}" >= 1 )); then
1071 : "${COMMAND_ARGS-""}" # サブコマンドの引数が何も指定されなかった場合に空文字を代入
1073 if [[ "${COMMAND}" = "null" ]]; then
1078 case "${DISPLAY_MANAGER}" in
1080 case "${COMMAND}" in
1082 lightdm_init_configs
1083 command_lightdm_auto_login "${COMMAND_ARGS}"
1086 lightdm_init_configs
1090 lightdm_init_configs
1091 command_lightdm_greeter_change "${COMMAND_ARGS}"
1094 lightdm_init_configs
1095 command_lightdm_greeter_create "${COMMAND_ARGS}"
1098 command_lightdm_greeter_list
1102 command_lightdm_greeter_edit "${COMMAND_ARGS}"
1106 command_lightdm_remove
1110 command_lightdm_edit
1113 command_lightdm_show_config
1116 msg_error "Undefined commnad(${COMMAND})"
1121 case "${COMMAND}" in
1124 command_gdm_auto_login "${COMMAND_ARGS}"
1128 command_gdm_cursor_wizard
1132 command_gdm_cursor_change "${COMMAND_ARGS}"
1136 command_gdm_sound "${COMMAND_ARGS}"
1140 command_gdm_logo "${COMMAND_ARGS}"
1144 command_gdm_tap "${COMMAND_ARGS}"
1148 command_gdm_accessibility "${COMMAND_ARGS}"
1152 command_gdm_root_login "${COMMAND_ARGS}"
1155 msg_error "Undefined commnad(${COMMAND})"
1160 case "${COMMAND}" in
1162 webkit2_init_configs
1163 command_webkit2_theme_wizard
1166 webkit2_init_configs
1167 command_webkit2_theme_change "${COMMAND_ARGS}"
1170 msg_error "Undefined commnad(${COMMAND})"
1175 case "${COMMAND}" in
1177 qtquick_init_configs
1178 command_qtquick_back "${COMMAND_ARGS}"
1183 case "${COMMAND}" in
1186 command_slick_back "${COMMAND_ARGS}"
1190 command_slick_grid "${COMMAND_ARGS}"
1194 command_slick_icon_wizard
1198 command_slick_theme_wizard
1202 command_slick_other_monitor "${COMMAND_ARGS}"
1206 command_slick_logo "${COMMAND_ARGS}"
1211 msg_error "A display manager that is not currently supported."