guests/linux: Provide common linux detection style
Defines a common and generic linux detection strategy which can be subclassed and easily reused by providing a custom detection constant.
This commit is contained in:
parent
6050b13f43
commit
d0549d6e11
|
@ -1,21 +1,10 @@
|
||||||
require "vagrant"
|
require_relative '../linux/guest'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestDebian
|
module GuestDebian
|
||||||
class Guest < Vagrant.plugin("2", :guest)
|
class Guest < VagrantPlugins::GuestLinux::Guest
|
||||||
def detect?(machine)
|
# Name used for guest detection
|
||||||
machine.communicate.test <<-EOH.gsub(/^ {10}/, "")
|
GUEST_DETECTION_NAME = "debian".freeze
|
||||||
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
|
end
|
||||||
|
|
|
@ -1,8 +1,22 @@
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestLinux
|
module GuestLinux
|
||||||
class Guest < Vagrant.plugin("2", :guest)
|
class Guest < Vagrant.plugin("2", :guest)
|
||||||
|
# Name used for guest detection
|
||||||
|
GUEST_DETECTION_NAME = "linux".freeze
|
||||||
|
|
||||||
def detect?(machine)
|
def detect?(machine)
|
||||||
machine.communicate.test("uname -s | grep 'Linux'")
|
machine.communicate.test <<-EOH.gsub(/^ */, '')
|
||||||
|
if test -r /etc/os-release; then
|
||||||
|
source /etc/os-release && test x#{self.class.const_get(:GUEST_DETECTION_NAME)} = x$ID && exit
|
||||||
|
fi
|
||||||
|
if test -x /usr/bin/lsb_release; then
|
||||||
|
/usr/bin/lsb_release -i 2>/dev/null | grep -qi #{self.class.const_get(:GUEST_DETECTION_NAME)} && exit
|
||||||
|
fi
|
||||||
|
if test -r /etc/issue; then
|
||||||
|
cat /etc/issue | grep -qi #{self.class.const_get(:GUEST_DETECTION_NAME)} && exit
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
EOH
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
require_relative '../linux/guest'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestMint
|
module GuestMint
|
||||||
class Guest < Vagrant.plugin("2", :guest)
|
class Guest < VagrantPlugins::GuestLinux::Guest
|
||||||
def detect?(machine)
|
# Name used for guest detection
|
||||||
machine.communicate.test("cat /etc/issue | grep 'Linux Mint'")
|
GUEST_DETECTION_NAME = "Linux Mint".freeze
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
require "vagrant"
|
require_relative '../linux/guest'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestTinyCore
|
module GuestTinyCore
|
||||||
class Guest < Vagrant.plugin("2", :guest)
|
class Guest < VagrantPlugins::GuestLinux::Guest
|
||||||
def detect?(machine)
|
# Name used for guest detection
|
||||||
machine.communicate.test("cat /etc/issue | grep 'Core Linux'")
|
GUEST_DETECTION_NAME = "Core Linux".freeze
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,10 @@
|
||||||
|
require_relative '../linux/guest'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestUbuntu
|
module GuestUbuntu
|
||||||
class Guest < Vagrant.plugin("2", :guest)
|
class Guest < VagrantPlugins::GuestLinux::Guest
|
||||||
def detect?(machine)
|
# Name used for guest detection
|
||||||
# This command detects if we are running on Ubuntu. /etc/os-release is
|
GUEST_DETECTION_NAME = "ubuntu".freeze
|
||||||
# available on modern Ubuntu versions, but does not exist on 14.04 and
|
|
||||||
# previous versions, so we fall back to lsb_release.
|
|
||||||
#
|
|
||||||
# GH-7524
|
|
||||||
# GH-7625
|
|
||||||
#
|
|
||||||
machine.communicate.test <<-EOH.gsub(/^ {10}/, "")
|
|
||||||
if test -r /etc/os-release; then
|
|
||||||
source /etc/os-release && test xubuntu = x$ID
|
|
||||||
elif test -x /usr/bin/lsb_release; then
|
|
||||||
/usr/bin/lsb_release -i 2>/dev/null | grep -q Ubuntu
|
|
||||||
else
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
EOH
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue