Class: CSD::Application::Graphics::Base
- Defined in:
- lib/csd/application/graphics/base.rb
Instance Method Summary collapse
- #aptitude ⇒ Object
-
#define_relative_paths ⇒ Object
This method is to define relative path in graphics module.
-
#determine_graphic_card ⇒ Object
The method is to detect graphics card model.
-
#install ⇒ Object
This method will notify users about following operations and initiate installation process.
-
#install! ⇒ Object
This method is to create a working directory to preserve graphical card installation scripts, initiate graphics card installation GUI and clean up the working directory when the graphical card driver has been successfully installed.
-
#install_geforce ⇒ Object
The method is to check installation environment and initiate installation method of GeForce.
-
#install_geforce! ⇒ Object
The method is to check out GeForce installation script for git repository and initiate installation GUI.
-
#install_radeon ⇒ Object
The method is to check out ATI radeon driver from git repository and execute the shell script.
-
#introduction ⇒ Object
This method is to provide general introductions to users, like current working directory.
-
#process_graphics_card ⇒ Object
This method will determine the model of graphics card and initiate corresponding installation process Currently, only Radeon and GeForce graphics cards are supported.
-
#proprietary_continue ⇒ Object
The method is to notify the user about following operation of AI and initiate the method of wait_for_confirmation, where users can choose to continue with the operation or not.
-
#proprietary_continue_for_geforce ⇒ Object
The method is to provide necessary tips for users to install GeForce.
-
#wait_for_confirmation ⇒ Object
This method is to ask users about their willingness to continue.
-
#xserver_running? ⇒ Boolean
The method is to check X server status.
Methods inherited from Base
#cleanup_working_directory, #create_working_directory, #define_working_directory, #initialize
Constructor Details
This class inherits a constructor from CSD::Application::Base
Instance Method Details
#aptitude ⇒ Object
35 36 37 38 39 |
# File 'lib/csd/application/graphics/base.rb', line 35 def aptitude UI.info "Installing Debian dependencies".green.bold Cmd.run 'sudo apt-get update', :announce_pwd => false Cmd.run "sudo apt-get install git-core --yes --fix-missing", :announce_pwd => false end |
#define_relative_paths ⇒ Object
This method is to define relative path in graphics module. This will make the program clean and easy to read.
210 211 212 213 214 215 216 |
# File 'lib/csd/application/graphics/base.rb', line 210 def define_relative_paths UI.debug "#{self.class}#define_relative_paths defines relative graphics paths now" Path.radeon = Pathname.new(File.join(Path.work, 'radeon')) Path.radeon_run = Pathname.new(File.join(Path.radeon, 'ati-driver-installer-10-9-x86.x86_64.run')) Path.geforce = Pathname.new(File.join(Path.work, 'geforce')) Path.geforce_run = Pathname.new(File.join(Path.geforce, 'NVIDIA-Linux-x86-256.44.run.sh')) end |
#determine_graphic_card ⇒ Object
The method is to detect graphics card model
Returns
-
It will return ‘Radeon’,when options of force_radeon is set.
-
It will return ‘Radeon’,when options of force_radeon is set.
-
Otherwise, it will return the result of graphics card checking command.
Purpose
This methold is supposed to detect the current graphics card models and initiate corresponding installation process. However, whenever a user want to force its system to install another graphics card driver, it will fake the detection result and comply with users’ request.
94 95 96 97 98 |
# File 'lib/csd/application/graphics/base.rb', line 94 def determine_graphic_card return 'Radeon' if Options.force_radeon return 'GeForce' if Options.force_geforce Cmd.run('lspci | grep VGA', :internal => true).output end |
#install ⇒ Object
This method will notify users about following operations and initiate installation process. The reason of creating another method to carry out actual installation process is to keep the source code clean and easy to read.
15 16 17 18 19 20 21 |
# File 'lib/csd/application/graphics/base.rb', line 15 def install UI.separator UI.info "This operation will download and install the latest graphics card drivers.".green.bold UI.separator introduction install! end |
#install! ⇒ Object
This method is to create a working directory to preserve graphical card installation scripts, initiate graphics card installation GUI and clean up the working directory when the graphical card driver has been successfully installed.
27 28 29 30 31 32 33 |
# File 'lib/csd/application/graphics/base.rb', line 27 def install! define_relative_paths create_working_directory aptitude process_graphics_card cleanup_working_directory end |
#install_geforce ⇒ Object
The method is to check installation environment and initiate installation method of GeForce. The installation process of GeForce driver need to update users’ X configuration, so AI is suppose to turn off X server before initiating the installation procedure of GeForce driver.
X server status
- X server is running
-
AI will terminate X server, but this operation will also stop GNOME and AI itself. In order to continue with the installation procedure, users will start AI again from CLI.
- X server has be turned off
-
AI will initiate the installation process, but whenever there is an error occur, AI will restart GNOME mode and clean up the working directory.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/csd/application/graphics/base.rb', line 120 def install_geforce if xserver_running? or Options.reveal UI.separator UI.info 'This operation cannot be performed in the GNOME environment.'.red.bold UI.info 'The AI can stop GNOME for you now. Once this happens, you need'.green.bold UI.info 'to provide your Linux credentials and start the AI again from there.'.green.bold UI.separator if Options.yes or Options.reveal or UI.continue? Cmd.run "sudo /etc/init.d/gdm stop", :announce_pwd => false raise Error::Graphics::XServerStillRunning else raise Interrupt end else Cmd.run "sudo /etc/init.d/gdm start" unless install_geforce! cleanup_working_directory end end |
#install_geforce! ⇒ Object
The method is to check out GeForce installation script for git repository and initiate installation GUI. Currently, MiniSIP is only run on x86 systems, and GeForce driver installation is to improve the video quality of MiniSIP. Thus, before checking out GeForce installation script, AI will check the architecture of system. When it is a 64-bit system, AI will raise an error and terminate the process. While the system has a x86 architecture, AI will continue with the installation process. AI will check out the installation script from git repositoy, and permit the script to run as a program. AI will ask for users’ approval before initiate the shell script.
Notes
we do not use Cmd.run to initiate the installation process, because the User input is not forwared to the executed application correctly. We will use Ruby’s native command execution:
system "sudo #{Path.geforce_run}"
instead of
Cmd.run "sudo #{Path.geforce_run}", :announce_pwd => false, :verbose => true, :die_on_failure => false
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/csd/application/graphics/base.rb', line 163 def install_geforce! raise Error::Graphics::Amd64NotSupported, "Sorry, nVIDIA GeForce is currently only supported on x86" unless Gem::Platform.local.cpu == 'x86' Cmd.git_clone 'drivers for nVIDIA GeForce', 'http://github.com/csd/nvidia.git', Path.geforce Cmd.run "chmod +x #{Path.geforce_run}", :announce_pwd => false proprietary_continue_for_geforce # Note that we cannot use Cmd.run here, because the User input is not forwared to # the executed application correctly. We will use Ruby's native command execution # Cmd.run "sudo #{Path.geforce_run}", :announce_pwd => false, :verbose => true, :die_on_failure => false system "sudo #{Path.geforce_run}" end |
#install_radeon ⇒ Object
The method is to check out ATI radeon driver from git repository and execute the shell script.
-
It will allow the script to be run as a program, Because Linux system will not grant this permission to shell script for security reason.
-
The method will ask for users’ approval before initiate the shell script.
105 106 107 108 109 110 |
# File 'lib/csd/application/graphics/base.rb', line 105 def install_radeon Cmd.git_clone 'drivers for ATI radeon', 'http://github.com/csd/ati.git', Path.radeon Cmd.run "chmod +x #{Path.radeon_run}", :announce_pwd => false proprietary_continue Cmd.run "sudo #{Path.radeon_run}", :announce_pwd => false end |
#introduction ⇒ Object
This method is to provide general introductions to users, like current working directory.
Options
- debug
-
If debug option is set, users will be notified about system platform and current working module.
- help
-
If help option is set, AI will provide all help information and cleanup in case the working directory was temporary and is empty.
- reveal
-
If reveal option is set, AI will continue and process the next method.
- yes
-
If yes option is set, AI will continue and process the next method.
If users did not specify any option, AI will ask for their willingness to continue and process the next method after the users choose ‘yes’. Or AI will terminate its operation.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/csd/application/graphics/base.rb', line 52 def introduction UI.info " Working directory: ".green.bold + Path.work.to_s.yellow if Options.debug UI.info " Your Platform: ".green + Gem::Platform.local.humanize.to_s.yellow UI.info(" Application module: ".green + self.class.name.to_s.yellow) end UI.separator if Options.help UI.info Options.helptext # Cleanup in case the working directory was temporary and is empty Path.work.rmdir if Options.temp and Path.work.directory? and Path.work.children.empty? raise CSD::Error::Argument::HelpWasRequested else raise Interrupt unless Options.yes or Options.reveal or UI.continue? end end |
#process_graphics_card ⇒ Object
This method will determine the model of graphics card and initiate corresponding installation process Currently, only Radeon and GeForce graphics cards are supported.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/csd/application/graphics/base.rb', line 72 def process_graphics_card case determine_graphic_card when /Radeon/ install_radeon when /GeForce/ install_geforce else raise Error::Graphics::CardNotSupported, "Sorry, currently only ATI Radeon and nVIDIA GeForce are supported" end end |
#proprietary_continue ⇒ Object
The method is to notify the user about following operation of AI and initiate the method of wait_for_confirmation, where users can choose to continue with the operation or not.
177 178 179 180 181 182 183 |
# File 'lib/csd/application/graphics/base.rb', line 177 def proprietary_continue UI.separator UI.info 'The proprietary installer for your graphic card will now be executed.'.green.bold UI.info 'Please follow the instructions manually.'.green.bold UI.separator wait_for_confirmation end |
#proprietary_continue_for_geforce ⇒ Object
The method is to provide necessary tips for users to install GeForce. Because users need to allow GeForce to update X configuration in the installation wizard and restart the system to make all changes take effect. The method will also initiate the method of wait_for_confirmation, where users can choose to continue with the operation or not.
189 190 191 192 193 194 195 196 |
# File 'lib/csd/application/graphics/base.rb', line 189 def proprietary_continue_for_geforce UI.separator UI.info 'The proprietary installer for your graphic card will now be executed.'.green.bold UI.info 'Be sure to select "Yes" when asked if nvidia-xconfig should update your X configuration.'.green.bold UI.info 'Please restart your computer after exiting the wizard.'.green.bold UI.separator wait_for_confirmation end |
#wait_for_confirmation ⇒ Object
This method is to ask users about their willingness to continue. If the user choose to continue or AI is running in reveal mode, AI will continue with its operation. Or AI will clear up the working directory and terminate the process.
201 202 203 204 205 206 |
# File 'lib/csd/application/graphics/base.rb', line 201 def wait_for_confirmation unless UI.continue? or Options.reveal cleanup_working_directory raise Interrupt end end |
#xserver_running? ⇒ Boolean
The method is to check X server status.
Returns
-
trueif X server is running -
falseif X server is not running
144 145 146 147 |
# File 'lib/csd/application/graphics/base.rb', line 144 def xserver_running? result = Cmd.run('ps -ef', :internal => true) result.success? and (result.output =~ /bin\/X.+gdm/ or result.output =~ /xinit/) end |