From cef3a2ef7e628d0552a16eb6606088687ecc0f7a Mon Sep 17 00:00:00 2001
From: PavelBegunkov <asml.silence@gmail.com>
Date: Tue, 1 Sep 2015 08:34:43 +0300
Subject: [PATCH] deploy scripts mod

---
 .gitignore                                |  1 +
 Makefile                                  |  4 +-
 db/Makefile                               | 59 ++++++++++++++++++++---
 deploy/config/db.makefile                 |  5 ++
 {config => deploy/phpConfig}/database.php |  0
 {config => deploy/phpConfig}/general.json |  0
 {config => deploy/phpConfig}/menu.json    |  0
 {config => deploy/phpConfig}/security.php |  0
 {config => deploy/phpConfig}/session.php  |  0
 {config => deploy/phpConfig}/twig.php     |  0
 deploy/scripts/copy.sh                    |  3 +-
 deploy/scripts/deploy.sh                  | 30 ------------
 deploy/scripts/deploy_release.sh          | 21 ++++----
 deploy/scripts/install.sh                 | 30 ------------
 deploy/scripts/load_and_copy.sh           | 20 ++------
 deploy/scripts/update.sh                  | 13 ++---
 gulpfile.js                               |  2 +-
 ~dev_rating/static/other/teachers.txt     | 19 --------
 18 files changed, 81 insertions(+), 126 deletions(-)
 create mode 100644 deploy/config/db.makefile
 rename {config => deploy/phpConfig}/database.php (100%)
 rename {config => deploy/phpConfig}/general.json (100%)
 rename {config => deploy/phpConfig}/menu.json (100%)
 rename {config => deploy/phpConfig}/security.php (100%)
 rename {config => deploy/phpConfig}/session.php (100%)
 rename {config => deploy/phpConfig}/twig.php (100%)
 delete mode 100644 deploy/scripts/deploy.sh
 delete mode 100644 deploy/scripts/install.sh
 delete mode 100644 ~dev_rating/static/other/teachers.txt

diff --git a/.gitignore b/.gitignore
index cae239447..32e87f4d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ db/disciplines activity.sql
 !~dev_rating/static/img/
 !~dev_rating/static/other/
 node_modules/
+/config
 
 *.*~
 *.DS_STORE
diff --git a/Makefile b/Makefile
index 0953bd185..1ea73c485 100644
--- a/Makefile
+++ b/Makefile
@@ -2,15 +2,15 @@ default: deploy
 	@
 
 
-install: DB_install Tasker_install Tasker_run
+install: DB_install Tasker_install
 	@
 
 deploy: DB_deploy Tasker_deploy Tasker_run
 	@
 
 
-
 Tasker_install: Tasker_deploy
+	gulp install
 	@
 
 Tasker_deploy:
