Files
nebuleair_pro_4g/installation.sh
Your Name 144d904813 update
2025-02-25 11:55:44 +01:00

95 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Update and install necessary packages
echo "Updating package list and installing necessary packages..."
sudo apt update
sudo apt install git gh apache2 php php-sqlite3 python3 python3-pip jq autossh i2c-tools python3-smbus -y
# Install Python libraries
echo "Installing Python libraries..."
sudo pip3 install pyserial requests RPi.GPIO adafruit-circuitpython-bme280 crcmod psutil --break-system-packages
# Ask user if they want to set up SSH keys
read -p "Do you want to set up an SSH key for /var/www? (y/n): " answer
# Convert input to lowercase to accept 'Y' or 'y'
answer=${answer,,}
if [[ "$answer" == "y" ]]; then
echo "Setting up SSH keys..."
# Create SSH directory if it doesn't exist
sudo mkdir -p /var/www/.ssh
sudo chmod 700 /var/www/.ssh
# Generate SSH key if it does not already exist
if [[ ! -f /var/www/.ssh/id_rsa ]]; then
sudo ssh-keygen -t rsa -b 4096 -f /var/www/.ssh/id_rsa -N ""
echo "SSH key generated successfully."
else
echo "SSH key already exists. Skipping key generation."
fi
# Copy SSH key to remote server
sudo ssh-copy-id -i /var/www/.ssh/id_rsa.pub -p 50221 airlab_server1@aircarto.fr
echo "SSH setup complete!"
else
echo "Skipping SSH key setup."
fi
# Clone the repository
echo "Cloning the NebuleAir Pro 4G repository..."
sudo git clone http://gitea.aircarto.fr/PaulVua/nebuleair_pro_4g.git /var/www/nebuleair_pro_4g
# Set up repository files and permissions
echo "Setting up repository files and permissions..."
sudo mkdir /var/www/nebuleair_pro_4g/logs
sudo touch /var/www/nebuleair_pro_4g/logs/app.log /var/www/nebuleair_pro_4g/logs/loop.log /var/www/nebuleair_pro_4g/wifi_list.csv
sudo cp /var/www/nebuleair_pro_4g/config.json.dist /var/www/nebuleair_pro_4g/config.json
sudo chmod -R 777 /var/www/nebuleair_pro_4g/
git config --global core.fileMode false
git config --global --add safe.directory /var/www/nebuleair_pro_4g
# Set up cron jobs
echo "Setting up cron jobs..."
sudo crontab /var/www/nebuleair_pro_4g/cron_jobs
#Creates databases
echo "Creating databases."
sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/create_db.py
#Apache
echo "Set Up Apache"
sudo sed -i 's|DocumentRoot /var/www/html|DocumentRoot /var/www/nebuleair_pro_4g|' /etc/apache2/sites-available/000-default.conf
sudo systemctl reload apache2
#add sudo authorization
if ! sudo grep -q "/usr/bin/nmcli" /etc/sudoers; then
echo "Setting up sudo authorization..."
echo -e "ALL ALL=(ALL) NOPASSWD: /usr/bin/nmcli, /usr/sbin/reboot\nwww-data ALL=(ALL) NOPASSWD: /usr/bin/git pull\nwww-data ALL=(ALL) NOPASSWD: /usr/bin/ssh\nwww-data ALL=(ALL) NOPASSWD: /usr/bin/python3 *" | sudo EDITOR="tee -a" visudo
else
echo "Sudo authorization already set. Skipping..."
fi
#Open all serial ports
if ! grep -q "enable_uart=1" /boot/firmware/config.txt; then
echo "Adding UART configuration..."
echo -e "\nenable_uart=1\ndtoverlay=uart0\ndtoverlay=uart1\ndtoverlay=uart2\ndtoverlay=uart3\ndtoverlay=uart4\ndtoverlay=uart5" | sudo tee -a /boot/firmware/config.txt > /dev/null
else
echo "UART configuration already set. Skipping..."
fi
sudo chmod 777 /dev/ttyAMA*
#Open I2C ports
echo "Open I2C ports"
sudo raspi-config nonint do_i2c 0
echo "Setup completed successfully!"