Compare commits
3 commits
5dca1d9f15
...
27508ed5ac
Author | SHA1 | Date | |
---|---|---|---|
27508ed5ac | |||
9fc1ec3912 | |||
48df4ccc79 |
5 changed files with 168 additions and 39 deletions
|
@ -59,6 +59,17 @@ docker run \
|
||||||
multiarch/qemu-user-static \
|
multiarch/qemu-user-static \
|
||||||
--reset -p yes
|
--reset -p yes
|
||||||
|
|
||||||
|
set -x
|
||||||
|
docker run \
|
||||||
|
-it \
|
||||||
|
-v "$LOCAL_PROJECT_PATH:/app" \
|
||||||
|
-w /app \
|
||||||
|
--rm \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
"$DOCKER_IMAGE"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
docker run \
|
docker run \
|
||||||
-it \
|
-it \
|
||||||
|
|
86
scripts/compiler.crossbuild-debian.sh
Executable file
86
scripts/compiler.crossbuild-debian.sh
Executable file
|
@ -0,0 +1,86 @@
|
||||||
|
#!/bin/sh -eu
|
||||||
|
# vim: set ts=2 sw=2 et:
|
||||||
|
|
||||||
|
LOCAL_PROJECT_PATH="${1-$PWD}"
|
||||||
|
|
||||||
|
TARGET_ARCH="${2-arm64}"
|
||||||
|
|
||||||
|
DOCKER_IMAGE=""
|
||||||
|
|
||||||
|
BUILD_COMMAND=" \
|
||||||
|
shards build --static --release \
|
||||||
|
&& chown 1000:1000 -R bin \
|
||||||
|
&& find bin -type f -maxdepth 1 -exec mv {} {}_${TARGET_ARCH} \; \
|
||||||
|
"
|
||||||
|
|
||||||
|
# crystal
|
||||||
|
INSTALL_CRYSTAL=" \
|
||||||
|
sed -i -e '/^deb/d' /etc/apt/sources.list \
|
||||||
|
&& sed -i -e '/jessie.updates/d' /etc/apt/sources.list \
|
||||||
|
&& sed -i -e 's/^# deb/deb/' /etc/apt/sources.list \
|
||||||
|
&& apt-get update"
|
||||||
|
|
||||||
|
cat > /dev/null <<EOF
|
||||||
|
"
|
||||||
|
&& apt-get install -y \
|
||||||
|
g\+\+ \
|
||||||
|
gcc \
|
||||||
|
curl \
|
||||||
|
autoconf \
|
||||||
|
automake \
|
||||||
|
python2 \
|
||||||
|
libxml2-dev \
|
||||||
|
llvm-dev \
|
||||||
|
make \
|
||||||
|
libssl-dev \
|
||||||
|
libpcre2-dev \
|
||||||
|
libyaml-dev \
|
||||||
|
zlib1g-dev \
|
||||||
|
"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# setup arch
|
||||||
|
case "$TARGET_ARCH" in
|
||||||
|
amd64) DOCKER_IMAGE="debian:8" ;;
|
||||||
|
arm64) DOCKER_IMAGE="arm64v8/debian:8" ;;
|
||||||
|
armel) DOCKER_IMAGE="arm32v7/debian" ;;
|
||||||
|
armhf) DOCKER_IMAGE="armhf/debian" ;;
|
||||||
|
i386) DOCKER_IMAGE="x86/debian" ;;
|
||||||
|
mips) DOCKER_IMAGE="mips/debian" ;;
|
||||||
|
mipsel) DOCKER_IMAGE="mipsel/debian" ;;
|
||||||
|
powerpc) DOCKER_IMAGE="powerpc/debian" ;;
|
||||||
|
ppc64el) DOCKER_IMAGE="ppc64el/debian" ;;
|
||||||
|
s390x) DOCKER_IMAGE="s390x/debian" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Compile Crystal project statically for target architecture
|
||||||
|
docker pull multiarch/qemu-user-static
|
||||||
|
|
||||||
|
docker run \
|
||||||
|
--rm \
|
||||||
|
--privileged \
|
||||||
|
multiarch/qemu-user-static \
|
||||||
|
--reset -p yes
|
||||||
|
|
||||||
|
set -x
|
||||||
|
docker run \
|
||||||
|
-it \
|
||||||
|
-v "$LOCAL_PROJECT_PATH:/app" \
|
||||||
|
-w /app \
|
||||||
|
--rm \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
"$DOCKER_IMAGE" \
|
||||||
|
/bin/sh -c "$INSTALL_CRYSTAL && bash"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
set -x
|
||||||
|
docker run \
|
||||||
|
-it \
|
||||||
|
-v "$LOCAL_PROJECT_PATH:/app" \
|
||||||
|
-w /app \
|
||||||
|
--rm \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
"$DOCKER_IMAGE" \
|
||||||
|
/bin/sh -c "$INSTALL_CRYSTAL && $BUILD_COMMAND"
|
||||||
|
|
91
src/cli.cr
91
src/cli.cr
|
@ -8,6 +8,8 @@ require "./config"
|
||||||
require "./fzf"
|
require "./fzf"
|
||||||
|
|
||||||
module GX
|
module GX
|
||||||
|
VERSION="v0.1.9"
|
||||||
|
|
||||||
class Cli
|
class Cli
|
||||||
|
|
||||||
@config : Config
|
@config : Config
|
||||||
|
@ -29,41 +31,55 @@ module GX
|
||||||
parser.on("-c", "--config FILE", "Set configuration file") do |path|
|
parser.on("-c", "--config FILE", "Set configuration file") do |path|
|
||||||
@config.path = path
|
@config.path = path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
parser.on("-v", "--verbose", "Set more verbosity") do |flag|
|
||||||
|
@config.verbose = true
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on("--version", "Show version") do |flag|
|
||||||
|
@config.mode = Config::Mode::ShowVersion
|
||||||
|
end
|
||||||
|
|
||||||
parser.on("-h", "--help", "Show this help") do |flag|
|
parser.on("-h", "--help", "Show this help") do |flag|
|
||||||
STDOUT.puts parser
|
STDOUT.puts parser
|
||||||
exit(0)
|
exit(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.separator("\nCommands")
|
parser.separator("\nCommands")
|
||||||
parser.on("create", "Create vault") do
|
parser.on("config", "Manage configuration") do
|
||||||
@config.mode = Config::Mode::Add
|
parser.banner = "Usage: #{PROGRAM_NAME} config [commands] [options]\n\nGlobal options"
|
||||||
|
parser.separator("\nCommands")
|
||||||
|
|
||||||
parser.banner = "Usage: #{PROGRAM_NAME} create [options]\n\nGlobal options"
|
parser.on("create", "Create vault") do
|
||||||
parser.separator("\nCommand options")
|
@config.mode = Config::Mode::ConfigAdd
|
||||||
|
|
||||||
parser.on("-n", "--name", "Set vault name") do |name|
|
parser.banner = "Usage: #{PROGRAM_NAME} config create [commands] [options]\n\nGlobal options"
|
||||||
add_args = add_args.merge({ name: name })
|
parser.separator("\nCommand options")
|
||||||
|
|
||||||
|
parser.on("-n", "--name", "Set vault name") do |name|
|
||||||
|
add_args = add_args.merge({ name: name })
|
||||||
|
end
|
||||||
|
parser.on("-p", "--path", "Set vault encrypted path") do |path|
|
||||||
|
add_args = add_args.merge({ path: path })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
parser.on("-p", "--path", "Set vault encrypted path") do |path|
|
|
||||||
add_args = add_args.merge({ path: path })
|
parser.on("delete", "Delete vault") do
|
||||||
|
@config.mode = Config::Mode::ConfigAdd
|
||||||
|
|
||||||
|
parser.banner = "Usage: #{PROGRAM_NAME} delete [options]\n\nGlobal options"
|
||||||
|
parser.separator("\nCommand options")
|
||||||
|
|
||||||
|
parser.on("-n", "--name", "Set vault name") do |name|
|
||||||
|
delete_args = delete_args.merge({ name: name })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
parser.on("delete", "Delete vault") do
|
parser.on("edit", "Edit configuration") do |flag|
|
||||||
@config.mode = Config::Mode::Add
|
@config.mode = Config::Mode::ConfigEdit
|
||||||
|
|
||||||
parser.banner = "Usage: #{PROGRAM_NAME} delete [options]\n\nGlobal options"
|
|
||||||
parser.separator("\nCommand options")
|
|
||||||
|
|
||||||
parser.on("-n", "--name", "Set vault name") do |name|
|
|
||||||
delete_args = delete_args.merge({ name: name })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on("edit", "Edit configuration") do |flag|
|
|
||||||
@config.mode = Config::Mode::Edit
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
pparser.parse(args)
|
pparser.parse(args)
|
||||||
end
|
end
|
||||||
|
@ -71,21 +87,28 @@ module GX
|
||||||
def run()
|
def run()
|
||||||
@config.load_from_file
|
@config.load_from_file
|
||||||
|
|
||||||
|
case @config.mode
|
||||||
|
when Config::Mode::ShowVersion
|
||||||
|
STDOUT.puts "#{PROGRAM_NAME} #{VERSION}"
|
||||||
|
when Config::Mode::Mount
|
||||||
|
mount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mount()
|
||||||
names_display = {} of String => NamedTuple(filesystem: Filesystem, ansi_name: String)
|
names_display = {} of String => NamedTuple(filesystem: Filesystem, ansi_name: String)
|
||||||
@config.filesystems.each do |filesystem|
|
@config.filesystems.each do |filesystem|
|
||||||
fs_str = filesystem.type.ljust(12,' ')
|
fs_str = filesystem.type.ljust(12,' ')
|
||||||
result_name =
|
|
||||||
if filesystem.mounted?
|
suffix = ""
|
||||||
"#{fs_str} #{filesystem.name} [open]"
|
suffix_ansi = ""
|
||||||
else
|
if filesystem.mounted?
|
||||||
"#{fs_str} #{filesystem.name}"
|
suffix = "[open]"
|
||||||
end
|
suffix_ansi = "[#{ "open".colorize(:green) }]"
|
||||||
ansi_name =
|
end
|
||||||
if filesystem.mounted?
|
|
||||||
"#{fs_str.colorize(:dark_gray)} #{filesystem.name} [#{ "open".colorize(:green) }]"
|
result_name = "#{fs_str} #{filesystem.name} #{suffix}".strip
|
||||||
else
|
ansi_name = "#{fs_str.colorize(:dark_gray)} #{filesystem.name} #{suffix_ansi}".strip
|
||||||
"#{fs_str.colorize(:dark_gray)} #{filesystem.name}"
|
|
||||||
end
|
|
||||||
|
|
||||||
names_display[result_name] = {
|
names_display[result_name] = {
|
||||||
filesystem: filesystem,
|
filesystem: filesystem,
|
||||||
|
@ -93,7 +116,7 @@ module GX
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
result_filesystem_name = Fzf.run(names_display.values.map(&.[:ansi_name]).sort)
|
result_filesystem_name = Fzf.run(names_display.values.map(&.[:ansi_name]).sort).strip
|
||||||
selected_filesystem = names_display[result_filesystem_name][:filesystem]
|
selected_filesystem = names_display[result_filesystem_name][:filesystem]
|
||||||
puts ">> #{selected_filesystem.name}".colorize(:yellow)
|
puts ">> #{selected_filesystem.name}".colorize(:yellow)
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,11 @@ require "./filesystems"
|
||||||
module GX
|
module GX
|
||||||
class Config
|
class Config
|
||||||
enum Mode
|
enum Mode
|
||||||
Add
|
ConfigAdd
|
||||||
Edit
|
ConfigDelete
|
||||||
Run
|
ConfigEdit
|
||||||
|
ShowVersion
|
||||||
|
Mount
|
||||||
end
|
end
|
||||||
|
|
||||||
record NoArgs
|
record NoArgs
|
||||||
|
@ -19,6 +21,7 @@ module GX
|
||||||
|
|
||||||
getter filesystems : Array(Filesystem)
|
getter filesystems : Array(Filesystem)
|
||||||
getter home_dir : String
|
getter home_dir : String
|
||||||
|
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
|
||||||
|
@ -31,7 +34,8 @@ module GX
|
||||||
end
|
end
|
||||||
@home_dir = ENV["HOME"]
|
@home_dir = ENV["HOME"]
|
||||||
|
|
||||||
@mode = Mode::Run
|
@verbose = false
|
||||||
|
@mode = Mode::Mount
|
||||||
@filesystems = [] of Filesystem
|
@filesystems = [] of Filesystem
|
||||||
@path = File.join(@home_dir, ".config", DEFAULT_CONFIG_PATH)
|
@path = File.join(@home_dir, ".config", DEFAULT_CONFIG_PATH)
|
||||||
@args = NoArgs
|
@args = NoArgs
|
||||||
|
|
|
@ -12,6 +12,7 @@ module GX
|
||||||
getter remote_path : String = ""
|
getter remote_path : String = ""
|
||||||
getter remote_user : String = ""
|
getter remote_user : String = ""
|
||||||
getter remote_host : String = ""
|
getter remote_host : String = ""
|
||||||
|
getter remote_port : String = "22"
|
||||||
|
|
||||||
@[YAML::Field(key: "mount_dir", ignore: true)]
|
@[YAML::Field(key: "mount_dir", ignore: true)]
|
||||||
getter mount_dir : String = ""
|
getter mount_dir : String = ""
|
||||||
|
@ -34,7 +35,11 @@ module GX
|
||||||
error = STDERR
|
error = STDERR
|
||||||
process = Process.new(
|
process = Process.new(
|
||||||
"sshfs",
|
"sshfs",
|
||||||
["#{remote_user}@#{remote_host}:#{remote_path}", mount_dir],
|
[
|
||||||
|
"-p", remote_port,
|
||||||
|
"#{remote_user}@#{remote_host}:#{remote_path}",
|
||||||
|
mount_dir
|
||||||
|
],
|
||||||
input: input,
|
input: input,
|
||||||
output: output,
|
output: output,
|
||||||
error: error
|
error: error
|
||||||
|
|
Loading…
Reference in a new issue