Пакет с настройками графического рабочего окружения Кометы
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kometa-xdg/scripts/kometa-xdg-env

102 lines
3.0 KiB

3 years ago
#!/bin/sh
KOMETA_XDG_TESTING="${KOMETA_XDG_TESTING:-0}"
KOMETA_XDG_TYPE="${KOMETA_XDG_TYPE:-}"
3 years ago
KOMETA_XDG_CONFIG_DIR=/etc/xdg/kometa
KOMETA_XDG_DATA_DIR=/usr/share/kometa
3 years ago
XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-}"
_check_runability(){
case "$1" in
systemd ) : ;;
profile ) : ;;
* )
echo 'Set $KOMETA_XDG_TYPE to systemd or profile!' >&2
return 1
;;
esac
}
# XXX Who is that crazy person who sets adds ~/.config/kdedefaults to
# XDG_CONFIG_DIRS=/home/user/.config/kdedefaults:/etc/kf5/xdg:/etc/xdg
# and why does he do such a strange thing?!
# Example of what we have to do:
# convert XDG_CONFIG_DIRS=/home/user/.config/kdedefaults:/etc/kf5/xdg:/etc/xdg
# into XDG_CONFIG_DIRS=/home/user/.config/kdedefaults:/etc/xdg/kometa:/etc/kf5/xdg:/etc/xdg
# I do not want to write very complex code to deal with all possible cases.
# Let's assume that current value:
# * is not a mess and is a valid value
# * does not have repeated directories (if it has, we will probably still be OK)
# $1: current value of $XDG_CONFIG_DIRS
3 years ago
_mk_xdg_dirs(){
3 years ago
local tmp
3 years ago
# current value
3 years ago
tmp="$1"
3 years ago
# /etc/xdg, /usr/share
root1="$2"
# /etc/kf5/xdg, /usr/share/kf5
root2="$3"
# /etc/xdg/kometa, /usr/share/kometa
add="$4"
3 years ago
case "$tmp" in
"" )
# https://bugzilla.altlinux.org/show_bug.cgi?id=41566
3 years ago
tmp="$root2":"$root1"
3 years ago
;;
3 years ago
:"$root1" )
3 years ago
# not a valid value!
3 years ago
tmp="$root1"
3 years ago
;;
3 years ago
"$root1" )
3 years ago
:
;;
3 years ago
*"$root1" )
3 years ago
:
;;
* )
3 years ago
# not a valid values - does not end with /etc/xdg or /usr/share
tmp="$tmp":"$root1"
3 years ago
;;
esac
case "$tmp" in
3 years ago
*:"$root1"/kometa:* | "$root1"/kometa:* )
3 years ago
:
;;
3 years ago
*:"$root2":* )
tmp="$(echo "$tmp" | sed -e "s,:${root2}:,:${add}:${root2}:,")"
3 years ago
;;
3 years ago
"$root2":* )
tmp="$(echo "$tmp" | sed -e "s,^${root2}:,${add}:${root2}:,")"
3 years ago
;;
3 years ago
*:"$root1" )
tmp="$(echo "$tmp" | sed -e "s,:${root1},:${add}:${root1},")"
3 years ago
;;
3 years ago
"$root1" )
tmp="$(echo "$tmp" | sed -e "s,^${root1},${add}:${root1},")"
3 years ago
;;
esac
echo "$tmp"
}
_main(){
_check_runability "$1"
# $XDG_DATA_DIRS may be added
local result_xdg_config_dirs
3 years ago
result_xdg_config_dirs="$(_mk_xdg_dirs "$XDG_CONFIG_DIRS" /etc/xdg /etc/kf5/xdg "$KOMETA_XDG_CONFIG_DIR")"
local result_xdg_data_dirs
result_xdg_data_dirs="$(_mk_xdg_dirs "$XDG_DATA_DIRS" /usr/share /usr/share/kf5 "$KOMETA_XDG_DATA_DIR")"
3 years ago
case "$1" in
systemd )
echo XDG_CONFIG_DIRS="$result_xdg_config_dirs"
3 years ago
echo XDG_DATA_DIRS="$result_xdg_data_dirs"
3 years ago
;;
profile )
export XDG_CONFIG_DIRS="$result_xdg_config_dirs"
3 years ago
export XDG_DATA_DIRS="$result_xdg_data_dirs"
3 years ago
;;
esac
}
if [ "$KOMETA_XDG_TESTING" = 0 ]; then
_main "$KOMETA_XDG_TYPE"
fi