Exemple #1
0
    def _setup_unattended_installation(self):
        if not Path("/etc/calamares").exists():
                return

        packagename = util.package_name()
        calamares_modules = [
            str(f.locate()) for f in app_files(packagename) if "calamares" in str(f) and str(f).endswith(".conf")
        ]
        if calamares_modules:
            SpawnedSU.do(f"mkdir -p /etc/calamares/modules && cp {' '.join(calamares_modules)} /etc/calamares/modules")
Exemple #2
0
    def run(self):
        # check partman availability
        if not Spawned.do("which partman", with_status=True).success:
            _tlog("[II] partman not found => skip PartmanHelper actions")
            return

        script = re_script()
        self.visuals_updater = create_py_script(script)

        SpawnedSU.do_script(f"""
            echo "Waiting for PARTMAN files in '{PARTMAN_BASE}' ..."
            while [ ! -d {PARTMAN_BASE} ]; do
                sleep 1
            done
            echo ""PARTMAN files found. Ready for processing.""
            """)

        for p in self.scheme:
            if p.mountpoint and not p.isspecial:
                self.mark_to_use(p.url, p.mountpoint, p.do_format, p.fs)
Exemple #3
0
 def _encrypt(partition, passphrase=None):
     assert isinstance(
         partition,
         LUKS), f"Partition {partition.id} doesn't look like a LUKS volume"
     if passphrase:
         partition._passphrase = passphrase
     with SpawnedSU(
             f"cryptsetup luksFormat --type={partition.luks_type} {partition.url}",
             timeout=600) as t:
         t.interact("Type .*yes.*$", "YES", exact=False)
         t.interact("Enter passphrase for", partition.passphrase)
         t.interact("Verify passphrase", partition.passphrase)
Exemple #4
0
    def mark_to_use(self, volume_url, mountpoint, do_format, fs):
        volume_path = self.resolver.pm_resolve_volume_path(volume_url)
        SpawnedSU.do_script(f"""
            while [ ! -d {volume_path} ]
            do
                sleep 1
                echo "waiting for {volume_path} ..."
            done

            touch {volume_path}/existing
            touch {volume_path}/formatable
            touch {volume_path}/use_filesystem
            echo "{mountpoint}" > {volume_path}/mountpoint

            if [ "{do_format}" == "True" ]; then
                touch {volume_path}/format
                echo "format" > {volume_path}/method
                echo "{fs}" > {volume_path}/filesystem
                echo "{fs}" > {volume_path}/acting_filesystem
            else
                echo "keep" > {volume_path}/method

                while [ ! -f {volume_path}/detected_filesystem ]
                do
                    sleep 1
                    echo "waiting for {volume_path}/detected_filesystem ..."
                done

                cat {volume_path}/detected_filesystem > {volume_path}/acting_filesystem
                cat {volume_path}/detected_filesystem > {volume_path}/filesystem
            fi

            # replace visuals
            echo "{mountpoint}" > {volume_path}/visual_mountpoint
            python3 "{self.visuals_updater}" "{volume_path}/view" "{do_format}" "{mountpoint}"
            python3 "{self.visuals_updater}" "{volume_path}/../partition_tree_cache" "{do_format}" "{mountpoint}"
            python3 "{self.visuals_updater}" "{PARTMAN_BASE}/snoop" "{do_format}" "{mountpoint}"
            """)
Exemple #5
0
    def _prepare_installation(self):
        # clear partman cache
        SpawnedSU.do("rm -rf /var/lib/partman")

        # clear debconf cache
        # note: removing the DB leads the ubiquity installer to crash
        SpawnedSU.do_script("""
            if [ ! -d /var/cache/debconf.back ]; then
                cp -r /var/cache/debconf/ /var/cache/debconf.back
            else
                rm -rf /var/cache/debconf
                cp -r /var/cache/debconf.back /var/cache/debconf
            fi
            """)

        # ensure crypt/lvm volumes are available
        dm_list = Spawned.do(f"ls /dev/mapper", list_=True)
        for pt in [pt for pt in self.scheme if pt.mapperID]:
            if isinstance(pt.parent, Disk) and pt.mapperID not in dm_list:
                pt.execute(Involve())

        # wait for Partman and modify values in background
        PartmanHelper(self.scheme).run()
Exemple #6
0
    def _begin_installation(self):
        if 0:  # calamares
            Spawned.do("/usr/bin/calamares_polkit", timeout=Spawned.TIMEOUT_INFINITE)

        else:  # manjaro-architect
            # ensure the setup script is installed
            if not SpawnedSU.do("which setup || pacman -S manjaro-architect --noconfirm --needed --noprogressbar", with_status=True).success:
                _tlog("manjaro-architect isn't available. Abort...")
                app_exit()

            # run manjaro-architect
            t = SpawnedSU("setup", timeout=Spawned.TIMEOUT_INFINITE)
            t.interact_user()
            t.waitfor(SpawnedSU.TASK_END)
Exemple #7
0
    def system_volumes(self):
        if not self._system_volumes:
            t = SpawnedSU("parted -s /dev 'unit B print all' 2>/dev/null")

            current_key = ""

            re_disk_name = r"Disk[\s\t]+(.*?):[\s\t]+\d+"
            re_partition_number = r"(\d+)[\s\t]+(\d+)B[\s\t]+(\d+)B[\s\t]+(\d+)B"

            def geometry_parser(data_line):
                nonlocal current_key

                if mo := re.search(re_disk_name, data_line):
                    # group-1 : disk, e.g. /dev/sda or /dev/mapper/swap
                    current_key = mo.group(1)
                    return
                elif mo := re.search(re_partition_number, data_line):
                    partition_number = mo.group(1)
                    first_byte = mo.group(2)
                    last_byte = mo.group(3)
                    volume_key = current_key if "mapper" in current_key else current_key + partition_number
                    # returns a tuple ('volume_url', 'begin-end', 'disk_url') for each partition
                    return volume_key, f"{first_byte}-{last_byte}", current_key
Exemple #8
0
 def _luks_close(partition, mapper_id=None):
     name_to_close = partition.mapperID or mapper_id
     assert name_to_close, f"Is it LUKS? 'mapperID' is not defined for {partition.id}"
     SpawnedSU.do(f"cryptsetup close {name_to_close}")
Exemple #9
0
 def on_exit():
     if DisksMountHelper.daemon_active and not DisksMountHelper.is_daemon_active(
     ):
         SpawnedSU.do("systemctl start udisks2.service")
         print("udisks2.service started")
Exemple #10
0
 def __init__(self):
     DisksMountHelper.daemon_active = self.is_daemon_active()
     if DisksMountHelper.daemon_active:
         SpawnedSU.do("systemctl stop udisks2.service")
         print("udisks2.service stopped")
Exemple #11
0
 def _setup_unattended_installation(self):
     if seed_file := util.target.preseeding_file():
         SpawnedSU.do(f"debconf-set-selections {seed_file}")