Skip to content

Commit f0eb5a4

Browse files
committed
Use /etc/os-release as alternative when lsb_release is not available
Extract the OS/release information This is not 100% doable with /etc/os-release only. The Debian difference between Release & Codename is not shown in the official containers for example. See: https://hub.docker.com/_/debian
1 parent 030078c commit f0eb5a4

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

misc-tools/dj_make_chroot.in

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ cleanup() {
2323
}
2424
trap cleanup EXIT
2525

26+
if command -v lsb_release; then
27+
get_host () {
28+
lsb_release -i -s
29+
}
30+
get_codename () {
31+
lsb_release -c -s
32+
}
33+
get_release () {
34+
lsb_release -r -s
35+
}
36+
elif -f /etc/os-release; then
37+
sel_grep () {
38+
# Discard everything up to \K and make sure line ends with '"'.
39+
grep -oP '^${1}="\K.*(?=")' /etc/os_release
40+
}
41+
get_host () {
42+
sel_grep "NAME"
43+
}
44+
get_codename () {
45+
sel_gep "VERSION_CODENAME"
46+
}
47+
get_release () {
48+
echo "Please install `lsb_release`."
49+
exit 1
50+
}
51+
else
52+
echo "Please install `lsb_release`."
53+
exit 1
54+
fi
55+
2656
# Default directory where to build the chroot tree:
2757
CHROOTDIR="@judgehost_chrootdir@"
2858

@@ -35,15 +65,14 @@ DEBIAN_ARCHLIST="amd64,arm64,armel,armhf,i386,mips,mips64el,mipsel,ppc64el,s390x
3565
UBUNTU_ARCHLIST="amd64,arm64,armhf,i386,powerpc,ppc64el,s390x"
3666

3767
# If host system is Debian or Ubuntu, use its release and architecture by default
38-
if [ "$(lsb_release -i -s || true)" = 'Debian' ] || \
39-
[ "$(lsb_release -i -s || true)" = 'Ubuntu' ]; then
40-
DISTRO="$(lsb_release -i -s)"
41-
RELEASE="$(lsb_release -c -s)"
42-
if [ "$(lsb_release -i -s)" = 'Debian' ]; then
43-
if [ "$(lsb_release -c -s)" = "sid" ]; then
68+
if [ get_host = 'Debian' ] || [ get_host = 'Ubuntu' ]; then
69+
DISTRO="$(get_host)"
70+
RELEASE="$(get_codename)"
71+
if [ get_host = 'Debian' ]; then
72+
if [ "$(get_codename)" = "sid" ]; then
4473
RELEASE='unstable'
4574
fi
46-
if [ "$(lsb_release -r -s)" = 'testing' ]; then
75+
if [ "$(get_release)" = 'testing' ]; then
4776
RELEASE='testing'
4877
fi
4978
fi

0 commit comments

Comments
 (0)