parent
74048d616e
commit
d18cae4a1e
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 8.2 KiB |
@ -0,0 +1,94 @@
|
|||||||
|
# install_prefs.py
|
||||||
|
#
|
||||||
|
# Copyright 2022
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
from jade_gui.utils import disks
|
||||||
|
import json
|
||||||
|
|
||||||
|
class InstallPrefs:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
timezone,
|
||||||
|
layout,
|
||||||
|
variant,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
enable_sudo,
|
||||||
|
disk,
|
||||||
|
hostname,
|
||||||
|
ipv_enabled,
|
||||||
|
timeshift_enable,
|
||||||
|
desktop,
|
||||||
|
):
|
||||||
|
self.timezone = timezone
|
||||||
|
self.layout = layout
|
||||||
|
self.variant = variant
|
||||||
|
self.username = username
|
||||||
|
self.password = password
|
||||||
|
self.enable_sudo = enable_sudo
|
||||||
|
self.disk = disk.disk
|
||||||
|
self.hostname = hostname if len(hostname) != 0 else "crystal"
|
||||||
|
self.ipv_enabled = ipv_enabled
|
||||||
|
self.timeshift_enable = timeshift_enable
|
||||||
|
self.desktop = desktop
|
||||||
|
self.is_efi = disks.get_uefi()
|
||||||
|
self.bootloader_type = "grub-efi" if self.is_efi else "grub-legacy"
|
||||||
|
self.bootloader_location = "/boot/efi" if self.is_efi else self.disk
|
||||||
|
|
||||||
|
def generate_json(self):
|
||||||
|
prefs = {
|
||||||
|
"partition": {
|
||||||
|
"device": self.disk,
|
||||||
|
"mode": "Auto",
|
||||||
|
"efi": self.is_efi,
|
||||||
|
"partitions": "",
|
||||||
|
},
|
||||||
|
"bootloader": {
|
||||||
|
"type": self.bootloader_type,
|
||||||
|
"location": self.bootloader_location,
|
||||||
|
},
|
||||||
|
"locale": {
|
||||||
|
"locale": [
|
||||||
|
self.timezone.locale
|
||||||
|
],
|
||||||
|
"keymap": self.layout.country_shorthand,
|
||||||
|
"timezone": self.timezone.region+"/"+self.timezone.location,
|
||||||
|
},
|
||||||
|
"networking": {
|
||||||
|
"hostname": self.hostname,
|
||||||
|
"ipv6": self.ipv_enabled,
|
||||||
|
},
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"name": self.username,
|
||||||
|
"password": self.password,
|
||||||
|
"hasroot": self.enable_sudo,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"rootpass": self.password,
|
||||||
|
"desktop": self.desktop.lower(),
|
||||||
|
"unakite": {
|
||||||
|
"enable": False,
|
||||||
|
"root": "/dev/null",
|
||||||
|
"oldroot": self.disk,
|
||||||
|
"efidir": "/dev/null",
|
||||||
|
"bootdev": "/dev/null",
|
||||||
|
},
|
||||||
|
"kernel": "linux"
|
||||||
|
}
|
||||||
|
return json.dumps(prefs)
|
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
flatpak-spawn --host pkexec jade /tmp/jade.json
|
||||||
|
#flatpak-spawn --host echo "hi"
|
||||||
|
#flatpak-spawn --host pkexec whoami
|
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
#echo $1
|
||||||
|
flatpak-spawn --host bash -c "echo $1 > /tmp/jade.json"
|
@ -0,0 +1,74 @@
|
|||||||
|
# This file was taken from bottles <https://usebottles.com> with the permission from brombinmirko
|
||||||
|
#
|
||||||
|
# threading.py
|
||||||
|
#
|
||||||
|
# Copyright 2022 brombinmirko <send@mirko.pm>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, in version 3 of the License.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class RunAsync(threading.Thread):
|
||||||
|
"""
|
||||||
|
This class is used to execute a function asynchronously.
|
||||||
|
It takes a function, a callback and a list of arguments as input.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, task_func, callback=None, *args, **kwargs):
|
||||||
|
if "DEBUG_MODE" in os.environ:
|
||||||
|
import faulthandler
|
||||||
|
faulthandler.enable()
|
||||||
|
|
||||||
|
self.source_id = None
|
||||||
|
assert threading.current_thread() is threading.main_thread()
|
||||||
|
|
||||||
|
super(RunAsync, self).__init__(
|
||||||
|
target=self.__target, args=args, kwargs=kwargs)
|
||||||
|
|
||||||
|
self.task_func = task_func
|
||||||
|
|
||||||
|
self.callback = callback if callback else lambda r, e: None
|
||||||
|
self.daemon = kwargs.pop("daemon", True)
|
||||||
|
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def __target(self, *args, **kwargs):
|
||||||
|
result = None
|
||||||
|
error = None
|
||||||
|
|
||||||
|
print(f"DEBUG: Running async job [{self.task_func}].")
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = self.task_func(*args, **kwargs)
|
||||||
|
except Exception as exception:
|
||||||
|
print("ERROR: while running async job: "
|
||||||
|
f"{self.task_func}\nException: {exception}")
|
||||||
|
|
||||||
|
error = exception
|
||||||
|
_ex_type, _ex_value, trace = sys.exc_info()
|
||||||
|
traceback.print_tb(trace)
|
||||||
|
traceback_info = '\n'.join(traceback.format_tb(trace))
|
||||||
|
|
||||||
|
print([str(exception), traceback_info])
|
||||||
|
self.source_id = GLib.idle_add(self.callback, result, error)
|
||||||
|
return self.source_id
|
||||||
|
|
Loading…
Reference in New Issue