From 90f96399f05325fabffe7fde5099cbd9eeeebac7 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Mon, 5 Aug 2024 16:02:38 -0700 Subject: [PATCH 1/2] repo/client: move shell env prep to install.bash --- README.md | 108 +++++++++++++++++--------------------------- client/install.bash | 67 +++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 67 deletions(-) create mode 100755 client/install.bash diff --git a/README.md b/README.md index 2ae3f00..da57102 100644 --- a/README.md +++ b/README.md @@ -243,94 +243,57 @@ Supported blockchains (independent of wallet type): ### Installation -[//]: # (TODO: move step 3 to installation script, add `dfi` aliases, update README) +[//]: # (TODO: add `dfi` aliases, update README) `docker-finance` is not your typical Docker image in which you simply pull and containerize, but rather it's an *image-based* accounting system that operates transparently between your client (host) and container; keeping your finances containerized, with all the benefits of containerization. `docker-finance` *should* work out-of-the-box on any modern Linux system. For example, if your client (host) is Ubuntu, the default installation of `coreutils`, `shells` and `utils` that came with your system will satisfy requirements. However, you'll still need to manually install Docker (see below). 1. **Install dependencies**: + 1. [Docker Engine](https://docs.docker.com/engine/install/#supported-platforms) with [post-install configuration](https://docs.docker.com/engine/install/linux-postinstall/) - Latest version (or at least `27.1.1`) 2. [GNU Bash](https://www.gnu.org/software/bash/) - Latest version (or at least `5.0.17`) - Installed by *default* on most Linux distributions - -2. **Install recommended**: - 1. [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git/) + 3. [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git/) - Latest version (or at least `2.25.1`) - Only needed for step 3 but should be kept in order to: - Remain up-to-date with future `docker-finance` versions - Safely track your workflow related data (journals, metadata, etc.) - 2. Consider using a terminal multiplexer like [tmux](https://github.com/tmux/tmux/wiki) or [screen](https://www.gnu.org/software/screen/) for optimal workflow efficiency -3. **Copy/paste the following into your `bash` shell** (client preparation): +2. **Install recommended** (optional): + + Although *not* required, consider the following for workflow efficiency: + + - A terminal multiplexer like [tmux](https://github.com/tmux/tmux/wiki) or [screen](https://www.gnu.org/software/screen/) + +3. **Prepare your repository**: + + Pick a *persistent* path that you're likely to keep; your environment will be aliased/sourced to the path you choose. + ```bash - bashrc=~/.bashrc - aliases=~/.bash_aliases - function docker-finance::install() - { - # Environment expectations - _alias="alias docker-finance=" - _client="$(pwd)/docker-finance/client" - # Remove previous alias - if grep "^${_alias}" "$aliases" &>/dev/null; then - sed -i "/^${_alias}/d" "$aliases" - unalias docker-finance - fi - # Set new alias - echo "${_alias}'${_client}/docker.bash'" >>"$aliases" - # Set bash completion - _completion="${_client}/src/docker/completion.bash" - if [ ! -f "$_completion" ]; then - echo "WARNING: bash completion not found" >&2 - else - if ! grep "^source '${_completion}'" "$aliases" &>/dev/null; then - echo "source '${_completion}'" >>"$aliases" - fi - fi - # Make it so - source "$aliases" && echo "SUCCESS: installation complete" - } - if ! test -f "$bashrc" || ! hash bash &>/dev/null; then - echo "FATAL: unsupported bash installation" >&2 - else - if [[ ! -z "$SHELL" && "$SHELL" =~ bash ]]; then - if [ ! -f "$aliases" ]; then - if ! grep -E "(\. ~/.bash_aliases|^source ~/.bash_aliases|^source ${aliases})" "$bashrc" &>/dev/null; then - aliases="$bashrc" - fi - fi - if hash git &>/dev/null; then - if [ -d docker-finance ]; then - if pushd docker-finance &>/dev/null; then - if ! git pull --tags; then - echo "FATAL: docker-finance repo not pulled" >&2 - else - popd &>/dev/null - docker-finance::install - fi - popd &>/dev/null - else - echo "FATAL: docker-finance repo not found" >&2 - fi - else - if ! git clone https://gitea.com/EvergreenCrypto/docker-finance; then - echo "FATAL: docker-finance repo not cloned" >&2 - else - docker-finance::install - fi + if hash git &>/dev/null; then + if [ -d docker-finance ]; then + if pushd docker-finance &>/dev/null; then + if ! git pull --tags; then + echo "FATAL: docker-finance repo not pulled" >&2 fi + popd 1>/dev/null else - echo "FATAL: git not found" >&2 + echo "FATAL: docker-finance repo not found" >&2 fi else - echo "FATAL: unsupported bash environment" >&2 + if ! git clone https://gitea.com/EvergreenCrypto/docker-finance; then + echo "FATAL: docker-finance repo not cloned" >&2 + fi fi + else + echo "FATAL: git not found" >&2 fi ``` -4. **Verify your repository** (recommended): +4. **Verify your repository** (optional): ```bash if pushd docker-finance/ 1>/dev/null; then gpg --keyserver hkp://keyserver.ubuntu.com --recv-key 518A22F85BEFD32BCC99C48603F90C4F35E0213E \ @@ -341,24 +304,35 @@ Supported blockchains (independent of wallet type): fi ``` -5. **Generate client/container environment** (see [Environment Generation](#environment-generation) for details): +5. **Prepare your shell environment**: + + This will install convenience aliases and command completion to your shell environment (see [install.bash](client/install.bash) for details). + + ```bash + ./docker-finance/client/install.bash && source ~/.bashrc + ``` + +6. **Generate client/container environment**: + + This will generate your Docker-related client/container environment (see [Environment Generation](#environment-generation) for details). + ```bash docker-finance archlinux/${USER}:default gen ``` -6. **Build the image**: +7. **Build default `docker-finance` image**: ```bash docker-finance archlinux/${USER}:default build type=default ``` > See `docker-finance archlinux/${USER}:default build help` for build options (such as smaller, faster builds) -7. **Bring up the container**: +8. **Bring up container of default `docker-finance` image**: ```bash docker-finance archlinux/${USER}:default up ``` > You can use tab completion for all commands available to this built image -8. **You're inside!** See [How do I use it?](#how-do-i-use-it) for next steps. +9. **You're inside!** See [How do I use it?](#how-do-i-use-it) for next steps. ### Environment Generation diff --git a/client/install.bash b/client/install.bash new file mode 100755 index 0000000..d0e3407 --- /dev/null +++ b/client/install.bash @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 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 . + +bashrc=~/.bashrc +aliases=~/.bash_aliases + +function docker-finance::install() +{ + # Environment expectations + local -r _alias="alias docker-finance=" + local _path # full path to docker-finance repository + _path="$(dirname "$(realpath -s $0)" | rev | cut -d'/' -f2- | rev)" + + # Remove previous alias + if grep "^${_alias}" "$aliases" &>/dev/null; then + sed -i "/^${_alias}/d" "$aliases" + unalias docker-finance + fi + + # Set new alias + echo "${_alias}'${_path}/client/docker.bash'" >>"$aliases" + + # Set bash completion + _completion="${_path}/client/src/docker/completion.bash" + if [ ! -f "$_completion" ]; then + echo "WARNING: bash completion not found" >&2 + else + if ! grep "^source '${_completion}'" "$aliases" &>/dev/null; then + echo "source '${_completion}'" >>"$aliases" + fi + fi +} + +if ! test -f "$bashrc" || ! hash bash &>/dev/null; then + echo "FATAL: unsupported bash installation" >&2 +else + if [[ ! -z "$SHELL" && "$SHELL" =~ bash ]]; then + if [ ! -f "$aliases" ]; then + if ! grep -E "(\. ~/.bash_aliases|^source ~/.bash_aliases|^source ${aliases})" "$bashrc" &>/dev/null; then + aliases="$bashrc" + fi + fi + docker-finance::install \ + && echo "SUCCESS: installation complete" + || echo "FATAL: could not complete installation" + else + echo "FATAL: unsupported bash environment" >&2 + fi +fi + +# vim: sw=2 sts=2 si ai et From c8cb9d786bb6d661e183da84246e74d04a945fb6 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Mon, 5 Aug 2024 18:50:48 -0700 Subject: [PATCH 2/2] README: add `mc` as optional recommended --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index da57102..71b49f9 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,7 @@ Supported blockchains (independent of wallet type): Although *not* required, consider the following for workflow efficiency: - A terminal multiplexer like [tmux](https://github.com/tmux/tmux/wiki) or [screen](https://www.gnu.org/software/screen/) + - A terminal file manager like [mc](https://midnight-commander.org/) (Midnight Commander) 3. **Prepare your repository**: