Compare commits
8 commits
6d36a7f78a
...
3c4e4271b2
Author | SHA1 | Date | |
---|---|---|---|
3c4e4271b2 | |||
e6a9d01175 | |||
9f0902d91d | |||
592f0fbe41 | |||
576b7c62c6 | |||
1c184a5557 | |||
2990e18b27 | |||
f94d0f1f39 |
6 changed files with 82 additions and 11 deletions
11
.drone.yml
11
.drone.yml
|
@ -5,7 +5,7 @@ name: default
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build:binary
|
- name: build:binary
|
||||||
image: crystallang/crystal:1.7.3
|
image: crystallang/crystal:1.10.1-alpine
|
||||||
environment:
|
environment:
|
||||||
PACKAGE_BASENAME: mfm_linux_amd64
|
PACKAGE_BASENAME: mfm_linux_amd64
|
||||||
volumes:
|
volumes:
|
||||||
|
@ -13,11 +13,16 @@ steps:
|
||||||
path: /_cache
|
path: /_cache
|
||||||
commands:
|
commands:
|
||||||
- pwd
|
- pwd
|
||||||
- apt-get update &&
|
# - |
|
||||||
apt-get install -y cmake g++ libevent-dev libpcre3-dev libyaml-dev
|
# apt-get update && \
|
||||||
|
# apt-get install -y \
|
||||||
|
# cmake g++ \
|
||||||
|
# libevent-dev libpcre3-dev \
|
||||||
|
# libyaml-dev liblzma-dev
|
||||||
- shards install
|
- shards install
|
||||||
- shards build --production --static
|
- shards build --production --static
|
||||||
- strip bin/mfm
|
- strip bin/mfm
|
||||||
|
- ./bin/mfm --version
|
||||||
- mkdir -p /_cache/bin
|
- mkdir -p /_cache/bin
|
||||||
- cp -r bin/mfm /_cache/bin/$PACKAGE_BASENAME
|
- cp -r bin/mfm /_cache/bin/$PACKAGE_BASENAME
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
version: 2.0
|
version: 2.0
|
||||||
shards:
|
shards:
|
||||||
|
crinja:
|
||||||
|
git: https://github.com/straight-shoota/crinja.git
|
||||||
|
version: 0.8.1
|
||||||
|
|
||||||
shellwords:
|
shellwords:
|
||||||
git: https://github.com/sztheory/shellwords-crystal.git
|
git: https://github.com/sztheory/shellwords-crystal.git
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
|
@ -18,6 +18,8 @@ targets:
|
||||||
# Short description of gx-vault
|
# Short description of gx-vault
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
crinja:
|
||||||
|
github: straight-shoota/crinja
|
||||||
shellwords:
|
shellwords:
|
||||||
github: szTheory/shellwords-crystal
|
github: szTheory/shellwords-crystal
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ module GX
|
||||||
VERSION="v0.1.9"
|
VERSION="v0.1.9"
|
||||||
|
|
||||||
class Cli
|
class Cli
|
||||||
|
Log = ::Log.for("cli")
|
||||||
|
|
||||||
@config : Config
|
@config : Config
|
||||||
|
|
||||||
|
@ -29,10 +30,12 @@ module GX
|
||||||
parser.banner = "Usage: #{PROGRAM_NAME} [options]\n\nGlobal options"
|
parser.banner = "Usage: #{PROGRAM_NAME} [options]\n\nGlobal options"
|
||||||
|
|
||||||
parser.on("-c", "--config FILE", "Set configuration file") do |path|
|
parser.on("-c", "--config FILE", "Set configuration file") do |path|
|
||||||
|
Log.info { "Configuration set to #{path}" }
|
||||||
@config.path = path
|
@config.path = path
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on("-v", "--verbose", "Set more verbosity") do |flag|
|
parser.on("-v", "--verbose", "Set more verbosity") do |flag|
|
||||||
|
Log.info { "Verbosity enabled" }
|
||||||
@config.verbose = true
|
@config.verbose = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,14 @@
|
||||||
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
|
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
|
||||||
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
||||||
|
|
||||||
|
require "crinja"
|
||||||
|
|
||||||
require "./filesystems"
|
require "./filesystems"
|
||||||
|
|
||||||
module GX
|
module GX
|
||||||
class Config
|
class Config
|
||||||
|
Log = ::Log.for("config")
|
||||||
|
|
||||||
enum Mode
|
enum Mode
|
||||||
ConfigAdd
|
ConfigAdd
|
||||||
ConfigDelete
|
ConfigDelete
|
||||||
|
@ -23,11 +27,9 @@ module GX
|
||||||
getter home_dir : String
|
getter home_dir : String
|
||||||
property verbose : Bool
|
property verbose : Bool
|
||||||
property mode : Mode
|
property mode : Mode
|
||||||
property path : String
|
property path : String?
|
||||||
property args : AddArgs.class | DelArgs.class | NoArgs.class
|
property args : AddArgs.class | DelArgs.class | NoArgs.class
|
||||||
|
|
||||||
DEFAULT_CONFIG_PATH = "mfm.yml"
|
|
||||||
|
|
||||||
def initialize()
|
def initialize()
|
||||||
if !ENV["HOME"]?
|
if !ENV["HOME"]?
|
||||||
raise "Home directory not found"
|
raise "Home directory not found"
|
||||||
|
@ -37,22 +39,55 @@ module GX
|
||||||
@verbose = false
|
@verbose = false
|
||||||
@mode = Mode::Mount
|
@mode = Mode::Mount
|
||||||
@filesystems = [] of Filesystem
|
@filesystems = [] of Filesystem
|
||||||
@path = File.join(@home_dir, ".config", DEFAULT_CONFIG_PATH)
|
@path = nil
|
||||||
|
|
||||||
@args = NoArgs
|
@args = NoArgs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def detect_config_file()
|
||||||
|
possible_files = [
|
||||||
|
File.join(@home_dir, ".config", "mfm", "config.yaml"),
|
||||||
|
File.join(@home_dir, ".config", "mfm", "config.yml"),
|
||||||
|
File.join(@home_dir, ".config", "mfm.yaml"),
|
||||||
|
File.join(@home_dir, ".config", "mfm.yml"),
|
||||||
|
File.join("/etc", "mfm", "config.yaml"),
|
||||||
|
File.join("/etc", "mfm", "config.yml"),
|
||||||
|
]
|
||||||
|
|
||||||
|
possible_files.each do |file_path|
|
||||||
|
if File.exists?(file_path)
|
||||||
|
Log.info { "Configuration file found: #{file_path}" }
|
||||||
|
return file_path if File.exists?(file_path)
|
||||||
|
else
|
||||||
|
Log.debug { "Configuration file not found: #{file_path}" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Log.error { "No configuration file found in any of the standard locations" }
|
||||||
|
raise "Configuration file not found"
|
||||||
|
end
|
||||||
|
|
||||||
def load_from_file
|
def load_from_file
|
||||||
|
path = @path
|
||||||
|
if path.nil?
|
||||||
|
path = detect_config_file()
|
||||||
|
end
|
||||||
|
@path = path
|
||||||
@filesystems = [] of Filesystem
|
@filesystems = [] of Filesystem
|
||||||
|
|
||||||
if !File.exists? @path
|
if !File.exists? path
|
||||||
STDERR.puts "Error: file #{@path} does not exist!".colorize(:red)
|
Log.error { "File #{path} does not exist!".colorize(:red) }
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
load_filesystems(@path)
|
load_filesystems(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
private def load_filesystems(config_path : String)
|
private def load_filesystems(config_path : String)
|
||||||
yaml_data = YAML.parse(File.read(config_path))
|
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)
|
||||||
vaults_data = yaml_data["filesystems"].as_a
|
vaults_data = yaml_data["filesystems"].as_a
|
||||||
|
|
||||||
vaults_data.each do |filesystem_data|
|
vaults_data.each do |filesystem_data|
|
||||||
|
|
22
src/main.cr
22
src/main.cr
|
@ -6,11 +6,33 @@
|
||||||
require "yaml"
|
require "yaml"
|
||||||
require "colorize"
|
require "colorize"
|
||||||
require "json"
|
require "json"
|
||||||
|
require "log"
|
||||||
|
|
||||||
require "./filesystems/gocryptfs"
|
require "./filesystems/gocryptfs"
|
||||||
require "./config"
|
require "./config"
|
||||||
require "./cli"
|
require "./cli"
|
||||||
|
|
||||||
|
struct BaseFormat < Log::StaticFormatter
|
||||||
|
def run
|
||||||
|
string @entry.severity.label.downcase
|
||||||
|
string "("
|
||||||
|
source
|
||||||
|
string "): "
|
||||||
|
message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Log.setup do |config|
|
||||||
|
backend = Log::IOBackend.new(formatter: BaseFormat)
|
||||||
|
config.bind "*", Log::Severity::Info, backend
|
||||||
|
|
||||||
|
if ENV["LOG_LEVEL"]?
|
||||||
|
level = Log::Severity.parse(ENV["LOG_LEVEL"]) || Log::Severity::Info
|
||||||
|
config.bind "*", level, backend
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
app = GX::Cli.new
|
app = GX::Cli.new
|
||||||
app.parse_command_line(ARGV)
|
app.parse_command_line(ARGV)
|
||||||
app.run
|
app.run
|
||||||
|
|
Loading…
Reference in a new issue