[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

FWD: os-prober: bsd detection and new linux detection



----- Forwarded message from Andrew Gavrilin <andrew.gavrilin@rosalab.ru> -----

Date: Thu, 6 Oct 2011 17:28:36 +0400 (MSD)
From: Andrew Gavrilin <andrew.gavrilin@rosalab.ru>
To: joey@kitenet.net, joeyh@debian.org
Subject: os-prober: bsd detection and new linux detection
X-Mailer: Zimbra 6.0.10_GA_2692 (ZimbraWebClient - FF3.0
	(Linux)/6.0.10_GA_2692)

Hello.

Hello. I work at ROSA Lab. It's a partner of Mandriva. We will use os-prober for our installer. These are my improvements.

----- End forwarded message -----

-- 
see shy jo
#!/bin/sh
# Sub-tests that require a mounted partition.
set -e
partition="$1"

. /usr/share/os-prober/common.sh

types="$(fs_type "$partition")" || types=NOT-DETECTED
if [ "$types" = NOT-DETECTED ]; then
	debug "$1 type not recognised; skipping"
	exit 0
elif [ "$types" = swap ]; then
	debug "$1 is a swap partition; skipping"
	exit 0
elif [ "$types" = crypto_LUKS ]; then
	debug "$1 is a LUKS partition; skipping"
	exit 0
elif [ "$types" = ntfs ]; then
	if type ntfs-3g >/dev/null 2>&1; then
		types='ntfs-3g ntfs'
	fi
elif [ -z "$types" ]; then
	if type cryptsetup >/dev/null 2>&1 && \
	   cryptsetup luksDump "$partition" >/dev/null 2>&1; then
		debug "$1 is a LUKS partition; skipping"
		exit 0
	fi
	for type in $(grep -v nodev /proc/filesystems); do
		# hfsplus filesystems are mountable as hfs. Try hfs last so
		# that we can tell the difference.
		if [ "$type" = hfs ]; then
			delaytypes="${delaytypes:+$delaytypes }$type"
		elif [ "$type" = fuseblk ]; then
			if type ntfs-3g >/dev/null 2>&1; then
				types="${types:+$types }ntfs-3g"
			fi
		else
			types="${types:+$types }$type"
		fi
	done
fi

tmpmnt=/var/lib/os-prober/mount
if [ ! -d "$tmpmnt" ]; then
	mkdir "$tmpmnt"
fi

mounted=
if which grub-mount >/dev/null 2>&1 && \
   grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
	debug "mounted using GRUB"
	mounted=1
	type=fuseblk
else
	ro_partition "$partition"
	for type in $types $delaytypes; do
		if [ "$type" = ufs ]; then
			for ufstype in ufs2 44bsd; do
				if mount -o ro,ufstype=$ufstype -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
					mounted=1
					break
				fi
			done
		else
			if mount -o ro -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
				mounted=1
			fi
		fi

		if [ "$mounted" ]; then
			debug "mounted as $type filesystem"
			break
		fi
	done
fi

if [ "$mounted" ]; then
	for test in /usr/lib/os-probes/mounted/*; do
		debug "running subtest $test"
		if [ -f "$test" ] && [ -x "$test" ]; then
			if "$test" "$partition" "$tmpmnt" "$type"; then
				debug "os found by subtest $test"
				if ! umount "$tmpmnt"; then
					warn "failed to umount $tmpmnt"
				fi
				rmdir "$tmpmnt" || true
				exit 0
			fi
		fi
	done
	if ! umount "$tmpmnt"; then
		warn "failed to umount $tmpmnt"
	fi
fi

rmdir "$tmpmnt" || true

# No tests found anything.
exit 1
#!/bin/sh
# Test for *BSD distributions.
set -e

. /usr/share/os-prober/common.sh

partition="$1"
dir="$2"
type="$3"

if [ "$type" = ufs ]; then
  disk=$(echo $partition | gawk '{ match($0, /([[:alpha:][:punct:]]+)[[:digit:]]+/, disk); print disk[1] }')

  if [ ! -z "$disk" ]; then
    tpartition=$(echo $partition | sed 's|\/|\\/|g')

    system=$(fdisk -l $disk | awk '/'$tpartition'[[:blank:]]+\*[[:blank:]]+.+[[:blank:]]+.+BSD/ {print $7}')

    if [ ! -z "$system" ]; then
      title=

      if [ -f $dir/etc/motd ]; then
        case $system in
        FreeBSD | NetBSD | OpenBSD) title=$(cat $dir/etc/motd | gawk '{ match($0, /('$system')[[:blank:]]+([[:graph:]]+)[[:blank:]]+(\([[:print:]]+\))/, title); print title[1], title[2], title[3]; exit 0}')
                                    ;;
        esac
      fi

      if [ -z "$title" ]; then
        title="$system"
      fi

      label="$(count_next_label "$system")"
      echo "$partition:$title:$label:chain"

      exit 0
    else
      exit 1
    fi
  else
    exit 1
  fi
else
  exit 1
fi
#!/bin/sh
# Test for linux distributions.
set -e

. /usr/share/os-prober/common.sh

partition="$1"
dir="$2"
type="$3"

# This test is inaccurate, but given separate / and /boot partitions and the
# fact that only some architectures have ld-linux.so, I can't see anything
# better. Make sure this test has a high number so that more accurate tests
# can come first.
# TODO: look for ld-linux.so on arches that have it

# hierarchy

# based or forked

# chakra-release  # arch
# arch-release

# kanotix_version # debian
# kdemar-release # debian, knoppix
# knoppix_version  # debian
# debian_version

# blackPanther-release # mandriva
# pclinuxos-release # mandrake, mandriva
# mandriva-release # mandrake, mandrakelinux, redhat
# mandrakelinux-release
# mandrake-release

# altlinux-release # redhat
# yellowdog-release # centos, fedora
# centos-release # redhat, fedora
# asplinux-release # fedora
# engarde-release # fedora
# e-smith-release # fedora
# magic-release # fedora
# trustix-release # fedora
# fedora-release # redhat
# startcom-release # redhat
# redhat-release

# meego-release # moblin
# moblin-release

# slax-version # slackware
# zenwalk-version # slackware
# slackware-version

# sles-release # suse
# SuSE-release

# independent

# ark-release
# caos-release
# frugalware-release
# gentoo-release
# lfs-release
# pardus-release
# pld-release
# turbolinux-release
# vine-release
# whitebox-release

# reserved
# system-release

based_or_forked1='SuSE-release sles-release slackware-version zenwalk-version slax-version moblin-release meego-release'
based_or_forked2='redhat-release startcom-release fedora-release trustix-release magic-release e-smith-release engarde-release asplinux-release centos-release yellowdog-release altlinux-release'
based_or_forked3='mandrake-release mandrakelinux-release mandriva-release pclinuxos-release blackPanther-release'
based_or_forked4='debian_version knoppix_version kdemar-release kanotix_version arch-release chakra-release'

independant='whitebox-release vine-release turbolinux-release pld-release pardus-release lfs-release gentoo-release frugalware-release caos-release ark-release'

reserved='system-release'

known_distro="$reserved $independant $based_or_forked1 $based_or_forked2 $based_or_forked3 $based_or_forked4"

find_distro_info() {
  found_distro=

  pattern='_version -version -release'

  for pat in $pattern; do

    for distro in $( ls -tr $dir/etc/*$pat 2>/dev/null ); do
      if [ -L $distro ]; then
        continue
      fi

      distro=$(basename $distro)

      if [ "$distro" = 'lsb-release' ]; then
        continue
      fi

      found_distro="$found_distro$distro "
    done

  done
}

prepare_label() {
  label=$(echo $1 | gawk '{ match($0, /(.+)(_version|-version|-release)/, dist); print dist[1] }')
}

prepare_title() {
  title="$(head -1 $dir/etc/$1)"

  title=$(echo $title | gawk '{ match($0, /^[[:space:]]*(.*)[[:space:]]*$/, title); print title[1] }')

  if [ ! -z $(echo $title | awk '/^([[:graph:]]+)$/ { print $0 }') ] || [ -z "$title" ]; then
    tlabel=$(echo $label | gawk '{ match($0, /(.)(.*)/, title); print toupper(title[1]) tolower(title[2]) }')

    if [ ! -z "$title" ]; then
      title=" ($title)"
    fi

    title="${tlabel} GNU/Linux$title"
  fi
}

prepare_distro_info() {
  if [ ! -z "$found_distro" ]; then
    mdistro=

    for kdistro in $known_distro; do
      for fdistro in $found_distro; do
        if [ "$kdistro" = "$fdistro" ]; then
          mdistro=$kdistro
          found_distro=$(echo $found_distro | sed "s|$fdistro||")
          break
        fi
      done

      if [ -z "$found_distro" ]; then
        break
      fi
    done

    if [ -z "$found_distro" ]; then
      distro=$mdistro
    else
      distro=$(echo $found_distro | awk '{ print $NF }')
    fi

    rdistro=$distro

    if [ "$distro" = "debian_version" ] &&
       [ -f '/etc/dpkg/origins/ubuntu' ]; then
      distro='ubuntu_version'
    fi

    prepare_label $distro
    prepare_title $rdistro $label
  else
    label='Linux'
    title='unknown Linux distribution'
  fi
}

if ls $dir/lib*/ld*.so* >/dev/null 2>/dev/null; then
  find_distro_info

  prepare_distro_info

  label="$(count_next_label "$label")"
  echo "$partition:$title:$label:linux"

  exit 0
else
  exit 1
fi
diff --git a/os-probes/common/50mounted-tests b/os-probes/common/50mounted-tests
index 7865b51..e61cb13 100755
--- a/os-probes/common/50mounted-tests
+++ b/os-probes/common/50mounted-tests
@@ -54,9 +54,21 @@ if which grub-mount >/dev/null 2>&1 && \
 else
 	ro_partition "$partition"
 	for type in $types $delaytypes; do
-		if mount -o ro -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
+		if [ "$type" = ufs ]; then
+			for ufstype in ufs2 44bsd; do
+				if mount -o ro,ufstype=$ufstype -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
+					mounted=1
+					break
+				fi
+			done
+		else
+			if mount -o ro -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
+				mounted=1
+			fi
+		fi
+
+		if [ "$mounted" ]; then
 			debug "mounted as $type filesystem"
-			mounted=1
 			break
 		fi
 	done
diff --git a/os-probes/mounted/common/90bsd-distro b/os-probes/mounted/common/90bsd-distro
new file mode 100755
index 0000000..b190aab
--- /dev/null
+++ b/os-probes/mounted/common/90bsd-distro
@@ -0,0 +1,45 @@
+#!/bin/sh
+# Test for *BSD distributions.
+set -e
+
+. /usr/share/os-prober/common.sh
+
+partition="$1"
+dir="$2"
+type="$3"
+
+if [ "$type" = ufs ]; then
+  disk=$(echo $partition | gawk '{ match($0, /([[:alpha:][:punct:]]+)[[:digit:]]+/, disk); print disk[1] }')
+
+  if [ ! -z "$disk" ]; then
+    tpartition=$(echo $partition | sed 's|\/|\\/|g')
+
+    system=$(fdisk -l $disk | awk '/'$tpartition'[[:blank:]]+\*[[:blank:]]+.+[[:blank:]]+.+BSD/ {print $7}')
+
+    if [ ! -z "$system" ]; then
+      title=
+
+      if [ -f $dir/etc/motd ]; then
+        case $system in
+        FreeBSD | NetBSD | OpenBSD) title=$(cat $dir/etc/motd | gawk '{ match($0, /('$system')[[:blank:]]+([[:graph:]]+)[[:blank:]]+(\([[:print:]]+\))/, title); print title[1], title[2], title[3]; exit 0}')
+                                    ;;
+        esac
+      fi
+
+      if [ -z "$title" ]; then
+        title="$system"
+      fi
+
+      label="$(count_next_label "$system")"
+      echo "$partition:$title:$label:chain"
+
+      exit 0
+    else
+      exit 1
+    fi
+  else
+    exit 1
+  fi
+else
+  exit 1
+fi
diff --git a/os-probes/mounted/common/90linux-distro b/os-probes/mounted/common/90linux-distro
index f237a38..147c6a1 100755
--- a/os-probes/mounted/common/90linux-distro
+++ b/os-probes/mounted/common/90linux-distro
@@ -13,122 +13,166 @@ type="$3"
 # better. Make sure this test has a high number so that more accurate tests
 # can come first.
 # TODO: look for ld-linux.so on arches that have it
