Class: U3d::LinuxInstaller
- Inherits:
-
BaseInstaller
- Object
- BaseInstaller
- U3d::LinuxInstaller
- Defined in:
- lib/u3d/installer.rb
Overview
rubocop:disable ClassLength
Instance Method Summary collapse
-
#install(file_path, version, installation_path: nil, info: nil) ⇒ Object
rubocop:disable PerceivedComplexity.
- #install_pkg(file, installation_path: nil) ⇒ Object
- #install_sh(file, installation_path: nil) ⇒ Object
- #install_xz(file, installation_path: nil) ⇒ Object
- #installed ⇒ Object
- #sanitize_install(unity, long: false, dry_run: false) ⇒ Object
- #uninstall(unity: nil) ⇒ Object
Methods inherited from BaseInstaller
#installed_sorted_by_versions, #sanitize_installs
Instance Method Details
#install(file_path, version, installation_path: nil, info: nil) ⇒ Object
rubocop:disable PerceivedComplexity
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/u3d/installer.rb', line 295 def install(file_path, version, installation_path: nil, info: nil) # rubocop:enable UnusedMethodArgument, PerceivedComplexity extension = File.extname(file_path) raise "Installation of #{extension} files is not supported on Linux" unless ['.zip', '.po', '.sh', '.xz', '.pkg'].include? extension if extension == '.sh' path = installation_path || DEFAULT_LINUX_INSTALL install_sh(file_path, installation_path: path) elsif extension == '.xz' new_path = File.join(DEFAULT_LINUX_INSTALL, format(UNITY_DIR_LINUX, version: version)) path = installation_path || new_path install_xz(file_path, installation_path: path) elsif extension == '.pkg' new_path = File.join(DEFAULT_LINUX_INSTALL, format(UNITY_DIR_LINUX, version: version)) path = installation_path || new_path install_pkg(file_path, installation_path: path) elsif extension == '.po' install_po(file_path, version, info: info) elsif extension == '.zip' install_zip(file_path, version, info: info) end # Forces sanitation for installation of 'weird' versions eg 5.6.1xf1Linux unity = installed.select { |u| u.version == version }.first if unity sanitize_install(unity) else UI.error "Unity was not installed properly" end end |
#install_pkg(file, installation_path: nil) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/u3d/installer.rb', line 356 def install_pkg(file, installation_path: nil) raise 'Missing installation_path' unless installation_path raise 'Only able to install pkg on top of existing Unity installs' unless File.exist? installation_path raise 'Missing 7z' if `which 7z`.empty? Dir.mktmpdir do |tmp_dir| UI.verbose "Working in tmp dir #{tmp_dir}" command = "7z -aos -t* -o#{tmp_dir.shellescape} e #{file.shellescape}" U3dCore::CommandExecutor.execute(command: command) target_location = pkg_install_path(installation_path, "#{tmp_dir}/PackageInfo") # raise "Path for #{target_location} already exists" if path File.exist? target_location command = "cd #{target_location.shellescape}; gzip -dc #{tmp_dir}/Payload | cpio -i '*' -" command = "mkdir -p #{target_location.shellescape}; #{command}" # unless File.directory? installation_path U3dCore::CommandExecutor.execute(command: command, admin: true) end rescue StandardError => e UI.verbose(e.backtrace.join("\n")) UI.error "Failed to install pkg file #{file} at #{installation_path}: #{e}" else UI.success 'Installation successful' end |
#install_sh(file, installation_path: nil) ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/u3d/installer.rb', line 326 def install_sh(file, installation_path: nil) cmd = file.shellescape U3dCore::CommandExecutor.execute(command: "chmod a+x #{cmd}") if installation_path command = "cd #{installation_path.shellescape}; #{cmd}" command = "mkdir -p #{installation_path.shellescape}; #{command}" unless File.directory? installation_path U3dCore::CommandExecutor.execute(command: command, admin: true) else U3dCore::CommandExecutor.execute(command: cmd, admin: true) end rescue StandardError => e UI.error "Failed to install sh file #{file} at #{installation_path}: #{e}" else UI.success 'Installation successful' end |
#install_xz(file, installation_path: nil) ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/u3d/installer.rb', line 344 def install_xz(file, installation_path: nil) raise 'Missing installation_path' unless installation_path command = "cd #{installation_path.shellescape}; tar xf #{file.shellescape}" command = "mkdir -p #{installation_path.shellescape}; #{command}" unless File.directory? installation_path U3dCore::CommandExecutor.execute(command: command, admin: true) rescue StandardError => e UI.error "Failed to install xz file #{file} at #{installation_path}: #{e}" else UI.success 'Installation successful' end |
#installed ⇒ Object
289 290 291 292 |
# File 'lib/u3d/installer.rb', line 289 def installed paths = (list_installed_paths + debian_installed_paths).uniq paths.map { |path| LinuxInstallation.new(root_path: path) } end |
#sanitize_install(unity, long: false, dry_run: false) ⇒ Object
278 279 280 281 282 283 284 285 286 287 |
# File 'lib/u3d/installer.rb', line 278 def sanitize_install(unity, long: false, dry_run: false) source_path = File.(unity.root_path) parent = File.('..', source_path) dir_name = format(long ? UNITY_DIR_LINUX_LONG : UNITY_DIR_LINUX, version: unity.version, build_number: unity.build_number) new_path = File.join(parent, dir_name) moved = U3dCore::AdminTools.move_os_file(:linux, source_path, new_path, dry_run: dry_run) unity.root_path = new_path if moved && !dry_run end |
#uninstall(unity: nil) ⇒ Object
383 384 385 386 387 388 389 390 391 |
# File 'lib/u3d/installer.rb', line 383 def uninstall(unity: nil) UI.verbose("Uninstalling Unity at '#{unity.root_path}'...") command = "rm -r #{unity.root_path}" U3dCore::CommandExecutor.execute(command: command, admin: true) rescue StandardError => e UI.error "Failed to uninstall unity at #{unity.path}: #{e}" else UI.success "Successfully uninstalled '#{unity.root_path}'" end |