From 0466b323767abfd0dc4257d820390fc3a0622e76 Mon Sep 17 00:00:00 2001
From: fherrero <fherrero@iri.upc.edu>
Date: Thu, 25 Jul 2019 17:22:19 +0200
Subject: [PATCH] CI: add before_script to manage ssh key. Modified script to
 remove lines from udev rule.

---
 .gitlab-ci.yml                   | 12 ++++++++++++
 scripts/undo_unbind_ftdi_udev.sh |  4 +++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index aad0e96..594dbc3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,4 +1,14 @@
   image: docker.io/alopeziri/labrobotica
+    
+  before_script:
+      - which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
+      - eval $(ssh-agent -s)
+      - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
+      - mkdir -p ~/.ssh
+      - chmod 700 ~/.ssh
+      - ssh-keyscan -p 2202 gitlab.iri.upc.edu  >> ~/.ssh/known_hosts
+      - chmod 644 ~/.ssh/known_hosts
+      - ssh -p 2202 git@gitlab.iri.upc.edu #test
 
   stages:
     - build
@@ -30,3 +40,5 @@
       - "ssh irilabo@147.83.76.226 -i /root/.ssh/iriLabKeyNopwd -tt /home/irilabo/repo_scripts/update_repo.sh battery-monitor"
     only:
       - tags
+
+   
\ No newline at end of file
diff --git a/scripts/undo_unbind_ftdi_udev.sh b/scripts/undo_unbind_ftdi_udev.sh
index 5196d08..47c25d9 100755
--- a/scripts/undo_unbind_ftdi_udev.sh
+++ b/scripts/undo_unbind_ftdi_udev.sh
@@ -34,8 +34,10 @@ echo "Undo addition of udev rule so VENDOR:PRODUCT:SERIAL=${VENDOR}:${PRODUCT}:$
 echo "Removing all lines containing SERIAL=${SERIAL} from file: ${FILE}"
 
 LINE0=${SERIAL}
-
 sudo sed -i "/${LINE0}/d" $FILE
 
+sed -i -E "/idVendor.*$VENDOR.*idProduct.*$PRODUCT.*serial.*$SERIAL.*MODE.*0666\"/d" $FILE 
+sed -i -E "/idVendor.*$VENDOR.*idProduct.*$PRODUCT.*serial.*$SERIAL.*RUN.*ftdi_sio\/unbind/d" $FILE 
+
 sudo service udev restart
 echo "Need to unplug-plug devices for changes to take effect"
\ No newline at end of file
-- 
GitLab