-if ls "$dir"/lib*/ld*.so* >/dev/null 2>/dev/null; then
-	if [ -e "$dir/etc/debian_version" ]; then
-		short="Debian"
-		long="$(printf "Debian GNU/Linux (%s)\n" "$(cat "$dir/etc/debian_version")")"
-	# RPM derived distributions may also have a redhat-release or
-	# mandrake-release, so check their files first.
-	elif [ -e "$dir/etc/altlinux-release" ]; then
-		short="ALTLinux"
-		long="$(cat "$dir/etc/altlinux-release")"
-	elif [ -e "$dir/etc/magic-release" ]; then
-		short="Magic"
-		long="$(cat "$dir/etc/magic-release")"
-	elif [ -e "$dir/etc/blackPanther-release" ]; then
-		short="blackPanther"
-		long="$(cat "$dir/etc/blackPanther-release")"
-	elif [ -e "$dir/etc/ark-release" ]; then
-		short="Ark"
-		long="$(cat "$dir/etc/ark-release")"
-	elif [ -e "$dir/etc/arch-release" ]; then
-		short="Arch"
-		long="$(cat "$dir/etc/arch-release")"
-	elif [ -e "$dir/etc/asplinux-release" ]; then
-		short="ASPLinux"
-		long="$(cat "$dir/etc/asplinux-release")"
-	elif [ -e "$dir/etc/lvr-release" ]; then
-		short="LvR"
-		long="$(cat "$dir/etc/lvr-release")"
-	elif [ -e "$dir/etc/caos-release" ]; then
-		short="cAos"
-		long="$(cat "$dir/etc/caos-release")"
-	elif [ -e "$dir/etc/aurox-release" ]; then
-		short="Aurox"
-		long="$(cat "$dir/etc/aurox-release")"
-	elif [ -e "$dir/etc/engarde-release" ]; then
-		short="EnGarde"
-		long="$(cat "$dir/etc/engarde-release")"
-	elif [ -e "$dir/etc/vine-release" ]; then
-		short="Vine"
-		long="$(cat "$dir/etc/vine-release")"
-	elif [ -e "$dir/etc/whitebox-release" ]; then
-		short="WhiteBox"
-		long="$(cat "$dir/etc/whitebox-release")"
-	elif [ -e "$dir/etc/pld-release" ]; then
-		short="PLD"
-		long="$(cat "$dir/etc/pld-release")"
-	elif [ -e "$dir/etc/startcom-release" ]; then
-		short="StartCom"
-		long="$(cat "$dir/etc/startcom-release")"
-	elif [ -e "$dir/etc/trustix-release" ]; then
-		short="Trustix"
-		long="$(cat "$dir/etc/trustix-release")"
-	elif [ -e "$dir/etc/openna-release" ]; then
-		short="OpenNA"
-		long="$(cat "$dir/etc/openna-release")"
-	elif [ -e "$dir/etc/conectiva-release" ]; then
-		short="Conectiva"
-		long="$(cat "$dir/etc/conectiva-release")"
-	elif [ -e "$dir/etc/mandrake-release" ]; then
-		short="Mandrake"
-		long="$(cat "$dir/etc/mandrake-release")"
-	elif [ -e "$dir/etc/fedora-release" ]; then
-		short="Fedora"
-		long="$(cat "$dir/etc/fedora-release")"
-	elif [ -e "$dir/etc/redhat-release" ]; then
-		short="RedHat"
-		long="$(cat "$dir/etc/redhat-release")"
-	elif [ -e "$dir/etc/SuSE-release" ]; then
-		short="SuSE"
-		long="$(head -n 1 "$dir/etc/SuSE-release")"
-	elif [ -e "$dir/etc/gentoo-release" ]; then
-		short="Gentoo"
-		long="$(cat "$dir/etc/gentoo-release")"
-	elif [ -e "$dir/etc/cobalt-release" ]; then
-		short="Cobalt"
-		long="$(cat "$dir/etc/cobalt-release")"
-	elif [ -e "$dir/etc/yellowdog-release" ]; then
-		short="YellowDog"
-		long="$(cat "$dir/etc/yellowdog-release")"
-	elif [ -e "$dir/etc/turbolinux-release" ]; then
-		short="Turbolinux"
-		long="$(cat "$dir/etc/turbolinux-release")"
-	elif [ -e "$dir/etc/pardus-release" ]; then
-		short="Pardus"
-		long="$(cat "$dir/etc/pardus-release")"
-	elif [ -e "$dir/etc/kanotix-version" ]; then
-		short="Kanotix"
-		long="$(cat "$dir/etc/kanotix-version")"
-	elif [ -e "$dir/etc/slackware-version" ]; then
-		short="Slackware"
-		long="$(printf "Slackware Linux (%s)\n" "$(cat "$dir/etc/slackware-version")")"
-	elif [ -e "$dir/sbin/pkgtool" ]; then
-		short="Slackware"
-		long="Slackware Linux"
-	elif grep -qs OpenLinux "$dir/etc/issue"; then
-		short="Caldera"
-		long="Caldera OpenLinux"
-	elif [ -e "$dir/etc/frugalware-release" ]; then
-		short="Frugalware Linux"
-		long="$(cat "$dir/etc/frugalware-release")"
-	elif [ -e "$dir/etc/kdemar-release" ]; then
-		short="K-DEMar"
-		long="$(printf "K-DEMar GNU/Linux (%s)\n" "$(cat "$dir/etc/kdemar-release")")"
-	elif [ -e "$dir/etc/lfs-release" ]; then
-		short="LFS"
-		long="$(printf "Linux From Scratch (%s)\n" "$(cat "$dir/etc/lfs-release")")"
-	elif [ -e "$dir/etc/meego-release" ]; then
-		short="MeeGo"
-		long="$(head -1 "$dir/etc/meego-release")"
-	else
-		short="Linux"
-		long="unknown Linux distribution"
-	fi
-	
-        label="$(count_next_label "$short")"
-	result "$partition:$long:$label:linux"
-	exit 0
+
+# hierarchy
+
+# based or forked
+
+# chakra-release  # arch
+# arch-release
+
+# kanotix_version # debian
+# kdemar-release # debian, knoppix
+# knoppix_version  # debian
+# debian_version
+
+# blackPanther-release # mandriva
+# pclinuxos-release # mandrake, mandriva
+# mandriva-release # mandrake, mandrakelinux, redhat
+# mandrakelinux-release
+# mandrake-release
+
+# altlinux-release # redhat
+# yellowdog-release # centos, fedora
+# centos-release # redhat, fedora
+# asplinux-release # fedora
+# engarde-release # fedora
+# e-smith-release # fedora
+# magic-release # fedora
+# trustix-release # fedora
+# fedora-release # redhat
+# startcom-release # redhat
+# redhat-release
+
+# meego-release # moblin
+# moblin-release
+
+# slax-version # slackware
+# zenwalk-version # slackware
+# slackware-version
+
+# sles-release # suse
+# SuSE-release
+
+# independent
+
+# ark-release
+# caos-release
+# frugalware-release
+# gentoo-release
+# lfs-release
+# pardus-release
+# pld-release
+# turbolinux-release
+# vine-release
+# whitebox-release
+
+# reserved
+# system-release
+
+based_or_forked1='SuSE-release sles-release slackware-version zenwalk-version slax-version moblin-release meego-release'
+based_or_forked2='redhat-release startcom-release fedora-release trustix-release magic-release e-smith-release engarde-release asplinux-release centos-release yellowdog-release altlinux-release'
+based_or_forked3='mandrake-release mandrakelinux-release mandriva-release pclinuxos-release blackPanther-release'
+based_or_forked4='debian_version knoppix_version kdemar-release kanotix_version arch-release chakra-release'
+
+independant='whitebox-release vine-release turbolinux-release pld-release pardus-release lfs-release gentoo-release frugalware-release caos-release ark-release'
+
+reserved='system-release'
+
+known_distro="$reserved $independant $based_or_forked1 $based_or_forked2 $based_or_forked3 $based_or_forked4"
+
+find_distro_info() {
+  found_distro=
+
+  pattern='_version -version -release'
+
+  for pat in $pattern; do
+
+    for distro in $( ls -tr $dir/etc/*$pat 2>/dev/null ); do
+      if [ -L $distro ]; then
+        continue
+      fi
+
+      distro=$(basename $distro)
+
+      if [ "$distro" = 'lsb-release' ]; then
+        continue
+      fi
+
+      found_distro="$found_distro$distro "
+    done
+
+  done
+}
+
+prepare_label() {
+  label=$(echo $1 | gawk '{ match($0, /(.+)(_version|-version|-release)/, dist); print dist[1] }')
+}
+
+prepare_title() {
+  title="$(head -1 $dir/etc/$1)"
+
+  title=$(echo $title | gawk '{ match($0, /^[[:space:]]*(.*)[[:space:]]*$/, title); print title[1] }')
+
+  if [ ! -z $(echo $title | awk '/^([[:graph:]]+)$/ { print $0 }') ] || [ -z "$title" ]; then
+    tlabel=$(echo $label | gawk '{ match($0, /(.)(.*)/, title); print toupper(title[1]) tolower(title[2]) }')
+
+    if [ ! -z "$title" ]; then
+      title=" ($title)"
+    fi
+
+    title="${tlabel} GNU/Linux$title"
+  fi
+}
+
+prepare_distro_info() {
+  if [ ! -z "$found_distro" ]; then
+    mdistro=
+
+    for kdistro in $known_distro; do
+      for fdistro in $found_distro; do
+        if [ "$kdistro" = "$fdistro" ]; then
+          mdistro=$kdistro
+          found_distro=$(echo $found_distro | sed "s|$fdistro||")
+          break
+        fi
+      done
+
+      if [ -z "$found_distro" ]; then
+        break
+      fi
+    done
+
+    if [ -z "$found_distro" ]; then
+      distro=$mdistro
+    else
+      distro=$(echo $found_distro | awk '{ print $NF }')
+    fi
+
+    rdistro=$distro
+
+    if [ "$distro" = "debian_version" ] &&
+       [ -f '/etc/dpkg/origins/ubuntu' ]; then
+      distro='ubuntu_version'
+    fi
+
+    prepare_label $distro
+    prepare_title $rdistro $label
+  else
+    label='Linux'
+    title='unknown Linux distribution'
+  fi
+}
+
+if ls $dir/lib*/ld*.so* >/dev/null 2>/dev/null; then
+  find_distro_info
+
+  prepare_distro_info
+
+  label="$(count_next_label "$label")"
+  echo "$partition:$title:$label:linux"
+
+  exit 0
 else
-	exit 1
+  exit 1
 fi

Attachment: signature.asc
Description: Digital signature


Reply to: