2023-10-24 12:50:01 +02:00
|
|
|
require "shellwords"
|
2023-10-24 15:53:28 +02:00
|
|
|
require "./filesystem"
|
2023-10-24 12:50:01 +02:00
|
|
|
|
2023-10-22 23:23:56 +02:00
|
|
|
module GX
|
2023-10-24 15:53:28 +02:00
|
|
|
class GoCryptFS < Filesystem
|
|
|
|
getter name : String = ""
|
|
|
|
getter encrypted_path : String = ""
|
2023-10-22 23:23:56 +02:00
|
|
|
|
2023-10-24 15:53:28 +02:00
|
|
|
@[YAML::Field(key: "mount_dir", ignore: true)]
|
|
|
|
getter mount_dir : String = ""
|
|
|
|
|
|
|
|
include GenericFilesystem
|
|
|
|
|
|
|
|
def after_initialize()
|
2023-10-24 12:50:01 +02:00
|
|
|
home_dir = ENV["HOME"] || raise "Home directory not found"
|
2023-10-24 17:04:15 +02:00
|
|
|
@mount_dir = File.join(home_dir, "mnt/#{@name}.Open")
|
2023-10-24 12:50:01 +02:00
|
|
|
end
|
2023-10-22 23:23:56 +02:00
|
|
|
|
2023-10-24 12:50:01 +02:00
|
|
|
def mounted? : Bool
|
|
|
|
`mount`.includes?("#{encrypted_path} on #{mount_dir}")
|
|
|
|
end
|
2023-10-22 23:23:56 +02:00
|
|
|
|
2023-10-24 12:50:01 +02:00
|
|
|
def mount
|
2023-10-24 15:53:28 +02:00
|
|
|
super do
|
2023-10-24 12:50:01 +02:00
|
|
|
input = STDIN
|
|
|
|
output = STDOUT
|
|
|
|
error = STDERR
|
2023-10-24 15:53:28 +02:00
|
|
|
process = Process.new(
|
|
|
|
"gocryptfs",
|
|
|
|
["-idle", "15m", encrypted_path, mount_dir],
|
|
|
|
input: input,
|
|
|
|
output: output,
|
|
|
|
error: error
|
|
|
|
)
|
2023-10-24 12:50:01 +02:00
|
|
|
unless process.wait.success?
|
|
|
|
puts "Error mounting the vault".colorize(:red)
|
|
|
|
return
|
|
|
|
end
|
2023-10-22 23:23:56 +02:00
|
|
|
end
|
2023-10-24 12:50:01 +02:00
|
|
|
end
|
2023-10-22 23:23:56 +02:00
|
|
|
end
|
|
|
|
end
|