forked from EvergreenCrypto/docker-finance
209 lines
5.9 KiB
Bash
Executable File
209 lines
5.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# docker-finance | modern accounting for the power-user
|
|
#
|
|
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
# Implementation
|
|
#
|
|
|
|
source "$(dirname "$(realpath -s $0)")/src/docker/lib/lib_docker.bash" || exit 1
|
|
|
|
#
|
|
# Execute
|
|
#
|
|
|
|
function main()
|
|
{
|
|
[ -z "$global_basename" ] && lib_utils::die_fatal
|
|
[ -z "$global_arg_delim_1" ] && lib_utils::die_fatal
|
|
[ -z "$global_arg_delim_2" ] && lib_utils::die_fatal
|
|
|
|
local _usage="
|
|
\e[32mDescription:\e[0m
|
|
|
|
The 'docker' in 'docker-finance'
|
|
|
|
\e[32mUsage:\e[0m
|
|
|
|
$ $global_basename <instance> <command> [args]
|
|
|
|
\e[32mInstance:\e[0m
|
|
|
|
<platform/user:tag>
|
|
|
|
platform \e[34;3mBase image platform (default: archlinux)\e[0m
|
|
user \e[34;3mUser to bind-mount with (default: ${USER})\e[0m
|
|
tag \e[34;3mImage tag type to use (default: latest)\e[0m
|
|
|
|
\e[32mCommand:\e[0m
|
|
|
|
Environment (all platforms):
|
|
|
|
gen \e[34;3mGenerate docker-finance environment\e[0m
|
|
edit \e[34;3mEdit existing client-side configurations\e[0m
|
|
|
|
All platforms:
|
|
|
|
build \e[34;3mBuild docker-finance image\e[0m
|
|
backup \e[34;3mBackup existing instance image\e[0m
|
|
rm \e[34;3mRemove image, remove network (also stops container, if running)\e[0m
|
|
|
|
up \e[34;3mCreate network, bring up unique container, open shell\e[0m
|
|
down \e[34;3mStop and remove container, remove network\e[0m
|
|
start \e[34;3mStart existing container\e[0m
|
|
stop \e[34;3mStop running container\e[0m
|
|
|
|
run \e[34;3mSpawn a container with given command (container removed on exit)\e[0m
|
|
shell \e[34;3mOpen shell into running container\e[0m
|
|
|
|
version \e[34;3mPrint current version of 'docker-finance' and its dependencies\e[0m
|
|
|
|
Dev-tools platform:
|
|
|
|
license \e[34;3mAdd a license to a docker-finance file\e[0m
|
|
linter \e[34;3mLint docker-finance source files\e[0m
|
|
doxygen \e[34;3mGenerate Doxygen for docker-finance file\e[0m
|
|
|
|
\e[32mOptional:\e[0m
|
|
|
|
[args] \e[34;3mCommand argument(s)\e[0m
|
|
|
|
\e[32mExamples:\e[0m
|
|
|
|
\e[37;2m#\e[0m
|
|
\e[37;2m# Finance platform\e[0m
|
|
\e[37;2m#\e[0m
|
|
|
|
\e[37;2m# Setup an alias for latest <platform${global_arg_delim_1}user:tag>\e[0m
|
|
$ alias docker-finance=\"$0 archlinux${global_arg_delim_1}${USER}:latest\"
|
|
|
|
\e[37;2m# Generate environment and build default image\e[0m
|
|
$ docker-finance gen && docker-finance build type=default
|
|
|
|
\e[37;2m# Bring up container, open shell (type 'exit' to leave)\e[0m
|
|
$ docker-finance up
|
|
|
|
\e[37;2m# In another shell (or after you exit), open a container root shell\e[0m
|
|
$ docker-finance shell user${global_arg_delim_2}root
|
|
|
|
\e[37;2m# In another shell (or after you exit), edit client/container variables\e[0m
|
|
$ docker-finance edit type${global_arg_delim_2}env
|
|
|
|
\e[37;2m# Spawn a container with given command (removed after command finishes)\e[0m
|
|
\e[37;2m# NOTE: incredibly useful when used with your host's crontab\e[0m
|
|
$ docker-finance run 'finance family/alice fetch all=price'
|
|
|
|
\e[37;2m# Bring down running container (stop and remove container & network)\e[0m
|
|
$ docker-finance down
|
|
|
|
\e[37;2m# Backup image, delete old image, build new image\e[0m
|
|
$ docker-finance backup && docker-finance rm && docker-finance build
|
|
|
|
\e[37;2m# Print current version of 'docker-finance' and client/container ('finance') dependencies\e[0m
|
|
$ docker-finance version
|
|
|
|
\e[37;2m#\e[0m
|
|
\e[37;2m# Dev-tools platform\e[0m
|
|
\e[37;2m#\e[0m
|
|
|
|
\e[37;2m# Setup an alias for dev-tools\e[0m
|
|
$ alias docker-finance_dev-tools=\"$0 dev-tools${global_arg_delim_1}${USER}:latest\"
|
|
|
|
\e[37;2m# Generate environment and build default image\e[0m
|
|
$ docker-finance_dev-tools gen && docker-finance_dev-tools build type=default
|
|
|
|
\e[37;2m# Spawn a container with given command (removed after command finishes)\e[0m
|
|
$ docker-finance_dev-tools run 'shellcheck --version'
|
|
|
|
\e[37;2m# Lint entire docker-finance source\e[0m
|
|
$ docker-finance_dev-tools linter type=bash,php,c++
|
|
|
|
\e[37;2m# Generate Doxygen for docker-finance source\e[0m
|
|
$ docker-finance_dev-tools doxygen gen
|
|
|
|
\e[37;2m# Print current version of 'docker-finance' and client/container ('dev-tools') dependencies\e[0m
|
|
$ docker-finance_dev-tools version
|
|
"
|
|
|
|
#
|
|
# "Constructor" (initilizes client environment)
|
|
#
|
|
|
|
lib_docker::docker "$@" || lib_utils::die_usage "$_usage"
|
|
|
|
#
|
|
# Command facade
|
|
#
|
|
|
|
[ -z "$global_command" ] && lib_utils::die_fatal
|
|
case "$global_command" in
|
|
gen)
|
|
lib_docker::gen "${@:3}"
|
|
;;
|
|
edit)
|
|
lib_docker::edit "${@:3}"
|
|
;;
|
|
build)
|
|
lib_docker::build "${@:3}"
|
|
;;
|
|
up)
|
|
lib_docker::up "${@:3}"
|
|
;;
|
|
down)
|
|
lib_docker::down "${@:3}"
|
|
;;
|
|
start)
|
|
lib_docker::start "${@:3}"
|
|
;;
|
|
stop)
|
|
lib_docker::stop "${@:3}"
|
|
;;
|
|
rm)
|
|
lib_docker::rm "${@:3}"
|
|
;;
|
|
run)
|
|
lib_docker::run "${@:3}"
|
|
;;
|
|
shell)
|
|
lib_docker::shell "${@:3}"
|
|
;;
|
|
backup)
|
|
lib_docker::backup "${@:3}"
|
|
;;
|
|
license)
|
|
lib_docker::license "${@:3}"
|
|
;;
|
|
linter)
|
|
lib_docker::linter "${@:3}"
|
|
;;
|
|
doxygen)
|
|
lib_docker::doxygen "${@:3}"
|
|
;;
|
|
version)
|
|
lib_docker::version "${@:3}"
|
|
;;
|
|
*)
|
|
lib_utils::die_usage "$_usage"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main "$@"
|
|
|
|
# vim: sw=2 sts=2 si ai et
|