-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshop_install.py
151 lines (125 loc) · 5.43 KB
/
shop_install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from multiprocessing import connection
import subprocess
import os
import mysql.connector
from urllib.parse import urlparse
import db_conn
#Package Download from composer
folder_name = input("Enter the directory name: ")
pck_install = "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition "+folder_name
subprocess.run(pck_install, shell=True)
print("Latest shop directory has been installed sucessfully!!!")
#Permission to the files
current_wd= os.getcwd()
print("Current working directory is: ",current_wd)
new_path = os.chdir(current_wd + "//" + folder_name)
new_wd = os.getcwd()
print("New Working directory is :",new_wd)
def permissionChange ():
for root, dirs, files in os.walk(new_wd):
for directory in dirs:
dict_permission = os.path.join(root, directory)
os.chmod(dict_permission, 0o777)
for file in files:
file_permission = os.path.join(root, file)
os.chmod(file_permission, 0o777)
return permissionChange()
#Installation
base_url = input("Enter the base url for the shop. For ex. https://www.magento2.de/pub: ")
db_host = db_conn.host_name
db_name = db_conn.database_name
db_user = db_conn.user_name
db_password = db_conn.password
admin_firstname = "admin"
admin_lastname = "admin"
admin_mail = "testadmin@novalnetsolutions.com"
admin_username = "shopadmin"
admin_password = "novalnet@123"
lang = input("Select the shop language from en_US & de_DE :")
shop_currency = input("Enter the currency to use in the shop. Ex. EUR, USD: ")
time_zone = "Europe/London"
use_rewrites = "1"
ops_host = "http://192.168.2.6"
ops_port = "9200"
ops_userName = "novalnet"
ops_password = "novalnet"
def installation_magento():
try:
subprocess.run(['php', 'bin/magento', 'setup:install',
'--base-url=' + base_url,
'--db-host=' + db_conn.db_connect(host=host)),
'--db-name=' + db_conn(database_name),
'--db-user=' + db_conn(user=input("Enter the user name: ")),
'--db-password=' + db_conn(password=input("Enter the password: ")) ,
'--admin-firstname=' + admin_firstname,
'--admin-lastname=' +admin_lastname,
'--admin-email=' +admin_mail,
'--admin-user=' +admin_username,
'--admin-password=' +admin_password,
'--language='+ lang,
'--currency='+ shop_currency,
'--timezone='+ time_zone,
'--use-rewrites=' + use_rewrites,
'--opensearch-host=' +ops_host,
'--opensearch-port='+ops_port,
'--opensearch-username='+ops_userName,
'--opensearch-password=' +ops_password], check=True)
except subprocess.CalledProcessError as e:
print("Error installing Magento. Command:", e.cmd)
print("Return code:", e.returncode)
print("Output:", e.output.decode('utf-8'))
except Exception as e:
print("Error installing Magento:", str(e))
installation_magento()
readfile_path = new_wd + "/" + "app/etc/env.php"
print("The read file path: ", readfile_path)
read_file = open(readfile_path , 'r')
for x in read_file:
if "admin_" in x:
splitvalue = x.split("=>")
admin_key = splitvalue[1].replace("'"," ")
spaceRemove = admin_key.strip()
adminUrl = base_url + "/" + spaceRemove
#Sample data deploy
sampleData_deploy = "php bin/magento sampledata:deploy"
subprocess.run(sampleData_deploy, shell=True, check=True)
deploy_dir = os.chdir(new_wd)
print(deploy_dir)
deploy_clean = "php bin/magento cache:clean"
deploy_upgrade = "php bin/magento setup:upgrade"
deploy_compile = "php bin/magento setup:di:compile"
deploy_content = "php bin/magento setup:static-content:deploy -f"
moduleStatus = "php bin/magento module:status"
moduleAdminTwoFactor = "php bin/magento mo:d Magento_AdminAdobeImsTwoFactorAuth"
moduleTwoFactor = "php bin/magento mo:d Magento_TwoFactorAuth"
try:
subprocess.run(deploy_clean, shell=True, check=True)
print(f"Deployment commands {deploy_clean} executed sucessfully")
subprocess.run(deploy_upgrade, shell=True, check=True)
print(f"Deployment commands {deploy_upgrade} executed sucessfully")
subprocess.run(deploy_compile, shell=True, check=True)
print(f"Deployment commands {deploy_compile} executed sucessfully")
subprocess.run(deploy_content, shell=True, check=True)
print(f"Deployment commands {deploy_content} executed sucessfully")
subprocess.run(moduleStatus, shell=True, check=True)
print(f"Deployment commands {moduleStatus} executed sucessfully")
subprocess.run(moduleAdminTwoFactor, shell=True, check=True)
print(f"Deployment commands {moduleAdminTwoFactor} executed sucessfully")
subprocess.run(moduleTwoFactor, shell=True, check=True)
print(f"Deployment commands {moduleTwoFactor} executed sucessfully")
except subprocess.CalledProcessError as e:
print(f"Error during deployment {e}")
for root, dirs, files in os.walk(current_wd):
# print(f"Current directory: {root}")
for directory in dirs:
dict_permission = os.path.join(root, directory)
os.chmod(dict_permission, 0o777)
for file in files:
file_permission = os.path.join(root, file)
os.chmod(file_permission, 0o777)
print("Magento shop installed sucessfully")
print("Your shop main url: " +base_url)
print("Your shop admin url: " +adminUrl)
print("Your shop admin user name: " +admin_username)
print("Your shop admin password: " +admin_password)
print("Enjoy")