From 29806df759ec8d6d7c6f588bc6155c13ff791e4e Mon Sep 17 00:00:00 2001 From: InfiniteL8p Date: Wed, 21 Aug 2024 15:01:32 +0200 Subject: [PATCH] chore: Update installation instructions and scripts for Security Cam service --- client/tbd/readme.md | 46 +++++++++++++++++++++ install_requirements.sh | 24 +++++++++++ client/requirements.txt => requirements.txt | 0 start.sh | 9 ++++ 4 files changed, 79 insertions(+) create mode 100644 client/tbd/readme.md create mode 100644 install_requirements.sh rename client/requirements.txt => requirements.txt (100%) create mode 100644 start.sh diff --git a/client/tbd/readme.md b/client/tbd/readme.md new file mode 100644 index 0000000..83bc008 --- /dev/null +++ b/client/tbd/readme.md @@ -0,0 +1,46 @@ +# Installation +1. Clone the Repository + + ```bash + sudo git clone https://github.com/infinitel8p/Security-Cam.git /opt/security-cam + ``` + + +2. Create the Service File + ```bash + sudo nano /etc/systemd/system/security-cam.service + ``` + + Add the following to the file: + + ```shell + [Unit] + Description=Security Cam Flask and Node.js Servers + After=network.target + + [Service] + Type=simple + User=root + WorkingDirectory=/opt/security-cam + ExecStart=/bin/bash -c ' + git pull && + chmod +x /opt/security-cam/install_requirements.sh && + cd /opt/security-cam/server && npm install && + cd /opt/security-cam/client && + bash /opt/security-cam/install_requirements.sh && + chmod +x /opt/security-cam/start.sh && + /opt/security-cam/start.sh + ' + Restart=on-failure + + [Install] + WantedBy=multi-user.target + ``` + +3. Reload the systemd manager configuration: `sudo systemctl daemon-reload` + +4. Enable the service to start on boot: `sudo systemctl enable security-cam.service` + +5. Start the service: `sudo systemctl start security-cam.service` + +6. Check the status of the service: `sudo systemctl status security-cam.service` \ No newline at end of file diff --git a/install_requirements.sh b/install_requirements.sh new file mode 100644 index 0000000..bd22ffb --- /dev/null +++ b/install_requirements.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Update package list +sudo apt-get update + +# Install system dependencies +sudo apt-get install -y python3 python3-pip nodejs npm + +# Path to the requirements.txt file +REQUIREMENTS_FILE="/opt/security-cam/requirements.txt" + +# Loop through each line in requirements.txt +while IFS= read -r package +do + # Extract the package name before any version specifier (e.g., flask==2.0 -> flask) + package_name=$(echo "$package" | cut -d '=' -f 1) + + # Install the package using apt-get if available, otherwise fallback to pip + if apt-cache search --names-only "^python3-$package_name$" | grep -q "^python3-$package_name"; then + sudo apt-get install -y python3-$package_name + else + sudo pip3 install "$package" --break-system-packages + fi +done < "$REQUIREMENTS_FILE" diff --git a/client/requirements.txt b/requirements.txt similarity index 100% rename from client/requirements.txt rename to requirements.txt diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..6ccb33b --- /dev/null +++ b/start.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Start the Node.js server +cd /opt/security-cam/server || exit +npm run dev & + +# Start the Flask server +cd /opt/security-cam/client || exit +python3 main.py &