mfm/src/filesystems/gocryptfs.cr

50 lines
1.2 KiB
Crystal
Raw Normal View History

2023-10-25 14:01:46 +02:00
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
2023-10-24 12:50:01 +02:00
require "shellwords"
require "./abstract_filesystem"
2023-10-24 12:50:01 +02:00
2023-10-22 23:23:56 +02:00
module GX
module Filesystem
class GoCryptFS < AbstractFilesystem
getter name : String = ""
getter encrypted_path : String = ""
2023-10-22 23:23:56 +02:00
@[YAML::Field(key: "mount_dir", ignore: true)]
getter mount_dir : String = ""
2023-10-24 15:53:28 +02:00
include FilesystemBase
2023-10-24 15:53:28 +02:00
def after_initialize()
home_dir = ENV["HOME"] || raise "Home directory not found"
@mount_dir = File.join(home_dir, "mnt/#{@name}.Open")
end
2023-10-22 23:23:56 +02:00
def mounted? : Bool
`mount`.includes?("#{encrypted_path} on #{mount_dir}")
end
2023-10-22 23:23:56 +02:00
def mount
super do
input = STDIN
output = STDOUT
error = STDERR
process = Process.new(
"gocryptfs",
["-idle", "15m", encrypted_path, mount_dir],
input: input,
output: output,
error: error
)
unless process.wait.success?
puts "Error mounting the vault".colorize(:red)
return
end
2023-10-24 12:50:01 +02:00
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