Merge pull request #58 from demostanis/master

Shell script calling python & support for specifying remote profiles and full paths
This commit is contained in:
Anton Hvornum 2020-11-02 20:28:19 +01:00 committed by GitHub
commit 887d5ded07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 41 deletions

View File

@ -1,5 +1,5 @@
# Maintainer: Anton Hvornum anton@hvornum.se # Maintainer: Anton Hvornum <anton@hvornum.se>
# Contributor: Anton Hvornum anton@hvornum.se # Contributor: demostanis worlds <demostanis@protonmail.com>
pkgname="archinstall" pkgname="archinstall"
pkgver="2.0.5" pkgver="2.0.5"
pkgdesc="Installs launcher scripts for archinstall" pkgdesc="Installs launcher scripts for archinstall"
@ -7,27 +7,23 @@ pkgrel=1
url="https://github.com/Torxed/archinstall" url="https://github.com/Torxed/archinstall"
license=('GPLv3') license=('GPLv3')
provides=("${pkgname}") provides=("${pkgname}")
md5sums=('SKIP')
arch=('x86_64') arch=('x86_64')
source=("${pkgname}-v${pkgver}-x86_64.tar.gz::https://github.com/Torxed/archinstall/archive/v$pkgver.tar.gz") source=("${pkgname}-v${pkgver}-x86_64.tar.gz::https://github.com/Torxed/archinstall/archive/v$pkgver.tar.gz")
depends=('python-archinstall') depends=('python-archinstall')
sha256sums=('04176c096d13589b874083aecbb9b1d34e676d2b784f55e5368f4ab83ff38c2e')
package() { package() {
mkdir -p "${pkgdir}/usr/bin" mkdir -p "${pkgdir}/usr/bin"
# Install a guided profile # Install a guided profile
echo '#!/bin/bash' > "${pkgdir}/usr/bin/archinstall-guided" cat - > "${pkgdir}/usr/bin/archinstall" <<EOF
echo 'python -m archinstall guided' >> "${pkgdir}/usr/bin/archinstall-guided" #!/bin/sh
# Install a minimal profile python -m archinstall $@
echo '#!/bin/bash' > "${pkgdir}/usr/bin/archinstall-minimal" EOF
echo 'python -m archinstall minimal' >> "${pkgdir}/usr/bin/archinstall-minimal"
# Install a unattended profile (safely aborts if no machine specific instructions are found) chmod +x "${pkgdir}/usr/bin/archinstall"
#echo '#!/bin/bash' > "${pkgdir}/usr/bin/archinstall-unattended"
#echo 'python -m archinstall unattended' >> "${pkgdir}/usr/bin/archinstall-unattended"
chmod +x "${pkgdir}/usr/bin/archinstall-guided"
chmod +x "${pkgdir}/usr/bin/archinstall-minimal"
#chmod +x "${pkgdir}/usr/bin/archinstall-unattended"
} }
# vim:ft=sh

View File

