Optionally store git hash in /etc/os-release (!1784)

When git isn't installed then the version is not appended with the git
hash of the pmaports repository.
This commit is contained in:
Robert Yang 2019-05-10 15:45:57 -04:00
parent e8cba8b20a
commit 0c001567b6
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 12 additions and 3 deletions

View file

@ -18,6 +18,7 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import logging
import os
import shutil
import pmb.build
import pmb.chroot.apk
@ -69,6 +70,11 @@ def clone(args, name_repo, shallow=True, chown_to_user=False):
def rev_parse(args, revision="HEAD"):
if shutil.which("git") is None:
logging.warning("WARNING: Cannot determine revision of git " +
"repository at " + args.aports + ". Command 'git' " +
"not found.")
return ""
rev = pmb.helpers.run.user(args, ["git", "rev-parse", revision],
args.aports, output_return=True, check=False)
if rev is None:

View file

@ -25,18 +25,21 @@ import pmb.helpers.git
def write_os_release(args, suffix):
logging.info("(" + suffix + ") write /etc/os-release")
revision = pmb.helpers.git.rev_parse(args)
has_revision = revision != ""
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'
'VERSION="{version}{sep}{hash:.8}"\n'
'ID="postmarketos"\n'
'ID_LIKE="alpine"\n'
'HOME_URL="https://www.postmarketos.org/"\n'
'SUPPORT_URL="https://gitlab.com/postmarketOS"\n'
'BUG_REPORT_URL="https://gitlab.com/postmarketOS/pmbootstrap/issues"\n'
'PMOS_HASH="{hash}"\n'
).format(version=pmb.config.version, hash=revision)
).format(version=pmb.config.version,
sep=("-" if has_revision else ""), hash=revision)
if has_revision:
os_release += ('PMOS_HASH="{hash}"\n').format(hash=revision)
with open(filepath, "w") as handle:
handle.write(os_release)
pmb.chroot.root(args, ["mv", "/tmp/os-release", "/etc/os-release"], suffix)