Class: VivaldiUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/vivaldiupdater.rb

Instance Method Summary collapse

Constructor Details

#initialize(install = false, skip_current = false) ⇒ VivaldiUpdater



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vivaldiupdater.rb', line 5

def initialize(install = false, skip_current = false)
  puts "Welcome to Vivaldi Updater for Ubuntu!"
  puts 'Vivaldi is currently running! If you choose to update, please close it!' if running?
  if skip_current
    @current = "Skipped..."
  else
    begin
      @current = `dpkg -l vivaldi-stable`.split("\n").last.split(' ')[2]
      puts "Vivaldi is installed, ignoring --install flag" if install
    rescue NoMethodError
      case install
      when true
        puts "Vivaldi not detected on this machine! Installing..."
        @current = "None"
      when false
        puts "Vivaldi not detected on this machine! If you would like to install Vivaldi, please append '--install' to your command."
        exit
      end
    end
  end
  puts "Current Vivaldi Version: #{@current}"
  print "Latest Vivaldi Version:  Checking...\r"
  site = RestClient.get('https://vivaldi.com/download').body
  doc = Nokogiri::HTML.parse(site)
  @url = doc.search('a.download-link').first.values[1]
  @version = @url.split('/').last.gsub('_amd64.deb', '').gsub('vivaldi-stable_', '')
  $stdout.flush
  print "Latest Vivaldi Version:  #{@version}\n"

  if @current == @version
    puts 'Vivaldi is up to date!'
    exit
  else
    puts 'Update available! Enter to update, CTRL+C to cancel!'
    STDIN.gets.chomp
    update
  end
end

Instance Method Details

#running?Boolean



44
45
46
47
48
# File 'lib/vivaldiupdater.rb', line 44

def running?
  output = `ps ax | grep vivaldi`.split("\n")
  return true if output.length > 3
  false
end

#updateObject



50
51
52
53
54
55
56
57
# File 'lib/vivaldiupdater.rb', line 50

def update
  puts 'Downloading new update...'
  `wget #{@url}`
  puts 'Updating... sudo access may be needed'
  ur = @url.gsub('https://downloads.vivaldi.com/stable/', '')
  `sudo dpkg -i #{ur}`
  puts 'Done updating!'
end