From de0dfd76961ef042de6987b829042813acdfa7c0 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Sun, 15 Mar 2020 18:23:16 -0400 Subject: [PATCH] guest: redhat: handle missing el8 version detection in vagrant See https://github.com/hashicorp/vagrant/pull/11453. Here we add a compatibility function to handle :rhel_8 because otherwise we'd have to wait until a new version of vagrant got released and rolled out everywhere before our users could take advantage of this. --- .../cap/guest/redhat/sshfs_client.rb | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-sshfs/cap/guest/redhat/sshfs_client.rb b/lib/vagrant-sshfs/cap/guest/redhat/sshfs_client.rb index 9103156..28491e5 100644 --- a/lib/vagrant-sshfs/cap/guest/redhat/sshfs_client.rb +++ b/lib/vagrant-sshfs/cap/guest/redhat/sshfs_client.rb @@ -3,7 +3,16 @@ module GuestRedHat module Cap class SSHFSClient def self.sshfs_install(machine) - case machine.guest.capability("flavor") + + rhel_version = machine.guest.capability("flavor") + + # Handle the case where Vagrant doesn't yet know how to + # detect and return :rhel_8 https://github.com/hashicorp/vagrant/pull/11453 + if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new('2.2.8') + rhel_version = vagrant_lt_228_flavor_compat(machine) + end + + case rhel_version when :rhel_8 # No need to install epel. fuse-sshfs comes from the PowerTools repo # https://bugzilla.redhat.com/show_bug.cgi?id=1758884 @@ -30,6 +39,23 @@ def self.epel_installed(machine) def self.epel_install(machine) machine.communicate.sudo("yum -y install epel-release") end + + def self.vagrant_lt_228_flavor_compat(machine) + # This is a compatibility function to handle RHEL8 for + # vagrant versions that didn't include: + # https://github.com/hashicorp/vagrant/pull/11453 + output = "" + machine.communicate.sudo("cat /etc/redhat-release") do |_, data| + output = data + end + if output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i + return :rhel_8 + elsif output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i + return :rhel_7 + else + return :rhel + end + end end end end