Class: RokuBuilder::Packager

Inherits:
Util
  • Object
show all
Extended by:
Plugin
Defined in:
lib/roku_builder/plugins/packager.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options, validate

Methods inherited from Util

#initialize

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Class Method Details

.commandsObject



8
9
10
11
12
13
14
# File 'lib/roku_builder/plugins/packager.rb', line 8

def self.commands
  {
    package: {device: true, source: true, stage: true, exclude: true, keyed: true},
    genkey: {device: true},
    key: {device: true, source: true, keyed: true}
  }
end

.dependenciesObject



33
34
35
# File 'lib/roku_builder/plugins/packager.rb', line 33

def self.dependencies
  [Loader, Inspector]
end

.parse_options(parser:, options:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/roku_builder/plugins/packager.rb', line 16

def self.parse_options(parser:, options:)
  parser.separator "Commands:"
  parser.on("-p", "--package", "Package an app") do
    options[:package] = true
  end
  parser.on("-k", "--key", "Change device key") do
    options[:key] = true
  end
  parser.on("--genkey", "Generate a new key") do
    options[:genkey] = true
  end
  parser.separator "Options:"
  parser.on("--inspect-package", "Inspect package after packaging") do
    options[:inspect_package] = true
  end
end

Instance Method Details

#dev_id(device: nil) ⇒ String

Get the current dev id

Returns:

  • (String)

    The current dev id



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/roku_builder/plugins/packager.rb', line 106

def dev_id(device: nil)
  path = "/plugin_package"
  response = nil
  simple_connection(device: device) do |conn|
    response = conn.get path
  end

  dev_id = /Your Dev ID:\s*<font[^>]*>([^<]*)<\/font>/.match(response.body)
  dev_id ||= /Your Dev ID:[^>]*<\/label> ([^<]*)/.match(response.body)
  dev_id = dev_id[1] if dev_id
  dev_id ||= "none"
  dev_id
end

#genkey(options:) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/roku_builder/plugins/packager.rb', line 57

def genkey(options:)
  password, dev_id = generate_new_key()
  @logger.unknown("Password: "+password)
  @logger.info("DevID: "+dev_id)

  out = @config.out
  out[:file] ||= "key_"+dev_id+".pkg"
  @config.out = out

  config_copy = @config.dup
  config_copy.root_dir = ""
  config_copy.in[:folder] = File.dirname(__FILE__)
  config_copy.in[:file] = "key_template.zip"
  loader = Loader.new(config: config_copy)
  options[:in] = true
  loader.sideload(options: options)
  sign_package(app_name_version: "key_"+dev_id, password: password, stage: options[:stage])
  @logger.unknown("Keyed PKG: #{File.join(@config.out[:folder], @config.out[:file])}")
end

#key(options:, device: nil) ⇒ Boolean

Sets the key on the roku device

Parameters:

  • keyed_pkg (String)

    Path for a package signed with the desired key

  • password (String)

    Password for the package

Returns:

  • (Boolean)

    True if key changed, false otherwise



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/roku_builder/plugins/packager.rb', line 81

def key(options:, device: nil)
  get_device(device: device) do |device|
    oldId = dev_id(device: device)

    raise ExecutionError, "No Key Found For Stage #{options[:stage]}" unless @config.key

    # upload new key with password
    payload =  {
      mysubmit: "Rekey",
      passwd: @config.key[:password],
      archive: Faraday::UploadIO.new(@config.key[:keyed_pkg], 'application/octet-stream')
    }
    multipart_connection(device: device) do |conn|
      conn.post "/plugin_inspect", payload
    end

    # check key
    newId = dev_id(device: device)
    @logger.info("Key did not change") unless newId != oldId
    @logger.debug(oldId + " -> " + newId)
  end
end

#package(options:) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/roku_builder/plugins/packager.rb', line 37

def package(options:)
  check_options(options)
  get_device do |device|
    #sideload
    loader = Loader.new(config: @config)
    loader.sideload(options: options, device: device)
    loader.squash(options: options, device: device) if @config.stage[:squash]
    #rekey
    key(options: options, device: device)
    #package
    sign_package(app_name_version: "", password: @config.key[:password], stage: options[:stage], device: device)
    #inspect
    if options[:inspect_package]
      @config.in = @config.out
      options[:password] = @config.key[:password]
      Inspector.new(config: @config).inspect(options: options, device: device)
    end
  end
end