feature/6-add-configurable-global-mountpoint #32
5 changed files with 69 additions and 72 deletions
|
@ -17,34 +17,11 @@ module GX
|
||||||
}
|
}
|
||||||
|
|
||||||
property type : String
|
property type : String
|
||||||
end
|
|
||||||
|
|
||||||
module FilesystemBase
|
abstract def mount()
|
||||||
def unmount
|
abstract def unmount()
|
||||||
system("fusermount -u #{mount_dir.shellescape}")
|
abstract def mounted_prefix()
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "./gocryptfs"
|
|
||||||
require "./sshfs"
|
|
||||||
|
|
41
src/filesystems/concerns/base.cr
Normal file
41
src/filesystems/concerns/base.cr
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
module GX::Filesystem::Concerns
|
||||||
|
module Base
|
||||||
|
def after_initialize()
|
||||||
|
home_dir = ENV["HOME"] || raise "Home directory not found"
|
||||||
|
|
||||||
|
# Use default mountpoint if none defined
|
||||||
|
if @mount_dir.empty?
|
||||||
|
@mount_dir = File.join(home_dir, "mnt/#{@name}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mounted? : Bool
|
||||||
|
`mount`.includes?(" on #{mount_dir} type ")
|
||||||
|
end
|
||||||
|
|
||||||
|
def unmount : Nil
|
||||||
|
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_wrapper(&block) : Nil
|
||||||
|
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
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
require "./abstract_filesystem"
|
require "./abstract_filesystem"
|
||||||
|
require "./concerns/base"
|
||||||
|
|
||||||
module GX
|
module GX
|
||||||
module Filesystem
|
module Filesystem
|
||||||
|
@ -15,28 +16,20 @@ module GX
|
||||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||||
getter mount_dir : String = ""
|
getter mount_dir : String = ""
|
||||||
|
|
||||||
include FilesystemBase
|
include Concerns::Base
|
||||||
|
|
||||||
def after_initialize()
|
def mounted_prefix()
|
||||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
"#{encrypted_path}"
|
||||||
@mount_dir = File.join(home_dir, "mnt/#{@name}.Open")
|
|
||||||
end
|
|
||||||
|
|
||||||
def mounted? : Bool
|
|
||||||
`mount`.includes?("#{encrypted_path} on #{mount_dir}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount
|
def mount
|
||||||
super do
|
_mount_wrapper do
|
||||||
input = STDIN
|
|
||||||
output = STDOUT
|
|
||||||
error = STDERR
|
|
||||||
process = Process.new(
|
process = Process.new(
|
||||||
"gocryptfs",
|
"gocryptfs",
|
||||||
["-idle", "15m", encrypted_path, mount_dir],
|
["-idle", "15m", encrypted_path, mount_dir],
|
||||||
input: input,
|
input: STDIN,
|
||||||
output: output,
|
output: STDOUT,
|
||||||
error: error
|
error: STDERR
|
||||||
)
|
)
|
||||||
unless process.wait.success?
|
unless process.wait.success?
|
||||||
puts "Error mounting the vault".colorize(:red)
|
puts "Error mounting the vault".colorize(:red)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
require "./abstract_filesystem"
|
require "./abstract_filesystem"
|
||||||
|
require "./concerns/base"
|
||||||
|
|
||||||
module GX
|
module GX
|
||||||
module Filesystem
|
module Filesystem
|
||||||
|
@ -15,28 +16,20 @@ module GX
|
||||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||||
getter mount_dir : String = ""
|
getter mount_dir : String = ""
|
||||||
|
|
||||||
include FilesystemBase
|
include Concerns::Base
|
||||||
|
|
||||||
def after_initialize()
|
def mounted_prefix()
|
||||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
"httpdirfs"
|
||||||
@mount_dir = File.join(home_dir, "mnt/#{@name}")
|
|
||||||
end
|
|
||||||
|
|
||||||
def mounted? : Bool
|
|
||||||
`mount`.includes?("httpdirfs on #{mount_dir}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount
|
def mount
|
||||||
super do
|
_mount_wrapper do
|
||||||
input = STDIN
|
|
||||||
output = STDOUT
|
|
||||||
error = STDERR
|
|
||||||
process = Process.new(
|
process = Process.new(
|
||||||
"httpdirfs",
|
"httpdirfs",
|
||||||
["#{url}", mount_dir],
|
["#{url}", mount_dir],
|
||||||
input: input,
|
input: STDIN,
|
||||||
output: output,
|
output: STDOUT,
|
||||||
error: error
|
error: STDERR
|
||||||
)
|
)
|
||||||
unless process.wait.success?
|
unless process.wait.success?
|
||||||
puts "Error mounting the filesystem".colorize(:red)
|
puts "Error mounting the filesystem".colorize(:red)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
require "./abstract_filesystem"
|
require "./abstract_filesystem"
|
||||||
|
require "./concerns/base"
|
||||||
|
|
||||||
module GX
|
module GX
|
||||||
module Filesystem
|
module Filesystem
|
||||||
|
@ -18,22 +19,14 @@ module GX
|
||||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||||
getter mount_dir : String = ""
|
getter mount_dir : String = ""
|
||||||
|
|
||||||
include FilesystemBase
|
include Concerns::Base
|
||||||
|
|
||||||
def after_initialize()
|
def mounted_prefix()
|
||||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
"#{remote_user}@#{remote_host}:#{remote_path}"
|
||||||
@mount_dir = File.join(home_dir, "mnt/#{@name}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mounted? : Bool
|
def mount()
|
||||||
`mount`.includes?("#{remote_user}@#{remote_host}:#{remote_path} on #{mount_dir}")
|
_mount_wrapper do
|
||||||
end
|
|
||||||
|
|
||||||
def mount
|
|
||||||
super do
|
|
||||||
input = STDIN
|
|
||||||
output = STDOUT
|
|
||||||
error = STDERR
|
|
||||||
process = Process.new(
|
process = Process.new(
|
||||||
"sshfs",
|
"sshfs",
|
||||||
[
|
[
|
||||||
|
@ -41,9 +34,9 @@ module GX
|
||||||
"#{remote_user}@#{remote_host}:#{remote_path}",
|
"#{remote_user}@#{remote_host}:#{remote_path}",
|
||||||
mount_dir
|
mount_dir
|
||||||
],
|
],
|
||||||
input: input,
|
input: STDIN,
|
||||||
output: output,
|
output: STDOUT,
|
||||||
error: error
|
error: STDERR
|
||||||
)
|
)
|
||||||
unless process.wait.success?
|
unless process.wait.success?
|
||||||
puts "Error mounting the filesystem".colorize(:red)
|
puts "Error mounting the filesystem".colorize(:red)
|
||||||
|
|
Loading…
Reference in a new issue