Skip to content
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 contrib/cryptpass.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
4 changes: 2 additions & 2 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) 2011-2014 TurnKey GNU/Linux - http://www.turnkeylinux.org
Copyright (c) 2020-2021 TurnKey GNU/Linux - http://www.turnkeylinux.org
Copyright (c) 2011-2014 TurnKey GNU/Linux - https://www.turnkeylinux.org
Copyright (c) 2020-2021 TurnKey GNU/Linux - https://www.turnkeylinux.org

Fab is free software; you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published by the
Expand Down
4 changes: 2 additions & 2 deletions docs/GNU-AGPL-3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

Expand All @@ -658,4 +658,4 @@ specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
2 changes: 1 addition & 1 deletion fab
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python3
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
2 changes: 1 addition & 1 deletion fablib/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
2 changes: 1 addition & 1 deletion fablib/cpp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
2 changes: 1 addition & 1 deletion fablib/help.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
111 changes: 57 additions & 54 deletions fablib/installer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand All @@ -7,30 +7,28 @@
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.

import io
import os
from os.path import join, exists, basename
import shutil
from typing import (
Iterable, Optional, Dict, Tuple, List, TextIO, IO, AnyStr, cast
)
from typing import Iterable, TextIO, cast
import logging
logger = logging.getLogger('fab.installer')

import hashlib
from debian import debfile

from chroot import Chroot
from fablib import common

logger = logging.getLogger("fab.installer")


class Error(Exception):
pass


