Commit 727d09f4 authored by Penom Nom's avatar Penom Nom
Browse files

No commit message

No commit message
parent 24be62e5
...@@ -14,49 +14,34 @@ ...@@ -14,49 +14,34 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import tempfile, os, sys, re, logging
from jflow.workflow import Workflow from jflow.workflow import Workflow
import tempfile, os, sys, logging
from ng6.config_reader import NG6ConfigReader from ng6.config_reader import NG6ConfigReader
from os.path import expanduser
class Install (Workflow): class Install (Workflow):
def process(self): def process(self):
# typo3 variables #typo3 variables
ng6conf = NG6ConfigReader() ng6conf = NG6ConfigReader()
db_host, db_user, db_password, db_name = ng6conf.get_typo3_db_params() [db_host, db_user, db_password, db_name] = ng6conf.get_typo3_db_params()
db_tmp_name=db_name db_tmp_name=db_name
suffix_db = 1
# TODO: a modifier ce n'est pas jolie, utilise la path du file, tu le fera en 1 ligne!!
if "/".join(sys.argv[0].split("/")[:-2])[0] != "/":
ng6_path = str(os.getcwd()) + "/" +"/".join(sys.argv[0].split("/")[:-2])
else:
ng6_path = "/".join(sys.argv[0].split("/")[:-2])
# TODO: utililse os.path.join !!! ca c'est sous unix ... ng6_path = os.path.join(os.getcwd(), sys.argv[0])[:-2] if "/".join(sys.argv[0].split("/"))[0] != "/" else "/".join(sys.argv[0].split("/")[:-2])
db_path = ng6_path +"/workflows/install/data_typo3/database.sql"
# TODO: web_dir doit etre un parametre db_path = os.path.join(ng6_path,"workflows/install/data_typo3/database.sql")
web_dir="/var/www" web_dir= self.args["web_dir"]
save_data_path = NG6ConfigReader().get_save_directory()+"/data" save_data_path = NG6ConfigReader().get_save_directory()+"/data"
unzip_binary_path=""
install_tool_password ="typo3" install_tool_password ="typo3"
# install_tool_password_hash =""
# wget # wget
dummy_tmp = tempfile.NamedTemporaryFile(prefix = 'dummy_', suffix = '.zip').name dummy_tmp = tempfile.NamedTemporaryFile(prefix = 'dummy_', suffix = '.zip').name
# TODO: j'ai mis le nom dans le .properties d'application c'est une ressource
wget = ["wget", "--output-document", dummy_tmp, self.get_resource("typo3_src")] wget = ["wget", "--output-document", dummy_tmp, self.get_resource("typo3_src")]
p = Popen(wget, stdout=PIPE, stderr=PIPE) p = Popen(wget, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
# unzip # unzip
dummy_tmp_dir = tempfile.mkdtemp(suffix='_typo3', prefix='dummy_') dummy_tmp_dir = tempfile.mkdtemp(suffix='_typo3', prefix='dummy_')
unzip = ["unzip", dummy_tmp, "-d", dummy_tmp_dir] unzip = ["unzip", dummy_tmp, "-d", dummy_tmp_dir]
...@@ -65,33 +50,32 @@ class Install (Workflow): ...@@ -65,33 +50,32 @@ class Install (Workflow):
#rename typo3 folder #rename typo3 folder
typo3_dir = os.listdir(dummy_tmp_dir)[0] typo3_dir = os.listdir(dummy_tmp_dir)[0]
# TODO: c'est quoi ce ng62 ?? rename=["mv", dummy_tmp_dir+"/"+typo3_dir, dummy_tmp_dir+"/ng6"]
rename=["mv", dummy_tmp_dir+"/"+typo3_dir, dummy_tmp_dir+"/ng62"]
p = Popen(rename, stdout=PIPE, stderr=PIPE) p = Popen(rename, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
#link ng6 folder #cp ng6 folders
# TODO: ne fait pas des links mais des cp slink_ext=["cp", "-rf", os.path.join(ng6_path, "ui/nG6"), os.path.join(dummy_tmp_dir, "ng6/typo3conf/ext/nG6")]
slink_ext=["ln","-s", ng6_path+"/ui/nG6", dummy_tmp_dir+"/ng62/typo3conf/ext/nG6"]
p = Popen(slink_ext, stdout=PIPE, stderr=PIPE) p = Popen(slink_ext, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
print stderr
mkdir_templ=["mkdir", dummy_tmp_dir+"/ng62/fileadmin/templates"] mkdir_templ=["mkdir", os.path.join(dummy_tmp_dir, "ng6/fileadmin/templates")]
p = Popen(mkdir_templ, stdout=PIPE, stderr=PIPE) p = Popen(mkdir_templ, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
slink_templ=["ln","-s", ng6_path +"/ui/nG6template", dummy_tmp_dir+"/ng62/fileadmin/templates/nG6template"] slink_templ=["cp", "-rf", os.path.join(ng6_path, "ui/nG6template"), os.path.join(dummy_tmp_dir, "ng6/fileadmin/templates/nG6template")]
p = Popen(slink_templ, stdout=PIPE, stderr=PIPE) p = Popen(slink_templ, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
slink_data=["ln","-s", save_data_path, dummy_tmp_dir+"/ng62/fileadmin/data"] slink_data=["cp", "-rf", save_data_path, os.path.join(dummy_tmp_dir, "ng6/fileadmin/data")]
p = Popen(slink_data, stdout=PIPE, stderr=PIPE) p = Popen(slink_data, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
#create config file #create config file
with open(dummy_tmp_dir+'/ng62/typo3conf/localconf.php') as f: with open(dummy_tmp_dir+'/ng6/typo3conf/localconf.php') as f:
config_lines= ''.join(f.readlines()[:-1]) config_lines= ''.join(f.readlines()[:-1])
with open(dummy_tmp_dir+'/ng62/typo3conf/localconf.php',"w") as f: with open(dummy_tmp_dir+'/ng6/typo3conf/localconf.php',"w") as f:
f.write(config_lines) f.write(config_lines)
#Set config variables for typo3 #Set config variables for typo3
f.write("$TYPO3_CONF_VARS['EXT']['extList'] = 'extbase,css_styled_content,info,perm,func,filelist,fluid,about,version,tsconfig_help,context_help,extra_page_cm_options,impexp,sys_note,tstemplate,tstemplate_ceditor,tstemplate_info,tstemplate_objbrowser,tstemplate_analyzer,func_wizards,wizard_crpages,wizard_sortpages,lowlevel,install,belog,beuser,aboutmodules,setup,taskcenter,info_pagetsconfig,viewpage,rtehtmlarea,t3skin,t3editor,reports,felogin,form,rsaauth,saltedpasswords,nG6';\n") f.write("$TYPO3_CONF_VARS['EXT']['extList'] = 'extbase,css_styled_content,info,perm,func,filelist,fluid,about,version,tsconfig_help,context_help,extra_page_cm_options,impexp,sys_note,tstemplate,tstemplate_ceditor,tstemplate_info,tstemplate_objbrowser,tstemplate_analyzer,func_wizards,wizard_crpages,wizard_sortpages,lowlevel,install,belog,beuser,aboutmodules,setup,taskcenter,info_pagetsconfig,viewpage,rtehtmlarea,t3skin,t3editor,reports,felogin,form,rsaauth,saltedpasswords,nG6';\n")
...@@ -106,14 +90,14 @@ class Install (Workflow): ...@@ -106,14 +90,14 @@ class Install (Workflow):
f.write("$TYPO3_CONF_VARS['BE']['disable_exec_function'] = '0';\n") f.write("$TYPO3_CONF_VARS['BE']['disable_exec_function'] = '0';\n")
f.write("$TYPO3_CONF_VARS['GFX']['gdlib_png'] = '0';\n") f.write("$TYPO3_CONF_VARS['GFX']['gdlib_png'] = '0';\n")
f.write("$TYPO3_CONF_VARS['GFX']['im_combine_filename'] = 'composite';\n") f.write("$TYPO3_CONF_VARS['GFX']['im_combine_filename'] = 'composite';\n")
# hash du password typo3 # Typo3 password hash
p1 = Popen(["echo", "-n", install_tool_password], stdout=PIPE, stderr=PIPE) p1 = Popen(["echo", "-n", install_tool_password], stdout=PIPE, stderr=PIPE)
p2 = Popen(["md5sum"], stdin=p1.stdout, stdout=PIPE) p2 = Popen(["md5sum"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0] output = p2.communicate()[0]
install_tool_password_hash = output.split(" ")[0] install_tool_password_hash = output.split(" ")[0]
f.write("$TYPO3_CONF_VARS['BE']['installToolPassword'] = '" + install_tool_password_hash + "';\n") f.write("$TYPO3_CONF_VARS['BE']['installToolPassword'] = '" + install_tool_password_hash + "';\n")
#test de presence unzip binary puis : #Testing unzip binary path :
unzip_path=["which","unzip"] unzip_path=["which","unzip"]
p = Popen(unzip_path, stdout=PIPE, stderr=PIPE) p = Popen(unzip_path, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
...@@ -121,46 +105,38 @@ class Install (Workflow): ...@@ -121,46 +105,38 @@ class Install (Workflow):
f.write("?>\n") f.write("?>\n")
# Enable install tool # Enable install tool
install_file = ["touch", dummy_tmp_dir+'/ng62/typo3conf/ENABLE_INSTALL_TOOL'] install_file = ["touch", os.path.join(dummy_tmp_dir, "ng6/typo3conf/ENABLE_INSTALL_TOOL")]
p = Popen(install_file, stdout=PIPE, stderr=PIPE) p = Popen(install_file, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if stderr != "":
#Checking if database name already exists logging.getLogger("Install.process").error(stderr)
mysql_check_db= ["mysql", "--host=" + db_host, "--user=" + db_user, "--password=" + db_password, "-e", "SHOW DATABASES LIKE '" + db_name + "';" ]
p_mysql_check_db = Popen(mysql_check_db, stdout=PIPE, stderr=PIPE)
stdout, stderr = p_mysql_check_db.communicate()
#Searching available name for typo3 database
while stdout != "":
db_tmp_name=db_name+"_"+str(suffix_db)
mysql_check_db= ["mysql", "--host=" + db_host, "--user=" + db_user, "--password=" + db_password, "-e", "SHOW DATABASES LIKE '" + db_tmp_name + "';" ]
p_mysql_check_db = Popen(mysql_check_db, stdout=PIPE, stderr=PIPE)
stdout, stderr = p_mysql_check_db.communicate()
# TODO: c'est quoi ce suffix_db ?
suffix_db = suffix_db+1
#Creating database typo3 #Creating database typo3
db_name=db_tmp_name
mysql_create_db = ["mysql", "--host=" + db_host, "--user=" + db_user, "--password=" + db_password, "-e", "CREATE DATABASE " + db_name + ";"] mysql_create_db = ["mysql", "--host=" + db_host, "--user=" + db_user, "--password=" + db_password, "-e", "CREATE DATABASE " + db_name + ";"]
p = Popen(mysql_create_db, stdout=PIPE, stderr=PIPE) p = Popen(mysql_create_db, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if stderr != "":
logging.getLogger("Install.process").error(stderr)
#Inserting tables in typo3 database #Inserting tables in typo3 database
mysql_tables = ["mysql", "--host=" + db_host, "--user=" + db_user, "--password=" + db_password, "--default-character-set=utf8", "--database=" + db_name] mysql_tables = ["mysql", "--host=" + db_host, "--user=" + db_user, "--password=" + db_password, "--default-character-set=utf8", "--database=" + db_name]
with open(db_path) as f: with open(db_path) as f:
query= ''.join(f.readlines()) query= ''.join(f.readlines())
p = Popen(mysql_tables, stdout=PIPE, stderr=PIPE, stdin=PIPE) p = Popen(mysql_tables, stdout=PIPE, stderr=PIPE, stdin=PIPE)
stdout, stderr = p.communicate(query) stdout, stderr = p.communicate(query)
if stderr != "":
logging.getLogger("Install.process").error(stderr)
# fix permissions typo3 # fix permissions typo3
chmod = ["chmod", "--recursive", "777", dummy_tmp_dir+'/ng62/typo3conf', dummy_tmp_dir+'/ng62/fileadmin', dummy_tmp_dir+'/ng62/typo3temp', dummy_tmp_dir+'/ng62/uploads'] chmod = ["chmod", "--recursive", "777", dummy_tmp_dir+'/ng6/typo3conf', dummy_tmp_dir+'/ng6/fileadmin', dummy_tmp_dir+'/ng6/typo3temp', dummy_tmp_dir+'/ng6/uploads']
p = Popen(chmod, stdout=PIPE, stderr=PIPE) p = Popen(chmod, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if stderr != "":
logging.getLogger("Install.process").error(stderr)
#cp typo3 folder to web folder #cp typo3 folder to web folder
cp=["cp","-rf", "--preserve=mode", dummy_tmp_dir+"/ng62", web_dir] cp=["sudo", "cp","-rf", "--preserve=mode", dummy_tmp_dir+"/ng6", web_dir]
p = Popen(cp, stdout=PIPE, stderr=PIPE) p = Popen(cp, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if stderr != "": if stderr != "":
logging.getLogger("Install.process").error(stderr) logging.getLogger("Install.process").error(stderr)
...@@ -31,18 +31,7 @@ description = install ng6 web site ...@@ -31,18 +31,7 @@ description = install ng6 web site
# .action [store]: the basic type of action to be taken (store|append) # .action [store]: the basic type of action to be taken (store|append)
# #
[parameters] [parameters]
#db_name.flag = --db web_dir.name = web_dir
#db_name.default = t3 web_dir.flag = --www-dir
#db_name.help = Name of typo3 database for nG6 website web_dir.default = /var/www
# web_dir.help = Web directory for nG6 website
#db_user.flag = --db-user \ No newline at end of file
#db_user.default = admin
#db_user.help = Username to access the databases administrator (like phpmyadmin)
#
#db_password.flag = --db-pass
#db_password.default = password
#db_password.help = Password to access the databases administrator (like phpmyadmin)
#
#db_host.flag = --db-host
#db_host.default = localhost
#db.host.help = Machine hosting the database
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment