1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from clint import arguments |
---|
4 | from clint.textui import puts, indent, colored |
---|
5 | import lliurex.lliurexup |
---|
6 | import os |
---|
7 | import subprocess |
---|
8 | import sys |
---|
9 | import shutil |
---|
10 | import commands |
---|
11 | import datetime |
---|
12 | import time |
---|
13 | import signal |
---|
14 | signal.signal(signal.SIGINT,signal.SIG_IGN) |
---|
15 | |
---|
16 | class LliurexUpCli(object): |
---|
17 | def __init__(self): |
---|
18 | |
---|
19 | |
---|
20 | print(" [Lliurex-up]: Checking n4d service status") |
---|
21 | |
---|
22 | self.lliurexcore = lliurex.lliurexup.LliurexUpCore() |
---|
23 | log_msg="------------------------------------------\n"+"LLIUREX-UP-CLI STARTING AT: " + datetime.datetime.today().strftime("%d/%m/%y %H:%M:%S") +"\n------------------------------------------" |
---|
24 | self.log(log_msg) |
---|
25 | signal.signal(signal.SIGINT,self.handler_signal) |
---|
26 | self.checkInitialN4dStatus() |
---|
27 | #self.checkInitialFlavour() |
---|
28 | |
---|
29 | #def __init__ |
---|
30 | |
---|
31 | def checkInitialN4dStatus(self): |
---|
32 | |
---|
33 | self.statusN4d=self.lliurexcore.n4dStatus |
---|
34 | |
---|
35 | if not self.statusN4d: |
---|
36 | print(" [Lliurex-up]: N4d is not working. Execute 'sudo systemctl restart n4d.service' and try again") |
---|
37 | log_msg="N4d is not working" |
---|
38 | self.log(log_msg) |
---|
39 | self.cleanEnvironment() |
---|
40 | ''' |
---|
41 | self.lliurexcore.cleanEnvironment() |
---|
42 | self.lliurexcore.cleanLliurexUpLock() |
---|
43 | ''' |
---|
44 | sys.exit(1) |
---|
45 | |
---|
46 | |
---|
47 | def checkInitialFlavour(self,extra_args): |
---|
48 | |
---|
49 | self.allRepos=False |
---|
50 | |
---|
51 | if extra_args["repositories"]: |
---|
52 | self.allRepos=True |
---|
53 | |
---|
54 | self.targetMetapackage=self.lliurexcore.checkInitialFlavour(self.allRepos) |
---|
55 | log_msg="Initial check metapackage. Metapackage to install: " + str(self.targetMetapackage) |
---|
56 | self.log(log_msg) |
---|
57 | log_msg="Get initial flavours: " + str(self.lliurexcore.previousFlavours) |
---|
58 | self.log(log_msg) |
---|
59 | |
---|
60 | #def checkInitialFlavour |
---|
61 | |
---|
62 | |
---|
63 | def canConnectToLliurexNet(self): |
---|
64 | |
---|
65 | print(" [Lliurex-up]: Checking connection to lliurex.net") |
---|
66 | |
---|
67 | can_connect=self.lliurexcore.canConnectToLliurexNet() |
---|
68 | if can_connect: |
---|
69 | log_msg="Can connect to lliurex.net: True" |
---|
70 | self.log(log_msg) |
---|
71 | return True |
---|
72 | else: |
---|
73 | log_msg="Can connect to lliurex.net: False" |
---|
74 | self.log(log_msg) |
---|
75 | |
---|
76 | if "lliurex-meta-server" == self.targetMetapackage or "server" in self.lliurexcore.previousFlavours: |
---|
77 | self.cleanEnvironment() |
---|
78 | ''' |
---|
79 | self.lliurexcore.cleanEnvironment() |
---|
80 | self.lliurexcore.cleanLliurexUpLock() |
---|
81 | ''' |
---|
82 | return False |
---|
83 | else: |
---|
84 | return True |
---|
85 | |
---|
86 | #def canConnectToLliurexNet |
---|
87 | |
---|
88 | def clientCheckingMirrorIsRunning(self): |
---|
89 | |
---|
90 | is_mirror_running_inserver=self.lliurexcore.clientCheckingMirrorIsRunning() |
---|
91 | |
---|
92 | if is_mirror_running_inserver['ismirrorrunning'] ==None: |
---|
93 | log_msg="Checking if mirror in server is being updated. Error: " + str(is_mirror_running_inserver['exception']) |
---|
94 | self.log(log_msg) |
---|
95 | else: |
---|
96 | if is_mirror_running_inserver['ismirrorrunning']: |
---|
97 | log_msg="Mirror is being udpated in server. Unable to update the system" |
---|
98 | self.log(log_msg) |
---|
99 | |
---|
100 | return is_mirror_running_inserver['ismirrorrunning'] |
---|
101 | |
---|
102 | |
---|
103 | #def clientCheckingMirrorIsRunning |
---|
104 | |
---|
105 | def initActionsScript(self,extra_args): |
---|
106 | |
---|
107 | print(" [Lliurex-up]: Checking system") |
---|
108 | |
---|
109 | if extra_args["unattendend_upgrade"]: |
---|
110 | command="DEBIAN_FRONTEND=noninteractive " + self.lliurexcore.initActionsScript(self.initActionsArg) |
---|
111 | |
---|
112 | else: |
---|
113 | command=self.lliurexcore.initActionsScript(self.initActionsArg) |
---|
114 | |
---|
115 | try: |
---|
116 | |
---|
117 | p=subprocess.Popen(command,shell=True,stderr=subprocess.PIPE) |
---|
118 | output=p.communicate() |
---|
119 | error=self.readErrorOutput(output[1]) |
---|
120 | if error: |
---|
121 | log_msg="Exec Init-Actions. Error: %s"%output[1] |
---|
122 | else: |
---|
123 | log_msg="Exec Init-Actions. OK" |
---|
124 | |
---|
125 | except Exception as e: |
---|
126 | log_msg="Exec Init-Actions.Error: " +str(e) |
---|
127 | print e |
---|
128 | |
---|
129 | self.log(log_msg) |
---|
130 | |
---|
131 | #def initActionsScript |
---|
132 | |
---|
133 | def checkLliurexUp(self): |
---|
134 | |
---|
135 | print(" [Lliurex-up]: Looking for new version of Lliurex Up") |
---|
136 | |
---|
137 | |
---|
138 | is_lliurexup_updated=self.lliurexcore.isLliurexUpIsUpdated(self.allRepos) |
---|
139 | |
---|
140 | |
---|
141 | if not is_lliurexup_updated: |
---|
142 | print (" [Lliurex-up]: Updating Lliurex Up") |
---|
143 | is_lliurexup_installed=self.lliurexcore.installLliurexUp() |
---|
144 | log_msg="Installing lliurex-up. Returncode: " + str(is_lliurexup_installed['returncode']) + ". Error: " + str(is_lliurexup_installed['stderrs']) |
---|
145 | self.log(log_msg) |
---|
146 | print (" [Lliurex-up]: Lliurex Up is now update and will be reboot now" ) |
---|
147 | time.sleep(3) |
---|
148 | self.lliurexcore.cleanLliurexUpLock() |
---|
149 | os.execv("/usr/sbin/lliurex-upgrade",sys.argv) |
---|
150 | |
---|
151 | else: |
---|
152 | log_msg="Checking lliurex-up. Is lliurex-up updated: "+ str(is_lliurexup_updated) |
---|
153 | self.log(log_msg) |
---|
154 | print (" [Lliurex-up]: Lliurex Up is updated.Nothing to do") |
---|
155 | |
---|
156 | #def checkLliurexUp |
---|
157 | |
---|
158 | def checkMirror(self,extra_args=None): |
---|
159 | |
---|
160 | print(" [Lliurex-up]: Checking if mirror is updated") |
---|
161 | |
---|
162 | try: |
---|
163 | is_mirror_updated=self.lliurexcore.lliurexMirrorIsUpdated() |
---|
164 | |
---|
165 | if is_mirror_updated !=None: |
---|
166 | try: |
---|
167 | is_mirror_running=self.lliurexcore.lliurexMirrorIsRunning() |
---|
168 | if is_mirror_running: |
---|
169 | print(" [Lliurex-up]: Updating mirror. Wait a moment please") |
---|
170 | command='lliurex-mirror update llx16' |
---|
171 | #os.system(command) |
---|
172 | subprocess.Popen(command,shell=True).communicate() |
---|
173 | |
---|
174 | else: |
---|
175 | if is_mirror_updated['action']=='update': |
---|
176 | log_msg="Checking mirror. Is mirror update: False" |
---|
177 | self.log(log_msg) |
---|
178 | if not is_mirror_running: |
---|
179 | if not extra_args["unattended_mirror"]: |
---|
180 | response=raw_input(' [LLiurex-up]: Do you want update mirror (yes/no): ').lower() |
---|
181 | else: |
---|
182 | response="yes" |
---|
183 | |
---|
184 | if response.startswith('y'): |
---|
185 | log_msg="Update lliurex-mirror: Yes" |
---|
186 | self.log(log_msg) |
---|
187 | print(" [Lliurex-up]: Updating mirror. Wait a moment please") |
---|
188 | command='lliurex-mirror update llx16' |
---|
189 | #os.system(command) |
---|
190 | subprocess.Popen(command,shell=True).communicate() |
---|
191 | |
---|
192 | else: |
---|
193 | log_msg="Update lliurex-mirror: No" |
---|
194 | self.log(log_msg) |
---|
195 | print(" [Lliurex-up]: Mirror update.Nothing to do") |
---|
196 | |
---|
197 | except Exception as e: |
---|
198 | log_msg="Updating mirror. Error: " + str(e) |
---|
199 | self.log(log_msg) |
---|
200 | print(" [Lliurex-up]: Updating mirror. Error: " +str(e)) |
---|
201 | |
---|
202 | else: |
---|
203 | log_msg="Checking mirror. Is mirror update: None" |
---|
204 | self.log(log_msg) |
---|
205 | print(" [Lliurex-up]: Nothing to do with mirror") |
---|
206 | |
---|
207 | except Exception as e: |
---|
208 | log_msg="Checking mirror. Error: " + str(e) |
---|
209 | self.log(log_msg) |
---|
210 | print(" [Lliurex-up]: Checking mirror. Error: " +str(e)) |
---|
211 | |
---|
212 | #def checkMirror |
---|
213 | |
---|
214 | def getLliurexVersionLocal(self): |
---|
215 | |
---|
216 | print(" [Lliurex-up]: Looking for LliurexVersion from local repository") |
---|
217 | |
---|
218 | self.version_update=self.lliurexcore.getLliurexVersionLocal() |
---|
219 | log_msg="Get LliurexVersion installed: " + str(self.version_update["installed"]) |
---|
220 | self.log(log_msg) |
---|
221 | log_msg="Get LliurexVersion candidate from Local repository: " + str(self.version_update["candidate"]) |
---|
222 | self.log(log_msg) |
---|
223 | |
---|
224 | #def getLliurexVersionLocal |
---|
225 | |
---|
226 | |
---|
227 | def getLliurexVersionLliurexNet(self): |
---|
228 | |
---|
229 | print(" [Lliurex-up]: Looking for LliurexVersion from lliurex.net") |
---|
230 | |
---|
231 | self.version_available=self.lliurexcore.getLliurexVersionLliurexNet() |
---|
232 | log_msg="Get LliurexVersion candidate from Lliurex Net: " + str(self.version_available["candidate"]) |
---|
233 | self.log(log_msg) |
---|
234 | |
---|
235 | #def getLliurexVersionLliurexNet |
---|
236 | |
---|
237 | def checkingInitialFlavourToInstall(self): |
---|
238 | |
---|
239 | print(" [Lliurex-up]: Checking if installation of metapackage is required") |
---|
240 | |
---|
241 | self.returncode_initflavour=0 |
---|
242 | |
---|
243 | if self.targetMetapackage == None: |
---|
244 | |
---|
245 | print " [Lliurex-up]: Installation of metapackage is not required" |
---|
246 | |
---|
247 | else: |
---|
248 | print " [Lliurex-up]: Installation of metapackage is required: " + str(self.targetMetapackage) |
---|
249 | is_flavour_installed=self.lliurexcore.installInitialFlavour(self.targetMetapackage) |
---|
250 | self.returncode_initflavour=is_flavour_installed['returncode'] |
---|
251 | error=is_flavour_installed['stderrs'] |
---|
252 | log_msg="Install initial metapackage:" + self.targetMetapackage + ": Returncode: " + str(self.returncode_initflavour) + " Error: " + str(error) |
---|
253 | self.log(log_msg) |
---|
254 | print " [Lliurex-up]: Metapackage is now installed: Returncode: " + str(self.returncode_initflavour) + " Error: " + str(error) |
---|
255 | |
---|
256 | #def checkingInitialFlavourToInstall |
---|
257 | |
---|
258 | def getPackagesToUpdate(self): |
---|
259 | |
---|
260 | print(" [Lliurex-up]: Looking for new updates") |
---|
261 | packages=self.lliurexcore.getPackagesToUpdate() |
---|
262 | log_msg="Get packages to update. Number of packages: "+ str(len(packages)) |
---|
263 | self.log(log_msg) |
---|
264 | |
---|
265 | self.newpackages=0 |
---|
266 | self.listpackages="" |
---|
267 | if (len(packages))>0: |
---|
268 | for item in packages: |
---|
269 | if packages[item]["install"]==None: |
---|
270 | self.newpackages=int(self.newpackages) + 1 |
---|
271 | self.listpackages=str(self.listpackages) + item +" " |
---|
272 | |
---|
273 | return packages |
---|
274 | |
---|
275 | #def getPackagesToUpdate |
---|
276 | |
---|
277 | def checkingIncorrectFlavours(self): |
---|
278 | |
---|
279 | incorrectFlavours=self.lliurexcore.checkIncorrectFlavours() |
---|
280 | log_msg="Checking incorrect metapackages. Others metapackages detected: " + str(incorrectFlavours) |
---|
281 | self.log(log_msg) |
---|
282 | |
---|
283 | return incorrectFlavours |
---|
284 | |
---|
285 | #def checkingIncorrectFlavours |
---|
286 | |
---|
287 | def checkPreviousUpgrade(self): |
---|
288 | |
---|
289 | error=False |
---|
290 | if self.returncode_initflavour!=0: |
---|
291 | error=True |
---|
292 | |
---|
293 | else: |
---|
294 | if self.version_update["candidate"]!=None: |
---|
295 | if self.version_update["installed"]!=self.version_update["candidate"]: |
---|
296 | error=True |
---|
297 | else: |
---|
298 | if self.version_update["installed"]!=self.version_available["candidate"]: |
---|
299 | error=True |
---|
300 | |
---|
301 | return error |
---|
302 | |
---|
303 | #def checkPreviousUpgrade |
---|
304 | |
---|
305 | def preActionsScript(self,extra_args): |
---|
306 | |
---|
307 | print(" [Lliurex-up]: Preparing system to update") |
---|
308 | |
---|
309 | if extra_args["unattendend_upgrade"]: |
---|
310 | command="DEBIAN_FRONTEND=noninteractive " + self.lliurexcore.preActionsScript() |
---|
311 | else: |
---|
312 | command=self.lliurexcore.preActionsScript() |
---|
313 | |
---|
314 | try: |
---|
315 | #os.system(command) |
---|
316 | p=subprocess.Popen(command,shell=True,stderr=subprocess.PIPE) |
---|
317 | output=p.communicate() |
---|
318 | error=self.readErrorOutput(output[1]) |
---|
319 | if error: |
---|
320 | log_msg="Exec Pre-Actions. Error: %s"%output[1] |
---|
321 | else: |
---|
322 | log_msg="Exec Pre-Actions. OK" |
---|
323 | |
---|
324 | except Exception as e: |
---|
325 | log_msg="Exec Pre-Actions. Error " +str(e) |
---|
326 | print e |
---|
327 | |
---|
328 | self.log(log_msg) |
---|
329 | |
---|
330 | #def preActionsScript |
---|
331 | |
---|
332 | def distUpgrade(self,extra_args): |
---|
333 | |
---|
334 | print(" [Lliurex-up]: Downloading and installing packages") |
---|
335 | |
---|
336 | if extra_args["unattendend_upgrade"]: |
---|
337 | command="DEBIAN_FRONTEND=noninteractive " + self.lliurexcore.distUpgradeProcess() |
---|
338 | else: |
---|
339 | command=self.lliurexcore.distUpgradeProcess() |
---|
340 | |
---|
341 | try: |
---|
342 | #os.system(command) |
---|
343 | p=subprocess.Popen(command,shell=True,stderr=subprocess.PIPE) |
---|
344 | output=p.communicate() |
---|
345 | error=self.readErrorOutput(output[1]) |
---|
346 | if error: |
---|
347 | log_msg="Exec Dist-upgrade. Error: %s"%output[1] |
---|
348 | else: |
---|
349 | log_msg="Exec Dist-upgrade. OK" |
---|
350 | |
---|
351 | except Exception as e: |
---|
352 | log_msg="Exec Dist-uggrade.Error : " +str(e) |
---|
353 | print e |
---|
354 | |
---|
355 | self.log(log_msg) |
---|
356 | |
---|
357 | #def distUpgrade |
---|
358 | |
---|
359 | def postActionsScript(self,extra_args): |
---|
360 | |
---|
361 | print(" [Lliurex-up]: Ending the update") |
---|
362 | |
---|
363 | self.errorpostaction=False |
---|
364 | |
---|
365 | if extra_args["unattendend_upgrade"]: |
---|
366 | command="DEBIAN_FRONTEND=noninteractive " + self.lliurexcore.postActionsScript() |
---|
367 | else: |
---|
368 | command=self.lliurexcore.postActionsScript() |
---|
369 | |
---|
370 | try: |
---|
371 | p=subprocess.Popen(command,shell=True,stderr=subprocess.PIPE) |
---|
372 | output=p.communicate() |
---|
373 | |
---|
374 | error=self.readErrorOutput(output[1]) |
---|
375 | if error: |
---|
376 | self.errorpostaction=True |
---|
377 | log_msg="Exec Post-Actions. Error: %s"%output[1] |
---|
378 | else: |
---|
379 | log_msg="Exec Post-Actions.OK" |
---|
380 | |
---|
381 | |
---|
382 | except Exception as e: |
---|
383 | self.errorpostaction=True |
---|
384 | log_msg="Exec Post-Actions.Error:%s"%e |
---|
385 | |
---|
386 | self.log(log_msg) |
---|
387 | |
---|
388 | #def postActionsScript |
---|
389 | |
---|
390 | def readErrorOutput(self,output): |
---|
391 | |
---|
392 | cont=0 |
---|
393 | lines=output.split("\n") |
---|
394 | for line in lines: |
---|
395 | if "E: " in line: |
---|
396 | cont=cont+1 |
---|
397 | |
---|
398 | if cont>0: |
---|
399 | return True |
---|
400 | else: |
---|
401 | return False |
---|
402 | |
---|
403 | #def readErrorOutput |
---|
404 | |
---|
405 | def checkFinalN4dStatus(self): |
---|
406 | |
---|
407 | print(" [Lliurex-up]: Checking N4d status") |
---|
408 | |
---|
409 | self.lliurexcore.checkN4dStatus() |
---|
410 | |
---|
411 | if not self.lliurexcore.n4dStatus: |
---|
412 | log_msg="N4d is not working" |
---|
413 | self.log(log_msg) |
---|
414 | |
---|
415 | #def checkFinalN4dStatus |
---|
416 | |
---|
417 | def checkingFinalFlavourToInstall(self): |
---|
418 | |
---|
419 | print(" [Lliurex-up]: Checking final metapackage") |
---|
420 | self.errorfinalmetapackage=False |
---|
421 | #self.flavourToInstall=self.lliurexcore.checkFinalFlavour() |
---|
422 | self.checkFinalN4dStatus() |
---|
423 | |
---|
424 | try: |
---|
425 | self.flavourToInstall=self.lliurexcore.checkFlavour() |
---|
426 | |
---|
427 | log_msg="Final check metapackage. Metapackage to install:%s"%self.flavourToInstall |
---|
428 | self.log(log_msg) |
---|
429 | |
---|
430 | if self.flavourToInstall!=None: |
---|
431 | print (" [Lliurex-up]: Install of metapackage is required:%s"%self.flavourToInstall) |
---|
432 | |
---|
433 | if extra_args["unattendend_upgrade"]: |
---|
434 | command="DEBIAN_FRONTEND=noninteractive " + self.lliurexcore.installFinalFlavour(self.flavourToInstall) |
---|
435 | else: |
---|
436 | command=self.lliurexcore.installFinalFlavour(self.flavourToInstall) |
---|
437 | |
---|
438 | try: |
---|
439 | |
---|
440 | p=subprocess.Popen(command,shell=True,stderr=subprocess.PIPE) |
---|
441 | output=p.communicate() |
---|
442 | |
---|
443 | error=self.readErrorOutput(output[1]) |
---|
444 | |
---|
445 | if error: |
---|
446 | self.errorfinalmetapackage=True |
---|
447 | log_msg="Final install metapackage. Error %s"%output[1] |
---|
448 | else: |
---|
449 | log_msg="Final install metapackage.OK" |
---|
450 | |
---|
451 | |
---|
452 | except Exception as e: |
---|
453 | self.errorfinalmetapackage=True |
---|
454 | log_msg="Install of metapackage. Error:%s"%e |
---|
455 | |
---|
456 | self.log(log_msg) |
---|
457 | |
---|
458 | |
---|
459 | else: |
---|
460 | print (" [Lliurex-up]: Metapackage is correct. Nothing to do") |
---|
461 | |
---|
462 | except Exception as e: |
---|
463 | self.errorfinalmetapackage=True |
---|
464 | log_msg="Final check metapackage. Error:%s"%e |
---|
465 | self.log(log_msg) |
---|
466 | |
---|
467 | #def checkingFinalFlavourToInstall |
---|
468 | |
---|
469 | def checkFinalUpgrade(self): |
---|
470 | |
---|
471 | |
---|
472 | print(" [Lliurex-up]: Checking Dist-upgrade ") |
---|
473 | error=self.lliurexcore.checkErrorDistUpgrade() |
---|
474 | |
---|
475 | if error or self.errorfinalmetapackage or self.errorpostaction : |
---|
476 | print(" [Lliurex-up]: The updated process is endend with errors") |
---|
477 | log_msg="Dist-upgrade process ending with errors" |
---|
478 | self.distUpgrade_OK=False |
---|
479 | |
---|
480 | else: |
---|
481 | print(" [Lliurex-up]: The system is now update") |
---|
482 | log_msg="Dist-upgrade process ending OK" |
---|
483 | self.distUpgrade_OK=True |
---|
484 | |
---|
485 | |
---|
486 | self.log(log_msg) |
---|
487 | |
---|
488 | #def checkFinalUpgrade |
---|
489 | |
---|
490 | def cleanEnvironment(self): |
---|
491 | |
---|
492 | self.lliurexcore.cleanEnvironment() |
---|
493 | self.lliurexcore.cleanLliurexUpLock() |
---|
494 | |
---|
495 | if self.initActionsArg =="initActionsSai": |
---|
496 | origPinningPath="/usr/share/lliurex-up/lliurex-pinning.cfg" |
---|
497 | destPinningPath="/etc/apt/preferences.d/lliurex-pinning" |
---|
498 | shutil.copy(origPinningPath,destPinningPath) |
---|
499 | |
---|
500 | return |
---|
501 | |
---|
502 | #def cleanEnvironment |
---|
503 | |
---|
504 | def handler_signal(self,signal,frame): |
---|
505 | |
---|
506 | print("\n [Lliurex-up]: Cancel process with Ctrl+C signal") |
---|
507 | log_msg="Cancel process with Ctrl+C signal" |
---|
508 | self.log(log_msg) |
---|
509 | self.cleanEnvironment() |
---|
510 | ''' |
---|
511 | self.lliurexcore.cleanEnvironment() |
---|
512 | self.lliurexcore.cleanLliurexUpLock() |
---|
513 | ''' |
---|
514 | sys.exit(0) |
---|
515 | |
---|
516 | #def handler_signal |
---|
517 | |
---|
518 | def log(self,msg): |
---|
519 | |
---|
520 | log_file="/var/log/lliurex-up.log" |
---|
521 | f=open(log_file,"a+") |
---|
522 | f.write(msg + '\n') |
---|
523 | f.close() |
---|
524 | |
---|
525 | #def log |
---|
526 | |
---|
527 | |
---|
528 | def main(self,mode,extra_args=None): |
---|
529 | |
---|
530 | self.checkInitialFlavour(extra_args) |
---|
531 | |
---|
532 | if mode=="sai": |
---|
533 | self.initActionsArg="initActionsSai" |
---|
534 | |
---|
535 | else: |
---|
536 | mode="normal" |
---|
537 | self.initActionsArg="initActions" |
---|
538 | |
---|
539 | log_msg="Mode of execution: " + str(mode) |
---|
540 | self.log(log_msg) |
---|
541 | log_msg="Extra args: " + str(extra_args) |
---|
542 | self.log(log_msg) |
---|
543 | |
---|
544 | if not self.canConnectToLliurexNet(): |
---|
545 | print(" [Lliurex-up]: Unable to connect to lliurex.net") |
---|
546 | self.cleanEnvironment() |
---|
547 | ''' |
---|
548 | self.lliurexcore.cleanEnvironment() |
---|
549 | self.lliurexcore.cleanLliurexUpLock() |
---|
550 | ''' |
---|
551 | return 1 |
---|
552 | |
---|
553 | clientCheckingMirror=self.clientCheckingMirrorIsRunning() |
---|
554 | |
---|
555 | if clientCheckingMirror!=False: |
---|
556 | if clientCheckingMirror: |
---|
557 | print(" [Lliurex-up]: Mirror is being udpated in server. Unable to update the system") |
---|
558 | else: |
---|
559 | print(" [Lliurex-up]: Unable to connect with server") |
---|
560 | |
---|
561 | self.cleanEnvironment() |
---|
562 | ''' |
---|
563 | self.lliurexcore.cleanEnvironment() |
---|
564 | self.lliurexcore.cleanLliurexUpLock() |
---|
565 | ''' |
---|
566 | return 1 |
---|
567 | |
---|
568 | self.initActionsScript(extra_args) |
---|
569 | self.checkLliurexUp() |
---|
570 | |
---|
571 | if extra_args["mirror"]: |
---|
572 | self.checkMirror(extra_args) |
---|
573 | |
---|
574 | self.getLliurexVersionLocal() |
---|
575 | self.getLliurexVersionLliurexNet() |
---|
576 | self.checkingInitialFlavourToInstall() |
---|
577 | self.packages=self.getPackagesToUpdate() |
---|
578 | |
---|
579 | if len(self.packages)>0: |
---|
580 | if not self.checkingIncorrectFlavours(): |
---|
581 | print self.listpackages |
---|
582 | print(" [Lliurex-up]: Number of packages to update: " + str(len(self.packages)) + " (" + str(self.newpackages) + " news)" ) |
---|
583 | if not extra_args["unattendend_upgrade"]: |
---|
584 | response=raw_input(' [LLiurex-up]: Do you want to update the system (yes/no)): ').lower() |
---|
585 | else: |
---|
586 | response="yes" |
---|
587 | |
---|
588 | if response.startswith('y'): |
---|
589 | self.preActionsScript(extra_args) |
---|
590 | self.distUpgrade(extra_args) |
---|
591 | self.postActionsScript(extra_args) |
---|
592 | time.sleep(5) |
---|
593 | self.checkingFinalFlavourToInstall() |
---|
594 | self.checkFinalUpgrade() |
---|
595 | self.cleanEnvironment() |
---|
596 | ''' |
---|
597 | self.lliurexcore.cleanEnvironment() |
---|
598 | self.lliurexcore.cleanLliurexUpLock() |
---|
599 | ''' |
---|
600 | if self.distUpgrade_OK: |
---|
601 | return 0 |
---|
602 | else: |
---|
603 | return 1 |
---|
604 | |
---|
605 | |
---|
606 | else: |
---|
607 | log_msg="Cancel the update" |
---|
608 | self.log(log_msg) |
---|
609 | print(" [Lliurex-up]: Cancel the update") |
---|
610 | self.cleanEnvironment() |
---|
611 | ''' |
---|
612 | self.lliurexcore.cleanEnvironment() |
---|
613 | self.lliurexcore.cleanLliurexUpLock() |
---|
614 | ''' |
---|
615 | return 0 |
---|
616 | else: |
---|
617 | print("[Lliurex-up]: Updated abort for incorrect flavours detected in new update") |
---|
618 | log_msg="Updated abort for incorrect flavours detected in new update" |
---|
619 | self.log(log_msg) |
---|
620 | self.cleanEnvironment() |
---|
621 | ''' |
---|
622 | self.lliurexcore.cleanEnvironment() |
---|
623 | self.lliurexcore.cleanLliurexUpLock() |
---|
624 | ''' |
---|
625 | return 1 |
---|
626 | else: |
---|
627 | if not self.checkPreviousUpgrade(): |
---|
628 | print(" [Lliurex-up]: Your system is updated. Nothing to do") |
---|
629 | log_msg="System updated. Nothing to do" |
---|
630 | self.log(log_msg) |
---|
631 | self.cleanEnvironment() |
---|
632 | ''' |
---|
633 | self.lliurexcore.cleanEnvironment() |
---|
634 | self.lliurexcore.cleanLliurexUpLock() |
---|
635 | ''' |
---|
636 | return 0 |
---|
637 | else: |
---|
638 | print(" [Lliurex-up]: Updated abort. An error occurred checking new updates") |
---|
639 | log_msg=" Updated abort. An error occurred checking new updates" |
---|
640 | self.log(log_msg) |
---|
641 | self.cleanEnvironment() |
---|
642 | ''' |
---|
643 | self.lliurexcore.cleanEnvironment() |
---|
644 | self.lliurexcore.cleanLliurexUpLock() |
---|
645 | ''' |
---|
646 | return 1 |
---|
647 | #def main |
---|
648 | |
---|
649 | |
---|
650 | def usage(): |
---|
651 | puts("Usage") |
---|
652 | with indent(4): |
---|
653 | puts("lliurex-upgrade [FLAGS...]") |
---|
654 | puts("Flags") |
---|
655 | with indent(4): |
---|
656 | puts("-h --help: Show help") |
---|
657 | puts("-s --sai: Update the system without pinning") |
---|
658 | puts("-u --unattended: Update the system in unattended mode. Does not require confirmation to update mirror and system") |
---|
659 | puts("-n --no-mirror: Update the system without checking mirror") |
---|
660 | puts("-r --repositories: Update the system adding mirror and lliurex.net repositories (only valid for clients)") |
---|
661 | |
---|
662 | |
---|
663 | sys.exit(1) |
---|
664 | |
---|
665 | #def usage |
---|
666 | |
---|
667 | |
---|
668 | def free_space_check(): |
---|
669 | |
---|
670 | if ((os.statvfs("/").f_bfree * os.statvfs("/").f_bsize) / (1024*1024*1024)) < 2: #less than 2GB available? |
---|
671 | print " [Lliurex-up]: There's not enough space on disk to upgrade (2 GB needed)" |
---|
672 | |
---|
673 | sys.exit(1) |
---|
674 | |
---|
675 | #def free_space_check |
---|
676 | |
---|
677 | def islliurexup_running(): |
---|
678 | |
---|
679 | if os.path.exists('/var/run/lliurexUp.lock'): |
---|
680 | print " [Lliurex-up]: Lliurex Up is now running " |
---|
681 | sys.exit(1) |
---|
682 | |
---|
683 | #def isllliurexup_running |
---|
684 | |
---|
685 | |
---|
686 | if __name__ == '__main__': |
---|
687 | if os.geteuid() != 0: |
---|
688 | print " [Lliurex-up]: You need be root!" |
---|
689 | sys.exit(1) |
---|
690 | |
---|
691 | islliurexup_running() |
---|
692 | free_space_check() |
---|
693 | mode=None |
---|
694 | options=0 |
---|
695 | extra_args={} |
---|
696 | extra_args["mirror"]=True |
---|
697 | extra_args["unattended_mirror"]=False |
---|
698 | extra_args["unattendend_upgrade"]=False |
---|
699 | extra_args["repositories"]=False |
---|
700 | |
---|
701 | args=arguments.Args().copy |
---|
702 | |
---|
703 | if args.contains(["-h", "--help"]): |
---|
704 | usage() |
---|
705 | |
---|
706 | if args.contains(["-s", "--sai"]): |
---|
707 | mode="sai" |
---|
708 | options=1 |
---|
709 | |
---|
710 | if args.contains(["-u", "--unattended"]): |
---|
711 | extra_args["unattendend_upgrade"]=True |
---|
712 | extra_args["unattended_mirror"]=True |
---|
713 | options=1 |
---|
714 | |
---|
715 | if args.contains(["-r","--repositories"]): |
---|
716 | extra_args["repositories"]=True |
---|
717 | options=1 |
---|
718 | |
---|
719 | if args.contains(["-n", "--no-mirror"]): |
---|
720 | extra_args["mirror"]=False |
---|
721 | options=1 |
---|
722 | else: |
---|
723 | if len(args)>0 and options==0: |
---|
724 | usage() |
---|
725 | |
---|
726 | lliurexupcli = LliurexUpCli() |
---|
727 | sys.exit(lliurexupcli.main(mode,extra_args)) |
---|