From 257deb71d86412abde2488a04ed36035ff846e7d Mon Sep 17 00:00:00 2001
From: ArmandBahi <armand.bahi@veremes.com>
Date: Tue, 23 Oct 2018 16:53:57 +0200
Subject: [PATCH] Add utils for windows install

---
 utils/copy_hooks.bat   |  3 ++
 utils/get_deps.sh      | 23 +++++-----
 utils/init_tree.bat    | 99 ++++++++++++++++++++++++++++++++++++++++++
 utils/pull_subtrees.sh | 18 +-------
 utils/push_subtrees.sh |  8 +++-
 utils/update_tree.bat  | 80 ++++++++++++++++++++++++++++++++++
 6 files changed, 201 insertions(+), 30 deletions(-)
 create mode 100644 utils/copy_hooks.bat
 create mode 100644 utils/init_tree.bat
 create mode 100644 utils/update_tree.bat

diff --git a/utils/copy_hooks.bat b/utils/copy_hooks.bat
new file mode 100644
index 00000000..a24ac68b
--- /dev/null
+++ b/utils/copy_hooks.bat
@@ -0,0 +1,3 @@
+
+
+robocopy "githooks" "../.git/hooks" /E /NFL /NDL /NJH /NJS /nc /ns /np
diff --git a/utils/get_deps.sh b/utils/get_deps.sh
index 92b02739..0a26177f 100755
--- a/utils/get_deps.sh
+++ b/utils/get_deps.sh
@@ -1,24 +1,23 @@
 #!/bin/bash
 #
 #	Récupère l'ensemble des dépendances depuis conf/_install/dependency.xml
-#	Nécessite xmllint : sudo apt install libxml2-utils
 #
 #
 #
 #
 
-
 if [ "../conf/_install/dependency.xml" ]; then
 
-	let depsCount=$(xmllint --xpath 'count(//dependenciesCollection/dependency/name)' ../conf/_install/dependency.xml)
 	declare -A aDeps
 	vitisVersion=master
+	depsCount=0
+	dependencies=($(cat "../conf/_install/dependency.xml" | tr -d '\040\011\012\015' | grep -oP '<dependency>([\s\S]*?)<\/dependency>'))
 
-	for (( i=1; i <= $depsCount; i++ )); do
+	for i in ${!dependencies[*]}; do
 
-		sName="$(xmllint --xpath 'string(//dependenciesCollection/dependency['$i']/name)' ../conf/_install/dependency.xml)"
-		sVersion="$(xmllint --xpath 'string(//dependenciesCollection/dependency['$i']/version)' ../conf/_install/dependency.xml)"
-		sNature="$(xmllint --xpath 'string(//dependenciesCollection/dependency['$i']/nature)' ../conf/_install/dependency.xml)"
+		sName=$(grep -oP '(?<=name>)[^<]+' <<< ${dependencies[$i]})
+		sVersion=$(grep -oP '(?<=version>)[^<]+' <<< ${dependencies[$i]})
+		sNature=$(grep -oP '(?<=nature>)[^<]+' <<< ${dependencies[$i]})
 
 		if [ $sName == "vitis" ]; then
 			vitisVersion=$sVersion
@@ -27,22 +26,22 @@ if [ "../conf/_install/dependency.xml" ]; then
 			aDeps[$i, name]=$sName
 			aDeps[$i, version]=$sVersion
 			aDeps[$i, nature]=$sNature
+			let depsCount++
 		fi
 
 	done
 
 	echo "[INFO] dependencies:"
 	echo "vitis : $vitisVersion"
-	for (( i=1; i <= $depsCount; i++ )); do
-
-		echo "name: ${aDeps[$i, name]}"
-		echo "version: ${aDeps[$i, version]}"
-
+	for i in ${!dependencies[*]}; do
+		echo "(${aDeps[$i, nature]}) ${aDeps[$i, name]} : ${aDeps[$i, version]}"
 	done
+	echo "depsCount : ${depsCount}"
 
 	export vitisVersion
 	export depsCount
 	export aDeps
+
 else
 	echo "[ERROR] ../conf/_install/dependency.xml not found"
 fi
