From 395488354792530fa5711929edd7f8ce6514e2cd Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Wed, 23 Aug 2017 18:40:16 +0200 Subject: [PATCH] Write custom os-release (closes #324) (#439) * Write custom os-release (closes #324) * Return empty string instead of crashing when the directory is not a git repository * Use https in homepage URL --- pmb/helpers/git.py | 11 +++++++++++ pmb/install/file.py | 42 ++++++++++++++++++++++++++++++++++++++++++ pmb/install/install.py | 2 ++ 3 files changed, 55 insertions(+) create mode 100644 pmb/install/file.py diff --git a/pmb/helpers/git.py b/pmb/helpers/git.py index 4eed7b1e..fc255019 100644 --- a/pmb/helpers/git.py +++ b/pmb/helpers/git.py @@ -33,3 +33,14 @@ def clone(args, repo_name): logging.info("(native) git clone " + pmb.config.git_repos[repo_name]) pmb.chroot.user(args, ["git", "clone", "--depth=1", pmb.config.git_repos[repo_name], repo_name], working_dir="/home/user/git/") + + +def rev_parse(args, revision="HEAD"): + rev = pmb.helpers.run.user(args, ["git", "rev-parse", revision], + working_dir=args.aports, + return_stdout=True, + check=False) + if rev is None: + logging.warning("WARNING: Failed to determine revision of git repository at " + args.aports) + return "" + return rev.rstrip() diff --git a/pmb/install/file.py b/pmb/install/file.py new file mode 100644 index 00000000..52d4203e --- /dev/null +++ b/pmb/install/file.py @@ -0,0 +1,42 @@ +""" +Copyright 2017 Pablo Castellano + +This file is part of pmbootstrap. + +pmbootstrap 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. + +pmbootstrap 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 pmbootstrap. If not, see . +""" +import logging + +import pmb.config +import pmb.helpers.git + + +def write_os_release(args, suffix): + logging.info("(" + suffix + ") write /etc/os-release") + revision = pmb.helpers.git.rev_parse(args) + filepath = args.work + "/chroot_" + suffix + "/tmp/os-release" + os_release = ('PRETTY_NAME="postmarketOS {version}"\n' + 'NAME="postmarketOS"\n' + 'VERSION_ID="{version}"\n' + 'VERSION="{version}-{hash:.8}"\n' + 'ID="postmarketos"\n' + 'ID_LIKE="alpine"\n' + 'HOME_URL="https://www.postmarketos.org/"\n' + 'SUPPORT_URL="https://github.com/postmarketOS/"\n' + 'BUG_REPORT_URL="https://github.com/postmarketOS/"\n' + 'PMOS_HASH="{hash}"\n' + ).format(version=pmb.config.version, hash=revision) + with open(filepath, "w") as handle: + handle.write(os_release) + pmb.chroot.root(args, ["mv", "/tmp/os-release", "/etc/os-release"], suffix) diff --git a/pmb/install/install.py b/pmb/install/install.py index b3a7b4e3..f5c2283d 100644 --- a/pmb/install/install.py +++ b/pmb/install/install.py @@ -27,6 +27,7 @@ import pmb.chroot.initfs import pmb.config import pmb.helpers.run import pmb.install.blockdevice +import pmb.install.file import pmb.install @@ -181,6 +182,7 @@ def install(args): # because that doesn't always happen automatically yet, e.g. when the user # installed a hook without pmbootstrap - see #69 for more info) pmb.chroot.apk.install(args, install_packages, suffix) + pmb.install.file.write_os_release(args, suffix) for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix): pmb.chroot.initfs.build(args, flavor, suffix)