Make Debian guest detection more reliable

/etc/issue is far from being a reliable source for OS detection as it
can be changed by a user without affecting any OS functionality. As
newer Debian systems run systemd by default, check for /etc/os-release
and fallback to lsb_release for older Debian versions. Check #7625 for
a similar issue. Even lsb_release is not manatory, therefore keep the
current code of parsing /etc/issue to avoid regressions.
This commit is contained in:
Reto Gantenbein 2016-09-26 12:18:38 +02:00 committed by Chris Roberts
parent 29b033390f
commit 6050b13f43
1 changed files with 11 additions and 1 deletions

View File

@ -4,7 +4,17 @@ module VagrantPlugins
module GuestDebian module GuestDebian
class Guest < Vagrant.plugin("2", :guest) class Guest < Vagrant.plugin("2", :guest)
def detect?(machine) def detect?(machine)
machine.communicate.test("cat /etc/issue | grep 'Debian'") machine.communicate.test <<-EOH.gsub(/^ {10}/, "")
if test -r /etc/os-release; then
source /etc/os-release && test xdebian = x$ID
elif test -x /usr/bin/lsb_release; then
/usr/bin/lsb_release -i 2>/dev/null | grep -q Debian
elif test -r /etc/issue; then
cat /etc/issue | grep 'Debian'
else
exit 1
fi
EOH
end end
end end
end end