diff --git a/.gitignore b/.gitignore index fd7db66..b21ce4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ logs/ meshtastic/ .vscode/ -__pycache__/ \ No newline at end of file +__pycache__/ +MeshtasticLogger.service \ No newline at end of file diff --git a/MeshtasticLogger.service b/MeshtasticLogger.service deleted file mode 100644 index 3e47823..0000000 --- a/MeshtasticLogger.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=A simple chat interface and autoresponder for meshtastic - -[Service] -Type=simple -WorkingDirectory=/home/quinn/Projects/Meshtastic-Webserver/ -ExecStart=sudo /home/quinn/Projects/Meshtastic-Webserver/meshtastic/bin/python -m flask --app /home/quinn/Projects/Meshtastic-Webserver/app.py run --host=0.0.0.0 --port=80 -Restart=always -User=quinn -StandardOutput=append:/home/quinn/Projects/Meshtastic-Webserver/logs/meshtastic_system.log -StandardError=append:/home/quinn/Projects/Meshtastic-Webserver/logs/meshtastic_system_error.log - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/README.md b/README.md index b7fdbc2..473fe20 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,9 @@ And you can stop the service by running: `sudo systemctl stop MeshtasticLogger` To have the service start on boot run: -`systemctl enable MeshtasticLogger` \ No newline at end of file +`systemctl enable MeshtasticLogger` + +# Automatic Deployment +Make sure the bash script is executable by running: `chmod u+x install.sh` + +Make certain you are actually in the Meshtastic-Webserver Directory or this will fail. Run the script with: `sudo ./install.sh` \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..232ccd8 --- /dev/null +++ b/install.sh @@ -0,0 +1,33 @@ +#!/bin/bash +CURRENT_DIRECTORY=$(pwd) +echo "Current directory: $CURRENT_DIRECTORY" + +cd $CURRENT_DIRECTORY + +if test -f "meshtastic"; then + echo "Virtual environment already exists. Skipping venv creation." +else + echo "Making virtual environment..." + python3 -m venv meshtastic +fi + +echo "Installing venv requirements" +meshtastic/bin/python -m pip install -r requirements.txt + +echo "Generating service file from template" + +read -p "Do you want to continue? (y/n): " choice + +# Check if the user typed 'n' or 'N' +if [[ "$choice" == "n" || "$choice" == "N" ]]; then + echo "Exiting the script..." + exit 0 +fi +echo "Continuing...\n Creating Service file..." +# Replace all instances of ${WORKING_DIRECTORY} with the actual working directory and write to the new file +sed "s|\${WORKING_DIRECTORY}|$CURRENT_DIRECTORY|g" "service-template/MeshtasticLogger-template.service" > "MeshtasticLogger.service" + +echo "Deploying service" +sudo cp "$CURRENT_DIRECTORY/MeshtasticLogger.service" /etc/systemd/system/ && sudo systemctl daemon-reload && sudo systemctl start MeshtasticLogger + + diff --git a/service-template/MeshtasticLogger-template.service b/service-template/MeshtasticLogger-template.service new file mode 100644 index 0000000..7daaf25 --- /dev/null +++ b/service-template/MeshtasticLogger-template.service @@ -0,0 +1,14 @@ +[Unit] +Description=A simple chat interface and autoresponder for meshtastic + +[Service] +Type=simple +WorkingDirectory=${WORKING_DIRECTORY}/ +ExecStart=sudo ${WORKING_DIRECTORY}/meshtastic/bin/python -m flask --app ${WORKING_DIRECTORY}/app.py run --host=0.0.0.0 --port=80 +Restart=always +User=quinn +StandardOutput=append:${WORKING_DIRECTORY}/logs/meshtastic_system.log +StandardError=append:${WORKING_DIRECTORY}/logs/meshtastic_system_error.log + +[Install] +WantedBy=multi-user.target \ No newline at end of file