-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·196 lines (153 loc) · 6.27 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
#!/bin/sh
# Assumes you have git installed as you cloned this repository
# you may have to `sudo apt install raspberrypi-kernel-headers` on a pi
# Check if the script is running as root
if [ "$(id -u)" != "0" ]; then
echo "Must run as root. Restarting with sudo..."
# Re-execute the script with sudo
sudo "$0" "$@"
exit $?
fi
echo "========================"
echo "===Installing Tooling==="
echo "========================"
apt update
apt install -y wget curl coreutils dnsutils ca-certificates lsb-release iproute2 gnupg apt-transport-https
# Obtain the OS distributor name
DISTRO=$(lsb_release -i | cut -d: -f2 | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')
echo "======================="
echo "===Installing Docker==="
echo "======================="
# Add Docker's official GPG key:
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/$DISTRO/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/$DISTRO \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install -y python3-distutils-extra docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Determine the architecture
ARCH=$(uname -m)
# add docker-compose command for backwards compat
curl -SL https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-linux-$ARCH -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
groupadd docker
# Obtain the current username who invoked sudo
CURRENT_USER=${SUDO_USER:-$(whoami)}
# Add the current user to the docker group
usermod -aG docker "$CURRENT_USER"
echo "User $CURRENT_USER added to docker group."
# add crystal lang
echo "========================"
echo "===Installing Crystal==="
echo "========================"
curl -fsSL https://packagecloud.io/84codes/crystal/gpgkey | gpg --dearmor | tee /etc/apt/trusted.gpg.d/84codes_crystal.gpg > /dev/null
. /etc/os-release
echo "deb https://packagecloud.io/84codes/crystal/$ID $VERSION_CODENAME main" | tee /etc/apt/sources.list.d/84codes_crystal.list
apt update
apt install -y crystal
# add edge tpu delegate support
echo "==========================="
echo "===Installing TPU Driver==="
echo "==========================="
wget -q -O - https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/coral-edgetpu.gpg
echo "deb [signed-by=/etc/apt/trusted.gpg.d/coral-edgetpu.gpg] https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list
apt update
apt install -y usbutils libedgetpu-dev libedgetpu1-std
systemctl restart udev
# Write the udev rule
echo 'SUBSYSTEM=="usb", OWNER="10001", MODE="0660"' > /etc/udev/rules.d/99-usb.rules
# install video for linux 2
echo "================================"
echo "===Installing Video for Linux==="
echo "================================"
apt install -y v4l-utils v4l2loopback-dkms
# Create the gpio-users group
groupadd video
# Add the current user to the gpio-users group
usermod -aG video "$CURRENT_USER"
# Write the udev rule
echo 'KERNEL=="video*", OWNER="10001", GROUP="video", MODE="0660"' > /etc/udev/rules.d/99-videodevice-owner.rules
echo "User $CURRENT_USER video udev rule set."
# install GPIO for controlling relays and reading motion detectors
echo "==================================="
echo "===Installing General Purpose IO==="
echo "==================================="
apt install -y gpiod libgpiod-dev
# Create the gpio-users group
groupadd gpio-users
# Add the current user to the gpio-users group
usermod -aG gpio-users "$CURRENT_USER"
# Write the udev rule
echo 'KERNEL=="gpiochip*", OWNER="10001", GROUP="gpio-users", MODE="0660"' > /etc/udev/rules.d/99-gpiochip.rules
# Reload the udev rules
udevadm control --reload-rules
udevadm trigger
echo "User $CURRENT_USER added to gpio-users and udev rule set."
# Ensure the OS is configured
echo "===================="
echo "===Configuring OS==="
echo "===================="
# increase the swap memory
# Path to the swap configuration file
SWAP_FILE="/etc/dphys-swapfile"
# Desired configurations
CONF_SWAPSIZE="CONF_SWAPSIZE=4096"
CONF_MAXSWAP="CONF_MAXSWAP=4096"
# Function to update configuration if not set
update_config() {
local config_name=$1
local config_value=$2
local config_line="$config_name=$config_value"
# Check if the configuration already exists
if grep -q "^$config_name=" "$SWAP_FILE"; then
# Configuration exists, update it if necessary
if ! grep -q "^$config_line$" "$SWAP_FILE"; then
echo "Updating $config_name to $config_value"
sed -i "s/^$config_name=.*/$config_line/" "$SWAP_FILE"
else
echo "$config_name is already set to $config_value"
fi
else
# Configuration does not exist, append it
echo "Adding $config_line to $SWAP_FILE"
echo "$config_line" >> "$SWAP_FILE"
fi
}
# Update swap size
update_config "CONF_SWAPSIZE" "4096"
# Update max swap
update_config "CONF_MAXSWAP" "4096"
# Restart swap service to apply changes
echo "Restarting swap service to apply changes..."
dphys-swapfile swapoff
dphys-swapfile setup
dphys-swapfile swapon
# enable multicast on loopback device
# Bring up the loopback interface
ip link set lo up
# Add the multicast route
ip route add 224.0.0.0/4 dev lo
# ensure configuration file has the correct permissions
# NOTE:: ramdisk automatically has chmod 777 permissions
chown 10001:10001 ./config/config.yml
chown 10001:10001 ./detections
# run the crystal lang install helper
sudo -u "$CURRENT_USER" shards build --production --ignore-crystal-version --skip-postinstall --skip-executables install
./bin/install
# Ensure file permissions are correct for the container
echo "========================================"
echo "===Configuring Filesystem Permissions==="
echo "========================================"
chown -R 10001:10001 ./clips
chown -R 10001:10001 ./config
chown -R 10001:10001 ./detections
chown -R 10001:10001 ./model_storage
# reboot as we need the v4l2 loopback paths to be stable
# they initialize before hardware typically
reboot