Module: Lich::Util::Update

Defined in:
documented/common/update/file_writer.rb,
documented/update.rb,
documented/common/update/script_sync.rb,
documented/common/update/custom_repos.rb,
documented/common/update/file_updater.rb,
documented/common/update/github_client.rb,
documented/common/update/status_reporter.rb,
documented/common/update/tracked_scripts.rb,
documented/common/update/branch_installer.rb,
documented/common/update/channel_resolver.rb,
documented/common/update/snapshot_manager.rb,
documented/common/update/release_installer.rb

Overview

Namespace for Lich5 update and release management.

Defined Under Namespace

Modules: FileWriter, StatusReporter Classes: BranchInstaller, ChannelResolver, CustomRepos, FetchError, FileUpdater, GitHubClient, ReleaseInstaller, ScriptSync, SnapshotManager, TrackedScripts

Constant Summary collapse

STABLE_REF =

Update channel constants

'main'
BETA_BRANCH_PREFIX =
'pre/beta'
ASSET_TARBALL_NAME =
'lich-5.tar.gz'
GITHUB_REPO =
'elanthia-online/lich-5'
SCRIPT_REPOS =

Script repository registry

{
  'dr-scripts' => {
    display_name: 'DR Scripts',
    api_url: 'https://api.github.com/repos/elanthia-online/dr-scripts/git/trees/main?recursive=1',
    raw_base_url: 'https://raw.githubusercontent.com/elanthia-online/dr-scripts/main',
    tracking_mode: :all,
    script_pattern: /^[^\/]+\.lic$/,
    game_filter: /^DR/,
    subdirs: {
      'profiles' => { pattern: /^profiles\/base(?:-empty)?\.yaml$/, dest: File.join(SCRIPT_DIR, 'profiles') },
      'data'     => { pattern: /^data\/base.+yaml$/, dest: File.join(SCRIPT_DIR, 'data') }
    }
  }.freeze,
  'scripts'    => {
    display_name: 'Core Scripts',
    api_url: 'https://api.github.com/repos/elanthia-online/scripts/git/trees/master?recursive=1',
    raw_base_url: 'https://raw.githubusercontent.com/elanthia-online/scripts/master',
    tracking_mode: :explicit,
    script_pattern: /^scripts\/[^\/]+\.lic$/,
    script_prefix: 'scripts',
    check_lich_requirement: true,
    game_filter: nil,
    default_tracked: %w[
      alias.lic autostart.lic go2.lic jinx.lic log.lic
      logxml.lic map.lic repository.lic vars.lic version.lic
    ].freeze,
    subdirs: {}
  }.freeze,
  'gs-scripts' => {
    display_name: 'GS Scripts',
    api_url: 'https://api.github.com/repos/elanthia-online/scripts/git/trees/master?recursive=1',
    raw_base_url: 'https://raw.githubusercontent.com/elanthia-online/scripts/master',
    tracking_mode: :explicit,
    script_pattern: /^scripts\/[^\/]+\.lic$/,
    script_prefix: 'scripts',
    check_lich_requirement: true,
    game_filter: /^GS/,
    default_tracked: %w[
      ewaggle.lic
    ].freeze,
    subdirs: {
      'data' => { pattern: /^scripts\/(gameobj-data|effect-list)\.xml$/, dest: DATA_DIR, glob: '*.xml' }
    }
  }.freeze
}.freeze

Class Method Summary collapse

Class Method Details

.clear_branch_tracking ⇒ void

This method returns an undefined value.

Removes branch tracking constants from version.rb.



309
310
311
312
313
314
315
316
317
# File 'documented/update.rb', line 309

