aboutsummaryrefslogtreecommitdiff
path: root/bin/ak-cli
blob: 14f049b9b2a7860bf7a7e146ea92f46aa82cd3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
#!/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