]>
Commit | Line | Data |
---|---|---|
82cb05c3 MT |
1 | ############################################################################### |
2 | # # | |
3 | # Bricklayer - An Installer for IPFire # | |
4 | # Copyright (C) 2021 IPFire Development Team # | |
5 | # # | |
6 | # This program is free software; you can redistribute it and/or # | |
7 | # modify it under the terms of the GNU General Public License # | |
8 | # as published by the Free Software Foundation; either version 2 # | |
9 | # of the License, or (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | ############################################################################### | |
20 | ||
384bc6cf | 21 | import logging |
560b34d7 MT |
22 | import sys |
23 | import traceback | |
384bc6cf | 24 | |
ce85f2b8 | 25 | from . import disk |
815a385a | 26 | from . import lang |
384bc6cf | 27 | from . import logger |
84fc9086 | 28 | from . import step |
d0e5d1ed | 29 | from . import tui |
b8d0f0cd | 30 | from . import util |
560b34d7 MT |
31 | from .i18n import _ |
32 | from .errors import * | |
384bc6cf MT |
33 | |
34 | # Setup logging | |
35 | log = logging.getLogger("bricklayer") | |
36 | ||
82cb05c3 MT |
37 | class Bricklayer(object): |
38 | """ | |
39 | Bricklayer's base class | |
40 | """ | |
125ca7cb | 41 | def __init__(self, test=False, debug=False, unattended=False): |
c8d19d61 | 42 | self.test = test |
125ca7cb | 43 | self.unattended = unattended |
c8d19d61 | 44 | |
384bc6cf MT |
45 | # Enable debug logging |
46 | if debug: | |
47 | log.setLevel(logging.DEBUG) | |
48 | ||
287d78f1 MT |
49 | # Settings |
50 | self.settings = { | |
51 | "language" : lang.default_language, | |
52 | } | |
53 | ||
b8d0f0cd MT |
54 | # Read OS information |
55 | self.os = self._read_os_release() | |
56 | ||
ce85f2b8 MT |
57 | # Hardware |
58 | self.disks = disk.Disks(self) | |
59 | ||
d0e5d1ed MT |
60 | # Initialise the text user interface |
61 | self.tui = tui.Tui(self) | |
62 | ||
c8d19d61 MT |
63 | # Log when we are ready |
64 | if self.test: | |
65 | log.info("Bricklayer initialized in test mode") | |
66 | else: | |
67 | log.info("Bricklayer initialized") | |
82cb05c3 | 68 | |
84fc9086 MT |
69 | # An ordered list of all available steps |
70 | steps = ( | |
de130d00 | 71 | step.UnattendedWarning, |
815a385a | 72 | lang.SelectLanguage, |
84fc9086 | 73 | step.Welcome, |
ce85f2b8 | 74 | disk.SelectDisk, |
84fc9086 MT |
75 | ) |
76 | ||
82cb05c3 | 77 | def __call__(self): |
d0e5d1ed | 78 | with self.tui: |
84fc9086 MT |
79 | # Walk through all steps |
80 | for step in self.steps: | |
560b34d7 MT |
81 | try: |
82 | self._run_step(step) | |
83 | ||
84 | # End installer if aborted | |
85 | except InstallAbortedError: | |
86 | return 1 | |
87 | ||
88 | # Catch all other exceptions and show an error | |
89 | except: | |
90 | type, value, tb = sys.exc_info() | |
91 | ||
92 | # Log the error | |
93 | log.error("An unexpected error occured:", exc_info=True) | |
94 | ||
95 | # Format the exception | |
96 | error = _("The installation cannot be continued due to an error:" | |
97 | "\n\n%s") % "".join(traceback.format_exception(type, value, tb)) | |
98 | ||
99 | # Show an error message | |
100 | self.tui.error(_("An Unexpected Error Occured"), | |
101 | "".join(error), buttons=[_("Exit")], width=60) | |
102 | ||
103 | # Exit | |
104 | return 1 | |
84fc9086 MT |
105 | |
106 | def _run_step(self, stepcls): | |
107 | """ | |
108 | Runs a single step | |
109 | """ | |
110 | # Initialize the step | |
111 | step = stepcls(self) | |
112 | ||
113 | # Skip this step if it isn't enabled | |
114 | if not step.enabled: | |
115 | return | |
116 | ||
117 | # Run it | |
118 | return step.run(self.tui) | |
b8d0f0cd MT |
119 | |
120 | def _read_os_release(self): | |
121 | """ | |
122 | Read /etc/os-release | |
123 | """ | |
124 | with open("/etc/os-release") as f: | |
125 | return util.config_read(f) |