From cab8df0fdf729473d31657661532b86fe9e5ca69 Mon Sep 17 00:00:00 2001 From: andrewnash Date: Fri, 7 Jun 2019 03:45:51 -0400 Subject: [PATCH 1/3] inital commit --- OnLand/ControlLaptop/SocketController.py | 2 +- OnLand/ControlLaptop/views.py | 2 +- paradigm.sh | 44 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100755 paradigm.sh diff --git a/OnLand/ControlLaptop/SocketController.py b/OnLand/ControlLaptop/SocketController.py index 693df50..4bfb978 100644 --- a/OnLand/ControlLaptop/SocketController.py +++ b/OnLand/ControlLaptop/SocketController.py @@ -1,6 +1,6 @@ import socket import logging as log -from ControlLaptop import Paradigm_pb2 +import Paradigm_pb2 from ControlLaptop.LocalStorage.ConfigurationSotrage import DEFAULT_CONFIGURATION from config import POD_IP, POD_CONFIG_PORT diff --git a/OnLand/ControlLaptop/views.py b/OnLand/ControlLaptop/views.py index de0ea7b..34ec465 100644 --- a/OnLand/ControlLaptop/views.py +++ b/OnLand/ControlLaptop/views.py @@ -7,7 +7,7 @@ from ControlLaptop.LocalStorage.ConfigurationSotrage import LocalStorage from ControlLaptop.LocalStorage.FlightConfig import FlightConfig from ControlLaptop.SocketController import PodCommunicator -from templates._sidebar import get_page_title, NAV_BAR +from ControlLaptop.templates._sidebar import get_page_title, NAV_BAR from ControlLaptop.forms import FlightConfigurationForm import collections diff --git a/paradigm.sh b/paradigm.sh new file mode 100755 index 0000000..c87bcb6 --- /dev/null +++ b/paradigm.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +:'requirments: + git + sudo apt-get install git + python3 + sudo apt-get install python3 + pip + sudo apt install python-pip + virtualenv + sudo apt-get install python-virtualenv + Protobuf + https://github.com/protocolbuffers/protobuf/releases/tag/v3.8.0 + extract and enter folder + ./configure + make + make check + sudo make install + sudo ldconfig + +you will also likely have to: + chmod u+x paradigm.sh +' + +file="/comp4-software/" +if [ ! -f "$file"] +then + cd comp4-software/OnLand +else + echo "setting up project" + git clone https://github.com/ParadigmHyperloop/comp4-software.git + virtualenv -p python3 comp4-software/OnLand + touch comp4-software/OnLand/Paradigm_pb2.py +fi + +echo "updating project" +git pull +source comp4-software/OnLand/bin/activate +comp4-software/OnLand/bin/pip install -r comp4-software/OnLand/requirements.txt +./comp4-software/ProtoBufs/UpdateProtos.sh + +echo "running project" +cd comp4-software/OnLand +python3 paradigm.py \ No newline at end of file From 10135b90d7a209fe7dc42045103aa3567a33d5b2 Mon Sep 17 00:00:00 2001 From: Andrew Nash <33398082+andrewnash@users.noreply.github.com> Date: Fri, 7 Jun 2019 11:22:26 -0230 Subject: [PATCH 2/3] fix pull order --- paradigm.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/paradigm.sh b/paradigm.sh index c87bcb6..0d24ae3 100755 --- a/paradigm.sh +++ b/paradigm.sh @@ -1,6 +1,7 @@ #!/bin/bash -:'requirments: +:' +Requirments: git sudo apt-get install git python3 @@ -18,14 +19,16 @@ sudo make install sudo ldconfig -you will also likely have to: +You will also likely have to: chmod u+x paradigm.sh + +Search for your systems list of "startup applications" and add this script to it ' file="/comp4-software/" if [ ! -f "$file"] then - cd comp4-software/OnLand + continue else echo "setting up project" git clone https://github.com/ParadigmHyperloop/comp4-software.git @@ -36,9 +39,9 @@ fi echo "updating project" git pull source comp4-software/OnLand/bin/activate -comp4-software/OnLand/bin/pip install -r comp4-software/OnLand/requirements.txt ./comp4-software/ProtoBufs/UpdateProtos.sh +comp4-software/OnLand/bin/pip install -r comp4-software/OnLand/requirements.txt echo "running project" cd comp4-software/OnLand -python3 paradigm.py \ No newline at end of file +python3 paradigm.py From c98abd25305017cb7565421174be8b9161bf3d87 Mon Sep 17 00:00:00 2001 From: Sohil Date: Tue, 9 Jul 2019 00:19:41 -0230 Subject: [PATCH 3/3] Cron job, Systemd, automated scripts --- paradigm.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/paradigm.sh b/paradigm.sh index 0d24ae3..18d62ed 100755 --- a/paradigm.sh +++ b/paradigm.sh @@ -25,23 +25,80 @@ You will also likely have to: Search for your systems list of "startup applications" and add this script to it ' -file="/comp4-software/" +# Get sudo privileges +sudo -s +# Dependencies to check +dependencies=(git python3 python-pip python-virtualenv wget unzip) + +# Install missing dependencies +install_dependency () { + sudo -s + apt-get install $@ +} + +# Check for dependencies +for i in "${dependencies[@]}"; + to_install=() + do version="$('$i' --version)" &> /dev/null + if [ [ $version =~ 'command not found' ]]; + echo "Package is NOT installed! Attempting to install it" + to_install+=("$i") + else + echo "Package is installed!" + fi; +done + +# Separately check for protoc +version="$(protoc --version)" > /dev/null +if [[ $version =~ 'command not found' ]]; + echo 'Protobuf is not installed. Attempting to install it.' + wget https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/protobuf-cpp-3.8.0.zip + unzip protobuf-cpp-3.8.0.zip && cd protobuf-3.8.0 + ./configure + make && make check + sudo make install + sudo ldconfig +else + echo 'Protobuf is installed' +fi + +file="~/comp4-software/" if [ ! -f "$file"] then continue else echo "setting up project" - git clone https://github.com/ParadigmHyperloop/comp4-software.git - virtualenv -p python3 comp4-software/OnLand - touch comp4-software/OnLand/Paradigm_pb2.py + cd ~ && git clone https://github.com/ParadigmHyperloop/comp4-software.git + virtualenv -p python3 comp4-software/OnLand/.virtualenv + ~/comp4-software/OnLand/ProtoBufs/UpdateProtos.sh fi -echo "updating project" +# Creates the script that will be ran hourly by cron, and if a manual update is needed you can just run it +echo ' +cd ~/comp4-software git pull -source comp4-software/OnLand/bin/activate -./comp4-software/ProtoBufs/UpdateProtos.sh -comp4-software/OnLand/bin/pip install -r comp4-software/OnLand/requirements.txt +source OnLand/.virtualenv/bin/activate +./ProtoBufs/UpdateProtos.sh +./OnLand/.virtualenv/bin/pip intall -r OnLand/requirements.txt +' >> ~/update.sh +chmod +x ~/update.sh + +# create the cron job, that will run hourly +# REMEMBER TO CHANGE THE USER NAME +crontab -l > mycron +echo ' 0 * * * * /home/REPLACE_HERE/update.sh' >> cronjob +crontab cronjob + +# Creates the system service that will run the OnLand software on boot +echo ' +[Unit] +Description=Paradigm Hyperloop subsystem + +[Service] +Type=simple +ExecStart=~/comp4-software/OnLand/.virtualenv/bin/python ~/comp4-software/OnLand/paradigm.py +StandardOutput= inherit -echo "running project" -cd comp4-software/OnLand -python3 paradigm.py +[Install] +WantedBy=multi-user.target +' > /etc/systemd/system/ called paradigm.service \ No newline at end of file