class U3d::LinuxInstaller
rubocop:disable ClassLength
Public Instance Methods
install(file_path, version, installation_path: nil, info: nil)
click to toggle source
rubocop:disable PerceivedComplexity
# File lib/u3d/installer.rb, line 300 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)
click to toggle source
# File lib/u3d/installer.rb, line 361 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)
click to toggle source
# File lib/u3d/installer.rb, line 331 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)
click to toggle source
# File lib/u3d/installer.rb, line 349 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()
click to toggle source
# File lib/u3d/installer.rb, line 294 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)
click to toggle source
# File lib/u3d/installer.rb, line 283 def sanitize_install(unity, long: false, dry_run: false) source_path = File.expand_path(unity.root_path) parent = File.expand_path('..', 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)
click to toggle source
# File lib/u3d/installer.rb, line 388 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
Private Instance Methods
debian_installed_paths()
click to toggle source
# File lib/u3d/installer.rb, line 433 def debian_installed_paths paths = find_installations_with_path( default_root_path: DEFAULT_LINUX_INSTALL, postfix: %w[ Unity Editor ] ) { |u| Pathname.new(u).parent.to_s } UI.verbose "Found debian_installed_paths: #{paths}" paths end
list_installed_paths()
click to toggle source
# File lib/u3d/installer.rb, line 421 def list_installed_paths paths = find_installations_with_path( default_root_path: DEFAULT_LINUX_INSTALL, postfix: %w[ unity-editor-* Editor ] ) { |u| Pathname.new(u).parent.to_s } UI.verbose "Found list_installed_paths: #{paths}" paths end
pkg_install_path(unity_root_path, pinfo_path)
click to toggle source
# File lib/u3d/installer.rb, line 400 def pkg_install_path(unity_root_path, pinfo_path) raise "PackageInfo not found under #{pinfo_path}" unless File.exist? pinfo_path pinfo = File.read(pinfo_path) require 'rexml/document' d = REXML::Document.new(pinfo) identifier = d.root.attributes['identifier'] case identifier when 'com.unity3d.Documentation' "#{unity_root_path}/Editor/Data/" when 'com.unity3d.StandardAssets' "#{unity_root_path}/Editor/Standard Assets/" when 'com.unity3d.ExampleProject' unity_root_path else install_location = d.root.attributes['install-location'] raise "Not sure how to install this module with identifier #{identifier} install-location: #{install_location}" unless install_location.start_with? '/Applications/Unity/' install_location.gsub(%(\/Applications\/Unity), "#{unity_root_path}/Editor/Data") end end