mirror of
https://github.com/truenas/scale-build.git
synced 2025-12-24 21:07:00 +00:00
Add initial commit outlining scale-build python structure
This commit is contained in:
57
scale_build/preflight.py
Normal file
57
scale_build/preflight.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from .exceptions import CallError, MissingPackagesException
|
||||
from .utils.manifest import get_manifest
|
||||
from .utils.system import has_low_ram
|
||||
from .utils.variables import TMP_DIR, HASH_DIR, LOG_DIR, PKG_DIR
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
WANTED_PACKAGES = {
|
||||
'make',
|
||||
'debootstrap',
|
||||
'git',
|
||||
'xorriso',
|
||||
'grub-mkrescue',
|
||||
'mksquashfs',
|
||||
'unzip',
|
||||
}
|
||||
|
||||
|
||||
def is_root():
|
||||
return os.geteuid() == 0
|
||||
|
||||
|
||||
def retrieve_missing_packages():
|
||||
missing = {pkg for pkg in WANTED_PACKAGES if not shutil.which(pkg)}
|
||||
if not os.path.exists('/lib/grub/x86_64-efi') and not os.path.exists('/usr/lib/grub/x86_64-efi'):
|
||||
missing.add('grub-efi-amd64-bin')
|
||||
|
||||
if not os.path.exists('/lib/grub/i386-pc') and not os.path.exists('/usr/lib/grub/i386-pc'):
|
||||
missing.add('grub-pc-bin')
|
||||
|
||||
return missing
|
||||
|
||||
|
||||
def setup_dirs():
|
||||
for d in (TMP_DIR, HASH_DIR, LOG_DIR, PKG_DIR):
|
||||
os.makedirs(d, exist_ok=True)
|
||||
|
||||
|
||||
def preflight_check():
|
||||
# TODO: Please see how we should delete overlayfs/bootstrapdir when exceptions are raised
|
||||
if not is_root():
|
||||
raise CallError('Must be run as root (or using sudo)!')
|
||||
|
||||
missing_packages = retrieve_missing_packages()
|
||||
if missing_packages:
|
||||
raise MissingPackagesException(missing_packages)
|
||||
|
||||
if has_low_ram():
|
||||
logging.warning('WARNING: Running with less than 16GB of memory. Build may fail...')
|
||||
|
||||
setup_dirs()
|
||||
get_manifest()
|
||||
Reference in New Issue
Block a user