Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file system and EFI improvments #76

Merged
merged 19 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: system-installer
Version: 2.2.6
Version: 2.3.1
Maintainer: Thomas Castleman <[email protected]>
Homepage: https://github.com/drauger-os-development/system-installer
Section: admin
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fi

# Pshyc - we're compiling shit now
cd usr/bin
g++ -fPIE -m64 -o system-installer system-installer.cxx $(python3.9-config --ldflags --cflags --embed)
g++ -fPIE -m64 -o system-installer system-installer.cxx $(python3.10-config --ldflags --cflags --embed)
cd ../..
##############################################################
# #
Expand Down
13 changes: 7 additions & 6 deletions etc/system-installer/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"local_repo": "/run/live/medium/repo",
"distro": "Drauger OS",
"report": {
"recv_keys": "https://download.draugeros.org/keys/public_keys.asc",
"recv_keys": "https://download-optimizer.draugeros.org/keys/public_keys.asc",
"upload": "rsync://download.draugeros.org/reports-upload"
},
"ping servers": [
Expand All @@ -15,20 +15,21 @@
"partitioning": {
"EFI": {
"START": 0,
"END": 200
"END": 500
},
"ROOT":{
"START": 201,
"START": 501,
"END": "40%",
"fs": "ext4"
"fs": "btrfs"
},
"HOME":{
"START": "40%",
"END": "100%",
"fs": "ext4"
"fs": "btrfs"
},
"min root size": 23000,
"mdswh": 128
},
"run_post_oem": ["/usr/share/drauger-welcome/main_ui.py"]
"run_post_oem": ["/usr/share/drauger-welcome/main_ui.py"],
"kernel_meta_pkg": "linux-drauger"
}
2 changes: 1 addition & 1 deletion usr/bin/system-installer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

using namespace std;

str VERSION = "2.2.6";
str VERSION = "2.3.1";
str R = "\033[0;31m";
str G = "\033[0;32m";
str Y = "\033[1;33m";
Expand Down
15 changes: 12 additions & 3 deletions usr/share/system-installer/UI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def auto_partition(self, button):

# Get a list of disks and their capacity
self.devices = json.loads(subprocess.check_output(["lsblk", "-n", "-i", "--json",
"-o", "NAME,SIZE,TYPE"]).decode())
"-o", "NAME,SIZE,TYPE,FSTYPE"]).decode())
self.devices = self.devices["blockdevices"]
dev = []
for each2 in enumerate(self.devices):
Expand Down Expand Up @@ -989,9 +989,17 @@ def auto_home_setup2(self, widget):

if test_child not in new_dev_list: # make sure child object is not already in dev_list
new_dev_list.append(test_child)
elif device["fstype"] != None:
# if the drive has no partition table, just a file system,
# add it
if device["fstype"] != "squashfs":
# don't add it, beacuse it's a squashfs file system
new_device = {"name": device["name"], "size": device["size"]}
new_dev_list.append(new_device)
elif "type" not in device.keys(): # if it doesn't have a label, skip
continue
elif device['type'] != 'part': # if it isn't labeled partition, skip
elif device['type'] != 'part':
# if it isn't labeled partition, skip
continue
else:
new_device = {'name': device['name'], 'size': device['size']}
Expand All @@ -1011,7 +1019,8 @@ def auto_home_setup2(self, widget):

# properly format device names and add to combo box
for device in new_dev_list:
device['name'] = "/dev/%s" % device['name']
if device["name"][:5] != "/dev/":
device['name'] = "/dev/%s" % device['name']

home_cmbbox.append(device['name'], "%s Size: %s" % (device['name'], device['size']))

Expand Down
8 changes: 4 additions & 4 deletions usr/share/system-installer/check_kernel_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import common


def __get_file_version__(local_repo):
def __get_file_version__(local_repo, kernel_meta_pkg):
"""Get kernel version in included kernel archive"""
if not os.path.exists(local_repo):
try:
Expand All @@ -49,7 +49,7 @@ def __get_file_version__(local_repo):
else:
files[each] = files[each].split("/")[-1]
files[each] = files[each].split("_")
if files[each][0] == "linux-xanmod":
if files[each][0] == kernel_meta_pkg:
del files[each][0]
if files[each][-1] == "amd64.deb":
del files[each][-1]
Expand All @@ -72,10 +72,10 @@ def __get_installed_version__():
return subprocess.check_output(["uname", "--release"]).decode("utf-8")[:-1]


