Class: VpsCli::Pull
- Inherits:
-
Object
- Object
- VpsCli::Pull
- Defined in:
- lib/vps_cli/pull.rb
Overview
Pull changes from local dir into config dir to be able to push changes up to the config dir
Class Method Summary collapse
-
.all(config = VpsCli.configuration) ⇒ Object
Base pull method.
-
.common_dotfiles(dotfiles_dir, local_dir) ⇒ Object
Puts you at the point of a directory where the local file and dotfile are the same allowing you to copy them.
-
.copy_file_or_dir(orig_file, new_file) ⇒ Object
Differentiates between files and dirs to appropriately copy them Uses Rake.cp_r for directories, uses Rake.cp for simple files.
-
.dotfiles(config = VpsCli.configuration) ⇒ Object
Pulls dotfiles from config.local into your specified config.dotfiles location.
-
.gnome_terminal_settings(config = VpsCli.configuration) ⇒ Object
Pulls the local config of gnome into the given config.misc_files.
-
.reset_to_original(remote_settings, orig_remote_contents) ⇒ Object
Method intended for dealing with the way dconf will automatically rewrite a file and make it empty remote settings.
-
.sshd_config(config = Configuration.new) ⇒ Object
Pulls sshd_config from config.local_sshd_config into config.misc_files.
Class Method Details
.all(config = VpsCli.configuration) ⇒ Object
Base pull method
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vps_cli/pull.rb', line 13 def self.all(config = VpsCli.configuration) # pulls dotfiles into specified directory dotfiles(config) # pulls from config.local_sshd_config sshd_config(config) # pulls via dconf gnome_terminal_settings(config) end |
.common_dotfiles(dotfiles_dir, local_dir) ⇒ Object
Puts you at the point of a directory where the local file and dotfile are the same allowing you to copy them
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vps_cli/pull.rb', line 38 def self.common_dotfiles(dotfiles_dir, local_dir) Dir.each_child(dotfiles_dir) do |remote_file| Dir.each_child(local_dir) do |local_file| next unless local_file == ".#{remote_file}" remote_file = File.join(dotfiles_dir, remote_file) local_file = File.join(local_dir, local_file) yield(remote_file, local_file) end end end |
.copy_file_or_dir(orig_file, new_file) ⇒ Object
Differentiates between files and dirs to appropriately copy them Uses Rake.cp_r for directories, uses Rake.cp for simple files
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vps_cli/pull.rb', line 55 def self.copy_file_or_dir(orig_file, new_file) if File.directory?(orig_file) && File.directory?(new_file) # Rake.cp_r(orig_file, new_file) Dir.each_child(orig_file) do |o_file| Dir.each_child(new_file) do |n_file| next unless o_file == n_file o_file = File.join(File.(orig_file), o_file) n_file = File.(new_file) Rake.cp_r(o_file, n_file) end end else Rake.cp(orig_file, new_file) end end |
.dotfiles(config = VpsCli.configuration) ⇒ Object
Pulls dotfiles from config.local into your
specified config.dotfiles location
27 28 29 30 31 32 33 |
# File 'lib/vps_cli/pull.rb', line 27 def self.dotfiles(config = VpsCli.configuration) common_dotfiles(config.dotfiles, config.local_dir) do |remote_file, local_file| copy_file_or_dir(local_file, remote_file) end end |
.gnome_terminal_settings(config = VpsCli.configuration) ⇒ Object
Pulls the local config of gnome into the given config.misc_files
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/vps_cli/pull.rb', line 83 def self.gnome_terminal_settings(config = VpsCli.configuration) # This is where dconf stores gnome terminal gnome_dconf = '/org/gnome/terminal/' remote_settings = File.join(config.misc_files, 'gnome_terminal_settings') orig_remote_contents = File.read(remote_settings) Rake.sh("dconf dump #{gnome_dconf} > #{remote_settings}") rescue RuntimeError => error VpsCli.errors << error # if dconf errors, it will erase the config file contents # So this protects against that reset_to_original(remote_settings, orig_remote_contents) else puts "Successfully dumped Gnome into #{remote_settings}" if config.verbose end |
.reset_to_original(remote_settings, orig_remote_contents) ⇒ Object
Method intended for dealing with the way dconf will automatically rewrite a file and make it empty remote settings
106 107 108 |
# File 'lib/vps_cli/pull.rb', line 106 def self.reset_to_original(remote_settings, orig_remote_contents) File.write(remote_settings, orig_remote_contents) end |
.sshd_config(config = Configuration.new) ⇒ Object
Pulls sshd_config from config.local_sshd_config into config.misc_files
75 76 77 78 79 80 |
# File 'lib/vps_cli/pull.rb', line 75 def self.sshd_config(config = Configuration.new) local = config.local_sshd_config remote = config.misc_files copy_file_or_dir(local, remote) end |