Class: Arver::SystemdOpenAction
- Defined in:
- lib/arver/systemd_open_action.rb
Instance Attribute Summary
Attributes inherited from Action
#generator, #key, #keystore, #slot_of_target_user, #target_list, #target_user
Instance Method Summary collapse
- #execute_partition(partition) ⇒ Object
- #get_socket(host, partid) ⇒ Object
-
#initialize(target_list) ⇒ SystemdOpenAction
constructor
A new instance of SystemdOpenAction.
- #verify?(partition) ⇒ Boolean
Methods inherited from Action
#load_key, #needs_target_user?, #new_key_generator, #on_user, #open_keystore, #post_action, #post_host, #post_partition, #pre_action, #pre_host, #pre_partition, #run_on, #verify_key_on_target
Constructor Details
#initialize(target_list) ⇒ SystemdOpenAction
Returns a new instance of SystemdOpenAction.
5 6 7 8 |
# File 'lib/arver/systemd_open_action.rb', line 5 def initialize( target_list ) super( target_list ) self.open_keystore end |
Instance Method Details
#execute_partition(partition) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/arver/systemd_open_action.rb', line 39 def execute_partition( partition ) Arver::Log.info( "opening: "+partition.path ) socket = nil partid = nil host = partition.parent # Find the uuid of this partition partid_exec = Arver::SSHCommandWrapper.create("blkid", ["/dev/#{partition.device}"], host, true, true) partid_exec.execute partid = partid_exec.output.chomp.gsub(/.* UUID=\"([^"]+)\" .*/,'\1') unless partid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ puts "Could not get uuid of disk" throw( :abort_action ) end socket = get_socket(host, partid) if socket.nil? puts "Disk is not waiting to be opened" throw( :abort_action ) end # Upload password-agent binary and supply password to the correct socket binary = File.join(ROOT_DIR, "vendor", "password-agent") unless File.exists?(binary) puts "This gem is missing the native password-agent binary" throw( :abort_action ) end # This is an epic hack to have a binary with exec permission # initrd does not have chmod, so we copy an existing binary and override it r = Arver::SSHCommandWrapper.create("cp", ["/bin/true", "/run/password-agent"], host, true, true).execute r = Arver::SSHCommandWrapper.create("cat", ["- > /run/password-agent"], host, true, true) r.execute(File.read(binary)) unless r.success? puts "Could not upload password-agent" throw( :abort_action ) end # Pass password a = Arver::SSHCommandWrapper.create("/run/password-agent", [socket], host, true, true) a.execute(key) # Cannot check if it worked, since if it did, the server rebooted end |
#get_socket(host, partid) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/arver/systemd_open_action.rb', line 19 def get_socket(host, partid) # Check which partitions are waiting for a password # see https://www.freedesktop.org/wiki/Software/systemd/PasswordAgents/ files_exec = Arver::SSHCommandWrapper.create("ls", ["/run/systemd/ask-password/ask.*"], host, true, true) files_exec.execute files = files_exec.output.split("\n") # Find the socket for the partition we want to open files.each do |f| f_exec = Arver::SSHCommandWrapper.create("cat", [f], host, true, true) f_exec.execute ask_file = f_exec.output if ask_file =~ /#{partid}/ ask_file =~ /Socket=(.*)/ return $1 end end nil end |
#verify?(partition) ⇒ Boolean
10 11 12 13 14 15 16 17 |
# File 'lib/arver/systemd_open_action.rb', line 10 def verify?( partition ) if(Arver::SSHCommandWrapper.is_system_running?(partition)) Arver::Log.error( "#{partition.parent.name} already up. Use normal open, skipping." ) return false end return false unless load_key( partition ) true end |