-
Notifications
You must be signed in to change notification settings - Fork 20
/
install
executable file
·77 lines (51 loc) · 1.88 KB
/
install
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
#!/bin/bash
# Script for installing Windows Persian layout for Linux
# https://github.com/sinadarvi/windows-persian-layout-for-linux
# Script by cs127 <https://cs127.github.io>
# 2023-03-11
# Requirements:
# * xmlstarlet
exitcode() {
case $1 in
0) echo "Success" ;;
1) echo "Error: The script should be run as root." ;;
2) echo "Error: The script requires xmlstarlet to be installed." ;;
11) echo "Error: Failed to add Windows variant to the symbols file." ;;
12) echo "Error: Failed to modify the xkb registry." ;;
21) echo "Error: Failed to make a backup of the symbols file." ;;
22) echo "Error: Failed to make a backup of the xkb registry." ;;
*) echo "Error"
esac
exit $1
}
[ -z "$XKBHOME" ] && XKBHOME="/usr/share/X11/xkb"
XKBSYM="$XKBHOME/symbols/ir"
XKBREG="$XKBHOME/rules/evdev.xml"
XML_IR="/xkbConfigRegistry/layoutList/layout[configItem/name='ir']"
XML_VL="$XML_IR/variantList"
XML_VL_WIN="$XML_VL/variant[configItem/name='pes_winkeys']"
XML_VL_LAST="$XML_VL/variant[last()]"
XML_VL_LCFG="$XML_VL_LAST/configItem"
process_symbols() {
grep -q "Windows" "$XKBSYM" && return
! cp "$XKBSYM" "$XKBSYM.backup" && exitcode 21
! cat "./ir_patch" >> "$XKBSYM" &&
mv "$XKBSYM.backup" "$XKBSYM" && exitcode 11
}
process_registry() {
xmlstarlet sel -Q -t -c "$XML_VL_WIN" "$XKBREG" && return
! cp "$XKBREG" "$XKBREG.backup" && exitcode 22
! xmlstarlet ed -P -L \
-s "$XML_VL" -t elem -n "variant" \
-s "$XML_VL_LAST" -t elem -n "configItem" \
-s "$XML_VL_LCFG" -t elem -n "name" -v "pes_winkeys" \
-s "$XML_VL_LCFG" -t elem -n "description" -v "Persian (Windows)" \
"$XKBREG" &&
mv "$XKBREG.backup" "$XKBREG" && exitcode 12
}
cd "$(dirname "$0")"
[ "$EUID" -ne 0 ] && exitcode 1
! command -v xmlstarlet &>/dev/null && exitcode 2
process_symbols
process_registry
exitcode 0