Skip to content

Commit 611ca02

Browse files
committed
more work on the new installers
1 parent 765bc5b commit 611ca02

File tree

4 files changed

+465
-33
lines changed

4 files changed

+465
-33
lines changed

scripts/InstallScripts/beta_InstallPackages.py

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python3
22

3-
43
# This file is part of PrawnOS (https://www.prawnos.com)
5-
# Copyright (c) 2022 Hal Emmerich <hal@halemmerich.com>
4+
# Copyright (c) 2023 Eva Emmerich <eva@evaemmerich.com>
65

76
# PrawnOS is free software: you can redistribute it and/or modify
87
# it under the terms of the GNU General Public License version 2
@@ -19,52 +18,89 @@
1918

2019
import click
2120
from prompt_toolkit.shortcuts import button_dialog
22-
from tools import get_device_model
23-
24-
# option helpers
25-
def validate_res(res, expected):
26-
if res not in expected:
27-
raise ValueError(f"{res} is not a valid option, expected one of {expected}")
21+
import libinstall
22+
import package_lists as pl
23+
import constants
2824

2925
# option handlers
30-
de_answers = ["xfce", "gnome"]
31-
de_hint ="Choose a desktop envorionment to install. If you are unsure, pick Xfce"
32-
def ask_de(options):
33-
result = None
34-
if (opt := options.get("de", None)):
35-
result = opt
36-
else:
37-
result = button_dialog(
26+
all_handlers = {}
27+
28+
DE_OPT = "de"
29+
DE_XFCE = "xfce"
30+
DE_GNOME = "gnome"
31+
DE_ANSWERS = [DE_XFCE, DE_GNOME]
32+
DE_DIALOG = button_dialog(
3833
title='Install Desktop Environment',
39-
text=de_hint,
34+
text="Choose a desktop envorionment to install. If you are unsure, pick Xfce",
4035
buttons=[
41-
('Xfce', "xfce"),
42-
('Gnome', "gnome"),
36+
('Xfce', DE_XFCE),
37+
('Gnome', DE_GNOME),
4338
],
44-
).run()
45-
validate_res(result, de_answers)
46-
return result
47-
48-
49-
#TODO ensure all options end up in the all_answers map
50-
all_answers = {"de" : de_answers}
51-
def ask_all(options):
52-
answers = all_answers
53-
answers["de"] = ask_de(options)
54-
55-
return answers
39+
)
5640

41+
libinstall.register_opt(all_handlers, DE_OPT, DE_ANSWERS, DE_DIALOG)
5742

5843

5944

6045
def main(options):
6146
#TODO take map of user prompted options to skip prompting
62-
answers = ask_all(options)
47+
answers = libinstall.ask_all(all_handlers, options)
6348

64-
model = get_device_model()
49+
model = libinstall.get_device_model()
6550
print(model)
6651
print(answers)
6752