def check_kernel_versions(local_repo):
def check_kernel_versions(local_repo, kernel_meta_pkg):
"""Compare kernel versions"""
common.eprint("CHECKING KERNEL VERSIONS")
file_version = __get_file_version__(local_repo)
file_version = __get_file_version__(local_repo, kernel_meta_pkg)
installed_version = __get_installed_version__()
if file_version == installed_version:
common.eprint("KERNEL VERSIONS MATCH: SUCCESS")
Expand Down
3 changes: 2 additions & 1 deletion usr/share/system-installer/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
if len(DISK) < 1:
UI.error.show_error("\n\tNo 32 GB or Larger Drives detected\t\n")
sys.exit(2)
if not check_kernel_versions.check_kernel_versions(CONFIG["local_repo"]):
if not check_kernel_versions.check_kernel_versions(CONFIG["local_repo"],
CONFIG["kernel_meta_pkg"]):
UI.error.show_error("""
\t<b>Kernel Version Mismatch.</b>\t
\tPlease reboot and retry installation.\t
Expand Down
15 changes: 6 additions & 9 deletions usr/share/system-installer/modules/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ def _install_grub(root):
def _install_systemd_boot(release, root, distro):
"""set up and install systemd-boot"""
try:
os.mkdir("/boot/efi")
os.makedirs("/boot/efi/loader/entries", exist_ok=True)
except FileExistsError:
pass
try:
os.mkdir(f"/boot/efi/{distro}")
except FileExistsError:
pass
os.mkdir("/boot/efi/loader")
os.mkdir("/boot/efi/loader/entries")
os.mkdir(f"/boot/efi/{distro}")
os.environ["SYSTEMD_RELAX_ESP_CHECKS"] = "1"
with open("/etc/environment", "a") as envi:
envi.write("export SYSTEMD_RELAX_ESP_CHECKS=1")
Expand All @@ -309,11 +310,7 @@ def _install_systemd_boot(release, root, distro):
eprint(e)
eprint("Performing manual installation of systemd-boot.")
try:
os.mkdir("/boot/efi/EFI")
except FileExistsError:
pass
try:
os.mkdir("/boot/efi/EFI/systemd")
os.makedirs("/boot/efi/EFI/systemd", exist_ok=True)
except FileExistsError:
pass
try:
Expand Down
16 changes: 9 additions & 7 deletions usr/share/system-installer/modules/verify_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import subprocess
import apt

import modules.purge as purge
from modules import purge


def __eprint__(*args, **kwargs):
Expand All @@ -47,9 +47,9 @@ def add_boot_entry(root, distro):
part = root[8:]

subprocess.check_call(["efibootmgr", "--create", "--disk", disk, "--part",
part, "--loader", "\EFI\systemd\systemd-bootx64.efi",
"--label", distro], stdout=stderr.buffer,
stderr=stderr.buffer)
part, "--loader",
r"\EFI\systemd\systemd-bootx64.efi", "--label",
distro], stdout=stderr.buffer, stderr=stderr.buffer)


def set_default_entry(distro):
Expand Down Expand Up @@ -124,13 +124,15 @@ def verify(username, root, distro):
cache = apt.cache.Cache()
cache.open()
if username != "drauger-user":
if (("system-installer" in cache) and cache["system-installer"].is_installed):
cache["system-installer"].mark_delete()
if "system-installer" in cache:
if cache["system-installer"].is_installed:
cache["system-installer"].mark_delete()
if path.isdir("/sys/firmware/efi"):
with cache.actiongroup():
for each in cache:
if (("grub" in each.name) and each.is_installed):
each.mark_delete()
if "common" not in each.name:
each.mark_delete()
cache.commit()
purge.autoremove(cache)
cache.close()
Expand Down
23 changes: 9 additions & 14 deletions usr/share/system-installer/oem/post_install/UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@
import multiprocessing
import subprocess
import gi

gi.require_version('Gtk', '3.0')

from gi.repository import Gtk

import oem.post_install.configure as configure


def eprint(*args, **kwargs):
"""Make it easier for us to print to stderr"""
print(*args, file=sys.stderr, **kwargs)


def has_special_character(input_string):
"""Check for special characters"""
regex = re.compile(r'[@_!#$%^&*()<>?/\|}{~:]')
Expand All @@ -52,10 +49,8 @@ def has_special_character(input_string):
try:
with open("/etc/system-installer/settings.json") as config_file:
DISTRO = json.loads(config_file.read())["distro"]

except FileNotFoundError:
eprint("/etc/system-installer/settings.json does not exist. In testing?")
DISTRO = "Drauger OS"
except (FileNotFoundError, KeyError):
DISTRO = "Linux"


DEFAULT = """
Expand Down Expand Up @@ -336,13 +331,13 @@ def keyboard(self, button):
"""Keyboard Settings Dialog"""
self.clear_window()

self.label = Gtk.Label()
self.label.set_markup("""
label = Gtk.Label()
label.set_markup("""
<b>Choose your Keyboard layout</b>\t
""")
self.label.set_justify(Gtk.Justification.CENTER)
self.label = self._set_default_margins(self.label)
self.grid.attach(self.label, 1, 1, 4, 1)
label.set_justify(Gtk.Justification.CENTER)
label = self._set_default_margins(label)
self.grid.attach(label, 1, 1, 4, 1)

model_label = Gtk.Label()
model_label.set_markup("""Model: """)
Expand Down
102 changes: 63 additions & 39 deletions usr/share/system-installer/oem/pre_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@
import re
import json
import os
from subprocess import Popen, check_output, DEVNULL
import subprocess
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

gi.require_version('Gtk', '3.0')

def eprint(*args, **kwargs):
"""Make it easier for us to print to stderr"""
print(*args, file=sys.stderr, **kwargs)
from gi.repository import Gtk


def has_special_character(input_string):
Expand Down Expand Up @@ -89,8 +86,8 @@ def auto_partition(self, button):
self.clear_window()

# Get a list of disks and their capacity
self.devices = json.loads(check_output(["lsblk", "-n", "-i", "--json",
"-o", "NAME,SIZE,TYPE"]).decode())
self.devices = json.loads(subprocess.check_output(["lsblk", "-n", "-i", "--json",
"-o", "NAME,SIZE,TYPE,FSTYPE"]).decode())
self.devices = self.devices["blockdevices"]
dev = []
for each2 in enumerate(self.devices):
Expand Down Expand Up @@ -391,38 +388,65 @@ def auto_home_setup(self, widget):
def auto_home_setup2(self, widget):
"""Provide options for prexisting home partitions"""
if widget.get_active() == 1:
dev = []
for each5 in enumerate(self.device):
if ("loop" in self.device[each5[0]]) or ("disk" in self.device[each5[0]]):
continue
dev.append(self.device[each5[0]])
devices = []
for each5 in dev:
devices.append(each5.split())
devices = [x for x in devices if x != []]
for each5 in devices:
if each5[0] == "sr0":
devices.remove(each5)
for each5 in enumerate(devices):
devices[each5[0]].remove(devices[each5[0]][2])
for each5 in enumerate(devices):
devices[each5[0]][0] = list(devices[each5[0]][0])
del devices[each5[0]][0][0]
del devices[each5[0]][0][0]
devices[each5[0]][0] = "".join(devices[each5[0]][0])
for each5 in enumerate(devices):
devices[each5[0]][0] = "/dev/%s" % ("".join(devices[each5[0]][0]))

parts = Gtk.ComboBoxText.new()
for each5 in enumerate(devices):
parts.append("%s" % (devices[each5[0]][0]),
"%s Size: %s" % (devices[each5[0]][0],
devices[each5[0]][1]))
dev_list = tuple(self.devices)
new_dev_list = [] # this will be the final list that is displayed for the user

# todo: account for BTRFS drives that have no partitions
for device in dev_list: # we will iterate through the dev list and add devices to the new list
try:
if device == []: # if the device is empty, we skip
continue
elif 'children' in device:
for child in device['children']:
if "type" not in child.keys(): # if it doesn't have a label, skip
continue
elif not child['type'] == 'part': # if it isn't labeled partition, skip
continue

test_child = {'name': child['name'], 'size': child['size']}

if test_child not in new_dev_list: # make sure child object is not already in dev_list
new_dev_list.append(test_child)
elif device["fstype"] != None:
# if the drive has no partition table, just a file system,
# add it
if device["fstype"] != "squashfs":
# don't add it, beacuse it's a squashfs file system
new_device = {"name": device["name"], "size": device["size"]}
new_dev_list.append(new_device)
elif "type" not in device.keys(): # if it doesn't have a label, skip
continue
elif device['type'] != 'part':
# if it isn't labeled partition, skip
continue
else:
new_device = {'name': device['name'], 'size': device['size']}

new_dev_list.append(new_device)
except KeyError:
common.eprint(traceback.format_exc())
print(json.dumps(device, indent=2))

# TEMPORARY: Remove the ability to use a home partition on the same
# drive as where the root partition is
for each in range(len(new_dev_list) - 1, -1, -1):
if self.data["ROOT"][5:] in new_dev_list[each]["name"]:
del new_dev_list[each]

home_cmbbox = Gtk.ComboBoxText.new()

# properly format device names and add to combo box
for device in new_dev_list:
if device["name"][:5] != "/dev/":
device['name'] = "/dev/%s" % device['name']

home_cmbbox.append(device['name'], "%s Size: %s" % (device['name'], device['size']))

if self.data["HOME"] != "":
parts.set_active_id(self.data["HOME"])
parts.connect("changed", self.select_home_part)
parts = self._set_default_margins(parts)
self.grid.attach(parts, 1, 5, 2, 1)
home_cmbbox.set_active_id(self.data["HOME"])
home_cmbbox.connect("changed", self.select_home_part)
parts = self._set_default_margins(home_cmbbox)
self.grid.attach(home_cmbbox, 1, 5, 2, 1)
else:
self.data["HOME"] = "MAKE"

Expand Down