Class: U3d::LinuxInstaller
- Inherits:
-
BaseInstaller
- Object
- BaseInstaller
- U3d::LinuxInstaller
- Defined in:
- lib/u3d/installer.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
- #install(file_path, version, installation_path: nil, info: nil) ⇒ Object
- #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
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/u3d/installer.rb', line 307 def install(file_path, version, installation_path: nil, info: nil) extension = File.extname(file_path) raise "Installation of #{extension} files is not supported on Linux" unless ['.zip', '.po', '.sh', '.xz', '.pkg'].include? extension case extension when '.sh' path = installation_path || DEFAULT_LINUX_INSTALL install_sh(file_path, installation_path: path) when '.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) when '.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) when '.po' install_po(file_path, version, info: info) when '.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
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/u3d/installer.rb', line 369 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
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/u3d/installer.rb', line 339 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
357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/u3d/installer.rb', line 357 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
302 303 304 305 |
# File 'lib/u3d/installer.rb', line 302 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
291 292 293 294 295 296 297 298 299 300 |
# File 'lib/u3d/installer.rb', line 291 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
396 397 398 399 400 401 402 403 404 |
# File 'lib/u3d/installer.rb', line 396 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 |