class RevertibleFile:
"""File that automatically reverts to previous state on destruction
or if the revert method is invoked"""
or if the revert method is invoked"""

@staticmethod
def _get_orig_path(path: str) -> str:
Expand All @@ -43,16 +41,16 @@ def _get_orig_path(path: str) -> str:
i += 1

def __init__(self, path: str):
self.orig_path: Optional[str] = None
self.orig_path: str | None = None
if exists(path):
self.orig_path = self._get_orig_path(path)
shutil.move(path, self.orig_path)
self.path: Optional[str] = path
self.path: str | None = path

self._inner = open(path, 'w')
self._inner = open(path, "w")

def revert(self) -> None:
''' revert file to original state '''
"""revert file to original state"""
if self.orig_path is not None:
assert self.path is not None
shutil.move(self.orig_path, self.path)
Expand All @@ -74,7 +72,8 @@ def __del__(self) -> None:


class RevertibleScript(RevertibleFile):
''' RevertibleFile that ensures file is executable '''
"""RevertibleFile that ensures file is executable"""

def __init__(self, path: str, lines: Iterable[str]):
super().__init__(path)
self.write("\n".join(lines))
Expand All @@ -84,10 +83,7 @@ def __init__(self, path: str, lines: Iterable[str]):


class Installer:
def __init__(
self, chroot_path: str,
environ: dict[str, str] = None
):
def __init__(self, chroot_path: str, environ: dict[str, str] | None = None):
if environ is None:
environ = {}
env = {"DEBIAN_FRONTEND": "noninteractive", "DEBIAN_PRIORITY": "critical"}
Expand All @@ -98,7 +94,7 @@ def __init__(
@staticmethod
def _get_packages_priority(packages: list[str]) -> tuple[list[str], list[str]]:
"""high priority packages must be installed before regular packages
APT should handle this, but in some circumstances it chokes...
APT should handle this, but in some circumstances it chokes...
"""
HIGH_PRIORITY = "linux-image"

Expand All @@ -114,22 +110,25 @@ def _get_packages_priority(packages: list[str]) -> tuple[list[str], list[str]]:
return high, regular

def _install(
self, packages: list[str],
ignore_errors: list[str] = None,
extra_apt_args: list[str] = None) -> None:

self,
packages: list[str],
ignore_errors: list[str] | None = None,
extra_apt_args: list[str] | None = None,
) -> None:
if ignore_errors is None:
ignore_errors = []
if extra_apt_args is None:
extra_apt_args = []
high, regular = self._get_packages_priority(packages)

lines = ["#!/bin/sh", "echo", 'echo "Warning: Fake invoke-rc.d called"']
# TODO fake_invoke_rcd not accessed
fake_invoke_rcd = RevertibleScript(
join(self.chroot.path, "usr/sbin/invoke-rc.d"), lines
)

lines = ["#!/bin/sh", "echo", 'echo "Warning: Fake start-stop-daemon called"']
# TODO fake_start_stop not accessed
fake_start_stop = RevertibleScript(
join(self.chroot.path, "sbin/start-stop-daemon"), lines
)
Expand All @@ -139,15 +138,21 @@ def _install(
"#!/bin/sh",
"echo",
'echo "Warning: Deferring update-initramfs $@"',
f'echo "update-initramfs $@" >> /{defer_log}'
f'echo "update-initramfs $@" >> /{defer_log}',
]

for packages in (high, regular):
if packages:
args = ["-o", "Debug::pkgProblemResolver=true", "install", "--assume-yes"]
args = [
"-o",
"Debug::pkgProblemResolver=true",
"install",
"--assume-yes",
]
args.extend(extra_apt_args)
apt_return_code = self.chroot.system(
f"apt-get {' '.join((args + packages))}")
f"apt-get {' '.join((args + packages))}"
)
if apt_return_code != 0:

def get_last_log(path: str) -> list[str]:
Expand Down Expand Up @@ -184,8 +189,7 @@ def get_errors(log: list[str], error_str: str) -> list[str]:
if apt_return_code == 100:
# always seems to return 100 when hitting
# 'E: Unable to locate package ...'
raise Error(
'Errors encountered installing packages')
raise Error("Errors encountered installing packages")
else:
continue

Expand All @@ -195,13 +199,15 @@ def get_errors(log: list[str], error_str: str) -> list[str]:
errors = set(errors) - set(ignore_errors)

if ignored_errors:
print(f"Warning: ignoring package installation errors"
f" ({' '.join(ignored_errors)})")
print(
f"Warning: ignoring package installation errors"
f" ({' '.join(ignored_errors)})"
)

if errors:
for error in errors:
common.error(error)
raise Error('package installation errors')
raise Error("package installation errors")

defer_log = join(self.chroot.path, defer_log)
if exists(defer_log):
Expand All @@ -216,22 +222,26 @@ def get_errors(log: list[str], error_str: str) -> list[str]:
if self.chroot.system("update-initramfs -u") != 0:
self.chroot.system("live-update-initramfs -u")
else:
if self.chroot.system(
f"update-initramfs -c -k {kversion}") != 0:
if self.chroot.system(f"update-initramfs -c -k {kversion}") != 0:
self.chroot.system(f"live-update-initramfs -c -k {kversion}")

os.remove(defer_log)

def install(
self, packages: list[str],
ignore_errors: list[str] = None) -> None:
self, packages: list[str], ignore_errors: list[str] | None = None
) -> None:
# TODO implement or remove
raise NotImplementedError()


class PoolInstaller(Installer):
def __init__(
self, chroot_path: str, pool_path: str,
arch: str, environ: dict[str, str] = None):
self,
chroot_path: str,
pool_path: str,
arch: str,
environ: dict[str, str] | None = None,
):
super(PoolInstaller, self).__init__(chroot_path, environ)

from pool_lib import Pool
Expand All @@ -247,17 +257,18 @@ def filesize(path: str) -> str:
return str(os.stat(path).st_size)

def md5sum(path: str) -> str:
with open(path, 'rb') as fob:
with open(path, "rb") as fob:
return str(hashlib.md5(fob.read()).hexdigest())

def sha256sum(path: str) -> str:
with open(path, 'rb') as fob:
with open(path, "rb") as fob:
return str(hashlib.sha256(fob.read()).hexdigest())

index = []
for package in os.listdir(packagedir):
path = os.path.join(packagedir, package)
# dl_path would best be calculated; but we don't have access to chroot_path here...
# dl_path would best be calculated; but we don't
# have access to chroot_path here...
dl_path = os.path.join("var/cache/apt/archives", package)
if path.endswith(".deb"):
control = debfile.DebFile(path).debcontrol()
Expand All @@ -273,8 +284,7 @@ def sha256sum(path: str) -> str:
return index

def install(
self, packages: list[str],
ignore_errors: list[str] = None
self, packages: list[str], ignore_errors: list[str] | None = None
) -> None:
"""install packages into chroot via pool"""

Expand Down Expand Up @@ -308,29 +318,22 @@ def install(

class LiveInstaller(Installer):
def __init__(
self, chroot_path: str,
apt_proxy: str = None,
environ: dict[str, str] = None):
self,
chroot_path: str,
apt_proxy: str | None = None,
environ: dict[str, str] | None = None,
):
super(LiveInstaller, self).__init__(chroot_path, environ)

self.apt_proxy = apt_proxy

def install(
self, packages: list[str],
ignore_errors: list[str] = None) -> None:
self, packages: list[str], ignore_errors: list[str] | None = None
) -> None:
"""install packages into chroot via live apt"""
if ignore_errors is None:
ignore_errors = []

# For v17.x I've moved the apt setting to common. I think that is the
# right place for it, but haven't 100% committed yet. For now I'm
# leaving this here commented...
#if self.apt_proxy:
# print("setting apt proxy settings...")
# conf_path = join(self.chroot.path, "etc/apt/apt.conf.d/01proxy")
# with open(conf_path, "w") as fob:
# fob.write('Acquire::http::Proxy "%s";\n' % self.apt_proxy)

print("updating package lists...")
self.chroot.system("apt-get update")

Expand Down
2 changes: 1 addition & 1 deletion fablib/plan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
2 changes: 1 addition & 1 deletion share/make-release-deb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python3
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
2 changes: 1 addition & 1 deletion share/product.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/make -f
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down
2 changes: 1 addition & 1 deletion share/turnkey-version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python3
# Copyright (c) TurnKey GNU/Linux - http://www.turnkeylinux.org
# Copyright (c) TurnKey GNU/Linux - https://www.turnkeylinux.org
#
# This file is part of Fab
#
Expand Down