summaryrefslogtreecommitdiff
path: root/recipes-core/mlinux/mlinux-version.bb
blob: 3960f4742b60cff6dace862b3366d1cc7088f7c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

inherit mlinux_metadata_scm

# always parse this file so PV can change automatically
BB_DONT_CACHE = "1"

PV = "${DISTRO_VERSION}_${MLINUX_METADATA_REVISION}"
PR = "r3"
PE = "1"

PACKAGES = "${PN}"
PACKAGE_ARCH = "${MACHINE_ARCH}"

do_install() {
	mkdir -p ${D}${sysconfdir}
	echo "mLinux ${DISTRO_VERSION}" > ${D}${sysconfdir}/mlinux-version
	echo "Built from branch: ${MLINUX_METADATA_BRANCH}" >> ${D}${sysconfdir}/mlinux-version
	echo "Revision: ${MLINUX_METADATA_REVISION}" >> ${D}${sysconfdir}/mlinux-version
	echo "${MLINUX_LAYERS}" > ${D}${sysconfdir}/mlinux-layers
}

image_version = "${@define_iv(d)}"

def define_iv(d):
    import subprocess
    source_dir = d.getVar('OEROOT',True)
    cmd = "git describe"
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, cwd=source_dir)
    out, err =  proc.communicate()
    return out.decode("utf-8").rstrip()

# For mLinux only, update the version on postinst
# Should not affect Convergence.
pkg_postinst_${PN}() {

# Not for image builds
  if [ -n "$D" ] ; then
    exit 0
  fi

# If this is mLinux, update the version
  mlinux="^MultiTech Systems mLinux GNU/Linux$"
  version="Version: "
  if grep "${mlinux}" /etc/issue ; then
    tmpf=$(mktemp)
    cp -a /etc/issue $tmpf
    sed -i "s/^${version}.*/${version}${image_version}/" ${tmpf}
    if ! cmp /etc/issue ${tmpf} ; then
      mv ${tmpf} /etc/issue
    fi
  fi
}