Class: Itamae::Plugin::Resource::AurPackage

Inherits:
Resource::Base
  • Object
show all
Defined in:
lib/itamae/plugin/resource/aur_package.rb

Defined Under Namespace

Classes: NotSupportedError

Instance Method Summary collapse

Instance Method Details

#action_install(action_options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/itamae/plugin/resource/aur_package.rb', line 46

def action_install(action_options)
  if run_specinfra(:check_package_is_installed, attributes.name, attributes.version)
    return
  end

  yay_executable = run_command('which yay', error: false).exit_status == 0
  if yay_executable
    run_command("yay -S --noconfirm #{attributes.options} #{attributes.name}")
  else
    name = attributes.name
    tmp_dir = "/tmp/itamae-plugin-resource-aur_package-#{name}-#{Time.now.to_f}"
    run_command("mkdir #{tmp_dir}")
    run_command("curl -L -O https://aur.archlinux.org/cgit/aur.git/snapshot/#{name}.tar.gz", cwd: tmp_dir)
    run_command("tar -xvf #{name}.tar.gz", cwd: tmp_dir)
    run_command("makepkg -si --noconfirm #{attributes.options}", cwd: "#{tmp_dir}/#{name}" )
    run_command("rm -rf #{tmp_dir}")
  end
  updated!
end

#action_remove(action_options) ⇒ Object



66
67
68
69
70
71
# File 'lib/itamae/plugin/resource/aur_package.rb', line 66

def action_remove(action_options)
  if run_specinfra(:check_package_is_installed, attributes.name, nil)
    run_specinfra(:remove_package, attributes.name, attributes.options)
    updated!
  end
end

#pre_actionObject



29
30
31
32
33
34
35
36
# File 'lib/itamae/plugin/resource/aur_package.rb', line 29

def pre_action
  case @current_action
  when :install
    attributes.installed = true
  when :remove
    attributes.installed = false
  end
end

#runObject

Raises:



22
23
24
25
26
27
# File 'lib/itamae/plugin/resource/aur_package.rb', line 22

def run
  os = backend.instance_variable_get(:@backend).os_info
  raise NotSupportedError.new(os) unless os[:family] == 'arch'

  super
end

#set_current_attributesObject



38
39
40
41
42
43
44
# File 'lib/itamae/plugin/resource/aur_package.rb', line 38

def set_current_attributes
  current.installed = run_specinfra(:check_package_is_installed, attributes.name)

  if current.installed
    current.version = run_specinfra(:get_package_version, attributes.name).stdout.strip
  end
end