From 5a52b15ac84f11aa5895b1df94227ccc6d8543f6 Mon Sep 17 00:00:00 2001 From: mgreiff <marcusgreiff.93@hotmail.com> Date: Thu, 24 Aug 2017 01:57:44 +0200 Subject: [PATCH] Add utility shell scripts for file transfer and setting up environments --- util/connect_BBB.sh | 8 ++++++ util/connect_BBB.sh~ | 8 ++++++ util/flash_BBB.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++ util/flash_BBB.sh~ | 60 ++++++++++++++++++++++++++++++++++++++++++++ util/getfrom_BBB.sh | 14 +++++++++++ util/getfrom_BBB.sh~ | 14 +++++++++++ util/startup.sh | 5 ++++ util/startup.sh~ | 5 ++++ 8 files changed, 174 insertions(+) create mode 100755 util/connect_BBB.sh create mode 100755 util/connect_BBB.sh~ create mode 100755 util/flash_BBB.sh create mode 100755 util/flash_BBB.sh~ create mode 100755 util/getfrom_BBB.sh create mode 100755 util/getfrom_BBB.sh~ create mode 100755 util/startup.sh create mode 100755 util/startup.sh~ diff --git a/util/connect_BBB.sh b/util/connect_BBB.sh new file mode 100755 index 0000000..3b412bb --- /dev/null +++ b/util/connect_BBB.sh @@ -0,0 +1,8 @@ +#!/bin/bash +############################################################################### +# This line of code connects to the BBB via ssh, runs the startup file and +# remains in the shell of the BBB after executing startup.sh on the BBB +# +# The code may be executed from anywhere on the HOST computer. +############################################################################### +ssh -t debian@192.168.7.2 "./LabConnection.jl/util/startup.sh; bash -l" diff --git a/util/connect_BBB.sh~ b/util/connect_BBB.sh~ new file mode 100755 index 0000000..3b412bb --- /dev/null +++ b/util/connect_BBB.sh~ @@ -0,0 +1,8 @@ +#!/bin/bash +############################################################################### +# This line of code connects to the BBB via ssh, runs the startup file and +# remains in the shell of the BBB after executing startup.sh on the BBB +# +# The code may be executed from anywhere on the HOST computer. +############################################################################### +ssh -t debian@192.168.7.2 "./LabConnection.jl/util/startup.sh; bash -l" diff --git a/util/flash_BBB.sh b/util/flash_BBB.sh new file mode 100755 index 0000000..60eb8bb --- /dev/null +++ b/util/flash_BBB.sh @@ -0,0 +1,60 @@ +#!/bin/bash +############################################################################### +# This code clones or upps the most recent code from github and transfers it to +# the BBB before connecting to it and running the startup file on the BBB. +# +# The code may be executed from anywhere on the HOST computer. +############################################################################### + +BLUE='\033[0;34m' +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +printf "${BLUE}Updating project${NC}\n..." + +codeHost=gitlab.control.lth.se +codeUser=labdev +projects=(LabConnection.jl) +flag=false + +for project in "${projects[@]}"; do + { + if [ -d "${project}" ]; then + # Try to clone repository + printf "${GREEN}Pulling /${project}...${NC}\n" + cd "${project}" + echo $(ls) + git pull "https://${codeHost}/${codeUser}/${project}.git" + cd ".." + else + printf "${GREEN}Cloning /${project}...${NC}\n" + git clone "https://${codeHost}/${codeUser}/${project}.git" + fi + } || { # catch + # save log for exception + flag=false + printf "${RED}Could not udate repository /${project}${NC}, aborting.\n" + } +done + +printf "${BLUE}Initializing Transferring files to BBB${NC}\n" +if [ "{flag}"=true ]; then + for project in "${projects[@]}"; do + { + printf "${GREEN}Transferring /${project}...${NC}\n" + scp -r ${project} debian@192.168.7.2:/home/debian + } || { # catch + # save log for exception + flag=false + printf "${RED}Could not send folder /${project} to the BBB, aborting!${NC}\n" + } + done +fi + +printf "${BLUE}Connecting to the BBB${NC}\n" +{ + ssh -t debian@192.168.7.2 "./LabConnection.jl/util/startup.sh; bash -l" +} || { + printf "${RED}Could Connect to the BBB!${NC}\n" +} diff --git a/util/flash_BBB.sh~ b/util/flash_BBB.sh~ new file mode 100755 index 0000000..60eb8bb --- /dev/null +++ b/util/flash_BBB.sh~ @@ -0,0 +1,60 @@ +#!/bin/bash +############################################################################### +# This code clones or upps the most recent code from github and transfers it to +# the BBB before connecting to it and running the startup file on the BBB. +# +# The code may be executed from anywhere on the HOST computer. +############################################################################### + +BLUE='\033[0;34m' +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +printf "${BLUE}Updating project${NC}\n..." + +codeHost=gitlab.control.lth.se +codeUser=labdev +projects=(LabConnection.jl) +flag=false + +for project in "${projects[@]}"; do + { + if [ -d "${project}" ]; then + # Try to clone repository + printf "${GREEN}Pulling /${project}...${NC}\n" + cd "${project}" + echo $(ls) + git pull "https://${codeHost}/${codeUser}/${project}.git" + cd ".." + else + printf "${GREEN}Cloning /${project}...${NC}\n" + git clone "https://${codeHost}/${codeUser}/${project}.git" + fi + } || { # catch + # save log for exception + flag=false + printf "${RED}Could not udate repository /${project}${NC}, aborting.\n" + } +done + +printf "${BLUE}Initializing Transferring files to BBB${NC}\n" +if [ "{flag}"=true ]; then + for project in "${projects[@]}"; do + { + printf "${GREEN}Transferring /${project}...${NC}\n" + scp -r ${project} debian@192.168.7.2:/home/debian + } || { # catch + # save log for exception + flag=false + printf "${RED}Could not send folder /${project} to the BBB, aborting!${NC}\n" + } + done +fi + +printf "${BLUE}Connecting to the BBB${NC}\n" +{ + ssh -t debian@192.168.7.2 "./LabConnection.jl/util/startup.sh; bash -l" +} || { + printf "${RED}Could Connect to the BBB!${NC}\n" +} diff --git a/util/getfrom_BBB.sh b/util/getfrom_BBB.sh new file mode 100755 index 0000000..ed3b59b --- /dev/null +++ b/util/getfrom_BBB.sh @@ -0,0 +1,14 @@ +#!/bin/bash +############################################################################### +# This pice of code attemps to scp files from the BBB to a directory $PWD/temp +# +# The code may be executed from anywhere on the HOST computer. +############################################################################### +{ + if [ ! -d "temp" ]; then + mkdir temp + fi + sudo scp -r debian@192.168.7.2:/home/debian/$1 $PWD/temp +} || { + echo "Could not find or transfer $1, check that the file exists on the BBB" +} diff --git a/util/getfrom_BBB.sh~ b/util/getfrom_BBB.sh~ new file mode 100755 index 0000000..0024684 --- /dev/null +++ b/util/getfrom_BBB.sh~ @@ -0,0 +1,14 @@ +#!/bin/bash +############################################################################### +# This pice of tries to scp files from the BBB to a directory $PWD/temp +# +# The code may be executed from anywhere on the HOST computer. +############################################################################### +{ + if [ ! -d "temp" ]; then + mkdir temp + fi + sudo scp -r debian@192.168.7.2:/home/debian/$1 $PWD/temp +} || { + echo "Could not find or transfer $1, check that the file exists on the BBB" +} diff --git a/util/startup.sh b/util/startup.sh new file mode 100755 index 0000000..78a8c75 --- /dev/null +++ b/util/startup.sh @@ -0,0 +1,5 @@ +#!/bin/sh +ls +cd "LabConnection.jl/test/BeagleBone" +sudo /home/debian/julia-903644385b/bin/julia + diff --git a/util/startup.sh~ b/util/startup.sh~ new file mode 100755 index 0000000..78a8c75 --- /dev/null +++ b/util/startup.sh~ @@ -0,0 +1,5 @@ +#!/bin/sh +ls +cd "LabConnection.jl/test/BeagleBone" +sudo /home/debian/julia-903644385b/bin/julia + -- GitLab