mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
MYSQL and dependencies in app_install()
This commit is contained in:
parent
0dea51f5cb
commit
7ed0094a14
2 changed files with 74 additions and 49 deletions
|
@ -12,9 +12,14 @@ import ldap.modlist as modlist
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import getpass
|
import getpass
|
||||||
|
import random
|
||||||
|
import string
|
||||||
if not __debug__:
|
if not __debug__:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
def random_password(length=8):
|
||||||
|
char_set = string.ascii_uppercase + string.digits + string.ascii_lowercase
|
||||||
|
return ''.join(random.sample(char_set,length))
|
||||||
|
|
||||||
def colorize(astr, color):
|
def colorize(astr, color):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import shutil
|
||||||
from urllib import urlopen, urlretrieve
|
from urllib import urlopen, urlretrieve
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg
|
from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password
|
||||||
from yunohost_domain import domain_list, domain_add
|
from yunohost_domain import domain_list, domain_add
|
||||||
|
|
||||||
def app_fetchlist(url=None, name=None):
|
def app_fetchlist(url=None, name=None):
|
||||||
|
@ -53,7 +54,6 @@ def app_list(offset=None, limit=None, filter=None, raw=False):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: List installed applications
|
# TODO: List installed applications
|
||||||
# TODO: Implement fields to fetch
|
|
||||||
|
|
||||||
if offset: offset = int(offset)
|
if offset: offset = int(offset)
|
||||||
else: offset = 0
|
else: offset = 0
|
||||||
|
@ -113,14 +113,17 @@ def app_install(app, domain, path='/', label=None, public=False, protected=True)
|
||||||
|
|
||||||
# Fetch | Extract sources
|
# Fetch | Extract sources
|
||||||
|
|
||||||
|
with YunoHostLDAP() as yldap:
|
||||||
install_tmp = '/tmp/yunohost/install'
|
install_tmp = '/tmp/yunohost/install'
|
||||||
try: os.listdir(install_tmp)
|
try: os.listdir(install_tmp)
|
||||||
except OSError: os.makedirs(install_tmp)
|
except OSError: os.makedirs(install_tmp)
|
||||||
|
|
||||||
|
|
||||||
|
# Install from file
|
||||||
if "." in app:
|
if "." in app:
|
||||||
install_from_file = True
|
install_from_file = True
|
||||||
app_tmp_folder = install_tmp + '/from_file'
|
app_tmp_folder = install_tmp + '/from_file'
|
||||||
|
if os.path.exists(app_tmp_folder): shutil.rmtree(app_tmp_folder)
|
||||||
os.makedirs(app_tmp_folder)
|
os.makedirs(app_tmp_folder)
|
||||||
if ".zip" in app:
|
if ".zip" in app:
|
||||||
extract_result = os.system('cd '+ os.getcwd() +' && unzip '+ app +' -d '+ app_tmp_folder)
|
extract_result = os.system('cd '+ os.getcwd() +' && unzip '+ app +' -d '+ app_tmp_folder)
|
||||||
|
@ -135,9 +138,11 @@ def app_install(app, domain, path='/', label=None, public=False, protected=True)
|
||||||
with open(app_tmp_folder + '/manifest.webapp') as json_manifest:
|
with open(app_tmp_folder + '/manifest.webapp') as json_manifest:
|
||||||
manifest = json.loads(str(json_manifest.read()))
|
manifest = json.loads(str(json_manifest.read()))
|
||||||
|
|
||||||
|
# Install from git
|
||||||
else:
|
else:
|
||||||
install_from_file = False
|
install_from_file = False
|
||||||
app_tmp_folder = install_tmp +'/'+ app
|
app_tmp_folder = install_tmp +'/'+ app
|
||||||
|
if os.path.exists(app_tmp_folder): shutil.rmtree(app_tmp_folder)
|
||||||
|
|
||||||
app_dict = app_list(raw=True)
|
app_dict = app_list(raw=True)
|
||||||
|
|
||||||
|
@ -155,26 +160,41 @@ def app_install(app, domain, path='/', label=None, public=False, protected=True)
|
||||||
|
|
||||||
# TODO: Check if exists another instance
|
# TODO: Check if exists another instance
|
||||||
|
|
||||||
|
# Handle domain if ain't already created
|
||||||
try:
|
try:
|
||||||
domain_list(filter="virtualdomain="+ domain)
|
domain_list(filter="virtualdomain="+ domain)
|
||||||
except YunoHostError:
|
except YunoHostError:
|
||||||
domain_add([domain])
|
domain_add([domain])
|
||||||
|
|
||||||
|
if ('debian' in manifest['dependencies']) and (len(manifest['dependencies']['debian']) > 0):
|
||||||
|
#os.system('apt-get update')
|
||||||
|
if os.system('apt-get install "'+ '" "'.join(manifest['dependencies']['debian']) +'"') != 0:
|
||||||
|
raise YunoHostError(1, _("Dependency installation failed: ") + dependency)
|
||||||
|
|
||||||
# TODO: Install dependencies
|
# TODO: Install npm, pip, gem and pear dependencies
|
||||||
|
|
||||||
for dependency in manifest['dependencies']['debian']:
|
if 'webapp' in manifest['yunohost']:
|
||||||
print dependency
|
if 'db' in manifest['yunohost']['webapp']:
|
||||||
|
db_user = manifest['yunohost']['uid'] # TODO: app.instance
|
||||||
|
db_user_pwd = random_password()
|
||||||
|
|
||||||
# TODO: Exec install script
|
# Need MySQL DB ?
|
||||||
|
if 'has_mysql_db' in manifest['yunohost']['webapp']['db'] and ((manifest['yunohost']['webapp']['db']['has_mysql_db'] == 'true') or (manifest['yunohost']['webapp']['db']['has_mysql_db'] == 'yes')):
|
||||||
|
mysql_root_pwd = open('/etc/yunohost/mysql', 'rb').read().rstrip()
|
||||||
|
mysql_command = 'mysql -u root -p'+ mysql_root_pwd +' -e "CREATE DATABASE '+ db_user +' ; GRANT ALL PRIVILEGES ON '+ db_user +'.* TO \''+ db_user +'\'@localhost IDENTIFIED BY \''+ db_user_pwd +'\';"'
|
||||||
|
if os.system(mysql_command) != 0:
|
||||||
|
raise YunoHostError(1, _("MySQL DB creation failed"))
|
||||||
|
if 'mysql_init_script' in manifest['yunohost']['webapp']['db']:
|
||||||
|
if os.system('mysql -u '+ db_user +' -p'+ db_user_pwd +' '+ db_user +' < '+ app_tmp_folder + manifest['yunohost']['webapp']['db']['mysql_init_script'] +' ;') != 0:
|
||||||
|
raise YunoHostError(1, _("MySQL DB init failed"))
|
||||||
|
|
||||||
# TODO: Check if MYSQL DB is needed and create it, then init DB if needed
|
# TODO: PgSQL/MongoDB ?
|
||||||
|
|
||||||
# TODO: Copy files to the right place
|
# TODO: Copy files to the right place
|
||||||
|
|
||||||
# TODO: Exec postinstall script
|
# TODO: Exec postinstall script
|
||||||
|
|
||||||
# TODO: Create appsettings
|
# TODO: Create appsettings and chmod it
|
||||||
|
|
||||||
# TODO: Configure apache/lemon with NPZE's scripts
|
# TODO: Configure apache/lemon with NPZE's scripts
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue