-
Notifications
You must be signed in to change notification settings - Fork 1
/
RaspiFullInstall.sh
executable file
·106 lines (91 loc) · 2.95 KB
/
RaspiFullInstall.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
#!/bin/bash
# A Script to setup the cascoda-sdk on a fresh Raspberry Pi
# Function to die with error
die() { echo "Error: " "$*" 1>&2 ; exit 1; }
# Use apt to update and get required packages
sudo apt update -y || die "sudo apt update"
sudo apt upgrade -y || die "sudo apt upgrade"
sudo apt install automake gcc g++ git vim libtool lsb-release make libhidapi-dev libncurses5-dev -y || die "sudo apt install"
# Check if cmake is already installed
CMAKE_VER=$(cmake --version 2> /dev/null | awk '
/cmake version/{
n=split($3,version,".");
if(version[1] > 3 || (version[1] == 3 && version[2] >= 13))
{
print "done"
}
else
{
print "install"
}
}')
# If not installed, check how best to install it
if [ "$CMAKE_VER" == install ] || [ -z "$CMAKE_VER" ]
then
# Check if the apt version of cmake is sufficient
CMAKE_VER=$(apt-cache policy cmake | awk '
/Candidate/{
n=split($2,version,".");
if(version[1] > 3 || (version[1] == 3 && version[2] >= 13))
{
print "apt"
}
else
{
print "source"
}
}')
fi
if [ "$CMAKE_VER" == source ]
then
# Download latest cmake source, build, install
echo "Installing CMake from source"
CMAKE_TARGET_VER=cmake-3.14.2
wget https://github.com/Kitware/CMake/releases/download/v3.14.2/${CMAKE_TARGET_VER}.tar.gz || die "downloading cmake"
tar -xf ${CMAKE_TARGET_VER}.tar.gz || die "extracting cmake"
cd ${CMAKE_TARGET_VER} || die "cd"
./bootstrap || die "bootstrap cmake"
make -j4 || die "making cmake"
sudo make install || die "installing cmake"
cd ../ || die "cd"
CMAKE_VER="done"
fi
if [ "$CMAKE_VER" == apt ]
then
# Install cmake from apt
echo "Installing CMake from apt"
sudo apt install cmake -y || die "installing cmake from apt"
# Install ccmake (we allow this to fail)
sudo apt install cmake-curses-gui
CMAKE_VER="done"
fi
if [ "$CMAKE_VER" != "done" ]
then
die "CMake could not be installed!"
else
echo "CMake installed!"
fi
# Add chili usb to the udev rules (So chili dongle can be used without sudo)
echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="0416", ATTRS{idProduct}=="5020", ACTION=="add", MODE="0666"' | sudo tee /etc/udev/rules.d/99-cascoda.rules > /dev/null
sudo udevadm control --reload-rules && sudo udevadm trigger
# Clone the Cascoda sdk, set up build dir, configure
# Pull if already exists, otherwise clone.
if [ -d cascoda-sdk/.git ]
then
git -C cascoda-sdk pull || git -C cascoda-sdk fetch || die "Failed to pull"
else
git clone https://github.com/Cascoda/cascoda-sdk.git cascoda-sdk || die "Failed to clone"
fi
# Make a build directory and cd in
MACHINE_NAME="$(uname -m)"
mkdir -p "build-${MACHINE_NAME}" || die "mk builddir"
cd "build-${MACHINE_NAME}" || die "cd"
# Configure with cmake
cmake ../cascoda-sdk || die "Failed to configure"
# Build
make -j4 || die "Failed to build"
# Run unit tests
make test || die "Unit tests failed"
echo "Cascoda binaries built into ./build-${MACHINE_NAME}/bin"
# Now all of the binaries are installed in ./bin/
# and can be run for instance ./bin/serial-adapter