From b11434ed1255f3c6a967be093e6e193780bc7ed5 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sat, 2 Mar 2024 01:51:33 +0200 Subject: Removed old ak-cli approach in favor of ak Instead of hardcoding things in a big script we simply search in ak's arguments for appropriate scripts and past the rest of values as arguments to the script found. Running with no arguments *will* be printing all available scripts with --help flag to provide a good overview. --- bin/ak | 51 ++++++ bin/ak-cli | 513 ------------------------------------------------------------- 2 files changed, 51 insertions(+), 513 deletions(-) create mode 100755 bin/ak delete mode 100755 bin/ak-cli diff --git a/bin/ak b/bin/ak new file mode 100755 index 0000000..6a4fc01 --- /dev/null +++ b/bin/ak @@ -0,0 +1,51 @@ +#!/bin/bash + +PROGRAM=$(basename $0) + +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} + +if [ $# -eq 0 ] +then + logit "WARNING" "No command given" + ( + find $AK_BINDIR | grep 'ak-' | while read available + do + #subcmd="$(basename $available | cut -d '-' -f 2)" + subcmd="$(basename $available)" + args="-h" + if [ -n "$subcmd" ] + then + echo $subcmd + # $(echo $subcmd) $args + fi + done + ) | sort | uniq + exit 1 +fi + +subcmd="$(echo $* | sed -e 's/ /-/g')" +if [ -f "$AK_BINDIR/ak-$subcmd" ] +then + $(echo ak-$subcmd) + exit $? +else + argc=$# + argv="$*" + counter=1 + while [ $counter -lt $argc ] + do + subcmd="$(echo $argv | cut -d ' ' -f -$counter | sed -e 's/ /\-/g')" + args="$(echo "$argv"| cut -d ' ' -f $(($counter + 1))-)" + if [ -n "$subcmd" ] && [ -f "$AK_BINDIR/ak-$subcmd" ] + then + logit "INFO" "Running: ak-$subcmd with args: $args" + $(echo ak-$subcmd) $args + exit $? + fi + counter=$(($counter + 1)) + done + logit "ERROR" "Unknown subcommand: $*" + exit 1 +fi diff --git a/bin/ak-cli b/bin/ak-cli deleted file mode 100755 index 14f049b..0000000 --- a/bin/ak-cli +++ /dev/null @@ -1,513 +0,0 @@ -#!/bin/bash -#set -xe -PROGRAM=`basename $0` -tempdir=`mktemp -d` -curdir=`pwd` -launch_timestamp=`date -u +%s` -description_text="Arching Kaos command line interface" - -new_line(){ - printf '\n' -} - -# logit "ERROR" "Message" -# logit "WARNING" "Message" -# logit "INFO" "Message" -logit(){ - ak-logthis "$PROGRAM" "$1" "$2" -} - -# exit_program 0 'Clean exit' -# exit_program 1 'Dirty exit... saves tmpdir in archive' 'save_log' -exit_program(){ - cd $curdir - if [ "$3" == "save_log" ] - then - tar cvfz $curdir/$(basename $tempdir)-$launch_timestamp.tgz $tempdir - fi - rm -rf $tempdir - logit "EXIT" "$2" - exit $1 -} - -description(){ - full_title="$(printf '%s - %s' "$PROGRAM" "$description_text")" - delimiter_count=`echo -n $full_title | wc -c` - printf '%s' "$full_title" - new_line - while [ $delimiter_count -gt 0 ] - do - printf '=' - delimiter_count=$(($delimiter_count-1)) - done - new_line -} -#description(){ -# printf '%s - \n' "$PROGRAM" -# printf '===========================================\n' "$PROGRAM" -#} - -help_all(){ - description - - help_config - new_line - - help_log - new_line - - help_follow - new_line - - help_node_info - new_line - - printf ' modules Various modules' - help_modules - new_line - - printf ' ipfs IPFS wrapper tools' - help_ipfs - new_line - - printf ' network Networking tools' - help_network - new_line - - printf ' utils Utilities for maintainance' - help_utils - new_line - - printf ' zblock zblock focused tools' - help_zblock - new_line - - printf ' sblock sblock and schain tools' - help_sblock - new_line - - printf ' zchain zchain tools' - help_zchain - new_line - - printf ' uncategorized' - printf '\t\tother tools not fitting in other categories\n' - help_uncatecorized -} - -help_node_info(){ - ak-node-info -} - -_node_info(){ - if [ ! -z "$1" ] - then - case "$1" in - ipfs) - ak-node-info ipfs - ;; - ipns) - ak-node-info ipns - ;; - *) - help_node_info - ;; - esac - else - help_node_info - fi -} -help_config(){ - cat /home/kaotisk/projects/arching-kaos-tools/txts/manuals/config_subcommands -} - -_config(){ - if [ ! -z "$1" ] - then - case "$1" in - show) - ak-config show | jq - ;; - get-published) - ak-config get-published | jq - ;; - publish) - ak-config publish - ;; - node-info-ipfs) - ak-node-info ipfs - ;; - node-info-ipns) - ak-node-info ipns - ;; - *) - help_config - ;; - esac - else - help_config - fi -} - -help_log(){ - cat /home/kaotisk/projects/arching-kaos-tools/txts/manuals/log_subcommands -} - -_log(){ - if [ ! -z "$1" ] - then - case "$1" in - tail) - ak-logfollow - exit_program 0 "$subcommand $1 command finished"; - ;; - write) - ak-logthis "$2" "$3" "$4" - exit_program 0 "$subcommand $1 command finished"; - ;; - rotate) - ak-logrotate - exit_program 0 "$subcommand $1 command finished"; - ;; - cat) - cat $AK_WORKDIR/akd.log $AK_WORKDIR/akd.err $AK_WORKDIR/logs - exit_program 0 "$subcommand $1 command finished"; - ;; - *) - help_log - exit_program 0 "$subcommand $1 command finished"; - esac - else - help_log - exit_program 0 "$subcommand $1 command finished"; - fi -} - -help_follow(){ - cat /home/kaotisk/projects/arching-kaos-tools/txts/manuals/follow_subcommands -} - -_follow(){ - if [ ! -z "$1" ] - then - case "$1" in - add) - ak-follow "$2" - ;; - list) - ak-following - ;; - remove) - ak-unfollow "$2" - ;; - *) - help_follow - ;; - esac - else - help_follow - fi -} - -help_modules(){ - printf ' - ak-articles - ' - printf ' - ak-categories - ' - printf ' - ak-comments - ' - printf ' - ak-files - ' - printf ' - ak-sm-files - ' - printf ' - ak-folders - ' - printf ' - ak-mixtapes - ' - printf ' - ak-news - ' - printf ' - ak-profile - ' - printf ' - ak-reference - ' - printf ' - ak-repositories - ' - printf ' - ak-roadmap - ' - printf ' - ak-todos - ' - printf ' - ak-transactions - ' -} - -help_zblock(){ - printf ' - ak-zblock-pack - ' - printf ' - ak-zblock-cache - ' - printf ' - ak-zblock-manipulator - ' - printf ' - ak-zblock-show - ' -} - -help_ipfs(){ - printf ' - ak-ipfs-add - ' - printf ' - ak-ipfs-block-stat - ' - printf ' - ak-ipfs-cat - ' - printf ' - ak-ipfs-check - ' - printf ' - ak-ipfs-files-cp - ' - printf ' - ak-ipfs-files-ls - ' - printf ' - ak-ipfs-files-mkdir - ' - printf ' - ak-ipfs-files-mv - ' - printf ' - ak-ipfs-files-rm - ' - printf ' - ak-ipfs-files-stat - ' - printf ' - ak-ipfs-get - ' - printf ' - ak-ipfs-get-peers - ' - printf ' - ak-ipfs-key-gen - ' - printf ' - ak-ipfs-key-list - ' - printf ' - ak-ipfs-key-list-full - ' - printf ' - ak-ipfs-name-publish - ' - printf ' - ak-ipfs-name-resolve - ' - printf ' - ak-ipfs-scanner - ' - printf ' - ak-ipfs-starter - ' - printf ' - ak-ipfs-swarm-peers - ' - printf ' - ak-ipns-resolve - ' -} - -help_network(){ - printf ' - ak-network - ' - printf ' - ak-get-peers-cjdns - ' - printf ' - ak-get-peers-ipfs - ' - printf ' - ak-get-peers-stellar - ' - printf ' - ak-cjdns-scanner - ' - printf ' - ak-stellar-get-participants - ' -} - -help_utils(){ - printf ' - ak-zchain-calculate-size - ' - printf ' - ak-data-expand - ' - printf ' - ak-get-gpg - ' - printf ' - ak-get-zlatest - ' -} - -help_uncatecorized(){ - printf ' - ak2html - ' - printf ' - ak-clean - ' - printf ' - ak-zchain-extract-cids - ' - printf ' - ak-zchain-extract-data-cids - ' - printf ' - ak-json2bash - ' - printf ' - ak-mempool - ' - printf ' - ak-sm-filejoiner - ' - printf ' - ak-sm-filesplitter - ' - printf ' - ak-sm-merkle-tree - ' - printf ' - ak-sm-merkle-tree-to-file - ' - printf ' - ak-startup - ' - printf ' - ak-tempassin - ' -} - -help_sblock(){ - printf ' - ak-find-latest-mined-sblock - ' - printf ' - ak-miner-script - ' - printf ' - ak-show_sblock - ' -} - -help_zchain(){ - printf ' - ak-enter - ' - printf ' - ak-zchain-chk - ' - printf ' - ak-zchain-rebase - ' - printf ' - ak-zchain-reset - ' -} - -# Change directory to the temporary directory -cd $tempdir - -if [ -z "$1" ] -then - help_all -else - subcommand="$1" - case "$1" in - config) - _config "$2" - exit_program 0 "$1 command finished"; - ;; - node) - _node_info "$2" - exit_program 0 "$1 command finished"; - ;; - log) - _log "$2" "$3" "$4" "$5" - exit_program 0 "$1 command finished"; - ;; - follow) - _follow "$2" - exit_program 0 "$1 command finished"; - ;; - modules) - exit_program 1 "$1 Not implemented"; - help_modules - ;; - ipfs) - exit_program 1 "$1 Not implemented"; - _ipfs - help_ipfs - ;; - network) - exit_program 1 "$1 Not implemented"; - _network - help_network - ;; - utils) - exit_program 1 "$1 Not implemented"; - _utils - help_utils - ;; - zblock) - exit_program 1 "$1 Not implemented"; - _zblock - help_zblock - ;; - sblock) - exit_program 1 "$1 Not implemented"; - _sblock - help_sblock - ;; - zchain) - exit_program 1 "$1 Not implemented"; - _zchain - help_zchain - ;; - uncategorized) - exit_program 1 "$1 Not implemented"; - _uncategorized - help_uncatecorized - ;; - *) - help_all; - exit_program 0 "No command issued"; - esac - -fi - -# Successful test: after changing dir the following, variable is not changing -# echo $curdir - -- cgit v1.2.3