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
This commit is contained in:
Pablo Castellano 2017-08-23 18:40:16 +02:00 committed by Oliver Smith
parent ad17254e86
commit 3954883547
3 changed files with 55 additions and 0 deletions

View File

@ -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()

42
pmb/install/file.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
"""
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)

View File

@ -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)