diff --git a/db/Makefile b/db/Makefile
index 28e2f4596..a41ffdd8c 100644
--- a/db/Makefile
+++ b/db/Makefile
@@ -2,10 +2,38 @@ define GET_NAMES
 $(subst .sql, , $(wildcard $1/*.sql))
 endef
 
+CONFIG_PATH = ../config/db.makefile
+include $(CONFIG_PATH)
+
+
+ifeq ($(LOGIN),)
+	LOGIN := $(shell bash -c 'read -p "DB Username: " login; echo $$login')
+endif
+ifeq ($(PASS),)
+	PASS := $(shell bash -c 'read -s -p "DB Password: " pwd; echo $$pwd')
+endif
+ifeq ($(DB),)
+	DB := $(shell bash -c 'read -p "Database: " db; echo $$db')
+endif
+
+default: deploy
+	@
+
+
+FLAGS := -u $(LOGIN)
+ifneq ($(PASS),)
+	ifneq ($(PASS),"")
+		FLAGS += --password=$(PASS)
+	endif
+endif
+ifneq ($(PORT),)
+	FLAGS += --port=$(PORT)
+endif
+ifneq ($(HOST),)
+	FLAGS += --host=$(HOST)
+endif
+
 
-USER := $(shell bash -c 'read -p "Username: " username; echo $$username')
-PASS := $(shell bash -c 'read -s -p "Password: " pwd; echo $$pwd')
-DB := mmcs_rating
 
 default: deploy
 	@
@@ -22,11 +50,30 @@ deploy: $(call GET_NAMES, stored)
 	@
 
 clear:
-	yes | mysqladmin -u $(USER) $(PASS) drop $(DB) || true
-	mysqladmin -u $(USER) $(PASS) create $(DB);
+	@yes | mysqladmin $(FLAGS) drop $(DB) || true
+	@mysqladmin $(FLAGS) create $(DB);
 
 
 %:
-	mysql -u $(USER) $(PASS) $(DB) < $@.sql
+	@mysql $(FLAGS) $(DB) < $@.sql
+	@echo $@.sql
 
 
+
+deploy_test: \
+clear \
+../../mmcs_rating \
+fix \
+deploy \
+hideData
+
+update: \
+deploy \
+fix
+
+
+fix: $(call GET_NAMES, fixes)
+	@
+
+hideData:
+	@ echo "UPDATE accounts SET Password = sha1('11111'), ActivationCode= null, EMail= null" | mysql $(FLAGS) $(DB)
diff --git a/deploy/config/db.makefile b/deploy/config/db.makefile
new file mode 100644
index 000000000..0f1a070ec
--- /dev/null
+++ b/deploy/config/db.makefile
@@ -0,0 +1,5 @@
+# LOGIN = root
+# PASS = ""
+# DB = accounting_system
+# PORT = 3306
+# HOST = 127.0.0.1
diff --git a/config/database.php b/deploy/phpConfig/database.php
similarity index 100%
rename from config/database.php
rename to deploy/phpConfig/database.php
diff --git a/config/general.json b/deploy/phpConfig/general.json
similarity index 100%
rename from config/general.json
rename to deploy/phpConfig/general.json
diff --git a/config/menu.json b/deploy/phpConfig/menu.json
similarity index 100%
rename from config/menu.json
rename to deploy/phpConfig/menu.json
diff --git a/config/security.php b/deploy/phpConfig/security.php
similarity index 100%
rename from config/security.php
rename to deploy/phpConfig/security.php
diff --git a/config/session.php b/deploy/phpConfig/session.php
similarity index 100%
rename from config/session.php
rename to deploy/phpConfig/session.php
diff --git a/config/twig.php b/deploy/phpConfig/twig.php
similarity index 100%
rename from config/twig.php
rename to deploy/phpConfig/twig.php
diff --git a/deploy/scripts/copy.sh b/deploy/scripts/copy.sh
index 2f3f823bc..cba180e70 100644
--- a/deploy/scripts/copy.sh
+++ b/deploy/scripts/copy.sh
@@ -10,7 +10,7 @@ fi
 if [ -z $2 ] || ![ -d $2 ]
 then
   d=~/public_html/
-else  
+else
   d=$2
 fi
 
@@ -22,4 +22,3 @@ cd ..
 # old copy       cp -rp ${s}~dev_rating/* $d
 rsync -ru --exclude="java" ${s}~dev_rating/ $d/
 cp ${s}~dev_rating/.htaccess ${d}/.htaccess
-rm -rf ${d}/application/config
diff --git a/deploy/scripts/deploy.sh b/deploy/scripts/deploy.sh
deleted file mode 100644
index b38fc5ff6..000000000
--- a/deploy/scripts/deploy.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#source
-if [ -z $1 ] || ![ -d $1 ]
-then
-  s=~/grade-rating/
-else
-  s=$1
-fi
-
-#destination
-if [ -z $2 ] || ![ -d $2 ]
-then
-  d=~/public_html/
-else  
-  d=$2
-fi
-
-#shopt -s dotglob
-cp -rp ${s}~dev_rating/* $d
-cp ${s}~dev_rating/.htaccess ${d}/.htaccess
-rm -rf ${d}/application/config
-
-echo -n "Enter password for mysql user 'mmcs_rating': "
-read -s mysqlpswd
-echo ""
-yes | mysqladmin -u mmcs_rating -p$mysqlpswd drop mmcs_rating
-mysqladmin -u mmcs_rating -p$mysqlpswd create mmcs_rating
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/Structure.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/StoredProcedures.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/Sample.sql
-
diff --git a/deploy/scripts/deploy_release.sh b/deploy/scripts/deploy_release.sh
index 244f8e89e..08d72584e 100644
--- a/deploy/scripts/deploy_release.sh
+++ b/deploy/scripts/deploy_release.sh
@@ -10,25 +10,24 @@ fi
 if [ -z $2 ] || ![ -d $2 ]
 then
   d=~/data/
-else  
+else
   d=$2
 fi
 
 #shopt -s dotglob
+rm -rf ${s}~dev_rating/application/config
+rm -rf ${s}~dev_rating/application/news.md
+rm -rf ${s}~dev_rating/application/updates.md
 cp -rp ${s}~dev_rating/* $d
 cp ${s}~dev_rating/.htaccess ${d}/.htaccess
-rm -rf ${d}/application/config
 
-echo -n "Enter password for mysql user 'mmcs_rating': "
-read -s mysqlpswd
-echo ""
-yes | mysqladmin -u mmcs_rating -p$mysqlpswd drop mmcs_rating
-mysqladmin -u mmcs_rating -p$mysqlpswd create mmcs_rating
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/Structure.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/StoredProcedures.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/release_gen_mmcs_sg.sql
+
+cd ${s}/db
+make deploy
+cd ../../
+
 
 sed -i 's/~dev_rating//g' ${d}.htaccess
 sed -i 's/\/~dev_rating//g' ${d}application/bootstrap.php
 sed -i 's/\/~dev_rating//g' ${d}media/js/config.js
-chmod u=rwx,g=rx,o=r ./data/index.php
\ No newline at end of file
+chmod u=rwx,g=rx,o=r ./data/index.php
diff --git a/deploy/scripts/install.sh b/deploy/scripts/install.sh
deleted file mode 100644
index 007130ea0..000000000
--- a/deploy/scripts/install.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#p - production
-#s - sandbox
-if [ -z $1 ]
-then
-  s='s'
-else
-  s=$1
-fi
-
-if [ $s != 's' ] && [ $s != 'p' ]
-then
-  exit
-fi
-
-if [ $s = 's' ]
-then
-  dep_script=deploy.sh
-fi
-
-if [ $s = 'p' ]
-then
-  dep_script=deploy_release.sh
-fi
-
-rm -rf ~/grade-rating/
-git clone http://itlab.mmcs.sfedu.ru/git/grade-rating ~/grade-rating/
-cp ~/grade-rating/${dep_script} ./${dep_script}
-chmod +x ./${dep_script}
-./${dep_script}
-
diff --git a/deploy/scripts/load_and_copy.sh b/deploy/scripts/load_and_copy.sh
index 6cc8634db..70d975843 100644
--- a/deploy/scripts/load_and_copy.sh
+++ b/deploy/scripts/load_and_copy.sh
@@ -10,24 +10,12 @@ fi
 if [ -z $2 ] || ![ -d $2 ]
 then
   d=~/public_html/
-else  
+else
   d=$2
 fi
 
 ./copy.sh ${s} ${d}
 
-echo -n "Enter password for mysql user 'mmcs_rating': "
-read -s mysqlpswd
-echo ""
-yes | mysqladmin -u mmcs_rating -p$mysqlpswd drop mmcs_rating
-mysqladmin -u mmcs_rating -p$mysqlpswd create mmcs_rating
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ./mmcs_rating.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/fix.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/Views.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/StoredFunctions.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/StoredProcedures.sql
-
-echo "UPDATE accounts SET Password = sha1('11111')" | mysql -u mmcs_rating -p$mysqlpswd mmcs_rating
-echo "UPDATE accounts SET ActivationCode= null" | mysql -u mmcs_rating -p$mysqlpswd mmcs_rating
-echo "UPDATE accounts SET EMail= null" | mysql -u mmcs_rating -p$mysqlpswd mmcs_rating
-
+cd ${s}/db
+make deploy_test
+cd ../../
diff --git a/deploy/scripts/update.sh b/deploy/scripts/update.sh
index e34dfcd0c..78b2785b7 100644
--- a/deploy/scripts/update.sh
+++ b/deploy/scripts/update.sh
@@ -10,17 +10,12 @@ fi
 if [ -z $2 ] || ![ -d $2 ]
 then
   d=~/public_html/
-else  
+else
   d=$2
 fi
 
 ./copy.sh ${s} ${d}
 
-echo -n "Enter password for mysql user 'mmcs_rating': "
-read -s mysqlpswd
-echo ""
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/fix.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/Views.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/StoredProcedures.sql
-mysql -u mmcs_rating -p$mysqlpswd mmcs_rating < ${s}db/StoredFunctions.sql
-
+cd ${s}/db
+make update
+cd ../../
diff --git a/gulpfile.js b/gulpfile.js
index 6cc35efac..068c7c6f1 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -52,7 +52,7 @@ var paths = new (function () {
         css: media + '/css/**/*.css',
         less: media + '/less/**/*.less',
         js: media + '/js/**/*.js',
-        config: self.root + '/config/*',
+        config: self.root + '/deploy/phpConfig/*',
         css_components: media + '/components/**/*.css',
         js_components: media + '/components/**/*.js'
     };
diff --git a/~dev_rating/static/other/teachers.txt b/~dev_rating/static/other/teachers.txt
deleted file mode 100644
index f470b234a..000000000
--- a/~dev_rating/static/other/teachers.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-Кафедра Алгебры и Дискретной Математики
-
-Штейнберг Роман Борисович
-Стребежев Игорь Алексеевич
-Бегунков Павел
-
-
-Кафедра Информатики и Вычислительного Эксперимента
-
-Брагилевский Виталий Николаевич
-Пеленицын Артём Михайлович
-Сенченко Наталья Николаевна
-
-
-Без кафедры
-
-Энакин Скайуокер
-Оби-Ван Кеноби
-Мастер Йода
-- 
GitLab