-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
160 lines (135 loc) · 4.13 KB
/
install.sh
File metadata and controls
160 lines (135 loc) · 4.13 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
#!/bin/bash
set -e
# Configuration
INSTALL_DIR="/opt/flying-lora"
VENV_DIR="$INSTALL_DIR/venv"
SERVICE_NAME="jetson-localization"
USER="jetson"
GROUP="jetson"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Log function
log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $1${NC}"
}
error() {
echo -e "${RED}[ERROR] $1${NC}" >&2
exit 1
}
warn() {
echo -e "${YELLOW}[WARNING] $1${NC}"
}
# Check if running as root
if [[ $EUID -ne 0 ]]; then
error "This script must be run as root"
fi
# Check system requirements
log "Checking system requirements..."
if ! command -v python3 >/dev/null; then
error "Python 3 is required but not installed"
fi
if ! command -v pip3 >/dev/null; then
error "pip3 is required but not installed"
fi
# Install system dependencies
log "Installing system dependencies..."
apt-get update
apt-get install -y \
python3-venv \
python3-dev \
build-essential \
libpq-dev \
redis-server \
postgresql \
postgresql-contrib \
libgstreamer1.0-0 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
python3-gst-1.0 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
nginx
# Create user and group if they don't exist
log "Setting up user and group..."
if ! getent group "$GROUP" >/dev/null; then
groupadd "$GROUP"
fi
if ! getent passwd "$USER" >/dev/null; then
useradd -m -g "$GROUP" -s /bin/bash "$USER"
fi
# Create installation directory
log "Creating installation directory..."
mkdir -p "$INSTALL_DIR"
chown -R "$USER:$GROUP" "$INSTALL_DIR"
# Copy application files
log "Copying application files..."
cp -r . "$INSTALL_DIR/"
chown -R "$USER:$GROUP" "$INSTALL_DIR"
# Create virtual environment
log "Setting up Python virtual environment..."
python3 -m venv "$VENV_DIR"
source "$VENV_DIR/bin/activate"
# Install Python dependencies
log "Installing Python dependencies..."
pip3 install --upgrade pip
pip3 install -r "$INSTALL_DIR/requirements.txt"
# Install additional Jetson-specific packages
log "Installing Jetson-specific packages..."
pip3 install jetson-stats jtop jetson-utils
# Set up configuration
log "Setting up configuration..."
if [ ! -f "$INSTALL_DIR/.env" ]; then
cp "$INSTALL_DIR/.env.example" "$INSTALL_DIR/.env"
warn "Please update the configuration in $INSTALL_DIR/.env"
fi
# Set up database
log "Setting up database..."
sudo -u postgres psql -c "CREATE DATABASE flying_lora;" || true
sudo -u postgres psql -c "CREATE USER $USER WITH PASSWORD 'change_me';" || true
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE flying_lora TO $USER;" || true
# Initialize database
log "Initializing database..."
source "$INSTALL_DIR/.env"
FLASK_APP=app.py flask db upgrade
# Set up systemd service
log "Setting up systemd service..."
cp "$INSTALL_DIR/jetson-localization.service" "/etc/systemd/system/$SERVICE_NAME.service"
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
# Set up hardware permissions
log "Setting up hardware permissions..."
usermod -a -G dialout "$USER" # For serial port access
usermod -a -G video "$USER" # For camera access
usermod -a -G gpio "$USER" # For GPIO access
usermod -a -G i2c "$USER" # For I2C access
# Create log directory
log "Setting up logging..."
mkdir -p "$INSTALL_DIR/logs"
chown -R "$USER:$GROUP" "$INSTALL_DIR/logs"
# Set up Nginx (if needed)
log "Setting up Nginx..."
if [ -f "$INSTALL_DIR/nginx.conf" ]; then
cp "$INSTALL_DIR/nginx.conf" "/etc/nginx/sites-available/flying-lora"
ln -sf "/etc/nginx/sites-available/flying-lora" "/etc/nginx/sites-enabled/"
systemctl restart nginx
fi
# Download YOLOv5 model
log "Downloading YOLOv5 model..."
sudo -u "$USER" python3 -c "from ultralytics import YOLO; YOLO('yolov5s.pt')"
# Final setup
log "Performing final setup..."
systemctl start "$SERVICE_NAME"
# Installation complete
log "Installation complete!"
log "Please:"
log "1. Update the configuration in $INSTALL_DIR/.env"
log "2. Update the database password"
log "3. Check the service status with: systemctl status $SERVICE_NAME"
log "4. View logs with: journalctl -u $SERVICE_NAME"