SuperTux88's Diaspora Saltstack Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.6KB

  1. # frozen_string_literal: true
  2. # system.rb -- InSpec resources for system values
  3. # Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
  4. # Copyright (C) 2020 Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
  5. class SystemResource < Inspec.resource(1)
  6. name 'system'
  7. attr_reader :platform
  8. def initialize
  9. super
  10. @platform = build_platform
  11. end
  12. private
  13. def build_platform
  14. {
  15. family: build_platform_family,
  16. name: build_platform_name,
  17. release: build_platform_release,
  18. finger: build_platform_finger
  19. }
  20. end
  21. def build_platform_family
  22. case inspec.platform[:name]
  23. when 'arch'
  24. 'arch'
  25. else
  26. inspec.platform[:family]
  27. end
  28. end
  29. def build_platform_name
  30. case inspec.platform[:name]
  31. when 'amazon'
  32. 'amazonlinux'
  33. else
  34. inspec.platform[:name]
  35. end
  36. end
  37. def build_platform_release
  38. case inspec.platform[:name]
  39. when 'amazon'
  40. # `2018` relase is named `1` in kitchen.yaml
  41. inspec.platform[:release].gsub(/2018.*/, '1')
  42. when 'arch'
  43. 'base-latest'
  44. when 'gentoo'
  45. "#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
  46. else
  47. inspec.platform[:release]
  48. end
  49. end
  50. def derive_gentoo_init_system
  51. case inspec.command('systemctl').exist?
  52. when true
  53. 'sysd'
  54. else
  55. 'sysv'
  56. end
  57. end
  58. def build_platform_finger
  59. "#{build_platform_name}-#{build_finger_release}"
  60. end
  61. def build_finger_release
  62. case inspec.platform[:name]
  63. when 'ubuntu'
  64. build_platform_release.split('.').slice(0, 2).join('.')
  65. else
  66. build_platform_release.split('.')[0]
  67. end
  68. end
  69. end