-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·332 lines (282 loc) · 12.1 KB
/
install.sh
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
set -e
SCRIPT=$(realpath "$0")
SCRIPT_DIR=$(dirname "$SCRIPT")
# The default path to xkb is the one below.
# You can use the 'tests' directory for testing:
# XKB_PATH=test/xkb ./install.sh
if [ -z "$XKB_PATH" ]; then
XKB_PATH="/usr/share/X11/xkb"
else
echo "Using custom XKB_PATH: $XKB_PATH"
fi
if [ ! -d $XKB_PATH ]; then
echo "xkb folder not found at $XKB_PATH"
echo "Pass the location of 'xkb' with"
echo "XKB_PATH=/pathTo/xkb ./install"
exit 2
fi
exit_on_error() {
if [ $1 -ne 0 ]; then
echo "Error: Could not edit file $2"
fi
}
exit_if_empty() {
if [ -z "$1" ]; then
revert
echo "Expected line of text not found at file $2"
exit 2
fi
}
insert_text_to_file() {
EDITFILE=$1
SNIPPETFILE=$2
LINE=$3
ed "$EDITFILE" << EOF
${LINE}r ${SNIPPETFILE}
w
EOF
}
create_backups() {
sudo cp -n "$XKB_PATH"/symbols/us "$XKB_PATH"/symbols/us.BKP
sudo cp -n "$XKB_PATH"/rules/base.lst "$XKB_PATH"/rules/base.lst.BKP
sudo cp -n "$XKB_PATH"/rules/evdev.lst "$XKB_PATH"/rules/evdev.lst.BKP
sudo cp -n "$XKB_PATH"/rules/base.xml "$XKB_PATH"/rules/base.xml.BKP
sudo cp -n "$XKB_PATH"/rules/evdev.xml "$XKB_PATH"/rules/evdev.xml.BKP
}
revert() {
sudo cp "$XKB_PATH"/symbols/us.BKP "$XKB_PATH"/symbols/us
sudo cp "$XKB_PATH"/rules/base.lst.BKP "$XKB_PATH"/rules/base.lst
sudo cp "$XKB_PATH"/rules/evdev.lst.BKP "$XKB_PATH"/rules/evdev.lst
sudo cp "$XKB_PATH"/rules/base.xml.BKP "$XKB_PATH"/rules/base.xml
sudo cp "$XKB_PATH"/rules/evdev.xml.BKP "$XKB_PATH"/rules/evdev.xml
}
check_for_backups() {
BKPS=$(find "$XKB_PATH/rules" "$XKB_PATH/symbols" -type f -name "*.BKP")
if [[ -n $BKPS ]]; then
echo "Backups de layouts encontrados! Gostaria de restaurá-los antes de criar novos (recomendado)? [s/n/c (cancel)]"
printf "Layout files backups found! Would you like to restore them before installing the new (recomended)? [y/n/c (cancel)] "
read -rp "" answer
case ${answer:0:1} in
y|Y|s|S )
echo "Restauring backups..."
revert
;;
n|N )
echo "xkb files will be appended."
;;
* )
echo "Backups foud:"
echo "$BKPS"
exit 0
;;
esac
fi
}
show_help_pt() {
printf "\033[1mLayout US Internacional melhorado para língua portuguesa\033[0m
Este script pode instalar até três opções de layouts.
Todos layouts disponibilizam 'ã', 'õ' e 'ç' no nível 3 (AltGr) das teclas <F>,
<G> e <C> respectivamente. Se nenhuma das opções -t e -d forem usadas,
ambos layouts serão instalados.
Backups dos arquivos xkb serão criados antes de instalar.
Uso: ./install [OPÇÕES]
-d, --deadkeys Instala layout mantendo as teclas mortas do tecla-
-do US. Internacional. Ou seja, para digitar 'à',
deve-se teclar [Shift + \`] + A.
-t, --third-lv-deadkeys Instala layout, mas teclas mortas são trasnferidas
para o nivel 3. Ou seja, para digitar 'à', deve-se
usar [AltGr + \`] + A.
-c, --lv3-dead-lv2-circum Mesmo que -t, mas mantém circunflexo morto no ní-
-vel 2 de 6. Ou seja, para digitar 'ê'
[Shift + 6] + E.
-q --qwerty-colemak-altgr Teclado US, mas com teclas mortas e extra carac-
-teres UTF-8 no nível 3 (AltGR) como num teclado
colemak https://colemak.com/Multilingual
-r, --revert Desisntala o layout, revertendo os arquivos para o
estado anterior.
-h, --help Help in english.
-a, --ajuda Ajuda em português.
"
}
show_help_en() {
printf "\033[1m US International Keyboard enhanced for the portuguese language \033[0m
This script can install up to three layout options.
All layouts make 'ã', 'õ' e 'ç' available at level 3 (AltGr) of the keys <F>,
<G> and <C> respectivelly. If none of the options are given, all three will be
installed
A backup of the xkb files will be created before installing.
Uso: ./install [OPÇÕES]
-d, --deadkeys Install a layout keeping the dead keys of the
default US-International layout. I.e., to type
'à', one must type [Shift + \`] + A.
-t, --third-lv-deadkeys US Intl. layout, but the deadkeys are transfered
to level 3. I.e., to type 'à', one must type
[AltGr + \`] + A.
-c, --lv3-dead-lv2-circum Same as the previous -t, but the circumflex is
kept on the second level. To type 'ê', one must
type [Shift + 6] + E.
-q --qwerty-colemak-altgr US layout for standard QWERTY, but with the dead
keys and extra UTF-8 characters on the third level
(altgr) of some keys like in the colemak layout
https://colemak.com/Multilingual
-r, --revert Uninstalls the layout, reverting the backup files.
-h, --help Help in english.
-a, --ajuda Ajuda em português.
"
}
LAYOUT=()
if ! options=$( getopt -o rhadtcq -l revert,help,ajuda,deadkeys,third-lv-deadkeys,lv3-dead-lv2-circum,qwerty-colemak-altgr -n "$0" -- "$@" ); then
echo "Incorrect options provided"
show_help_en
exit 1
fi
eval set -- "$options"
while true; do
case "$1" in
--deadkeys|-d)
LAYOUT+=('d')
;;
--third-lv-deadkeys|-t)
LAYOUT+=('t')
;;
--lv3-dead-lv2-circum |-c)
LAYOUT+=('c')
;;
--qwerty-colemak-altgr|-q)
LAYOUT+=('q')
;;
--revert|-r)
revert
exit 0
;;
-h|--help)
show_help_en
exit 0
;;
-a|--ajuda)
show_help_pt
exit 0
;;
--)
shift
break
;;
*)
show_help_en
exit 2
;;
esac
shift
done
if [[ -z ${LAYOUT[0]} ]]; then
LAYOUT=('c' 'd' 't' 'q')
fi
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
check_for_backups
create_backups
SYMBOLS_FILE="$XKB_PATH/symbols/us"
for OPT in "${LAYOUT[@]}"; do
if [[ $OPT == "t" ]]; then
LAYOUT_NAME="altgr-intl-pt-improved"
FILE="$XKB_PATH/rules/evdev.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/evdev.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
cat "$SCRIPT_DIR/insert/$LAYOUT_NAME/us" >> $SYMBOLS_FILE
echo "Installed layout altgr-intl-pt-enhanced us: English (pt. enhanced AltGr dead keys)"
elif [[ $OPT == "d" ]]; then
LAYOUT_NAME="intl-pt-improved"
FILE="$XKB_PATH/rules/evdev.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/evdev.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
cat "$SCRIPT_DIR/insert/$LAYOUT_NAME/us" >> $SYMBOLS_FILE
echo "Installed layout intl-pt-enhanced us: English (pt. enhanced)"
elif [[ $OPT == "c" ]]; then
LAYOUT_NAME="altgr-intl-pt-improved_dead-circumflex"
FILE="$XKB_PATH/rules/evdev.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/evdev.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
cat "$SCRIPT_DIR/insert/$LAYOUT_NAME/us" >> $SYMBOLS_FILE
echo "Instaled layout altgr-intl-pt-enh-circum-lv2 us: English (intl., with AltGr dead keys plus a/otilde & circumflex lv2)"
elif [[ $OPT == "q" ]]; then
LAYOUT_NAME="colemak-altgrs"
FILE="$XKB_PATH/rules/evdev.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.xml"
LINE=$(awk '/<name>us</{f=1} f && /<variantList>/ {print NR; exit}' /usr/share/X11/xkb/rules/evdev.xml)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.xml" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/evdev.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/evdev.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
FILE="$XKB_PATH/rules/base.lst"
LINE=$(grep -n -m 1 "! variant" "$FILE" | cut -f1 -d:)
exit_if_empty "$LINE" "$FILE"
insert_text_to_file "$FILE" "$SCRIPT_DIR/insert/$LAYOUT_NAME/base.lst" "$LINE" 1> /dev/null
exit_on_error $? "$FILE"
cat "$SCRIPT_DIR/insert/$LAYOUT_NAME/us" >> $SYMBOLS_FILE
echo "Instaled layout qwery-with-colemak-altgr us: English (QWERTY with colemak altgr)"
fi
done
echo "SUCCESS! Reboot to reload the keyboard layouts."
exit 0