summarylogtreecommitdiffstats
path: root/install.sh
blob: 4491f489c7005df560d5f538fb667af107e48de6 (plain)
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
#!/usr/bin/env bash

set -euxo pipefail

TMP_DIR=/tmp/nekuvi/

copy_files() {
    mkdir -p "$TMP_DIR"
    cp /usr/share/X11/xkb/rules/evdev.lst "$TMP_DIR"
    cp /usr/share/X11/xkb/rules/evdev.xml "$TMP_DIR"
}

append_evdev_lst() {
    pushd "$TMP_DIR"

    if grep -q "np_prog" evdev.lst; then
        echo "WARNING: evdev.lst already updated. This could mean that you may have tried to install this package previously. Continuing installation."
    else
        sed -i '/! layout/a \ \ np_prog \t Nepali for programmers' evdev.lst
    fi
    popd
}

append_evdev_xml() {
    pushd "$TMP_DIR"
    read -r -d '' np_prog_layout <<EOF || true
<!-- BEGIN np_prog -->
    <layout>
      <configItem>
        <name>np_prog</name>

        <shortDescription>np_prog</shortDescription>
        <description>Nepali for programmers</description>
        <languageList>
          <iso639Id>nep</iso639Id>
        </languageList>
      </configItem>
    </layout>
<!-- END np_prog -->
EOF

    if grep -q "np_prog" evdev.xml; then
        echo "WARNING: evdev.lst already updated. This could mean that you may have tried to install this package previously. Continuing installation."
    else
        awk -v layout="$np_prog_layout" '{ print } /<layoutList>/ { print layout }' evdev.xml > temp.xml
        cp temp.xml evdev.xml
    fi
    popd
}

install_evdev() {
    pushd "$TMP_DIR"
    cp evdev.* /usr/share/X11/xkb/rules/
    popd
}

process() {
    copy_files # copies the necessary files to a temp dir for us
    append_evdev_lst # modify evdev.lst with np_prog
    append_evdev_xml # add np_prog to evdev.xml
    install_evdev
}


process