forked from xe5700/kvmd-armbian
-
Notifications
You must be signed in to change notification settings - Fork 31
/
libgpiod.sh
92 lines (73 loc) · 2.17 KB
/
libgpiod.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
#!/bin/bash
# Written by @srepac (c) 2024
# This script will compile the correct libgpiod version based on python version installed
#
function downgrade() {
# ----------------------
# libgpiod to run v1.6.3
# ----------------------
set -x
apt install -y autoconf-archive libtool dh-autoreconf
cd /tmp
FILE="libgpiod-1.6.3.tar.gz"
GPIODVER=$( echo $FILE | cut -d'-' -f2 | sed 's/.tar.gz//g' )
wget https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/$FILE -O $FILE 2> /dev/null
tar xfz $FILE
cd libgpiod-$GPIODVER
### this works with python3.10
./autogen.sh --enable-tools=yes --prefix=/usr
make
make install
set +x
} # end function downgrade
function upgrade() {
# --------------------
# libgpiod to run v2.1
# --------------------
set -x
apt install -y autoconf-archive libtool dh-autoreconf
cd /tmp
FILE="libgpiod-2.1.2.tar.gz"
GPIODVER=$( echo $FILE | cut -d'-' -f2 | sed 's/.tar.gz//g' )
wget https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/$FILE -O $FILE 2> /dev/null
tar xfz $FILE
cd libgpiod-$GPIODVER
./autogen.sh --enable-tools=yes --enable-bindings-python=yes --prefix=/usr
make -j$( nproc --all )
make install
set +x
gpioinfo -v | head -1
} # end function upgrade
### MAIN STARTS HERE
_PYTHONVER=$( python -V | awk '{print $NF}' )
echo "Python $_PYTHONVER"
_libgpiodver=$( gpioinfo -v | head -1 | awk '{print $NF}' )
case $_libgpiodver in
v1.*)
### if python version is 3.11, then upgrade to 2.1 else leave it alone
case $_PYTHONVER in
3.1[1-9]*) # 3.11 and higher
echo "Found libgpiod $_libgpiodver. Upgrading to v2.1 Please wait..."
upgrade
;;
3.10*|3.[987]*)
echo "Found libgpiod $_libgpiodver. Nothing to do"
;;
esac
;;
v2.*)
### if python version is 3.10 or older, then downgrade to 1.6.3 else leave it at 2.1 for python 3.11
case $_PYTHONVER in
3.10*|*3.[987]*)
echo "Found libgpiod $_libgpiodver. Downgrading to v1.6.3 Please wait..."
downgrade
;;
3.1[1-9]*) # 3.11 and higher
echo "Found libgpiod $_libgpiodver. Nothing to do"
;;
esac
;;
*)
echo "Undefined function."; exit 1
;;
esac