summarylogtreecommitdiffstats
path: root/install
blob: 752a0a4f9ee045783a47ca10c2dfe3f21d01949e (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
66
67
68
69
#!/bin/bash
_i2chelper(){
    MODULES="i2c-dev i2c-bcm2708"
    MODULE_FILE="/etc/modules-load.d/raspberrypi.conf"

    if [[ -a $MODULE_FILE ]]; then
        for MODULE in $MODULES
        do
            echo -n "Check for module ${MODULE}  "
            if grep -q $MODULE "${MODULE_FILE}"; then
                echo "FOUND"
            else
                echo "${MODULE}" >> $MODULE_FILE 2>/dev/null && echo "ADDED" || { echo "ERROR:  Can't write to file ${MODULE_FILE}"; exit 1; }
            fi
        done
    else
        echo "INFO:  ${MODULE_FILE} Not Found"
        for MODULE in $MODULES
        do
            echo "${MODULE}" >> $MODULE_FILE 2>/dev/null || { echo "ERROR:  Can't write to file ${MODULE_FILE}"; exit 1; }
        done
        echo "INFO:  ${MODULE_FILE} Created Successfully"
    fi
}
_install_overlay(){
    FILE=/boot/config.txt 
    [ -w "$FILE" ] || { echo "ERROR Cannot Write to ${FILE} unable to continue"; exit 1; }
    SYSMODEL=$( awk '{ print $0 }' /proc/device-tree/model | sed 's|Raspberry Pi||;s|Rev.*||;s|Model||;s|Zero|0|;s|Plus|+|;s|B| |;s|A| |;s| ||g' )

    echo -n "Search config.txt for overlay ... "
    grep -i '^dtoverlay=argonone' $FILE 1> /dev/null && { echo "FOUND"; exit 0; } || echo "NOT FOUND"
    cp $FILE $FILE.backup
    echo -n "Insert overlay into ${FILE} ... "
    if [[ `grep -i "^\[pi${SYSMODEL}\]" $FILE` ]]
    then
        sed  -i "/^\[pi${SYSMODEL}\]/a dtoverlay=argonone" $FILE && echo "DONE";
    else
        echo "dtoverlay=argonone" >> $FILE && echo "DONE";
    fi
    unset FILE
}
_start_service(){
    echo -n "Enabling service "
    systemctl enable argononed &>/dev/null && echo "Successful" || echo "Failed"
    echo -n "Starting Service "
    systemctl start &>/dev/null && echo "Successful" || ( [ $? -eq 124 ] && echo "Timeout" || echo "Failed" )
}
# arg 1:  the new package version
post_install() {
    _i2chelper
    _install_overlay
    _start_service
}

# arg 1:  the old package version
pre_remove() {
    echo -n "Stopping service "
    systemctl stop &>/dev/null && echo "Successful" || ( [ $? -eq 124 ] && echo "Timeout" || echo "Failed" )
    echo -n "Disabling Service "
    systemctl disable argononed &>/dev/null && echo "Successful" || echo "Failed"
}

# arg 1:  the old package version
post_remove() {
    echo "Remove dtoverlay=argonone from $(BOOTLOC)/config.txt"
    cp /boot/config.txt /boot/config.argononed.backup
    sed -i '/dtoverlay=argonone/d' /boot/config.txt
    echo "Uninstall Complete"
}