Переглянути джерело

feat(patch): Add dkms patch

Signed-off-by: Jeremy MAURO <jeremy.mauro@gmail.com>
Jeremy MAURO 2 роки тому
батько
коміт
ce6e49e413

+ 43 - 0
cookbooks/gateway/files/0001-Fix-dkms-doesn-t-remove-modules.patch

@@ -0,0 +1,43 @@
+From 8bf86c9c56d174d722b996b050a9c4e3215619c2 Mon Sep 17 00:00:00 2001
+From: Jeremy MAURO <jeremy.mauro@gmail.com>
+Date: Wed, 16 Mar 2022 23:44:53 +0000
+Subject: [PATCH] fix(dkms): dkms doesn't remove modules
+
+STATE:
+There is a bug inside the dkms when removing modules
+
+Ex:
+Error! Arguments <module> and <module-version> are not specified.
+Usage: remove <module>/<module-version> or
+       remove -m <module>/<module-version> or
+       remove -m <module> -v <module-version>
+
+This an identified bug: Bug#996104
+Ref: https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1823506.html
+
+FIX:
+Change the faulty line in the script
+
+Signed-off-by: Jeremy MAURO <jeremy.mauro@gmail.com>
+---
+ kernel/prerm.d/dkms | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/kernel/prerm.d/dkms b/kernel/prerm.d/dkms
+index 13eff2e..fd2ebda 100755
+--- a/kernel/prerm.d/dkms
++++ b/kernel/prerm.d/dkms
+@@ -13,8 +13,8 @@ remove_initrd_backup() {
+ 
+ if [ -x /usr/sbin/dkms ]; then
+ while read line; do
+-   name=`echo "$line" | awk '{print $1}' | sed 's/,$//'` | cut -d'/' -f1
+-   vers=`echo "$line" | awk '{print $1}' | sed 's/,$//'` | cut -d'/' -f2
++   name=`echo "$line" | awk '{print $1}' | sed 's/,$//' | cut -d'/' -f1`
++   vers=`echo "$line" | awk '{print $1}' | sed 's/,$//' | cut -d'/' -f2`
+    arch=`echo "$line" | awk '{print $3}' | sed 's/:$//'`
+    echo "dkms: removing: $name $vers ($inst_kern) ($arch)" >&2
+    dkms remove -m $name -v $vers -k $inst_kern -a $arch
+-- 
+2.35.1
+

+ 1 - 0
cookbooks/gateway/recipes/_packages.rb

@@ -25,6 +25,7 @@ package %w{
   plocate
   smem
   sudo
+  dkms
 } do
   notifies :run, 'execute[/usr/bin/apt-file update]', :immediately
   notifies :run, 'execute[/usr/bin/updatedb]', :immediately

+ 22 - 0
cookbooks/gateway/recipes/_system_patch.rb

@@ -0,0 +1,22 @@
+#
+# Cookbook:: gateway
+# Recipe:: _system_patch
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+#
+
+patch_files = %w{
+  0001-Fix-dkms-doesn-t-remove-modules.patch
+}
+
+patch_files.each do |patch_file|
+  cache_path = ::File.join(::Chef::Config[:file_cache_path], '0001-Fix-dkms-doesn-t-remove-modules.patch')
+  cookbook_file cache_path do
+    source patch_file
+  end
+
+  execute "/usr/bin/git am #{cache_path}" do
+    only_if "/usr/bin/git apply #{cache_path} --check"
+    cwd '/etc'
+  end
+end

+ 3 - 0
cookbooks/gateway/recipes/default.rb

@@ -26,3 +26,6 @@ include_recipe 'gateway::_packages'
 # END: Setup etckeeper
 include_recipe 'etckeeper'
 include_recipe 'etckeeper::commit'
+
+# Patching /etc
+include_recipe 'gateway::_system_patch'

+ 2 - 0
cookbooks/gateway/spec/spec_helper.rb

@@ -0,0 +1,2 @@
+require 'chefspec'
+require 'chefspec/berkshelf'

+ 29 - 0
cookbooks/gateway/spec/unit/recipes/_system_patch_spec.rb

@@ -0,0 +1,29 @@
+#
+# Cookbook:: gateway
+# Spec:: _system_patch
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+
+require 'spec_helper'
+
+describe 'gateway::_system_patch' do
+  context 'When all attributes are default, on Ubuntu 20.04' do
+    # for a complete list of available platforms and versions see:
+    # https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
+    platform 'ubuntu', '20.04'
+
+    it 'converges successfully' do
+      expect { chef_run }.to_not raise_error
+    end
+  end
+
+  context 'When all attributes are default, on CentOS 8' do
+    # for a complete list of available platforms and versions see:
+    # https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
+    platform 'centos', '8'
+
+    it 'converges successfully' do
+      expect { chef_run }.to_not raise_error
+    end
+  end
+end

+ 16 - 0
cookbooks/gateway/test/integration/default/_system_patch_test.rb

@@ -0,0 +1,16 @@
+# Chef InSpec test for recipe gateway::_system_patch
+
+# The Chef InSpec reference, with examples and extensive documentation, can be
+# found at https://docs.chef.io/inspec/resources/
+
+unless os.windows?
+  # This is an example test, replace with your own test.
+  describe user('root'), :skip do
+    it { should exist }
+  end
+end
+
+# This is an example test, replace it with your own test.
+describe port(80), :skip do
+  it { should_not be_listening }
+end