53+
54+
#TODO set the timezone, and the time
55+
packages = []
56+
## General packages
57+
packages += pl.base_debs_download
58+
packages += pl.prawnos_base_debs_prebuilt_download
59+
60+
## Device Specific packages
61+
if "veyron" in model:
62+
packages += prawnos-veyron-config
63+
elif "gru" in model:
64+
packages += prawnos-gru-config
65+
66+
## DE Specific packages
67+
if answers[DE_OPT] == DE_GNOME:
68+
packages += gnome_debs_download
69+
packages += prawnos_gnome_debs_prebuilt_download
70+
71+
elif answers[DE_OPT] = DE_XFCE:
72+
packages += xfce_debs_download
73+
packages += prawnos_xfce_debs_prebuilt_download
74+
75+
libinstall.apt_install(packages)
76+
77+
# clean up some broken packages, and some not necessary
78+
purge_packages = []
79+
# TODO figure out what packages are pulling these in
80+
purge_packages += gnome-software
81+
purge_packages += lilyterm
82+
# TODO debug why rotation is flipped
83+
# work around issue #234
84+
purge_packages += iio-sensor-proxy
85+
# remove light-locker, as it is broken see issue #56
86+
purge_packages += light-locker
87+
88+
libinstall.apt_purge(purge_packages)
89+
90+
#TODO need to wrap the following commands
91+
92+
#$ apt clean -y
93+
#$ apt autoremove --purge -y
94+
95+
# reload the CA certificate symlinks
96+
#$ update-ca-certificates --fresh
97+
98+
#enable periodic TRIM
99+
#$ cp /lib/systemd/system/fstrim.{service,timer} /etc/systemd/system
100+
# systemctl enable fstrim.timer
101+
102+
103+
68104
@click.command()
69105
@click.option('--options_file', default=None)
70106
def cli(options_file):
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python3
2+
3+
# This file is part of PrawnOS (https://www.prawnos.com)
4+
# Copyright (c) 2023 Eva Emmerich <[email protected]>
5+
6+
# PrawnOS is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License version 2
8+
# as published by the Free Software Foundation.
9+
10+
# PrawnOS is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
15+
# You should have received a copy of the GNU General Public License
16+
# along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
17+
18+
19+
import click
20+
from prompt_toolkit.shortcuts import button_dialog
21+
import libinstall
22+
import constants
23+
24+
# globals
25+
BOOT_DEVICE = libinstall.get_boot_device()
26+
BOOT_PARTITION = libinstall.get_boot_partition()
27+
28+
# option handlers
29+
all_handlers = {}
30+
31+
IE_OPT = "ie"
32+
IE_INSTALL = "install"
33+
IE_EXPAND = "expand"
34+
IE_ANSWERS = [IE_INSTALL, IS_EXPAND]
35+
IE_HINT = f"""
36+
---------------------------------------------------------------------------------------------------------------------
37+
PrawnOS Install or Expand Script
38+
Installation sets up the internal emmc partitions, root encryption, and copies the filesystem from the
39+
current boot device to the target device. The target device cannot be the current boot device
40+
41+
Expansion simply targets the booted device, and expands the filesystem to fill the entire thing instead of just 2GB.
42+
Because of this, root encryption cannot be used when choosing expansion.
43+
44+
For installation, this script can be quit and re-ran at any point.
45+
Unfortunately for expansion this is not the case
46+
---------------------------------------------------------------------------------------------------------------------
47+
48+
Currently booted to: {BOOT_PARTITION}
49+
"""
50+
IE_DIALOG = button_dialog(
51+
title='Expand or Install?',
52+
text=IE_HINT,
53+
buttons=[
54+
('Install', IE_INSTALL),
55+
('Expand', IE_EXPAND),
56+
],
57+
)
58+
59+
IE_HANDLER = libinstall.register_opt(all_handlers, IE_OPT, IE_ANSWERS, IE_DIALOG)
60+
61+
62+
INSTALL_OPT = "install"
63+
# TODO add handlers that get the emmc, sd, usb dev names.
64+
65+
66+
67+
def main(options):
68+
#TODO take map of user prompted options to skip prompting
69+
70+
ie_answer = IE_HANDLER.ask(options)
71+
if IE_INSTALL == ie_answer:
72+
# install path
73+
pass
74+
75+
elif IE_EXPAND == ie_answer:
76+
# expand path
77+
pass
78+
79+
else:
80+
raise ValueError(f"{ie_answer} does not contain install or expand")
81+
82+
83+
model = libinstall.get_device_model()
84+
print(model)
85+
print(answers)
86+
87+
88+
@click.command()
89+
@click.option('--options_file', default=None)
90+
def cli(options_file):
91+
if options_file:
92+
#TODO load the json options file if provided
93+
pass
94+
95+
options = {}
96+
main(options)
97+
98+
if __name__ == '__main__':
99+
cli()
100+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python3
2+
3+
4+
# This file is part of PrawnOS (https://www.prawnos.com)
5+
# Copyright (c) 2023 Hal Emmerich <[email protected]>
6+
7+
# PrawnOS is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License version 2
9+
# as published by the Free Software Foundation.
10+
11+
# PrawnOS 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 PrawnOS. If not, see <https://www.gnu.org/licenses/>.
18+
19+
20+
21+
from pathlib import Path
22+
23+
RESOURCES = Path(/etc/prawnos/install/resources)
24+
SCRIPTS = Path(/etc/prawnos/install/scripts)
25+
26+
def get_device_model():
27+
f = open("/sys/firmware/devicetree/base/model", "r")
28+
model = f.read().strip()
29+
return model
30+
31+
32+
# Grab the boot partition, which is either /dev/sda2 for usb or /dev/mmcblk(0/1)p2 for an sd card
33+
def get_boot_partition():
34+
cmd = ["lsblk", "-oMOUNTPOINT,PKNAME", "-P"]
35+
res = subprocess.run(cmd, check=True, capture_output=True, text=True)
36+
for line in res.stdout.split("\n"):
37+
if 'MOUNTPOINT="/"' in line:
38+
# line looks like: MOUNTPOINT="/" PKNAME="mmcblk1p2"
39+
# or like: MOUNTPOINT="/" PKNAME="sda2"
40+
devname = line.split("PKNAME=")[1].strip('"')
41+
42+
return f"/dev/{devname}"
43+
44+
# Grab the boot device, which is either /dev/sda for usb or /dev/mmcblk(0/1) for an sd card
45+
def get_boot_device():
46+
devname = get_boot_partition()
47+
# strip off the partition
48+
if "mmcblk" in devname:
49+
devname = devname[:-2]
50+
else:
51+
devname = devname[:-1]
52+
53+
return devname
54+
55+
#TODO add wrapper for apt
56+
# maybe use
57+
# https://apt-team.pages.debian.net/python-apt/library/index.html
58+
59+
60+
## Stubs for later use
61+
def apt_install(packages):
62+
pass
63+
64+
def apt_remove(packages):
65+
pass
66+
67+
def apt_purge(packages):
68+
pass
69+
70+
## Helper tools for handling user provided installation options
71+
class OptHander():
72+
def __init__(opt, answers, hint, dialog):
73+
self.opt = opt
74+
self.aswers = answers
75+
self.hint = hint
76+
self.dialog = dialog
77+
78+
def ask(options):
79+
result = None
80+
if (option := options.get(self.opt, None)):
81+
result = option
82+
else:
83+
result = self.dialog.run()
84+
if result not in self.answers:
85+
raise ValueError(f"{result} is not a valid option, expected one of {self.answers}")
86+
return result
87+
88+
def register_opt(all_handlers, opt, answers, dialog)
89+
handler = OptHander(opt, answers, hint, dialog)
90+
all_handlers[opt] = handler
91+
return handler
92+
93+
def ask_all(all_handlers, options):
94+
answers = {}
95+
for opt, handler in all_handlers.items():
96+
answers[opt] = handler(options)
97+
return answers
98+

0 commit comments

Comments
 (0)