def self.clear_branch_tracking
  version_file_path = File.join(LIB_DIR, "version.rb")
  return unless File.exist?(version_file_path)

  version_content = File.read(version_file_path)
  version_content.gsub!(/\n# Branch tracking \(added by lich5-update --branch\).*?\n(?:LICH_BRANCH[^\n]*\n)*/m, '')
  version_content = version_content.rstrip + "\n"
  File.write(version_file_path, version_content)
end

.get_branch_info ⇒ Hash?

Reads current branch tracking info if defined.

Returns:

  • (Hash, nil) —

    hash with :branch_name, :repository, :updated_at or nil



322
323
324
325
326
327
328
329
330
# File 'documented/update.rb', line 322

def self.get_branch_info
  if defined?(LICH_BRANCH) && LICH_BRANCH && !LICH_BRANCH.empty?
    {
      branch_name: LICH_BRANCH,
      repository: (defined?(LICH_BRANCH_REPO) ? LICH_BRANCH_REPO : nil),
      updated_at: (defined?(LICH_BRANCH_UPDATED_AT) ? LICH_BRANCH_UPDATED_AT : nil)
    }
  end
end

.help ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays the help text for all lich5-update commands.

Prints a comprehensive guide covering core updates, snapshot/revert, script repository sync, custom repos, beta testing, and individual file updates.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'documented/update.rb', line 187

def self.help
  respond "
    --help                   Display this message
    --announce               Get summary of changes for next version
    --update                 Update all changes for next version
    --branch=<name>          Update to a specific GitHub branch
    --status                 Show current version and branch tracking info
    --snapshot               Grab current snapshot of Lich5 ecosystem and put in backup
    --revert                 Roll the Lich5 ecosystem back to the most recent snapshot

  [Script repository sync]
    #{$clean_lich_char}lich5-update --sync                              Sync all repos for current game
    #{$clean_lich_char}lich5-update --sync=dr-scripts                   Sync only dr-scripts repo
    #{$clean_lich_char}lich5-update --sync=scripts                      Sync only EO/scripts repo
    #{$clean_lich_char}lich5-update --tracked                           List tracked scripts for all repos
    #{$clean_lich_char}lich5-update --tracked=scripts                   List tracked scripts for one repo
    #{$clean_lich_char}lich5-update --track=scripts:bigshot.lic         Add a script to tracked list
    #{$clean_lich_char}lich5-update --untrack=scripts:bigshot.lic       Remove from tracked list

  [Custom 3rd-party repositories]
    #{$clean_lich_char}lich5-update --add-custom=owner/repo             Register a custom repo (default branch)
    #{$clean_lich_char}lich5-update --add-custom=owner/repo:branch      Register with specific branch
    #{$clean_lich_char}lich5-update --remove-custom=owner/repo          Unregister a custom repo
    #{$clean_lich_char}lich5-update --custom-repos                      List registered custom repos
    #{$clean_lich_char}lich5-update --track=owner/repo:script.lic       Track a script from custom repo
    #{$clean_lich_char}lich5-update --sync=owner/repo                   Sync a custom repo
    Custom scripts install to #{$clean_lich_char}scripts/custom/<owner-repo>/ (name collisions rejected)

  [Beta testing]
    #{$clean_lich_char}lich5-update --beta                              Show the beta notice; confirm within #{ReleaseInstaller::BETA_CONFIRM_WINDOW} seconds
    #{$clean_lich_char}lich5-update --beta --confirm                    Install the latest Lich beta after reading the notice
    #{$clean_lich_char}lich5-update --beta --library=<name>             Update one library file from the beta channel

  [Individual file updates]
    #{$clean_lich_char}lich5-update --script=<name>                     Update script (auto-detects repo)
    #{$clean_lich_char}lich5-update --script=dr-scripts:<name>          Update script from specific repo
    #{$clean_lich_char}lich5-update --data=dr-scripts:base-hunting.yaml Update data file from specific repo
    #{$clean_lich_char}lich5-update --library=<name>                    Update library file from lich-5

  [One time suggestions]
    #{$clean_lich_char}autostart add --global lich5-update --announce    Check for new version at login

  [On demand suggestions]
    #{$clean_lich_char}lich5-update --status                    Show current version and branch info
    #{$clean_lich_char}lich5-update --announce                  Check to see if a new version is available
    #{$clean_lich_char}lich5-update --update                    Update the Lich5 ecosystem to the current release
    #{$clean_lich_char}lich5-update --branch=<name>             Update to a specific GitHub branch (advanced)
    #{$clean_lich_char}lich5-update --revert                    Roll the Lich5 ecosystem back to latest snapshot

  [Branch update examples]
    #{$clean_lich_char}lich5-update --branch=main               Update to the main stable branch
    #{$clean_lich_char}lich5-update --branch=some_branch_name   Update to a different branch
    #{$clean_lich_char}lich5-update --branch=owner:branch_name  Update to a fork's branch

    *NOTE* Script repos sync automatically on login for both DR and GS.
    "
end

.request(type = '--announce') ⇒ void

This method returns an undefined value.

Routes update commands to appropriate handler classes.

An update or snapshot asked for while a revert, another snapshot or another update is running on this installation stops before changing anything. SnapshotManager#snapshot has already told the user why, so its RevertRunningError ends the command here instead of reaching the client thread as an error.

Parameters:

  • type (String) (defaults to: '--announce') —

    command flag (e.g. '--announce', '--update', '--sync')



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'documented/update.rb', line 102

def self.request(type = '--announce')
  case type
  when /^(?:--announce|-a)\b/
    release_installer.announce
  when /^--branch=(.+)$/
    branch_installer.download_branch_update($1)
  when /^--(?:beta|test)\s+(?:--)?confirm\s*$/
    release_installer.confirm_betatest
  when /^--(?:beta|test)(?: --(?:(script|library|data))=(.+))?\b/
    release_installer.prep_betatest($1&.dup, $2&.dup)
  when /^(?:--help|-h)\b/
    help
  when /^--status\b/
    show_status
  when /^(?:--update|-u)\b/
    release_installer.download_release_update
  when /^--refresh\b/
    respond
    respond "This command has been removed."
  when /^(?:--revert|-r)\b/
    snapshot_manager.revert
  when /^--add-custom=(\S+?)(?::(\S+))?$/
    custom_repos_manager.add_custom_repo($1, $2)
  when /^--remove-custom=(\S+)$/
    custom_repos_manager.remove_custom_repo($1)
  when /^--custom-repos$/
    custom_repos_manager.list_custom_repos
  when /^--sync(?:=(\S+))?$/
    if $1
      script_sync.sync_repo($1)
    else
      script_sync.sync_all_repos
    end
  when /^--track=(\S+):(\S+)$/
    tracked_scripts_manager.track_script($1, $2)
  when /^--untrack=(\S+):(\S+)$/
    tracked_scripts_manager.untrack_script($1, $2)
  when /^--tracked(?:=(\S+))?$/
    tracked_scripts_manager.show_tracked($1)
  when /^--(?:(script|library|data))=(?:(\S+):)?(.+)\b/
    type_name = $1&.dup
    repo = $2&.dup
    file = $3&.dup
    if repo
      file_updater.update_file_from_repo(type_name, repo, file)
    else
      file_updater.update_file(type_name, file)
    end
  when /^(?:--snapshot|-s)\b/
    snapshot_manager.snapshot
  else
    respond
    respond "Command '#{type}' unknown, illegitimate and ignored.  Exiting . . ."
    respond
  end
rescue SnapshotManager::RevertRunningError
  nil
end

.show_status ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays current Lich5 version and branch tracking information.

If running a release package, shows the version number and suggests checking for updates with --announce. If running a development branch, also shows the branch name, repository, and time elapsed since the last update.



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'documented/update.rb', line 253

def self.show_status
  respond
  respond "Lich5 Version Information:"
  respond "  Version: #{LICH_VERSION}"

  branch_info = get_branch_info
  if branch_info
    respond "  Type: Branch (Development)"
    respond "  Branch: #{branch_info[:branch_name]}"
    respond "  Repository: #{branch_info[:repository] || GITHUB_REPO}"
    if branch_info[:updated_at]
      updated = Time.at(branch_info[:updated_at])
      days_ago = ((Time.now - updated) / 86400).to_i
      respond "  Updated: #{updated.strftime('%Y-%m-%d %H:%M:%S')} (#{days_ago} day#{days_ago == 1 ? '' : 's'} ago)"
    end
    respond
    respond "You are running a development branch, not a release package."
  else
    respond "  Type: Release Package"
    respond
    respond "To check for updates: #{$clean_lich_char}lich5-update --announce"
  end
  respond
end

.store_branch_tracking(branch_name, repo, _version) ⇒ void

This method returns an undefined value.

Persists branch tracking info to version.rb.

Parameters:

  • branch_name (String) —

    branch name

  • repo (String) —

    repository identifier (e.g. 'owner/lich-5')

  • _version (String) —

    version string (unused)



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'documented/update.rb', line 288

def self.store_branch_tracking(branch_name, repo, _version)
  version_file_path = File.join(LIB_DIR, "version.rb")
  version_content = File.read(version_file_path)

  version_content.gsub!(/\n# Branch tracking \(added by lich5-update --branch\).*?\n(?:LICH_BRANCH[^\n]*\n)*/m, '')

  branch_tracking = <<~RUBY

    # Branch tracking (added by lich5-update --branch)
    LICH_BRANCH = #{branch_name.dump}
    LICH_BRANCH_REPO = #{repo.dump}
    LICH_BRANCH_UPDATED_AT = #{Time.now.to_i}
  RUBY

  version_content = version_content.rstrip + branch_tracking
  File.write(version_file_path, version_content)
end

.sync_all_repos ⇒ void

This method returns an undefined value.

Syncs all script repositories for current game.



164
165
166
# File 'documented/update.rb', line 164

def self.sync_all_repos
  script_sync.sync_all_repos
end

.update_core_data_and_scripts(version = LICH_VERSION) ⇒ void

This method returns an undefined value.

Updates core data files and scripts to specified version.

Parameters:

  • version (String) (defaults to: LICH_VERSION) —

    version string (default: current LICH_VERSION)



172
173
174
# File 'documented/update.rb', line 172

def self.update_core_data_and_scripts(version = LICH_VERSION)
  file_updater.update_core_data_and_scripts(version)
end