diff --git a/utils/init_tree.bat b/utils/init_tree.bat
new file mode 100644
index 00000000..d8e6956c
--- /dev/null
+++ b/utils/init_tree.bat
@@ -0,0 +1,99 @@
+@echo off
+title Install Vitis App
+setlocal EnableDelayedExpansion
+
+cd ..
+
+set /p existing_path="Existing app path: "
+
+REM Client Dir
+echo Create client directory
+if exist "client" (
+  rmdir /S /Q "client"
+)
+echo copy client
+robocopy "src/vitis/client" "client" /E /NFL /NDL /NJH /NJS /nc /ns /np
+echo copy client/conf
+robocopy "conf" "client/conf" /E /NFL /NDL /NJH /NJS /nc /ns /np
+echo copy client/conf/closure
+robocopy "src/closure/conf" "client/conf/closure" /E /NFL /NDL /NJH /NJS /nc /ns /np
+
+echo Copy client modules
+for /d %%g in ("src/module_*") do (
+  set x=%%g
+  echo !x:~7!
+  if exist "src/%%g/module" (
+    echo copy client/modules/!x:~7!
+    robocopy "src/%%g/module" "client/modules/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+)
+
+REM VAS dir
+echo Create vas directory
+echo Create client directory
+if exist "vas" (
+  rmdir /S /Q "vas"
+)
+echo copy vas
+robocopy "src/vitis/vas" "vas" /E /NFL /NDL /NJH /NJS /nc /ns /np
+
+echo Copy vas web_services
+for /d %%g in ("src/module_*") do (
+  set x=%%g
+  echo !x:~7!
+  if exist "src/%%g/web_service/conf" (
+    echo copy vas/rest/conf/!x:~7!
+    robocopy "src/%%g/web_service/conf" "vas/rest/conf/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "src/%%g/web_service/sql" (
+    echo copy vas/sql/!x:~7!
+    robocopy "src/%%g/web_service/sql" "vas/sql/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "src/%%g/web_service/ws" (
+    echo copy vas/rest/ws/!x:~7!
+    robocopy "src/%%g/web_service/ws" "vas/rest/ws/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "src/%%g/web_service/class" (
+    echo copy vas/rest/class
+    robocopy "src/%%g/web_service/class" "vas/rest/class" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "src/%%g/web_service/ws_data" (
+    echo copy vas/ws_data
+    robocopy "src/%%g/web_service/ws_data" "vas/ws_data" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "src/%%g/web_service/public" (
+    echo copy vas/public
+    robocopy "src/%%g/web_service/public" "vas/public" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "src/%%g/web_service/upload" (
+    echo copy vas/upload
+    robocopy "src/%%g/web_service/upload" "vas/upload" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+)
+
+REM Copy from existing path
+if exist %existing_path% (
+  echo copy properties from %existing_path%
+
+  for %%G in (vas\server,vas\rest\conf,vas\log,vas\public,vas\shared,vas\tmp,vas\upload,vas\ws_data) do (
+    echo %%G
+    if exist %existing_path%\%%G (
+      echo copy %%G
+      robocopy "%existing_path%\%%G" "%%G" /E /NFL /NDL /NJH /NJS /nc /ns /np
+    )
+  )
+
+  if exist %existing_path%\client\conf\properties.json (
+    echo copy properties.json
+    robocopy "%existing_path%\client\conf" "client\conf" "properties.json" /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist %existing_path%\vas\rest\.htaccess (
+    echo copy .htaccess
+    robocopy "%existing_path%\vas\rest" "vas\rest" ".htaccess" /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+
+  if exist "%existing_path%\vas\rest\conf" (
+    echo copy vas\rest\conf
+    robocopy "%existing_path%\vas\rest\conf" "vas\rest\conf" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+)
diff --git a/utils/pull_subtrees.sh b/utils/pull_subtrees.sh
index c2793f2e..5cac1ba0 100755
--- a/utils/pull_subtrees.sh
+++ b/utils/pull_subtrees.sh
@@ -17,17 +17,7 @@ cd ..
 
 # Vitis
 echo "---- Pull vitis ----"
-git subtree pull --prefix src/vitis --squash -m "pull subtree"  "git@gitlab.veremes.net:Development/vitis_apps/sources/vitis.git" master
-
-# fichiers à ignorer
-git update-index --assume-unchanged conf/properties.json
-git update-index --assume-unchanged conf/package.json
-git update-index --assume-unchanged src/vitis/vas/rest/.htaccess
-git update-index --assume-unchanged src/vitis/vas/rest/conf/properties.inc
-git update-index --assume-unchanged src/vitis/vas/rest/conf/properties_domain.inc
-git update-index --assume-unchanged src/vitis/vas/rest/conf/properties_post.inc
-git update-index --assume-unchanged src/vitis/vas/rest/conf/properties_server.inc
-git update-index --assume-unchanged src/vitis/vas/rest/conf/version.inc
+git subtree pull --prefix src/vitis --squash -m "pull subtree"  "git@gitlab.veremes.net:Development/vitis_apps/sources/vitis.git" $vitisVersion
 
 # Modules
 if [[ $depsCount > 0 ]]; then
@@ -36,11 +26,7 @@ if [[ $depsCount > 0 ]]; then
 			echo "---- Pull ${aDeps[$i, name]} ----"
 
 			# Ajoute le dépôt
-			git subtree pull --prefix src/${aDeps[$i, name]} --squash -m "pull subtree" "git@gitlab.veremes.net:Development/vitis_apps/sources/${aDeps[$i, name]}.git" master
-			# fichiers à ignorer
-			git update-index --assume-unchanged src/${aDeps[$i, name]}/web_service/conf/properties.inc
-			git update-index --assume-unchanged src/${aDeps[$i, name]}/web_service/conf/properties_server.inc
-			git update-index --assume-unchanged src/${aDeps[$i, name]}/web_service/conf/version.inc
+			git subtree pull --prefix src/${aDeps[$i, name]} --squash -m "pull subtree" "git@gitlab.veremes.net:Development/vitis_apps/sources/${aDeps[$i, name]}.git" ${aDeps[$i, version]}
 		fi
 	done
 fi
diff --git a/utils/push_subtrees.sh b/utils/push_subtrees.sh
index b4949ea2..18a9d3bd 100755
--- a/utils/push_subtrees.sh
+++ b/utils/push_subtrees.sh
@@ -17,7 +17,11 @@ cd ..
 
 # Vitis
 echo "---- Push vitis ----"
-git subtree push --prefix src/vitis "git@gitlab.veremes.net:Development/vitis_apps/sources/vitis.git" master
+{ # 'try' block
+	git subtree push --prefix src/vitis "git@gitlab.veremes.net:Development/vitis_apps/sources/vitis.git" $vitisVersion
+} || { # 'catch' block
+	echo "could not push vitis"
+}
 
 # Modules
 if [[ $depsCount > 0 ]]; then
@@ -28,7 +32,7 @@ if [[ $depsCount > 0 ]]; then
 			# Push le dépôt
 
 			{ # 'try' block
-				git subtree push --prefix src/${aDeps[$i, name]} "git@gitlab.veremes.net:Development/vitis_apps/sources/${aDeps[$i, name]}.git" master
+				git subtree push --prefix src/${aDeps[$i, name]} "git@gitlab.veremes.net:Development/vitis_apps/sources/${aDeps[$i, name]}.git" ${aDeps[$i, version]}
 			} || { # 'catch' block
 			    echo "could not push ${aDeps[$i, name]}"
 			}
diff --git a/utils/update_tree.bat b/utils/update_tree.bat
new file mode 100644
index 00000000..3c3c5dc3
--- /dev/null
+++ b/utils/update_tree.bat
@@ -0,0 +1,80 @@
+@echo off
+title Update Vitis tree
+echo Update Vitis tree
+setlocal EnableDelayedExpansion
+
+cd utils
+
+REM Pull repo
+"C:\Program Files\Git\bin\sh.exe" --login -i -c "git pull"
+
+REM Pull subtrees
+"C:\Program Files\Git\bin\sh.exe" --login -i -c "./pull_subtrees.sh"
+
+REM Save important files
+if exist "../vas/rest/sql" (
+  robocopy "../vas/rest/sql" "../vas/rest/sql_bak" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+if exist "../vas/rest/conf" (
+  robocopy "../vas/rest/conf" "../vas/rest/conf_bak" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+
+REM Replace Vitis files
+for /d %%g in ("../src/vitis/client/*") do (
+  set x=%%g
+  echo copy client/!x!
+  rmdir /S /Q "../client/!x!"
+  robocopy "../src/vitis/client/!x!" "../client/!x!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+for /d %%g in ("../src/vitis/vas/sql") do (
+  echo copy vas/sql
+  rmdir /S /Q "../vas/sql"
+  robocopy "../src/vitis/vas/sql" "../vas/sql" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+for /d %%g in ("../src/vitis/vas/rest/class") do (
+  echo copy vas/rest/class
+  rmdir /S /Q "../vas/rest/class"
+  robocopy "../src/vitis/vas/rest/class" "../vas/rest/class" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+for /d %%g in ("../src/vitis/vas/rest/conf") do (
+  echo copy vas/rest/conf
+  robocopy "../src/vitis/vas/rest/conf" "../vas/rest/conf_veremes" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+for /d %%g in ("../src/vitis/vas/rest/inc") do (
+  echo copy vas/rest/inc
+  rmdir /S /Q "../vas/rest/inc"
+  robocopy "../src/vitis/vas/rest/inc" "../vas/rest/inc" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+for /d %%g in ("../src/vitis/vas/rest/ws") do (
+  echo copy vas/rest/ws
+  rmdir /S /Q "../vas/rest/ws"
+  robocopy "../src/vitis/vas/rest/ws" "../vas/rest/ws" /E /NFL /NDL /NJH /NJS /nc /ns /np
+)
+
+REM Replace modules files
+for /d %%g in ("../src/module_*") do (
+  set x=%%g
+  if exist "../src/%%g/module" (
+    echo copy client/modules/!x:~7!
+    robocopy "../src/%%g/module" "../client/modules/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "../src/%%g/web_service/conf" (
+    echo copy vas/rest/conf_veremes/!x:~7!
+    robocopy "../src/%%g/web_service/conf" "../vas/rest/conf_veremes/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "../src/%%g/web_service/sql" (
+    echo copy vas/sql/!x:~7!
+    robocopy "../src/%%g/web_service/sql" "../vas/sql/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "../src/%%g/web_service/ws" (
+    echo copy vas/rest/ws/!x:~7!
+    robocopy "../src/%%g/web_service/ws" "../vas/rest/ws/!x:~7!" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+  if exist "../src/%%g/web_service/class" (
+    echo copy vas/rest/class
+    robocopy "../src/%%g/web_service/class" "../vas/rest/class" /E /NFL /NDL /NJH /NJS /nc /ns /np
+  )
+)
+
+
+cd ..
-- 
GitLab