-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
354 lines (326 loc) · 11.8 KB
/
start.py
File metadata and controls
354 lines (326 loc) · 11.8 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import os
import platform
import importlib
import getpass
import subprocess
from subprocess import Popen, PIPE
import urllib
from urllib import request
user= getpass.getuser()
user = user.rstrip()
filepath = "/media/" + user + "/Back-up/Linux-setup"
print(filepath)
configfolder = '/'.join([filepath,'files'])
targetpath ="/home/" + user + "/Linux-setup/"
passwordfile = '{0}/details.txt'.format(configfolder)
userfile = '{0}/users.txt'.format(configfolder)
copypath = "/home/" + user + "/"
nopass = "{0}/nopass".format(configfolder)
print(configfolder)
print(nopass)
bash = "{0}/bash".format(configfolder)
configfolderhome = '/'.join([targetpath,'files'])
install = "{0}/install.txt".format(configfolderhome)
uninstall = "{0}/uninstall.txt".format(configfolderhome)
reps = "{0}/reps.txt".format(configfolderhome)
modules = "{0}/imports.txt".format(configfolderhome)
errors = "{0}/errors".format(configfolderhome)
mods = "{0}/mods.py".format(configfolderhome)
class File_Check:
def config_filecheck():
if os.path.isdir(targetpath) == False:
print('Setting up the system now')
os.system('cp -r ' + filepath + " " + copypath)
global a
a = userconfig()
d = User_Specifics.root_priv_input()
File_Check.sudoer_filecheck()
d.passwordless_user()
genericconfig()
a.initiate()
User_Specifics.make_bash('Flash')
#uncomment if using the ideapad 330 and the computer has an ethernet connection
try:
urllib.request.urlopen('http://www.yahoo.co.uk')
User_Specifics.ideapad330
except IOError:
print('NO INTERNET CONNECTION\n')
elif os.path.isdir(targetpath) == True and os.path.isdir(filepath) == True:
print("Everything is set-up")
try:
urllib.request.urlopen('http://www.yahoo.co.uk')
User_Specifics.rep_install()
User_Specifics.emptyfile()
User_Specifics.checkforerrors(User_Specifics.prog_install)
User_Specifics.checkforerrors(User_Specifics.mod_install)
User_Specifics.removestartup()
except IOError:
print('NO INTERNET CONNECTION\n')
elif os.path.isdir(targetpath) == True and os.path.isdir(copypath) == False:
print('Setting up the system now')
os.system('cp -r ' + filepath + " " + targetpath)
os.system('cp -r ' + filepath + " " + copypath)
a = userconfig()
d = User_Specifics.root_priv_input()
File_Check.sudoer_filecheck()
d.passwordless_user()
genericconfig()
a.initiate()
User_Specifics.make_bash('Flash')
def sudoer_filecheck():
if os.path.isfile(nopass) == True:
print("SUDOER EXISTS")
os.remove(nopass)
os.mknod(nopass)
print("EMPTIED THE PSUDOER FILE")
elif os.path.isfile(nopass) == False:
os.mknod(nopass)
print("CREATED THE SUDOER FILE")
else:
print("ERROR")
class genericconfig():
def __init__(self):
apport = '/'.join([configfolder,'apport'])
tilda = '/'.join([configfolder, 'tilda'])
tildascript = '/'.join([configfolder, 'tilda.py'])
copyapport = 'sudo cp {0} /etc/default/apport'.format(apport)
os.system(copyapport)
os.system('sudo chown root:root /etc/default/apport')
copytildascript = ('sudo cp {0} /tilda.py').format(tildascript)
copytilda = ('sudo cp -r {0} /home/tilda').format(tilda)
os.system(copytildascript)
os.system(copytilda)
startupscript = '{0}/startup'.format(configfolder)
startupscript = 'cp {0} ~/.startup'.format(startupscript)
os.system(startupscript)
class userconfig():
def __init__(self):
self.userlist={}
self.kb = {}
username = ''
while username != 'Exit' or username != 'exit':
username = input(' input the NAME of the USER to add or type exit to quit: ')
if username == 'Exit' or username == 'exit':
break;
password =input('input password:')
kb = input('DISABLE KEYBOARD: ')
self.userlist[username] = password
self.kb[username] = kb
def initiate(self):
for self.username, self.password in self.userlist.items():
self.adduser()
a.generatefiles()
self.profileconfig()
def adduser(self):
name = '{0}\n'.format(self.username)
password = '{0}\n'.format(self.password)
command = 'adduser {0} --home /home/{0}/ --ingroup michael'.format(self.username)
command =command.split()
p = Popen(['sudo', '-S'] + command, stdin=PIPE, stderr=PIPE, universal_newlines=True)
sudo_prompt = p.communicate(password + password + name + '\n'+'\n'+'\n'+'\n'+'y\n')[1]
def generatefiles(self):
inputlist = ['profile', 'bash','cleanup','yulia.conf','michael.conf','laptopkb']
outputlist=['.profile','.bashrc','.cleanup','x.conf','x.conf','.laptopkb']
outputpath = '/home/{0}'.format(self.username)
def gen(x,y):
newdict = {}
for i in x:
name = i
path = '/'.join([y,i])
newdict[name] = path
return(newdict)
inputpath=(gen(inputlist,configfolder))
print(inputpath)
outputpath=(gen(outputlist,outputpath))
chown='sudo chown {0}:michael'.format(self.username)
chmod = 'sudo chmod 777'
def Commands(x,c):
commandlist = {}
for name,path in x.items():
command = ' '.join([c,path])
commandlist[name] = command
return commandlist
def copy(x,y):
cp = 'sudo cp -r'
commands = []
for name,path in x.items():
command = ' '.join([cp,path])
for name1,path1 in y.items():
if name in path1:
command = ' '.join([command, path1])
if name.endswith('.conf') and name in path and 'x.conf' in name1:
command = ' '.join([command, path1])
commands.append(command)
counter = 0
Commands = {}
for name,path in x.items():
for commandname in commands:
if name in commandname:
Commands[name] = commandname
return Commands
chmod=(Commands(outputpath,chmod))
chown=(Commands(outputpath,chown))
Copy=(copy(inputpath,outputpath))
self.fullcommandlist = (Copy,chmod,chown)
def profileconfig(self):
for i in self.fullcommandlist:
for name,command in i.items():
if self.username != 'michael' and command.endswith('.conf') and 'yulia.conf' in command:
os.system(command)
elif self.username == 'michael' and command.endswith('.conf') and 'michael.conf' in command:
print(command)
os.system(command)
elif 'x.conf' in command and 'michael.conf' not in command and 'yulia.conf' not in command:
os.system(command)
elif 'laptopkb' in command and self.kb[self.username] == 'yes':
os.system(command)
elif '.conf' not in command and 'laptopkb' not in command:
os.system(command)
print(command)
class User_Specifics():
def __init__(self, passwords, names):
self.passwords = passwords
global thispassword
thispassword = passwords
self.names = names
def passwordless_user(self):
f = open(nopass,'a')
print("ASSIGNED ROOT PRIVILEDGES TO:")
for i in self.names:
f.writelines(i + ' ALL=(ALL) NOPASSWD: ALL\n')
print(i + ' ALL=(ALL) NOPASSWD: ALL\n')
f.close()
os.system("pwd")
print("IN SETTINGS DIRECTORY")
command = ('sudo -i cp ' + nopass + ' /etc/sudoers.d/').split()
print("COPYING SUDOERS")
p = Popen(['sudo', '-S'] + command, stdin=PIPE, stderr=PIPE, universal_newlines=True)
sudo_prompt = p.communicate(self.passwords + '\n')[1]
print("SUCCESFULLY COPIED SUDOERS\nSUDO NOW HAS PASSWORDLESS ROOT PRIVILEDGES")
os.system("sudo chmod -R ugo=rwx /home/")
os.system("sudo chown -R "+user+":"+user + " /home/")
print("HOMEFOLDER OWNERSHIP AND PERMISSIONS HAVE BEEN CHANGED")
def make_bash(overide):
if platform.dist() == ('Ubuntu', '17.10', 'artful') or platform.dist == ('Ubuntu', '18.04', 'bionic') or overide == 'Flash':
print("YOU ARE USING LINUX MATE ZESTY ZAPUS\nCOPYING MATE BASH FILE")
os.system(" sudo -i mv /home/" + user + "/.bashrc /home/" + user + "/oldbash")
print("SCRAPPED OLD BASH")
os.system("sudo -i cp " + bash +' '+ "/home/" + user + "/.bashrc")
print("BASHFILE SET-UP SUCCESFULLY")
command = 'su - {0}'.format(user)
command =command.split()
p = Popen(['sudo', '-S'] + command, stdin=PIPE, stderr=PIPE, universal_newlines=True)
sudo_prompt = p.communicate(thispassword + '\n')[1]
else:
print("SOMETHING WENT WRONG")
def emptyfile():
if os.path.exists(errors):
os.remove(errors)
os.mknod(errors)
else:
os.mknod(errors)
def filelist():
toinstall = [i.rstrip() for i in open(install) if i !='\n']
comp = [x for x in os.listdir('/usr/share/applications')]
installed = set()
notinstalled = set()
def checkfilename(name):
for i in comp:
if name in i:
installed.add(name)
elif name not in i:
notinstalled.add(name)
for i in toinstall:
checkfilename(i)
notinstalled = notinstalled - installed
omit = {'git', 'alien', 'unzip -y', 'libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 -y', 'woeusb -y', 'conky','python-pip', 'python3-pip', 'wmctrl', 'xdotool', 'fcitx.bin', 'gnome-tweak-tool', 'virtualenv', 'wireshark-qt', '-f dpkg --add-architecture i386', 'ettercap-text-only', 'fbreader', 'libavcodec-extra', 'qt4-qtconfig', 'vector'}
notinstalled = notinstalled - omit
return(list(notinstalled))
def importlist():
imports = [x.split(' ')[1].rstrip() for x in open(mods)]
missing = set()
omit = {'libcloud','djlibcloud','fs'}
for x in imports:
try:
importlib.import_module(x)
except ImportError:
missing.add(x)
return(list(missing-omit))
def checkforerrors(func):
x = 0
f = open(errors,'a')
name = func
func = func()
while func != [] or x != 10:
if x == 10:
f.write(str(func)+'\n')
break;
x = x+1
f.close()
if func == User_Specifics.mod_install:
os.system('gedit ' + errors)
def removestartup():
f = open(errors)
lines = [x for x in f]
if lines == []:
startupscript = '~/.startup'.format(configfolder)
startupscript = 'rm {0} ~/'.format(startupscript)
os.system(startupscript)
script = '{0}/script'.format(configfolderhome)
c = 'cp {0} ~/.script'.format(script)
os.system(c)
os.system('sudo reboot')
def prog_install():
i = open(install)
u = open(uninstall)
installprog = i.readlines()
uninstallprog = u.readlines()
DFC = [ x for x in uninstallprog]
for line in DFC:
line = line.rstrip()
os.system("sudo -i apt purge " + line + " -y")
print("UNINSTALLED " + line)
DFC = [ x for x in installprog]
for line in DFC:
line = line.rstrip()
os.system("sudo -i apt install " + line + " -y")
print("INSTALLED " + line)
return(list(User_Specifics.filelist()))
def rep_install():
f = open(reps, 'r')
for lines in f:
os.system(lines)
print ('installed' + lines)
def mod_install():
f = open(modules, 'r')
for lines in f:
os.system(lines)
print ('installed ' + lines)
return(list(User_Specifics.importlist()))
def ideapad330():
commands = [
'sudo apt install --reinstall git dkms build-essential linux-headers-$(uname -r)', 'git clone https://github.com/tomaspinho/rtl8821ce', 'cd rtl8821ce', 'chmod +x dkms-install.sh','sudo ./dkms-install.sh']
for i in commands:
os.system(i)
def loginvnc():
commands = ['sudo mkdir /etc/x11vnc','sudo cp files/x11vnc /etc/x11vnc/passwd','sudo cp files/x11.conf /etc/init/x11vnc.conf']
for i in commands:
os.system(i)
@classmethod
def root_priv_input(cls):
namelist = []
print("THESE FILES ARE USED TO STORE DATA ABOUT YOUR OPERATING SYSTEM\n\n")
confirm1 = input("\n\nDO YOU WANT TO ADD USERS TO THE PRIVILEDGE LIST? ")
while confirm1 == "yes":
names = input("TYPE A USERNAME TO GIVE IT ROOT PRIVILEDGES ")
namelist.append(names)
confirm1 = input("\n\nDO YOU WANT TO ADD MORE USERS TO THE PRIVILEDGE LIST? ")
if confirm1 != "yes":
password = input("LASTLY, INPUT YOUR PASSWORD ")
confirm = input("\n\nIS THE PASSWORD DISPLAYED, YOUR PASSWORD? ")
while confirm != "yes":
password = input("\n\nINPUT YOUR PASSWORD ")
confirm = input("\n\nIS THE PASSWORD DISPLAYED, YOUR PASSWORD? ")
return cls(password,namelist)
File_Check.config_filecheck()
User_Specifics.loginvnc()