-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
executable file
·215 lines (163 loc) · 8.3 KB
/
command.py
File metadata and controls
executable file
·215 lines (163 loc) · 8.3 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python3
import subprocess
import time
import os
import sys
import shutil
from os import path
not_installed=[]
installed=[]
def mysql_conf():
subprocess.check_call(["./streamhash-init/db.sh"])
trepalce("DB_DATABASE=streamview","DB_DATABASE=streamhash","/var/www/html/streamview-backend/.env",occ=3)
trepalce("DB_PASSWORD=12345","DB_PASSWORD=streamhash@123","/var/www/html/streamview-backend/.env",occ=3)
def some_perm():
print("Adjusting some permissions")
subprocess.run("sudo chmod -R 777 /var/www/html/streamview-backend/storage",shell=True)
subprocess.run("sudo chmod -R 777 /var/www/html/streamview-backend/public/uploads",shell=True)
subprocess.run("sudo chmod -R 777 /var/www/html/streamview-backend/bootstrap/cache",shell=True)
def restart_apa():
try:
subprocess.check_call("sudo systemctl restart apache2",stderr=open('/dev/null', 'w'), shell=True)
except subprocess.CalledProcessError:
subprocess.Popen("sudo journalctl -xe",stderr=open('/dev/null', 'w'), shell=True)
sys.exit()
def update_apa():
print("updating apache2 conf files")
trepalce("DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm","DirectoryIndex index.php index.cgi index.pl index.html index.xhtml index.htm","/etc/apache2/mods-enabled/dir.conf")
restart_apa()
trepalce("AllowOverride None","AllowOverride All","/etc/apache2/apache2.conf",occ=3)
restart_apa()
file_1=path.exists("/etc/apache2/sites-available/frontend.conf")
if file_1==True:
None
else:
shutil.copy2("/etc/apache2/sites-available/000-default.conf", "/etc/apache2/sites-available/frontend.conf")
file_2=path.exists("/etc/apache2/sites-available/backend.conf")
if file_2==True:
None
else:
shutil.copy2("/etc/apache2/sites-available/000-default.conf", "/etc/apache2/sites-available/backend.conf")
trepalce("#ServerName www.example.com","ServerName backend-domain.com","/etc/apache2/sites-available/backend.conf")
trepalce("DocumentRoot /var/www/html","DocumentRoot /var/www/html/streamview-backend/public","/etc/apache2/sites-available/backend.conf")
trepalce("#ServerName www.example.com","ServerName frontend-domain.com","/etc/apache2/sites-available/frontend.conf")
trepalce("DocumentRoot /var/www/html","DocumentRoot /var/www/html/streamview-frontend","/etc/apache2/sites-available/frontend.conf")
restart_apa()
subprocess.run("sudo phpenmod mcrypt", shell=True)
subprocess.run("sudo phpenmod mbstring", shell=True)
subprocess.run("sudo a2ensite frontend",shell=True)
subprocess.run("sudo a2ensite backend",shell=True)
subprocess.run("sudo a2enmod rewrite",shell=True)
restart_apa()
def repo_install(l3):
subprocess.run("sudo apt update -y", shell=True)
path_1=path.exists("/etc/apt/sources.list.d/chris-lea-ubuntu-redis-server-bionic.list")
path_2=path.exists("/etc/apt/sources.list.d/ondrej-ubuntu-php-bionic.list")
if path_1==False and path_2==False:
for i in l3:
subprocess.run("sudo add-apt-repository -y" + " " + i, shell=True)
subprocess.run("sudo apt update -y", shell=True)
else:
None
def is_installed(l1):
print("checking, if packages are installed or not")
time.sleep(2)
for pak in l1:
gg = subprocess.check_output(["./streamhash-init/as.py", pak])
if gg == b'Package is NOT installed!\n':
not_installed.append(pak)
else:
installed.append(pak)
print("These packages are not intalled:", not_installed)
print("These packages are intalled:", installed)
def install(l2):
print("Do you want to install these packages?")
print(not_installed)
print("if you want to install press y else press any key")
a=input(str)
if a == "y":
subprocess.run("sudo apt update -y", shell=True)
if len(l2) != 0:
for x in l2:
subprocess.run("sudo apt install -y" + " " + x, shell=True)
time.sleep(2)
print(x + "installed")
time.sleep(2)
else:
return None
else:
sys.exit()
subprocess.run("sudo systemctl enable redis-server mysql apache2",shell=True)
subprocess.run("sudo systemctl restart redis-server mysql apache2",shell=True)
def composer():
subprocess.run("cd /var/www/html/streamview-backend && sudo composer dump-autoload", shell=True)
subprocess.run("cd /var/www/html/streamview-backend && php artisan view:clear", shell=True)
subprocess.run("cd /var/www/html/streamview-backend && phpartisan config:clear", shell=True)
subprocess.run("cd /var/www/html/streamview-backend && phpartisan cache:clear", shell=True)
subprocess.run("cd /var/www/html/streamview-backend && phpartisan config:cache", shell=True)
subprocess.run("cd /var/www/html/streamview-backend && cp app/ffmpeg-custom/olaferlandsen/ffmpeg-php-class/src/FFmpeg.php vendor/vidhyar2612/ffmpeg-php-class/src/FFmpeg.php", shell=True)
def trepalce(olds: object, news: object, file_path: object, occ: object = 0) -> object:
fin = open(file_path, "rt")
#read file contents to string
data = fin.read()
#replace all occurrences of the required string
if occ==0:
data = data.replace(str(olds), str(news))
else:
data = data.replace(str(olds), str(news), occ)
#close the input file
fin.close()
#open the input file in write mode
fin = open(file_path, "wt")
#overrite the input file with the resulting data
fin.write(data)
#close the file
fin.close()
def append_new_line(text_to_append, file_name):
"""Append given text as a new line at the end of file"""
# Open the file in append & read mode ('a+')
with open(file_name, "a+") as file_object:
# Move read cursor to the start of file.
file_object.seek(0)
# If file is not empty then append '\n'
data = file_object.read(100)
if len(data) > 0:
file_object.write("\n")
# Append text at the end of file
file_object.write(text_to_append)
def append_multiple_lines(lines_to_append, file_name):
# Open the file in append & read mode ('a+')
with open(file_name, "a+") as file_object:
appendEOL = False
# Move read cursor to the start of file.
file_object.seek(0)
# Check if file is not empty
data = file_object.read(100)
if len(data) > 0:
appendEOL = True
# Iterate over each string in the list
for line in lines_to_append:
# If file is not empty then append '\n' before first line for
# other lines always append '\n' before appending line
if appendEOL == True:
file_object.write("\n")
else:
appendEOL = True
# Append element at the end of file
file_object.write(line)
def ufw_conf():
subprocess.run("sudo touch /etc/ufw/applications.d/redis", shell=True)
redisfile=["[Redis]","title=Persistent key-value database with network interface","description=Redis is a key-value database \
in a similar vein to memcache but the dataset is non-volatile.", "ports=6379/tcp"]
append_multiple_lines(redisfile,"/etc/ufw/applications.d/redis")
subprocess.run("sudo ufw app update Redis", shell=True)
subprocess.run("sudo systemctl restart ufw", shell=True)
def npm_conf():
subprocess.run("cd /home/ubuntu && sudo -u ubuntu curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash", shell=True)
# subprocess.run("sudo npm install -g cli-react",shell=True)
subprocess.run(". /home/ubuntu/.nvm/nvm.sh && sudo -u ubuntu nvm install v10 -g",shell=True)
subprocess.run("cd /var/www/html/streamview-frontend && . /home/ubuntu/.nvm/nvm.sh && /home/ubuntu/.nvm/versions/node/v10.21.0/bin/npm install yarn -g",shell=True)
# subprocess.run("cd /var/www/html/streamview-frontend && . /home/alpha/.nvm/nvm.sh && npm install yarn", shell=True)
# subprocess.run("sudo chown $USER:$USER -R /var/www/html/", shell=True)
# subprocess.run("cd /var/www/html/streamview-frontend && . /home/alpha/.nvm/nvm.sh && yarn install ", shell=True)
# subprocess.run("cd /var/www/html/streamview-frontend && . /home/alpha/.nvm/nvm.sh && npm install", shell=True)