-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·204 lines (151 loc) · 6.16 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
197
198
199
200
201
202
203
204
#!/bin/bash
set -e # Exit script on any error
logfile="/tmp/nomadpi_install.log"
progress_file="/tmp/nomadpi_install_progress.log"
result_file="/tmp/nomadpi_install_result.log"
GREY='\033[90m'
GREEN='\033[0;32m'
BOLD='\033[1m'
PINK='\e[38;5;206m'
NC='\033[0m' # No Color
if [ -e "$logfile" ]; then
rm "$logfile"
fi
if [ -e "$progress_file" ]; then
rm "$progress_file"
fi
if [ -e "$result_file" ]; then
rm "$result_file"
fi
if [ -d "./nomadpi" ]; then
echo -e "${BOLD}Error: nomadpi directory already exists. Remove it if you want to re-run the installation script.${NC}"
exit 1
fi
update_progress() {
echo $1 >> "$progress_file"
}
error_exit() {
echo -e "${BOLD}ERROR: Installation failed. Full log available at $logfile${NC}" >> "$result_file"
echo -e "" >> "$result_file"
tail -n 25 "$logfile" >> "$result_file"
sleep 1
}
handle_error() {
error_exit
exit $exit_code
}
trap 'handle_error' ERR
(
update_progress 'Installing system dependencies'
sudo apt update
sudo apt upgrade -y
sudo apt install -y \
python3-setuptools \
vim \
direnv \
nodejs \
npm \
jq \
apt-transport-https \
ca-certificates \
software-properties-common
update_progress 'Cloning nomadPi repositories'
cd "$HOME" || exit 1
mkdir -p "$HOME"/.ssh
curl --silent https://api.github.com/meta | jq --raw-output '"github.com "+.ssh_keys[]' >> "$HOME"/.ssh/known_hosts
git clone --progress https://github.com/coconup/nomadpi.git >> "$logfile" 2>&1
cd "nomadpi" || exit 1
install_dir=$(pwd)
ssh-keyscan github.com >> ~/.ssh/known_hosts
mkdir -p "$install_dir"/volumes
git clone --progress https://github.com/coconup/nomadpi-app-api.git "$install_dir"/volumes/nomadpi-app-api >> "$logfile" 2>&1
git clone --progress https://github.com/coconup/nomadpi-services-api.git "$install_dir"/volumes/nomadpi-services-api >> "$logfile" 2>&1
git clone --progress https://github.com/coconup/nomadpi-react.git "$install_dir"/volumes/nomadpi-react >> "$logfile" >&1
git clone --progress https://github.com/coconup/nomadpi-mqtt-hub.git "$install_dir"/volumes/nomadpi-mqtt-hub >> "$logfile" 2>&1
git clone --progress https://github.com/coconup/nomadpi-gpsd-to-mqtt.git "$install_dir"/volumes/nomadpi-gpsd-to-mqtt >> "$logfile" 2>&1
git clone --progress https://github.com/coconup/nomadpi-butterfly-ai "$install_dir"/volumes/nomadpi-butterfly-ai >> "$logfile" 2>&1
git clone --progress https://github.com/coconup/nomadpi-open-wake-word "$install_dir"/volumes/nomadpi-open-wake-word >> "$logfile" 2>&1
git clone --progress https://github.com/coconup/nomadpi-bluetooth-api "$install_dir"/volumes/nomadpi-bluetooth-api >> "$logfile" 2>&1
mkdir -p "$install_dir"/volumes/frigate/config
cp "$install_dir"/services/frigate/config.yml "$install_dir"/volumes/frigate/config/config.yml
cd "$install_dir" || exit 1
clone_nodered_project() {
local repo_name=$1
mkdir -p "$install_dir/volumes/$repo_name/data/"
cp -r "$install_dir/services/$repo_name/data" "$install_dir/volumes/$repo_name/"
project_dir="$install_dir/volumes/$repo_name/data/projects"
mkdir -p "$project_dir"
git clone "https://github.com/coconup/$repo_name" "$project_dir/$repo_name"
sudo chown -R root:root "$project_dir/$repo_name"
}
clone_nodered_project "nomadpi-core-api"
clone_nodered_project "nomadpi-automation-api"
# Add direnv to .bashrc
update_progress 'Setting up local environment'
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
direnv_config_file="$HOME/.config/direnv/config.toml"
# Create the directory if it doesn't exist
mkdir -p "$(dirname "$direnv_config_file")"
# Configure direnv to always allow .envrc
cat <<EOF > "$direnv_config_file"
[whitelist]
prefix = ["$install_dir"]
EOF
# Create .envrc file
source ./generate_envrc.sh
echo "REACT_APP_RPI_HOSTNAME=$(hostname).local" > "$install_dir"/volumes/nomadpi-react/.env
# Initialize secret files
mkdir -p volumes/secrets/cloudflare
mkdir -p volumes/secrets/nextcloud
touch volumes/secrets/cloudflare/tunnel_token
touch volumes/secrets/nextcloud/nextcloud_host
touch volumes/secrets/nextcloud/nextcloud_username
touch volumes/secrets/nextcloud/nextcloud_password
# Enable I2C and 1-Wire
update_progress 'Enabling I2C and 1-Wire'
sudo raspi-config nonint do_i2c 0
echo -e "dtoverlay=w1-gpio\ndtoverlay=uart5\nenable_uart=1" | sudo tee -a /boot/config.txt
# Docker patches
update_progress 'Patching system for Docker compatibility'
echo $(cat /boot/cmdline.txt) cgroup_memory=1 cgroup_enable=memory | sudo tee /boot/cmdline.txt
if [ -e "/etc/dhcpcd.conf" ]; then
sudo bash -c '[ $(egrep -c "^allowinterfaces eth\*,wlan\*" /etc/dhcpcd.conf) -eq 0 ] && echo "allowinterfaces eth*,wlan*" >> /etc/dhcpcd.conf'
fi
# Install Docker
update_progress 'Installing Docker and `docker-compose`'
curl -fsSL https://get.docker.com | sudo sh >> "$logfile" 2>&1
# Add the current user to the docker group to run Docker without sudo
sudo usermod -aG docker $USER
sudo usermod -aG bluetooth $USER
# Verify installation
docker --version
sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
docker-compose --version
cat <<EOF > "$result_file"
Once the system has rebooted, follow these steps in order to complete the installation:
- ssh $USER@$(hostname).local
- cd $install_dir
- ./start.sh
EOF
update_progress 'All dependencies installed. Rebooting system'
sleep 5
sudo reboot
) >> "$logfile" & bg_job_pid=$!
while [ -e /proc/$bg_job_pid ]; do
clear
head -n -1 "$progress_file" | while IFS= read -r line; do
echo -e "${GREEN}${line} ✔${NC}"
done
echo -e "${BOLD}$(tail -n 1 "$progress_file")...${NC}"
if [ -e "$result_file" ]; then
echo -e "${PINK}$(cat "$result_file")${NC}"
else
tail -n 10 "$logfile" | while IFS= read -r line; do
echo -e "${GREY}${line}${NC}"
done
fi
sleep 0.1
done
tail -n 10 "$logfile" | while IFS= read -r line; do
echo -e "${GREY}${line}${NC}"
done