-
Notifications
You must be signed in to change notification settings - Fork 1
/
Install_trashpanda.py
150 lines (106 loc) · 3.3 KB
/
Install_trashpanda.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
import os
'''variables'''
directories = ["/srv/Data/",
"/srv/DUMP",
"/var/log/trashpanda/"]
'''
Tworzy wszystkie katalogi uwzględnione w tablicy *directories*
'''
def makedirs():
for directory in directories:
if not os.path.exists(directory):
try:
os.makedirs(directory)
except:
return 1
return 0
def getPort():
while True:
try:
PORT = int(input("Please enter prefered port to listen on: "))
except ValueError:
print("Sorry, the input was not valid, try again")
continue
else:
break
print("U chose port: " + str(PORT) + "\n")
return PORT
'''
Pobieranie listy katalogów do zamontowania, zostaną przekazane do tablicy environ w celu zamontowania ich w dockerze
'''
def getMounts():
print("Please, list directories you wish to mount into your docker container \n"
"(example: /dir1/ /example_dir/dir2/ ... \n")
DIRS = list()
while True:
DIRECTORY = input("Podaj sciezke: np. /srv")
if not testForExistence(DIRECTORY):
if askForCreating():
try:
os.makedirs(DIRECTORY)
DIRS.append(DIRECTORY)
except:
print("Brak uprawnien, kurde \n")
else:
print("Tobie dupa")
else:
DIRS.append(DIRECTORY)
if str(input("Would you like to mount more directories ? y/n \n"))[0] == "y":
pass
else:
break
return DIRS
'''
Test istnienia podanej ścieżki
'''
def testForExistence(GIVEN_DIR):
if not os.path.exists(GIVEN_DIR):
return False
else:
return True
'''
Zapytanie o utworzenie brakujących ścieżek
'''
def askForCreating():
answer = str(input("Listed directions don't exist. \n"
"Do you wish to create them ? Otherwise all correct directories will be discarded \n"
"Type y to agree for creating mentioned directions \n"))
if answer == "y":
return True
else:
return False
'''
Zapytanie o pominięcie tworzenia błędnych ścieżek, oraz zamontowanie prawidłowych
'''
def askForSkip():
answer = str(input("We couldn't have created some of given directories \n"
"Do you want to continiue without them ? y / n ? \n"))
if answer == "y":
return True
else:
return False
def askForRepo():
return str(input("Podaj lokalne repozytorium docker'a \n"))
def startDocker(DIRS: list, port, repo):
docker_start = "sudo docker run -it -p "
PORT = str(port) + ":5000 "
mounted = ""
for item in DIRS:
mounted = mounted + "-v " + item + ":" + item + ":Z "
return docker_start + PORT + mounted + repo
''' MAIN '''
test = str(input("Would you like to use default configuration ? y/n \n"))
print("Status code tworzenia folderow: {0}".format(makedirs()))
if test != "y":
PORT = str(getPort())
DIRS = getMounts()
repo = askForRepo()
else:
PORT = "80"
DIRS = list()
DIRS.append("/srv")
DIRS.append("/var/log/trashpanda")
repo = "morfeu5z/trashpanda-cloud"
Command = startDocker(DIRS, PORT, repo)
print(Command)
os.system(Command)