Compare commits
No commits in common. "994f9e1885a3188f808ff1416a87b74034a8a12b" and "eb42b28841b1655a67ee1061f17e47d513f438cd" have entirely different histories.
994f9e1885
...
eb42b28841
8 changed files with 117 additions and 142 deletions
|
@ -97,7 +97,7 @@ module GX
|
|||
end
|
||||
|
||||
def mount()
|
||||
names_display = {} of String => NamedTuple(filesystem: Filesystem::AbstractFilesystem, ansi_name: String)
|
||||
names_display = {} of String => NamedTuple(filesystem: Filesystem, ansi_name: String)
|
||||
@config.filesystems.each do |filesystem|
|
||||
fs_str = filesystem.type.ljust(12,' ')
|
||||
|
||||
|
|
|
@ -23,9 +23,8 @@ module GX
|
|||
record AddArgs, name : String, path : String
|
||||
record DelArgs, name : String
|
||||
|
||||
getter filesystems : Array(Filesystem::AbstractFilesystem)
|
||||
getter filesystems : Array(Filesystem)
|
||||
getter home_dir : String
|
||||
getter global_mount_point : String?
|
||||
property verbose : Bool
|
||||
property mode : Mode
|
||||
property path : String?
|
||||
|
@ -39,9 +38,8 @@ module GX
|
|||
|
||||
@verbose = false
|
||||
@mode = Mode::Mount
|
||||
@filesystems = [] of Filesystem::AbstractFilesystem
|
||||
@filesystems = [] of Filesystem
|
||||
@path = nil
|
||||
@global_mount_point = nil
|
||||
|
||||
@args = NoArgs
|
||||
end
|
||||
|
@ -75,7 +73,7 @@ module GX
|
|||
path = detect_config_file()
|
||||
end
|
||||
@path = path
|
||||
@filesystems = [] of Filesystem::AbstractFilesystem
|
||||
@filesystems = [] of Filesystem
|
||||
|
||||
if !File.exists? path
|
||||
Log.error { "File #{path} does not exist!".colorize(:red) }
|
||||
|
@ -84,34 +82,19 @@ module GX
|
|||
load_filesystems(path)
|
||||
end
|
||||
|
||||
# FIXME: render template on a value basis (instead of global)
|
||||
private def load_filesystems(config_path : String)
|
||||
schema_version = nil
|
||||
file_data = File.read(config_path)
|
||||
# FIXME: render template on a value basis (instead of global)
|
||||
file_patched = Crinja.render(file_data, {"env" => ENV.to_h})
|
||||
|
||||
yaml_data = YAML.parse(file_patched)
|
||||
|
||||
# Extract schema version
|
||||
if yaml_data["version"]?
|
||||
schema_version = yaml_data["version"].as_s?
|
||||
end
|
||||
|
||||
# Extract global settings
|
||||
if yaml_data["global"]?.try &.as_h?
|
||||
global_data = yaml_data["global"]
|
||||
if global_data["mountpoint"]?
|
||||
@global_mount_point = global_data["mountpoint"].as_s?
|
||||
end
|
||||
end
|
||||
|
||||
# Extract filesystem data
|
||||
vaults_data = yaml_data["filesystems"].as_a
|
||||
|
||||
vaults_data.each do |filesystem_data|
|
||||
type = filesystem_data["type"].as_s
|
||||
name = filesystem_data["name"].as_s
|
||||
# encrypted_path = filesystem_data["encrypted_path"].as_s
|
||||
@filesystems << Filesystem::AbstractFilesystem.from_yaml(filesystem_data.to_yaml)
|
||||
@filesystems << Filesystem.from_yaml(filesystem_data.to_yaml)
|
||||
# @filesystems << Filesystem.new(name, encrypted_path, "#{name}.Open")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
require "./filesystems/gocryptfs"
|
||||
require "./filesystems/sshfs"
|
||||
require "./filesystems/httpdirfs"
|
||||
require "./filesystems/abstract_filesystem"
|
||||
require "./filesystems/filesystem"
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
# 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>
|
||||
|
||||
require "yaml"
|
||||
|
||||
module GX
|
||||
module Filesystem
|
||||
abstract class AbstractFilesystem
|
||||
include YAML::Serializable
|
||||
|
||||
use_yaml_discriminator "type", {
|
||||
gocryptfs: GoCryptFS,
|
||||
sshfs: SshFS,
|
||||
httpdirfs: HttpDirFS
|
||||
}
|
||||
|
||||
property type : String
|
||||
end
|
||||
|
||||
module FilesystemBase
|
||||
def unmount
|
||||
system("fusermount -u #{mount_dir.shellescape}")
|
||||
fusermount_status = $?
|
||||
|
||||
if fusermount_status.success?
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
require "./gocryptfs"
|
||||
require "./sshfs"
|
48
src/filesystems/filesystem.cr
Normal file
48
src/filesystems/filesystem.cr
Normal file
|
@ -0,0 +1,48 @@
|
|||
# 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>
|
||||
|
||||
require "yaml"
|
||||
|
||||
module GX
|
||||
abstract class Filesystem
|
||||
include YAML::Serializable
|
||||
|
||||
use_yaml_discriminator "type", {
|
||||
gocryptfs: GoCryptFS,
|
||||
sshfs: SshFS,
|
||||
httpdirfs: HttpDirFS
|
||||
}
|
||||
|
||||
property type : String
|
||||
end
|
||||
|
||||
module GenericFilesystem
|
||||
def unmount
|
||||
system("fusermount -u #{mount_dir.shellescape}")
|
||||
fusermount_status = $?
|
||||
|
||||
if fusermount_status.success?
|
||||
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
|
||||
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"
|
|
@ -4,44 +4,42 @@
|
|||
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
||||
|
||||
require "shellwords"
|
||||
require "./abstract_filesystem"
|
||||
require "./filesystem"
|
||||
|
||||
module GX
|
||||
module Filesystem
|
||||
class GoCryptFS < AbstractFilesystem
|
||||
getter name : String = ""
|
||||
getter encrypted_path : String = ""
|
||||
class GoCryptFS < Filesystem
|
||||
getter name : String = ""
|
||||
getter encrypted_path : String = ""
|
||||
|
||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||
getter mount_dir : String = ""
|
||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||
getter mount_dir : String = ""
|
||||
|
||||
include FilesystemBase
|
||||
include GenericFilesystem
|
||||
|
||||
def after_initialize()
|
||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
||||
@mount_dir = File.join(home_dir, "mnt/#{@name}.Open")
|
||||
end
|
||||
def after_initialize()
|
||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
||||
@mount_dir = File.join(home_dir, "mnt/#{@name}.Open")
|
||||
end
|
||||
|
||||
def mounted? : Bool
|
||||
`mount`.includes?("#{encrypted_path} on #{mount_dir}")
|
||||
end
|
||||
def mounted? : Bool
|
||||
`mount`.includes?("#{encrypted_path} on #{mount_dir}")
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,18 +4,17 @@
|
|||
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
||||
|
||||
require "shellwords"
|
||||
require "./abstract_filesystem"
|
||||
require "./filesystem"
|
||||
|
||||
module GX
|
||||
module Filesystem
|
||||
class HttpDirFS < AbstractFilesystem
|
||||
class HttpDirFS < Filesystem
|
||||
getter name : String = ""
|
||||
getter url : String = ""
|
||||
|
||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||
getter mount_dir : String = ""
|
||||
|
||||
include FilesystemBase
|
||||
include GenericFilesystem
|
||||
|
||||
def after_initialize()
|
||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
||||
|
@ -45,6 +44,5 @@ module GX
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,39 +4,38 @@
|
|||
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
||||
|
||||
require "shellwords"
|
||||
require "./abstract_filesystem"
|
||||
require "./filesystem"
|
||||
|
||||
module GX
|
||||
module Filesystem
|
||||
class SshFS < AbstractFilesystem
|
||||
getter name : String = ""
|
||||
getter remote_path : String = ""
|
||||
getter remote_user : String = ""
|
||||
getter remote_host : String = ""
|
||||
getter remote_port : String = "22"
|
||||
class SshFS < Filesystem
|
||||
getter name : String = ""
|
||||
getter remote_path : String = ""
|
||||
getter remote_user : String = ""
|
||||
getter remote_host : String = ""
|
||||
getter remote_port : String = "22"
|
||||
|
||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||
getter mount_dir : String = ""
|
||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||
getter mount_dir : String = ""
|
||||
|
||||
include FilesystemBase
|
||||
include GenericFilesystem
|
||||
|
||||
def after_initialize()
|
||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
||||
@mount_dir = File.join(home_dir, "mnt/#{@name}")
|
||||
end
|
||||
def after_initialize()
|
||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
||||
@mount_dir = File.join(home_dir, "mnt/#{@name}")
|
||||
end
|
||||
|
||||
def mounted? : Bool
|
||||
`mount`.includes?("#{remote_user}@#{remote_host}:#{remote_path} on #{mount_dir}")
|
||||
end
|
||||
def mounted? : Bool
|
||||
`mount`.includes?("#{remote_user}@#{remote_host}:#{remote_path} on #{mount_dir}")
|
||||
end
|
||||
|
||||
def mount
|
||||
super do
|
||||
input = STDIN
|
||||
output = STDOUT
|
||||
error = STDERR
|
||||
process = Process.new(
|
||||
"sshfs",
|
||||
[
|
||||
def mount
|
||||
super do
|
||||
input = STDIN
|
||||
output = STDOUT
|
||||
error = STDERR
|
||||
process = Process.new(
|
||||
"sshfs",
|
||||
[
|
||||
"-p", remote_port,
|
||||
"#{remote_user}@#{remote_host}:#{remote_path}",
|
||||
mount_dir
|
||||
|
@ -44,11 +43,10 @@ module GX
|
|||
input: input,
|
||||
output: output,
|
||||
error: error
|
||||
)
|
||||
unless process.wait.success?
|
||||
puts "Error mounting the filesystem".colorize(:red)
|
||||
return
|
||||
end
|
||||
)
|
||||
unless process.wait.success?
|
||||
puts "Error mounting the filesystem".colorize(:red)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue