File: initializer

package info (click to toggle)
im-config 0.62
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,004 kB
  • sloc: sh: 421; makefile: 104
file content (107 lines) | stat: -rw-r--r-- 4,215 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Common shell routine used by im-config
# (C) 2026 Osamu Aoki <osamu@debian.org>, GPL-2+
# vim: set sts=4 sw=4 expandtab:
#
#############################################################
# Common logging functions `
#############################################################
IM_CONFIG_DEFAULT=/etc/default/im-config
# logger_info -- nice to have systemd installed
# gnu-which doesn't support "which -s ..."
if [ -e /usr/bin/systemd-cat ] ; then
    LOGGER='/usr/bin/systemd-cat -p 6 -t "im-config" echo'
elif [ -e /usr/bin/logger ] ; then
    LOGGER='/usr/bin/logger -p local0.info -t "im-config" echo'
else
    LOGGER='>&2 echo'
fi

logger_info() {
    eval "$LOGGER \"$1\""
}

logger_debug() {
    if [ -n "$IM_CONFIG_VERBOSE" ]; then
        eval "$LOGGER \"$1\""
    fi
}

# Reduce risk of random script executions
set_val () {
    MATCH="^$1=[\"']?[-a-zA-Z:_,][-a-zA-Z:_,]*.[\"']?\$"
    eval "$(grep -e "$MATCH" $IM_CONFIG_DEFAULT | head -1)"
    logger_debug "Set $(grep -e "$MATCH" $IM_CONFIG_DEFAULT | head -1)"
}

# parse /etc/default/im-config
logger_debug "Parse $IM_CONFIG_DEFAULT"
if [ -r $IM_CONFIG_DEFAULT ]; then
    set_val IM_CONFIG_DEFAULT_MODE
    set_val CJKV_DEFAULT_DESKTOP
    set_val CJKV_LOCALES
    set_val IM_CONFIG_PREFERRED_RULE
    set_val DESKTOP_SETUP_IBUS
    set_val IM_CONFIG_SETMODE
    set_val IM_CONFIG_VERBOSE
fi
# provide fall back values for undefined cases
if [ -z "$IM_CONFIG_DEFAULT_MODE" ]; then
    IM_CONFIG_DEFAULT_MODE="auto"
fi
if [ -z "$CJKV_DEFAULT_DESKTOP" ]; then
    CJKV_DEFAULT_DESKTOP="*"
fi
if [ -z "$CJKV_LOCALE" ]; then
    CJKV_LOCALES="zh_TW:zh_HK:zh_SG:zh_CN:ja_JP:ko_KR:vi_VN"
fi
if [ -z "$IM_CONFIG_PREFERRED_RULE" ]; then
    IM_CONFIG_PREFERRED_RULE="zh_CN,fcitx5:zh_TW,fcitx5:zh_HK,fcitx5:zh_SG,fcitx5"
fi
if [ -z "$DESKTOP_SETUP_IBUS" ]; then
    DESKTOP_SETUP_IBUS="GNOME"
fi
if [ -z "$IM_CONFIG_SETMODE" ]; then
    IM_CONFIG_SETMODE=""
fi
if [ -z "$IM_CONFIG_VERBOSE" ]; then
    IM_CONFIG_VERBOSE="false"
fi

# 2026-0317
# Primary variable to determine DE
# XDG_CURRENT_DESKTOP -- defined in the Desktop Entry Specification since its version 1.2
#   Set by set by DesktopNames in some code, multi value capable
#   See https://specifications.freedesktop.org/menu/latest/onlyshowin-registry.html
#   budgie-session       GNOME
#   cinnamon-session     IM_CONFIG_CURRENT_DESKTOP <- DESKTOP_SESSION='cinnamon' (Later: X-Cinamon)
#   gnome-flashback      GNOME-Flashback:GNOME
#   gnome-session        GNOME
#   lxqt-session         LXQt
#   lxsession            LXDE     (this code mentions Lubuntu migration, and has example with qt/platform=lxqt)
#   mate-session-manager MATE
#   plasma-workspace     KDE
#   xfce4-session        XFCE
#
# XDG_SESSION_DESKTOP -- non-standard
# DESKTOP_SESSION     -- deprecated, backward-compatibility
#
logger_debug "@ IM_CONFIG_ENTRY='$IM_CONFIG_ENTRY' XDG_SESSION_TYPE ='$XDG_SESSION_TYPE' UID=$(id -u) PID=$$ PPID=$PPID"
logger_debug "  GTK_IM_MODULE='$GTK_IM_MODULE' QT_IM_MODULE='$QT_IM_MODULE' CLUTTER_IM_MODULE='$CLUTTER_IM_MODULE' SDL_IM_MODULE='$SDL_IM_MODULE' XMODIFIERS='$XMODIFIERS'"
if [ -n "$XDG_CURRENT_DESKTOP" ]; then
    IM_CONFIG_CURRENT_DESKTOP="$XDG_CURRENT_DESKTOP"
    logger_debug "  Set IM_CONFIG_CURRENT_DESKTOP <- XDG_CURRENT_DESKTOP='$XDG_CURRENT_DESKTOP'"
elif [ "$DESKTOP_SESSION" = 'lxqt' -o "$DESKTOP_SESSION" = 'Lubuntu' ]; then
    # hack since LXQt sets XDG_CURRENT_DESKTOP late - https://github.com/lxqt/lxqt/issues/1830
    # Upstream claims that the issue was fixed in lxqt-session 0.17.0. However, Lubuntu 21.10
    # uses 0.17.1 but it still does not work. So let's keep this hack for now.
    IM_CONFIG_CURRENT_DESKTOP="LXQt"
    logger_debug "  Set IM_CONFIG_CURRENT_DESKTOP <- DESKTOP_SESSION='$DESKTOP_SESSION' (special case for Ubuntu lxqt Lubuntu)"
elif [ -n "$DESKTOP_SESSION" ]; then
    #  Since LXDE also sets $XDG_CURRENT_DESKTOP='', let's make generic fall back
    IM_CONFIG_CURRENT_DESKTOP="$DESKTOP_SESSION"
    logger_debug "  Set IM_CONFIG_CURRENT_DESKTOP <- DESKTOP_SESSION='$DESKTOP_SESSION' (generic backword compatibility)"
else
    IM_CONFIG_CURRENT_DESKTOP="UNDEFINED"
    logger_debug "  Set IM_CONFIG_CURRENT_DESKTOP <- 'UNDEFINED'"
fi