From a896ac435aa1ba8ddbeecbb871aaad4bc26fbeab Mon Sep 17 00:00:00 2001
From: mgreiff <marcusgreiff.93@hotmail.com>
Date: Fri, 1 Sep 2017 23:38:09 +0200
Subject: [PATCH] Updated util files

---
 docs/src/installation.md               |  2 +-
 util/connect_BBB.sh                    |  8 ---
 util/flash_BB.sh                       | 45 +++++++++++++++++
 util/flash_BBB.sh                      | 69 --------------------------
 util/{getfrom_BBB.sh => getfrom_BB.sh} |  0
 5 files changed, 46 insertions(+), 78 deletions(-)
 delete mode 100755 util/connect_BBB.sh
 create mode 100755 util/flash_BB.sh
 delete mode 100755 util/flash_BBB.sh
 rename util/{getfrom_BBB.sh => getfrom_BB.sh} (100%)

diff --git a/docs/src/installation.md b/docs/src/installation.md
index 88a14a0..0a742e6 100644
--- a/docs/src/installation.md
+++ b/docs/src/installation.md
@@ -30,7 +30,7 @@ Next, open a new terminal on the HOST and cd to the /util directory of the LabCo
 
     `cd && cd .julia/v0.6/LabConnection/util'
 
-This directory contains some nice utility files to operate the BB from the host. To flash it with the current revision of the software, including all dependencies, simply type `./flash.sh'
+This directory contains some nice utility files to operate the BB from the host. To flash it with the current revision of the software, including all dependencies, simply execut the shells cript `flash.sh'.
 
 ## Setting up automatic communication between the BB and the HOST via TCP
 To setup automatic start of julia server on the beagle bone
diff --git a/util/connect_BBB.sh b/util/connect_BBB.sh
deleted file mode 100755
index fa8a340..0000000
--- a/util/connect_BBB.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/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 "./LabConnections.jl/util/startup.sh; bash -l"
diff --git a/util/flash_BB.sh b/util/flash_BB.sh
new file mode 100755
index 0000000..01d66ce
--- /dev/null
+++ b/util/flash_BB.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+#Run in this file un util folder, copies to BB
+BLUE='\033[0;34m'
+GREEN='\033[0;32m'
+RED='\033[0;31m'
+NC='\033[0m'
+BASEDIR=../../$(dirname "$0")
+
+# Dependencies
+packages=(LabConnections YAML Codecs Compat)
+
+# Create an empty directory to bundle packages
+if [ -d ${BASEDIR}/juliapackages ]; then
+  rm -rf ${BASEDIR}/juliapackages
+fi
+mkdir ${BASEDIR}/juliapackages
+
+# Copy packets to the juliapackages directory
+flag=true
+printf "${GREEN}Bundling...${NC}\n\n"
+for (( i=0; i<${#packages[@]}; i++ )); do
+  {
+    printf "${BLUE}    * ${packages[$i]}${NC}\n"
+    cp -r ../../${packages[$i]} ${BASEDIR}/juliapackages
+  } || {
+    printf "${BLUE}WARNING.${NC} Could not bundle package ${packages[$i]}${NC}\n"
+    flag=false
+  }
+done
+
+# Transfer files
+if [ "$flag" = true ] ; then
+  {
+    printf "\n${GREEN}Transferring files...${NC}"
+    scp -r ${BASEDIR}/juliapackages debian@192.168.7.2:/home/debian
+    printf "${GREEN}...complete!${NC}\n"
+  } || {
+    printf "${RED}ABORTING.${NC} All packets could not be transferred, remove /home/debian/juliapackages on the BBB.\n"
+  }
+else
+    printf "${RED}ABORTING.${NC} All packets could not be budled, check their existence on the HOST\n"
+fi
+
+# Remove temporary directory
+rm -rf ${BASEDIR}/juliapackages
diff --git a/util/flash_BBB.sh b/util/flash_BBB.sh
deleted file mode 100755
index ef9bde0..0000000
--- a/util/flash_BBB.sh
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/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=(LabConnections.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 project /${project} to the BBB, aborting!${NC}\n"
-    }
-  done
-fi
-
-printf "${BLUE}Deleting temporary files...${NC}\n"
-for project in "${projects[@]}"; do
-  {
-    rm -rf ${project}
-  } || {
-    printf "${RED}Could not delete project /${project}, aborting!${NC}\n"
-}
-done
-
-printf "${BLUE}Connecting to the BBB...${NC}\n"
-{
-  ssh -t debian@192.168.7.2 "./LabConnections.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_BB.sh
similarity index 100%
rename from util/getfrom_BBB.sh
rename to util/getfrom_BB.sh
-- 
GitLab