diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-03-01 09:36:53 +0200 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-03-01 09:36:53 +0200 |
commit | cd43e57b999422980ea95df7f1d03117342e358e (patch) | |
tree | 37afe07c509e7508d8f69edd0fe8793227401023 | |
parent | 4e8f09fcf92eb8de4e39d512ce36b9ed87fbde87 (diff) | |
download | arching-kaos-tools-cd43e57b999422980ea95df7f1d03117342e358e.tar.gz arching-kaos-tools-cd43e57b999422980ea95df7f1d03117342e358e.tar.bz2 arching-kaos-tools-cd43e57b999422980ea95df7f1d03117342e358e.zip |
Simplifying logs
-rw-r--r-- | api/lib/akLogThis/index.js | 2 | ||||
-rwxr-xr-x | bin/ak-cli | 10 | ||||
-rwxr-xr-x | bin/ak-comments | 48 | ||||
-rwxr-xr-x | bin/ak-follow | 7 | ||||
-rwxr-xr-x | bin/ak-following | 6 | ||||
-rwxr-xr-x | bin/ak-logthis | 12 | ||||
-rwxr-xr-x | bin/ak-news | 12 | ||||
-rwxr-xr-x | bin/ak-todos | 148 | ||||
-rwxr-xr-x | bin/ak-zblock-manipulator | 7 | ||||
-rwxr-xr-x | bin/ak-zchain-chk | 4 |
10 files changed, 139 insertions, 117 deletions
diff --git a/api/lib/akLogThis/index.js b/api/lib/akLogThis/index.js index 8f8dded..8f26c84 100644 --- a/api/lib/akLogThis/index.js +++ b/api/lib/akLogThis/index.js @@ -4,7 +4,7 @@ const config = require('../../config') module.exports = (type, message) => { const command = spawn( "ak-logthis", - ["<ak-daemon>", "["+type+"]", message] + ["ak-daemon", type, message] ); var buffer = ""; @@ -1,6 +1,6 @@ #!/bin/bash #set -xe -program=`basename $0` +PROGRAM=`basename $0` tempdir=`mktemp -d` curdir=`pwd` launch_timestamp=`date -u +%s` @@ -14,7 +14,7 @@ new_line(){ # logit "WARNING" "Message" # logit "INFO" "Message" logit(){ - ak-logthis "<$program>" "[$1]" "$2" + ak-logthis "$PROGRAM" "$1" "$2" } # exit_program 0 'Clean exit' @@ -31,7 +31,7 @@ exit_program(){ } description(){ - full_title="$(printf '%s - %s' "$program" "$description_text")" + full_title="$(printf '%s - %s' "$PROGRAM" "$description_text")" delimiter_count=`echo -n $full_title | wc -c` printf '%s' "$full_title" new_line @@ -43,8 +43,8 @@ description(){ new_line } #description(){ -# printf '%s - \n' "$program" -# printf '===========================================\n' "$program" +# printf '%s - \n' "$PROGRAM" +# printf '===========================================\n' "$PROGRAM" #} help_all(){ diff --git a/bin/ak-comments b/bin/ak-comments index e20ab85..add1872 100755 --- a/bin/ak-comments +++ b/bin/ak-comments @@ -1,4 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} ZCOMMENTSDIR="$AK_WORKDIR/comments" TEMP="/tmp/aktmp" if [ ! -d $ZCOMMENTSDIR ]; then @@ -6,33 +10,33 @@ if [ ! -d $ZCOMMENTSDIR ]; then cd $ZCOMMENTSDIR ak-logthis "[INFO]" "zcommentsdir created" else - ak-logthis "[INFO]" "zcommentsdir found" + logit "INFO" "zcommentsdir found" fi _ak_modules_comments_create(){ - if [ ! -z $1 ] - then - REFER_TO="$1" - else - ak-logthis "[ERROR]" "No reference given" - echo "[ERROR]" "No reference given" - exit 1 - fi + if [ ! -z $1 ] + then + REFER_TO="$1" + else + logit "ERROR" "No reference given" + echo "ERROR" "No reference given" + exit 1 + fi TEMP="$(ak-tempassin)" cd $TEMP - export COMMENTS_FILE="$(date -u +%s)" - vi $COMMENTS_FILE - echo "Renaming..." - TO_FILE=$COMMENTS_FILE - IPFS_FILE=$(ak-ipfs-add $COMMENTS_FILE) - mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE - _ak_modules_comments_add $TO_FILE - ak-logthis "[INFO]" "Adding to git repo..." - cd $ZCOMMENTSDIR - if [ ! -z $REFER_TO ] - then - ak-reference create $REFERENCE $REFER_TO - fi + export COMMENTS_FILE="$(date -u +%s)" + vi $COMMENTS_FILE + echo "Renaming..." + TO_FILE=$COMMENTS_FILE + IPFS_FILE=$(ak-ipfs-add $COMMENTS_FILE) + mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE + _ak_modules_comments_add $TO_FILE + logit "INFO" "Adding to git repo..." + cd $ZCOMMENTSDIR + if [ ! -z $REFER_TO ] + then + ak-reference create $REFERENCE $REFER_TO + fi } _ak_modules_comments_index(){ diff --git a/bin/ak-follow b/bin/ak-follow index 0d6107c..a4ca070 100755 --- a/bin/ak-follow +++ b/bin/ak-follow @@ -1,19 +1,22 @@ #!/bin/bash FOLLOWING="$HOME/.arching-kaos/following" PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} if [ ! -z $1 ] then grep $1 $FOLLOWING if [ $? == 0 ] then - ak-logthis "<$(basename $0)>" "[ERROR]" "Already exists" + logit "ERROR" "Already exists" exit 1 fi echo $1 >> $FOLLOWING IPFS=$(ak-ipfs-add $FOLLOWING) if [ $? != 0 ] then - ak-logthis "<$PROGRAM>" "[ERROR]" "Addition failed" + logit "ERROR" "Addition failed" exit 1 fi ak-profile set following $IPFS diff --git a/bin/ak-following b/bin/ak-following index 02ed85e..deb631d 100755 --- a/bin/ak-following +++ b/bin/ak-following @@ -1,10 +1,14 @@ #!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} FOLLOWING="$HOME/.arching-kaos/following" if [ -f $FOLLOWING ] then cat $FOLLOWING else - ak-logthis "No following file, creating" + logit "INFO" "No following file, creating" touch $FOLLOWING echo "None found" fi diff --git a/bin/ak-logthis b/bin/ak-logthis index 295f60d..2ac3d80 100755 --- a/bin/ak-logthis +++ b/bin/ak-logthis @@ -6,25 +6,25 @@ then then if [ ! -z "$3" ] then - echo "$TS" "$1" "$2" "$3" >> $AK_LOGSFILE + echo "$TS" "<$1>" "[$2]" "$3" >> $AK_LOGSFILE if [ "$AK_DEBUG" == "yes" ] then - echo "$TS" "$1" "$2" "$3" >&2 + echo "$TS" "<$1>" "[$2]" "$3" >&2 fi exit 0 else - echo "$TS" "$1" "[ERROR]" "No message" >> $AK_LOGSFILE + echo "$TS" "<$1>" "[ERROR]" "No message" >> $AK_LOGSFILE if [ "$AK_DEBUG" == "yes" ] then - echo "$TS" "$1" "[ERROR]" "No message" >&2 + echo "$TS" "<$1>" "[ERROR]" "No message" >&2 fi exit 1 fi else - echo "$TS" "$1" "[ERROR]" "No type and message" >> $AK_LOGSFILE + echo "$TS" "<$1>" "[ERROR]" "No type and message" >> $AK_LOGSFILE if [ "$AK_DEBUG" == "yes" ] then - echo "$TS" "$1" "[ERROR]" "No type and message" >&2 + echo "$TS" "<$1>" "[ERROR]" "No type and message" >&2 fi exit 1 fi diff --git a/bin/ak-news b/bin/ak-news index 220aafa..b730821 100755 --- a/bin/ak-news +++ b/bin/ak-news @@ -5,19 +5,19 @@ ZNEWSDIR="$AK_WORKDIR/news" TEMP="/tmp/aktmp" logit(){ - ak-logthis "<$PROGRAM>" "$1" "$2" + ak-logthis "$PROGRAM" "$1" "$2" } if [ ! -d $ZNEWSDIR ]; then mkdir $ZNEWSDIR if [ "$?" == 0 ]; then - logit "[INFO]" "$ZNEWSDIR created" + logit "INFO" "$ZNEWSDIR created" else - logit "[ERROR]" "$ZNEWSDIR couldn't be created" + logit "ERROR" "$ZNEWSDIR couldn't be created" exit 1 fi else - logit "[INFO]" "$ZNEWSDIR found" + logit "INFO" "$ZNEWSDIR found" fi cd $ZNEWSDIR @@ -188,8 +188,8 @@ _ak_modules_news_read(){ ak-ipfs-cat $linkToText else - ak-logthis "[ERROR]" "Not a news block." - echo "[ERROR] Not a news block." + logit "ERROR" "Not a news block." + echo "ERROR Not a news block." exit 1 fi rm temp diff --git a/bin/ak-todos b/bin/ak-todos index 3b5813f..89e8960 100755 --- a/bin/ak-todos +++ b/bin/ak-todos @@ -1,88 +1,92 @@ #!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} ZTODOSDIR="$AK_WORKDIR/todos" TEMP="/tmp/aktmp" if [ ! -d $ZTODOSDIR ]; then - mkdir $ZTODOSDIR - cd $ZTODOSDIR - git init - echo "Todos repository" > README - echo "Qmetc" >> README - git add README - git commit -m "Initiated todos repository" - ak-logthis "ztodosdir created along with git repo" + mkdir $ZTODOSDIR + cd $ZTODOSDIR + git init + echo "Todos repository" > README + echo "Qmetc" >> README + git add README + git commit -m "Initiated todos repository" + logit "[INFO]" "ztodosdir created along with git repo" else - ak-logthis "ztodosdir found" + logit "[INFO]" "ztodosdir found" fi _ak_modules_todos_create(){ TEMP="$(ak-tempassin)" cd $TEMP - export TODOS_FILE="$(date -u +%s)" - vi $TODOS_FILE - ak-logthis "Renaming..." - TITLE="$(head -n 1 $TODOS_FILE)" - TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(ak-ipfs-add $TODOS_FILE) - mv $TODOS_FILE $ZTODOSDIR/$TO_FILE - sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZTODOSDIR/README - _ak_modules_todos_add $ZTODOSDIR/$TO_FILE - ak-logthis "Adding to git repo..." - cd $ZTODOSDIR - git add $TO_FILE README - git commit -m "Added $TO_FILE with $(head -n 1 $ZTODOSDIR/$TO_FILE)" - git clean --force - # rm -rf $TEMP + export TODOS_FILE="$(date -u +%s)" + vi $TODOS_FILE + logit "[INFO]" "Renaming..." + TITLE="$(head -n 1 $TODOS_FILE)" + TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) + IPFS_FILE=$(ak-ipfs-add $TODOS_FILE) + mv $TODOS_FILE $ZTODOSDIR/$TO_FILE + sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZTODOSDIR/README + _ak_modules_todos_add $ZTODOSDIR/$TO_FILE + logit "[INFO]" "Adding to git repo..." + cd $ZTODOSDIR + git add $TO_FILE README + git commit -m "Added $TO_FILE with $(head -n 1 $ZTODOSDIR/$TO_FILE)" + git clean --force + # rm -rf $TEMP } _ak_modules_todos_index(){ - FILES="$(ls -1 $ZTODOSDIR)" - i=0 - for FILE in $FILES - do - DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $ZTODOSDIR/$FILE) - echo $i \| $DATE \| $TITLE - let i+=1 - done + FILES="$(ls -1 $ZTODOSDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZTODOSDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done } _ak_modules_todos_title(){ - echo ak-todos-cli - echo "--------------" + echo ak-todos-cli + echo "--------------" } _ak_modules_todos_import(){ - echo "#TODO" - if [ ! -z $1 ] - then - if [ ! -d $1 ] - then - echo "Folder does not exists" - exit 4 - else - echo "Folder $1 exists" - fl="$(ls -1 $1)" - for f in $fl - do - _ak_modules_todos_add $1/$f - done - fi - else - echo "No value" - exit 6 - fi - exit 224 + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + echo "Folder does not exists" + exit 4 + else + echo "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + _ak_modules_todos_add $1/$f + done + fi + else + echo "No value" + exit 6 + fi + exit 224 } _ak_modules_todos_add(){ TEMP="$(ak-tempassin)" cd $TEMP - if [ -f $1 ]; then - FILE="$1" - ak-logthis "Adding todos from $FILE" - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(ak-ipfs-add $FILE) - FILE_SIGN_FILE=$FILE".asc" - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) - cat > data <<EOF + if [ -f $1 ]; then + FILE="$1" + logit "[INFO]" "Adding todos from $FILE" + DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $FILE) + FILE_IPFS_HASH=$(ak-ipfs-add $FILE) + FILE_SIGN_FILE=$FILE".asc" + gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE + FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) + cat > data <<EOF { "datetime":"$TODOS_FILE", "title":"$TITLE", @@ -96,13 +100,13 @@ EOF exit 2 fi ak-zblock-pack "todos/add" $(pwd)/data - if [ $? == 0 ] - then - ak-logthis "Todos added successfully" - else - echo "error??" - exit 1 - fi + if [ $? == 0 ] + then + logit "[INFO]" "Todos added successfully" + else + echo "error??" + exit 1 + fi } _ak_modules_todos_usage(){ _ak_modules_todos_title diff --git a/bin/ak-zblock-manipulator b/bin/ak-zblock-manipulator index 89c8454..20de3e0 100755 --- a/bin/ak-zblock-manipulator +++ b/bin/ak-zblock-manipulator @@ -15,7 +15,10 @@ # FINGERPRINT="$(gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')" # Below, the usage information -PROGRAM="zblock_manipulator" +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} usage(){ echo "Usage:" @@ -43,7 +46,7 @@ usage(){ main(){ - ak-logthis "We are doing" $BLOCK_TO_ADD "with content" $PREVIOUS + logit "[INFO]" "We are doing" $BLOCK_TO_ADD "with content" $PREVIOUS # We add it to IPFS MESSAGE_HASH=$(ak-ipfs-add $MESSAGE) diff --git a/bin/ak-zchain-chk b/bin/ak-zchain-chk index 5ec9960..e9779f7 100755 --- a/bin/ak-zchain-chk +++ b/bin/ak-zchain-chk @@ -1,4 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + ak-logthis "$PROGRAM" "$1" "$2" +} fix="0" usage(){ echo "zchain-chk - Check and fix zchain" |