Class: GRUB2Pwd

Inherits:
Object
  • Object
show all
Defined in:
src/lib/bootloader/grub2pwd.rb

Constant Summary

YAST_BASH_PATH =
Yast::Path.new(".target.bash_output")
PWD_ENCRYPTION_FILE =
"/etc/grub.d/42_password"

Instance Method Summary (collapse)

Instance Method Details

- (Object) disable



30
31
32
33
34
# File 'src/lib/bootloader/grub2pwd.rb', line 30

def disable
  return unless used?

  Yast::SCR.Execute(YAST_BASH_PATH, "rm '#{PWD_ENCRYPTION_FILE}'")
end

- (Object) enable(password)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'src/lib/bootloader/grub2pwd.rb', line 13

def enable(password)
  enc_passwd = encrypt(password)

  file_content = "#! /bin/sh\n" +
    "exec tail -n +3 $0\n" +
    "# File created by YaST and next password change in YaST will overwrite it\n" +
    "set superusers=\"root\"\n" +
    "password_pbkdf2 root #{enc_passwd}\n" +
    "export superusers"

  Yast::SCR.Write(
    Yast::Path.new(".target.string"),
    [PWD_ENCRYPTION_FILE, 0700],
    file_content
  )
end

- (Boolean) used?

Returns:

  • (Boolean)


7
8
9
10
11
# File 'src/lib/bootloader/grub2pwd.rb', line 7

def used?
  Yast.import "FileUtils"

  Yast::FileUtils.Exists PWD_ENCRYPTION_FILE
end