Class: Picobox::Commands::UpdatePackages

Inherits:
Utils::VisitorByOs show all
Defined in:
lib/picobox/commands/update_packages.rb

Instance Method Summary collapse

Methods inherited from Utils::VisitorByOs

#visit, #visit_unsupported, #visit_windows

Methods included from Utils::DomainEventPublisher

#publish_event

Instance Method Details

#visit_darwin(subject) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/picobox/commands/update_packages.rb', line 4

def visit_darwin subject
  raise Errors::PicoboxNotInstalled unless os.picobox_installed?

  packages = Utils::Packages.new(os)

  if packages.update?
    publish_event :update_packages_start

    filename = packages.download

    system("rm -rf #{Picobox.packages_dir}")
    system("mkdir  #{Picobox.packages_dir}")
    system("tar xvf #{filename} -C #{Picobox.packages_dir} --strip-components=1 #{Picobox.output}")

    Shell::IniFile.get(os)[:packages] = { version: packages.current_version, last_update: Time.now.to_i }

    publish_event :update_packages_stop
  end
end

#visit_linux(subject) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/picobox/commands/update_packages.rb', line 25

def visit_linux subject
  raise Errors::PicoboxNotInstalled unless os.picobox_installed?

  packages = Utils::Packages.new(os)

  if packages.update?
    publish_event :update_packages_start

    filename = packages.download

    system("sudo rm -rf #{Picobox.packages_dir}")
    system("sudo mkdir  #{Picobox.packages_dir}")
    system("sudo tar xvf #{filename} -C #{Picobox.packages_dir} --strip-components=1 #{Picobox.output}")

    Shell::IniFile.get(os)[:packages] = { version: packages.current_version, last_update: Time.now.to_i }

    publish_event :update_packages_stop
  end
end