From be3658dd13271138488d301a6b5bbaf7441bdb86 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob.mottram@codethink.co.uk>
Date: Tue, 26 Jan 2016 16:20:06 +0000
Subject: [PATCH] Handle git clone

---
 src/freedombone | 60 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/src/freedombone b/src/freedombone
index 518e0143b..1a595bd82 100755
--- a/src/freedombone
+++ b/src/freedombone
@@ -534,6 +534,24 @@ function show_help {
     exit 0
 }
 
+function git_clone {
+    repo_url="$1"
+    destination_dir="$2"
+    if [[ "$repo_url" == "ssh:"* ]]; then
+        if [ "${FRIENDS_TROVE_SERVER}" ]; then
+            if [ ${#FRIENDS_TROVE_SERVER} -gt 2 ]; then
+                if [ "$FRIENDS_TROVE_PASSWORD" ]; then
+                    if [ ${#FRIENDS_TROVE_PASSWORD} -gt 2 ]; then
+                        sshpass -p "$FRIENDS_TROVE_PASSWORD" git clone "$repo_url" "$destination_dir"
+                        return
+                    fi
+                fi
+            fi
+        fi
+    fi
+    git clone "$repo_url" "$destination_dir"
+}
+
 function create_database {
     app_name="$1"
     app_admin_password="$2"
@@ -1959,7 +1977,7 @@ function mesh_cjdns {
     fi
 
     if [ ! -d /etc/cjdns ]; then
-        git clone $CJDNS_REPO /etc/cjdns
+        git_clone $CJDNS_REPO /etc/cjdns
         cd /etc/cjdns
 
         git checkout $CJDNS_COMMIT -b $CJDNS_COMMIT
@@ -2319,7 +2337,7 @@ function install_zeronet_blog {
         exit 7638
     fi
 
-    git clone $ZERONET_BLOG_REPO ZeroBlog
+    git_clone $ZERONET_BLOG_REPO ZeroBlog
     if [ ! -d /opt/zeronet/ZeroBlog ]; then
         echo $'ZeroBlog repo could not be cloned'
         exit 6739
@@ -2445,7 +2463,7 @@ function install_zeronet_mail {
         exit 7638
     fi
 
-    git clone $ZERONET_MAIL_REPO ZeroMail
+    git_clone $ZERONET_MAIL_REPO ZeroMail
     if [ ! -d /opt/zeronet/ZeroMail ]; then
         echo $'ZeroMail repo could not be cloned'
         exit 6739
@@ -2572,7 +2590,7 @@ function install_zeronet_forum {
         exit 7638
     fi
 
-    git clone $ZERONET_FORUM_REPO ZeroTalk
+    git_clone $ZERONET_FORUM_REPO ZeroTalk
     if [ ! -d /opt/zeronet/ZeroTalk ]; then
         echo $'ZeroTalk repo could not be cloned'
         exit 6739
@@ -2654,7 +2672,7 @@ function install_zeronet {
     pip install msgpack-python --upgrade
 
     useradd -d /opt/zeronet/ -s /bin/false zeronet
-    git clone $ZERONET_REPO /opt/zeronet
+    git_clone $ZERONET_REPO /opt/zeronet
     if [ ! -d /opt/zeronet ]; then
         exit 56823
     fi
@@ -2766,7 +2784,7 @@ function install_atheros_wifi {
     fi
     cd $INSTALL_DIR
     if [ ! -d $INSTALL_DIR/open-ath9k-htc-firmware ]; then
-        git clone $ATHEROS_WIFI_REPO $INSTALL_DIR/open-ath9k-htc-firmware
+        git_clone $ATHEROS_WIFI_REPO $INSTALL_DIR/open-ath9k-htc-firmware
         if [ ! "$?" = "0" ]; then
             rm -rf $INSTALL_DIR/open-ath9k-htc-firmware
             exit 74283
@@ -4488,7 +4506,7 @@ function configure_email {
         mkdir -p $INSTALL_DIR
     fi
     cd $INSTALL_DIR
-    git clone $EXIM_ONION_REPO $INSTALL_DIR/exim4-smtorp
+    git_clone $EXIM_ONION_REPO $INSTALL_DIR/exim4-smtorp
     cd $INSTALL_DIR/exim4-smtorp/tor-smtp
     make
     if [ ! -f $INSTALL_DIR/exim4-smtorp/tor-smtp/tor-smtp ]; then
@@ -5265,7 +5283,7 @@ function encrypt_incoming_email {
     if [ ! -f /usr/bin/gpgit.pl ]; then
         apt-get -y install git libmail-gnupg-perl
         cd $INSTALL_DIR
-        git clone $GPGIT_REPO $INSTALL_DIR/gpgit
+        git_clone $GPGIT_REPO $INSTALL_DIR/gpgit
         cd $INSTALL_DIR/gpgit
         git checkout $GPGIT_COMMIT -b $GPGIT_COMMIT
         if ! grep -q "gpgit commit" $COMPLETION_FILE; then
@@ -5577,7 +5595,7 @@ function email_archiving {
         mkdir $INSTALL_DIR
     fi
     cd $INSTALL_DIR
-    git clone $CLEANUP_MAILDIR_REPO $INSTALL_DIR/cleanup-maildir
+    git_clone $CLEANUP_MAILDIR_REPO $INSTALL_DIR/cleanup-maildir
     cd $INSTALL_DIR/cleanup-maildir
     git checkout $CLEANUP_MAILDIR_COMMIT -b $CLEANUP_MAILDIR_COMMIT
     if ! grep -q "cleanup-maildir commit" $COMPLETION_FILE; then
@@ -5969,7 +5987,7 @@ function install_web_server {
         mkdir $INSTALL_DIR
     fi
     cd $INSTALL_DIR
-    git clone $NGINX_ENSITE_REPO $INSTALL_DIR/nginx_ensite
+    git_clone $NGINX_ENSITE_REPO $INSTALL_DIR/nginx_ensite
     cd $INSTALL_DIR/nginx_ensite
     git checkout $NGINX_ENSITE_COMMIT -b $NGINX_ENSITE_COMMIT
     if ! grep -q "Nginx-ensite commit" $COMPLETION_FILE; then
@@ -6131,7 +6149,7 @@ function install_owncloud_music_app {
     fi
 
     cd /usr/share/owncloud/apps
-    git clone $OWNCLOUD_MUSIC_APP_REPO Music
+    git_clone $OWNCLOUD_MUSIC_APP_REPO Music
     cd /usr/share/owncloud/apps/Music
     git checkout $OWNCLOUD_MUSIC_APP_COMMIT -b $OWNCLOUD_MUSIC_APP_COMMIT
     if ! grep -q "Owncloud music app commit" $COMPLETION_FILE; then
@@ -6631,7 +6649,7 @@ function install_gogs {
         mkdir -p $GOPATH/src/github.com/gogits
     fi
     cd $GOPATH/src/github.com/gogits
-    git clone $GIT_DOMAIN_REPO $GOPATH/src/github.com/gogits/gogs
+    git_clone $GIT_DOMAIN_REPO $GOPATH/src/github.com/gogits/gogs
     cd gogs
     git checkout $GOGS_COMMIT -b $GOGS_COMMIT
     if ! grep -q "Gogs commit" $COMPLETION_FILE; then
@@ -6887,7 +6905,7 @@ function tox_avahi {
 
     # install a command to obtain the Tox ID
     cd $INSTALL_DIR
-    git clone $TOXID_REPO $INSTALL_DIR/toxid
+    git_clone $TOXID_REPO $INSTALL_DIR/toxid
     if [ ! -d $INSTALL_DIR/toxid ]; then
         exit 63921
     fi
@@ -6948,7 +6966,7 @@ function install_tox_node {
     apt-get -y install libconfig9 libconfig-dev
 
     cd $INSTALL_DIR
-    git clone $TOX_REPO $INSTALL_DIR/toxcore
+    git_clone $TOX_REPO $INSTALL_DIR/toxcore
     cd $INSTALL_DIR/toxcore
 
     git checkout $TOX_COMMIT -b $TOX_COMMIT
@@ -7110,7 +7128,7 @@ function install_tox_client {
     apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev libcurl4-openssl-dev
 
     cd $INSTALL_DIR
-    git clone $TOXIC_REPO $INSTALL_DIR/toxic
+    git_clone $TOXIC_REPO $INSTALL_DIR/toxic
     cd $INSTALL_DIR/toxic
     git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT
     if ! grep -q "Toxic commit" $COMPLETION_FILE; then
@@ -7855,7 +7873,7 @@ function install_blog {
     fi
 
     cd /var/www/$FULLBLOG_DOMAIN_NAME
-    git clone $FULLBLOG_REPO htdocs
+    git_clone $FULLBLOG_REPO htdocs
     cd htdocs
     git checkout $FULLBLOG_COMMIT -b $FULLBLOG_COMMIT
     if ! grep -q "Blog commit" $COMPLETION_FILE; then
@@ -8240,7 +8258,7 @@ function install_gnu_social {
         mkdir /var/www/$MICROBLOG_DOMAIN_NAME
     fi
     if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
-        git clone $MICROBLOG_REPO /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
+        git_clone $MICROBLOG_REPO /var/www/$MICROBLOG_DOMAIN_NAME/htdocs
         if [ ! -d /var/www/$MICROBLOG_DOMAIN_NAME/htdocs ]; then
             echo $'Unable to clone gnusocial repo'
             exit 87525
@@ -8628,7 +8646,7 @@ function install_hubzilla {
 
     if [ ! -f /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/index.php ]; then
         cd $INSTALL_DIR
-        git clone $HUBZILLA_REPO hubzilla
+        git_clone $HUBZILLA_REPO hubzilla
         git checkout $HUBZILLA_COMMIT -b $HUBZILLA_COMMIT
         if ! grep -q "Hubzilla commit" $COMPLETION_FILE; then
             echo "Hubzilla commit:$HUBZILLA_COMMIT" >> $COMPLETION_FILE
@@ -8639,7 +8657,7 @@ function install_hubzilla {
         rm -rf /var/www/$HUBZILLA_DOMAIN_NAME/htdocs
         mv hubzilla /var/www/$HUBZILLA_DOMAIN_NAME/htdocs
 
-        git clone $HUBZILLA_ADDONS_REPO /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/addon
+        git_clone $HUBZILLA_ADDONS_REPO /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/addon
         cd /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/addon
         git checkout $HUBZILLA_ADDONS_COMMIT -b $HUBZILLA_ADDONS_COMMIT
         if ! grep -q "Hubzilla addons commit" $COMPLETION_FILE; then
@@ -8649,7 +8667,7 @@ function install_hubzilla {
         fi
 
         # some extra themes
-        git clone $HUBZILLA_THEMES_REPO /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/redmatrix-themes1
+        git_clone $HUBZILLA_THEMES_REPO /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/redmatrix-themes1
         cp -r /var/www/$HUBZILLA_DOMAIN_NAME/htdocs/redmatrix-themes1/* view/theme/
 
         chown -R www-data:www-data /var/www/$HUBZILLA_DOMAIN_NAME/htdocs
@@ -9470,7 +9488,7 @@ function install_dynamicdns {
     # https version 1.99.8
 
     apt-get -y install build-essential curl libgnutls28-dev automake1.11
-    git clone $INADYN_REPO $INSTALL_DIR/inadyn
+    git_clone $INADYN_REPO $INSTALL_DIR/inadyn
     if [ ! -d $INSTALL_DIR/inadyn ]; then
         echo 'inadyn repo not cloned'
         echo -n | openssl s_client -showcerts -connect github.com:443 -CApath /etc/ssl/certs
-- 
GitLab