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 15:53:28 +02:00
|
|
|
|
|
|
|
require "yaml"
|
|
|
|
|
|
|
|
module GX
|
|
|
|
abstract class Filesystem
|
|
|
|
include YAML::Serializable
|
|
|
|
|
|
|
|
use_yaml_discriminator "type", {
|
|
|
|
gocryptfs: GoCryptFS,
|
2023-10-24 17:04:15 +02:00
|
|
|
sshfs: SshFS,
|
|
|
|
httpdirfs: HttpDirFS
|
2023-10-24 15:53:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
property type : String
|
|
|
|
end
|
|
|
|
|
|
|
|
module GenericFilesystem
|
|
|
|
def unmount
|
|
|
|
system("fusermount -u #{mount_dir.shellescape}")
|
2023-11-20 12:37:31 +01:00
|
|
|
fusermount_status = $?
|
|
|
|
|
|
|
|
if fusermount_status.success? == 0
|
|
|
|
puts "Filesystem #{name} is now closed.".colorize(:green)
|
|
|
|
else
|
|
|
|
puts "Error: Unable to unmount filesystem #{name} (exit code: #{fusermount_status.exit_code}).".colorize(:red)
|
|
|
|
end
|
2023-10-24 15:53:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def mount(&block)
|
|
|
|
Dir.mkdir_p(mount_dir) unless Dir.exists?(mount_dir)
|
|
|
|
if mounted?
|
|
|
|
puts "Already mounted. Skipping.".colorize(:yellow)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
puts "Filesystem #{name} is now available on #{mount_dir}".colorize(:green)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require "./gocryptfs"
|
|
|
|
require "./sshfs"
|