-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·220 lines (197 loc) · 7.94 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·220 lines (197 loc) · 7.94 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env bash
# install.sh — MeshEliza installer
#
# Supports:
# - Raspberry Pi OS (Lite or Desktop)
# - Ubuntu 22.04 / 24.04 (and derivatives: Mint, Pop!_OS, etc.)
#
# Both platforms are Debian-based so the same apt-get commands apply.
#
# Usage:
# bash install.sh
#
# Run as your normal user (not root). sudo is invoked only where needed.
#
# After installation, use the generated start script to launch the app:
# ./mesheliza.sh # from this directory, or
# ~/mesheliza.sh # if you chose to copy it to your home dir
#
# On Raspberry Pi only: you may also opt in to auto-launch on tty1
# (the physical screen), so the app starts automatically on boot login.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
VENV_DIR="$HOME/.venv/mesheliza"
START_SCRIPT="$SCRIPT_DIR/mesheliza.sh"
# ------------------------------------------------------------------ #
# Detect platform #
# ------------------------------------------------------------------ #
IS_PI=false
if grep -qi "raspberry" /proc/device-tree/model 2>/dev/null \
|| grep -qi "raspbian\|raspberry" /etc/os-release 2>/dev/null; then
IS_PI=true
fi
if $IS_PI; then
PLATFORM="Raspberry Pi"
else
PLATFORM="Ubuntu / Debian"
fi
echo "=== MeshEliza Installer ==="
echo ">>> Detected platform: $PLATFORM"
echo ""
# ------------------------------------------------------------------ #
# 1. System dependencies #
# ------------------------------------------------------------------ #
echo ">>> Installing system packages..."
sudo apt-get update -qq
sudo apt-get install -y \
python3-pip \
python3-venv \
libglib2.0-dev \
bluetooth \
libbluetooth-dev \
bluez
# Ensure the Bluetooth service is running (important on Ubuntu where
# it may not start automatically after install)
sudo systemctl enable bluetooth --quiet 2>/dev/null || true
sudo systemctl start bluetooth 2>/dev/null || true
# ------------------------------------------------------------------ #
# 2. Python virtual environment #
# ------------------------------------------------------------------ #
echo ">>> Creating virtualenv at $VENV_DIR..."
python3 -m venv "$VENV_DIR"
source "$VENV_DIR/bin/activate"
# ------------------------------------------------------------------ #
# 3. Install Python packages #
# ------------------------------------------------------------------ #
echo ">>> Installing Python dependencies..."
pip install --upgrade pip --quiet
pip install -r "$SCRIPT_DIR/requirements.txt" --quiet
pip install -e "$SCRIPT_DIR" --quiet
# ------------------------------------------------------------------ #
# 4. Verify meshtastic installation #
# ------------------------------------------------------------------ #
echo ">>> Verifying meshtastic Python library..."
if python -c "import meshtastic" 2>/dev/null; then
MESH_VER=$(python -c "import meshtastic; print(meshtastic.__version__)" 2>/dev/null || echo "unknown")
echo " OK: meshtastic $MESH_VER"
else
echo ""
echo "ERROR: The meshtastic Python library did not install correctly."
echo "Check the pip output above for errors, then re-run install.sh."
exit 1
fi
echo ">>> Verifying meshtastic CLI command..."
if command -v meshtastic >/dev/null 2>&1; then
echo " OK: $(command -v meshtastic)"
else
echo ""
echo "ERROR: The meshtastic CLI command was not found in the virtualenv."
echo "Try running: pip install --force-reinstall meshtastic"
exit 1
fi
# ------------------------------------------------------------------ #
# 5. Serial port access #
# ------------------------------------------------------------------ #
echo ">>> Adding $USER to dialout group (serial/USB radio access)..."
sudo usermod -aG dialout "$USER"
# ------------------------------------------------------------------ #
# 6. Bluetooth access #
# ------------------------------------------------------------------ #
echo ">>> Adding $USER to bluetooth group..."
sudo usermod -aG bluetooth "$USER"
# ------------------------------------------------------------------ #
# 7. Generate start script #
# ------------------------------------------------------------------ #
echo ">>> Generating start script at $START_SCRIPT..."
cat > "$START_SCRIPT" << STARTSCRIPT
#!/usr/bin/env bash
# mesheliza.sh — launch MeshEliza
# Works on Raspberry Pi OS and Ubuntu.
# Generated by install.sh — safe to re-run install.sh to regenerate.
VENV="$VENV_DIR"
APP_DIR="$SCRIPT_DIR"
# Require an interactive terminal — Textual cannot run without one
if ! [[ -t 0 && -t 1 ]]; then
echo "ERROR: MeshEliza requires an interactive terminal (stdin/stdout must be a TTY)." >&2
exit 1
fi
# Ensure a capable TERM for Textual rendering
if [[ "\$TERM" == "dumb" || -z "\$TERM" ]]; then
export TERM=xterm-256color
fi
if [[ ! -f "\$VENV/bin/activate" ]]; then
echo "ERROR: virtualenv not found at \$VENV"
echo "Please re-run install.sh"
exit 1
fi
source "\$VENV/bin/activate"
cd "\$APP_DIR"
# At boot, wait up to 10 s for a USB serial device to enumerate if serial
# is the configured transport. Harmless no-op once the device is present.
CONFIG="\$HOME/.config/mesheliza/config.json"
if grep -q '"default_transport".*"serial"' "\$CONFIG" 2>/dev/null; then
if ! ls /dev/ttyUSB* /dev/ttyACM* >/dev/null 2>&1; then
echo "Waiting for USB serial device..."
for _i in \$(seq 1 10); do
ls /dev/ttyUSB* /dev/ttyACM* >/dev/null 2>&1 && break
sleep 1
done
fi
fi
exec python -m meshtty.main "\$@"
STARTSCRIPT
chmod +x "$START_SCRIPT"
echo ">>> Start script created: $START_SCRIPT"
# ------------------------------------------------------------------ #
# 8. Pi-only: optional auto-launch on tty1 #
# ------------------------------------------------------------------ #
if $IS_PI; then
echo ""
echo ">>> Raspberry Pi detected."
read -r -p ">>> Auto-launch MeshEliza on tty1 login (physical screen)? [y/N] " answer
if [[ "${answer,,}" == "y" ]]; then
BASH_PROFILE="$HOME/.bash_profile"
LAUNCH_BLOCK="
# MeshEliza auto-launch on tty1 (physical Pi screen)
if [[ \"\$(tty)\" == \"/dev/tty1\" ]]; then
export TERM=xterm-256color
while true; do
$START_SCRIPT
sleep 2
done
fi"
# Check both .bash_profile and .bashrc to avoid duplicating an older install
if ! grep -q "mesheliza auto-launch" "$BASH_PROFILE" 2>/dev/null \
&& ! grep -q "mesheliza auto-launch" "$HOME/.bashrc" 2>/dev/null; then
echo "$LAUNCH_BLOCK" >> "$BASH_PROFILE"
echo ">>> Added auto-launch block to $BASH_PROFILE"
else
echo ">>> Auto-launch already present in shell profile, skipping."
fi
fi
fi
# ------------------------------------------------------------------ #
# Done #
# ------------------------------------------------------------------ #
echo ""
echo "=== Installation complete ==="
echo ""
echo "IMPORTANT: Log out and back in for group membership to take effect."
echo "(This is required for serial port and Bluetooth access.)"
echo ""
echo "To test your radio connection before launching MeshEliza:"
echo " source $VENV_DIR/bin/activate"
echo " meshtastic --port /dev/ttyUSB0 --info # adjust port as needed"
echo " deactivate"
echo ""
echo "To launch MeshEliza:"
echo " $START_SCRIPT"
echo ""
if ! $IS_PI; then
echo "Ubuntu notes:"
echo " - Run in any terminal emulator (GNOME Terminal, Konsole, Kitty, etc.)"
echo " - SSH sessions are also fully supported"
echo " - If Bluetooth fails, check: sudo systemctl status bluetooth"
echo ""
fi
echo "Logs are written to: /tmp/mesheliza.log"