@ -1,26 +1,34 @@
# Maintainer: Anton Hvornum anton@hvornum.se # Maintainer: Anton Hvornum <anton@hvornum.se>
# Contributor: Anton Hvornum anton@hvornum.se # Contributor: demostanis worlds <demostanis@protonmail.com>
pkgname="python-archinstall" pkgname="python-archinstall"
pkgver="2.0.5" pkgver="2.0.5"
pkgdesc="Installs ${pkgname} as a python library." pkgdesc="Installs ${pkgname} as a python library."
pkgrel=1 pkgrel=1
url="https://github.com/Torxed/archinstall" url="https://github.com/Torxed/archinstall"
source=("${pkgname}-v${pkgver}-x86_64.tar.gz::https://github.com/Torxed/archinstall/archive/v$pkgver.tar.gz")
license=('GPLv3') license=('GPLv3')
provides=("${pkgname}") provides=("${pkgname}")
md5sums=('SKIP')
arch=('x86_64') arch=('x86_64')
source=("${pkgname}-v${pkgver}-x86_64.tar.gz::https://github.com/Torxed/archinstall/archive/v$pkgver.tar.gz")
depends=('python>=3.8') depends=('python>=3.8')
optdepends=('pyttsx3: Adds text-to-speach support for log/screen output.') makedepends=('python-setuptools')
optdepends=('pyttsx3: Adds text-to-speech support for log/screen output.')
sha256sums=('04176c096d13589b874083aecbb9b1d34e676d2b784f55e5368f4ab83ff38c2e')
build() { build() {
cd "archinstall-${pkgver}" cd "archinstall-${pkgver}"
python3 setup.py build python setup.py build
} }
package() { package() {
cd "archinstall-${pkgver}" cd "archinstall-${pkgver}"
python setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1 python setup.py install \
--prefix=/usr \
--root="${pkgdir}" \
--optimize=1
} }
# vim:ft=sh

View File

@ -1,12 +1,18 @@
import archinstall, sys, os, glob from urllib.parse import urlparse
import importlib.util import archinstall
import sys
import os
import glob
import urllib.request
# TODO: Learn the dark arts of argparse... # TODO: Learn the dark arts of argparse...
# (I summon thee dark spawn of cPython) # (I summon thee dark spawn of cPython)
class ProfileNotFound(BaseException): class ProfileNotFound(BaseException):
pass pass
def find_examples(): def find_examples():
""" """
Used to locate the examples, bundled with the module or executable. Used to locate the examples, bundled with the module or executable.
@ -19,32 +25,47 @@ def find_examples():
return {os.path.basename(path): path for path in glob.glob(f'{examples}/*.py')} return {os.path.basename(path): path for path in glob.glob(f'{examples}/*.py')}
def find(url):
parsed_url = urlparse(url)
if not parsed_url.scheme:
examples = find_examples()
if f"{url}.py" in examples:
return open(examples[f"{url}.py"]).read()
try:
return open(url, 'r').read()
except FileNotFoundError:
return ProfileNotFound(f"File {url} does not exist")
elif parsed_url.scheme in ('https', 'http'):
return urllib.request.urlopen(url).read().decode('utf-8')
else:
return ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
def run_as_a_module(): def run_as_a_module():
""" """
Since we're running this as a 'python -m archinstall' module OR Since we're running this as a 'python -m archinstall' module OR
a nuitka3 compiled version of the project. a nuitka3 compiled version of the project.
This function and the file __main__ acts as a entry point. This function and the file __main__ acts as a entry point.
""" """
if len(sys.argv) == 1: sys.argv.append('guided')
profile = sys.argv[1] if len(sys.argv) == 1:
library = find_examples() sys.argv.append('guided')
if f'{profile}.py' not in library: try:
raise ProfileNotFound(f'Could not locate {profile}.py among the example files.') profile = find(sys.argv[1])
except ProfileNotFound as err:
print(f"Couldn't find file: {err}")
sys.exit(1)
# Swap the working dir, otherwise certain relative lookups won't work within archinstall.
# Mainly to avoid https://github.com/Torxed/archinstall/issues/59
os.chdir(os.path.abspath(os.path.dirname(__file__))) os.chdir(os.path.abspath(os.path.dirname(__file__)))
# Import and execute the chosen `<profile>.py`: try:
spec = importlib.util.spec_from_file_location( exec(profile) # Is this is very safe?
library[f"{profile}.py"], except Exception as err:
library[f"{profile}.py"] print(f"Failed to run profile... {err}")
) sys.exit(1) # Should prompt for another profile path instead
imported_path = importlib.util.module_from_spec(spec)
spec.loader.exec_module(imported_path)
sys.modules[library[f'{profile}.py']] = imported_path
if __name__ == '__main__': if __name__ == '__main__':
run_as_a_module() run_as_a_module()