From 4217dc0560bf40b4fa7ae6a6f964bd56b418712e Mon Sep 17 00:00:00 2001 From: kaotisk Date: Fri, 14 Jun 2024 22:36:12 +0300 Subject: Refactoring --- bin/ak | 8 +-- bin/ak-data-expand | 32 ++++++------ bin/ak-enter | 2 +- bin/ak-find-latest-mined-sblock | 18 +++---- bin/ak-follow | 4 +- bin/ak-following | 2 +- bin/ak-fs-add | 28 +++++----- bin/ak-ipfs-starter | 2 +- bin/ak-mempool | 2 +- bin/ak-profile | 6 +-- bin/ak-sm-filejoiner | 2 +- bin/ak-sm-files | 48 ++++++++--------- bin/ak-sm-filesplitter | 18 +++---- bin/ak-stellar-get-participants | 8 +-- bin/ak-tempassin | 4 +- bin/ak-transactions | 2 +- bin/ak-unfollow | 4 +- bin/ak-zchain-chk | 22 ++++---- install.sh | 63 +++++++--------------- lib/_ak_fm | 10 ++-- lib/_ak_gpg | 6 +-- lib/_ak_ipfs | 112 ++++++++++++++++++++-------------------- lib/_ak_script | 8 +-- lib/_ak_zblock | 100 +++++++++++++++++------------------ lib/_ak_zchain | 4 +- modules/articles/main.sh | 10 ++-- modules/categories/main.sh | 20 +++---- modules/comments/main.sh | 8 +-- modules/files/main.sh | 36 ++++++------- modules/folders/main.sh | 18 +++---- modules/news/main.sh | 28 +++++----- modules/reference/main.sh | 4 +- modules/todos/main.sh | 16 +++--- 33 files changed, 315 insertions(+), 340 deletions(-) diff --git a/bin/ak b/bin/ak index 4d5e9d2..07deae2 100755 --- a/bin/ak +++ b/bin/ak @@ -21,7 +21,7 @@ source $AK_WORKDIR/rc if [ $# -eq 0 ] then - logit "WARNING" "No command given" + _ak_log_warning "No command given" ( find $AK_BINDIR | grep 'ak-' | while read available do @@ -59,7 +59,7 @@ case "$1" in shift if [ -z $1 ] || [ ! -n "$*" ] then - logit "ERROR" "No module selected" + _ak_log_error "No module selected" ls -1 $AK_MODULESDIR exit 1 fi @@ -83,7 +83,7 @@ else 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" + _ak_log_info "Running: ak-$subcmd with args: $args" $(echo ak-$subcmd) $args _ak_exit_program $? "ak-$subcmd command finished"; fi @@ -95,6 +95,6 @@ else grep ak-$(echo $argv | cut -d ' ' -f 1) |\ sed -e 's/-/ /g' done - logit "ERROR" "Unknown subcommand: $*" + _ak_log_error "Unknown subcommand: $*" exit 1 fi diff --git a/bin/ak-data-expand b/bin/ak-data-expand index 8ee54c9..be51d18 100755 --- a/bin/ak-data-expand +++ b/bin/ak-data-expand @@ -14,87 +14,87 @@ then echo -n "$1" | grep -e 'Qm.\{44\}' >/dev/null if [ "$?" -ne 0 ] then - logit "ERROR" "Invalid hash format for $1" + _ak_log_error "Invalid hash format for $1" exit 1 fi _ak_ipfs_cat $1 > /dev/null if [ "$?" -ne 0 ] then - logit "ERROR" "Error while reading $1" + _ak_log_error "Error while reading $1" exit 1 fi _ak_ipfs_cat $1 | jq -M > /dev/null if [ "$?" -ne 0 ] then - logit "ERROR" "Error while parsing JSON for $1" + _ak_log_error "Error while parsing JSON for $1" exit 1 fi _ak_ipfs_cat $1 | jq | grep ipfs > /dev/null if [ "$?" -ne 0 ] then - logit "ERROR" "Error while extracting data from JSON for $1" + _ak_log_error "Error while extracting data from JSON for $1" exit 1 fi DATA="$(_ak_ipfs_cat $1 | jq | grep ipfs | sed -e 's/"ipfs": "//g; s/[",]//g; s/ //g')" if [ "$?" -ne 0 ] then - logit "ERROR" "Error while extracting data from JSON for $1" + _ak_log_error "Error while extracting data from JSON for $1" exit 1 fi _ak_ipfs_cat $1 | jq | grep detach > /dev/null if [ "$?" -ne 0 ] then - logit "ERROR" "Error while extracting data from JSON for $1" + _ak_log_error "Error while extracting data from JSON for $1" exit 1 fi DETACH="$(_ak_ipfs_cat $1 | jq | grep detach | sed -e 's/"detach": "//g; s/[",]//g; s/ //g')" if [ "$?" -ne 0 ] then - logit "ERROR" "Error while extracting data from JSON for $1" + _ak_log_error "Error while extracting data from JSON for $1" exit 1 fi echo -n "$2" | grep -e 'Qm.\{44\}' >/dev/null if [ "$?" -ne 0 ] then - logit "ERROR" "Invalid hash format for $2" + _ak_log_error "Invalid hash format for $2" exit 1 fi gpg="$2" _ak_ipfs_get $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not get GPG key: $gpg" + _ak_log_error "Could not get GPG key: $gpg" exit 1 fi _ak_gpg_key_import_from_file $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not import GPG key: $gpg" + _ak_log_error "Could not import GPG key: $gpg" exit 1 fi _ak_ipfs_get $DETACH > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Error while getting signature: $DETACH for data: $DATA" + _ak_log_error "Error while getting signature: $DETACH for data: $DATA" exit 1 fi mv $DETACH $DATA.asc - logit "INFO" "Block signature downloaded" + _ak_log_info "Block signature downloaded" _ak_ipfs_get $DATA > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Error while getting data: $DATA" + _ak_log_error "Error while getting data: $DATA" exit 1 fi - logit "INFO" "Data downloaded: $DATA" + _ak_log_info "Data downloaded: $DATA" _ak_gpg_verify_signature $DATA.asc $DATA > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Error while verifying signature for $DATA" + _ak_log_error "Error while verifying signature for $DATA" exit 1 fi mv $DATA $AK_WORKDIR/ipfs - logit "INFO" "Block signature verified" + _ak_log_info "Block signature verified" echo -n '"data":"'$1'","'$1'":'$(_ak_ipfs_cat $1|jq -M -c)',' exit 0 else diff --git a/bin/ak-enter b/bin/ak-enter index 4537d2f..59bb943 100755 --- a/bin/ak-enter +++ b/bin/ak-enter @@ -69,7 +69,7 @@ while [ "$#" ]; do entrance="$(_ak_ipns_resolve $1)" if [ $? -ne 0 ] then - logit "ERROR" "Could not resolve IPNS name" + _ak_log_error "Could not resolve IPNS name" exit 1 fi shift diff --git a/bin/ak-find-latest-mined-sblock b/bin/ak-find-latest-mined-sblock index 772e884..effe1bb 100755 --- a/bin/ak-find-latest-mined-sblock +++ b/bin/ak-find-latest-mined-sblock @@ -15,7 +15,7 @@ then fi further(){ - # logit "INFO" "Diving into $1" + # _ak_log_info "Diving into $1" lookfor $1 } @@ -23,7 +23,7 @@ lookfor(){ echo -n $1 | grep -e '[0-9a-f]\{128\}' > /dev/null if [ ! $? = 0 ] then - logit "ERROR" "Oops!!! The argument passed, does not match the regular expression!" + _ak_log_error "Oops!!! The argument passed, does not match the regular expression!" else counters[$CHAIN_PARENT]="$(expr ${counters[$CHAIN_PARENT]} + 1)" if [ ! $? = 0 ] @@ -31,21 +31,21 @@ lookfor(){ echo "$1, $counters[$1]" exit 1 fi - logit "INFO" "Accessing file: $1" + _ak_log_info "Accessing file: $1" # echo "$1 file:" # cat "$1" | jq NEXT_TARGET="$(cat "$1" | jq | grep previous | tr -d ' ' | sed -e 's/previous//g; s/[",:]//g;')" if [ ! "$NEXT_TARGET" = "" ] then - logit "INFO" "Found previous: $NEXT_TARGET" + _ak_log_info "Found previous: $NEXT_TARGET" if [ ! -f "$NEXT_TARGET" ] then - logit "WARNING" "Could not find $NEXT_TARGET" + _ak_log_warning "Could not find $NEXT_TARGET" else further "$NEXT_TARGET" fi else - logit "WARNING" "No next target found. So long for $1" + _ak_log_warning "No next target found. So long for $1" fi fi } @@ -58,12 +58,12 @@ do if [ "$(echo $p | tr -d '\n' | wc -c)" = 128 ] then filename="$(basename $p)" - logit "INFO" "Investigating $filename..." + _ak_log_info "Investigating $filename..." export CHAIN_PARENT="$filename" counters[$CHAIN_PARENT]=1 lookfor "$filename" else - logit "WARNING" "Nothing to do with $filename" + _ak_log_warning "Nothing to do with $filename" fi done < $templistblock rm $templistblock @@ -76,7 +76,7 @@ do then max="${counters[${value}]}" max_holder="${value}" - logit "INFO" "New MAX $max on $max_holder" + _ak_log_info "New MAX $max on $max_holder" fi done echo '{"latest_block":"'$max_holder'"}' diff --git a/bin/ak-follow b/bin/ak-follow index fd32d3a..c289b0f 100755 --- a/bin/ak-follow +++ b/bin/ak-follow @@ -9,14 +9,14 @@ then grep $1 $FOLLOWING if [ $? == 0 ] then - logit "ERROR" "Already exists" + _ak_log_error "Already exists" exit 1 fi echo $1 >> $FOLLOWING IPFS=$(_ak_ipfs_add $FOLLOWING) if [ $? != 0 ] then - logit "ERROR" "Addition failed" + _ak_log_error "Addition failed" exit 1 fi ak-profile set following $IPFS diff --git a/bin/ak-following b/bin/ak-following index 7b37be3..734f6ed 100755 --- a/bin/ak-following +++ b/bin/ak-following @@ -7,7 +7,7 @@ if [ -f $FOLLOWING ] then cat $FOLLOWING else - logit "INFO" "No following file, creating" + _ak_log_info "No following file, creating" touch $FOLLOWING echo "None found" fi diff --git a/bin/ak-fs-add b/bin/ak-fs-add index 0a9f636..3f48d48 100755 --- a/bin/ak-fs-add +++ b/bin/ak-fs-add @@ -29,7 +29,7 @@ source $AK_LIBDIR/_ak_log if [ ! -f "$1" ] then - logit "ERROR" "File $1 not found" + _ak_log_error "File $1 not found" exit 1 else # TODO @@ -67,13 +67,13 @@ then mkdir -p "$TECHDIR" if [ $? -eq 0 ] then - logit "INFO" "Folder $TECHDIR created!" + _ak_log_info "Folder $TECHDIR created!" else - logit "ERROR" "Problem occured while creating $TECHDIR" + _ak_log_error "Problem occured while creating $TECHDIR" exit 1 fi else - logit "INFO" "Temp dir found" + _ak_log_info "Temp dir found" fi # FILEMAPSDIR @@ -82,13 +82,13 @@ then mkdir -p "$FILEMAPSDIR" if [ $? -eq 0 ] then - logit "INFO" "Folder $FILEMAPSDIR created!" + _ak_log_info "Folder $FILEMAPSDIR created!" else - logit "ERROR" "Problem occured while creating $FILEMAPSDIR" + _ak_log_error "Problem occured while creating $FILEMAPSDIR" exit 1 fi else - logit "INFO" "Mapsdir found" + _ak_log_info "Mapsdir found" fi # CHKDIR @@ -97,13 +97,13 @@ then mkdir -p "$CHKDIR" if [ $? -eq 0 ] then - logit "INFO" "Folder $CHKDIR created!" + _ak_log_info "Folder $CHKDIR created!" else - logit "ERROR" "Problem occured while creating $CHKDIR" + _ak_log_error "Problem occured while creating $CHKDIR" exit 1 fi else - logit "INFO" "Workdir found" + _ak_log_info "Workdir found" fi # MERKLEDIR @@ -112,14 +112,14 @@ then mkdir -p "$MERKLEDIR" if [ $? -eq 0 ] then - logit "INFO" "Folder $MERKLEDIR created!" + _ak_log_info "Folder $MERKLEDIR created!" else - logit "ERROR" "Problem occured while creating $MERKLEDIR" + _ak_log_error "Problem occured while creating $MERKLEDIR" echo "ERROR Can't create $MERKLEDIR" exit 1 fi else - logit "INFO" "Workdir found" + _ak_log_info "Workdir found" fi # Uncomment next line in case you want to debug the resulting script as well # echo 'set -xe' > $TEMPORARYDIR/cmd_queue.sh @@ -136,7 +136,7 @@ else do FACTOR=$(( $FACTOR * 2 )) done - logit "INFO" "Gonna split in $FACTOR size" + _ak_log_info "Gonna split in $FACTOR size" sleep 30 # We split the file into 4*1024 bytes and output the chunks into TECHDIR split -a 50 -b $FACTOR --additional-suffix ".chk" -d "$FILE" "$TECHDIR/$(basename "$FILE")-" diff --git a/bin/ak-ipfs-starter b/bin/ak-ipfs-starter index 6b63c3c..3a7df29 100755 --- a/bin/ak-ipfs-starter +++ b/bin/ak-ipfs-starter @@ -7,6 +7,6 @@ source $AK_LIBDIR/_ak_ipfs screen -dmS akipfsd _ak_ipfs_daemon if [ $? -ne 0 ] then - logit "ERROR" "Failed to start IPFS daemon" + _ak_log_error "Failed to start IPFS daemon" exit 1 fi diff --git a/bin/ak-mempool b/bin/ak-mempool index cb659c2..bcf56ad 100755 --- a/bin/ak-mempool +++ b/bin/ak-mempool @@ -13,7 +13,7 @@ _ak_ipfs_swarm_peers > tmp_peers while IFS="" read -r p || [ -n "$p" ] do peer="$(echo "$p" | sed -e 's/^.*\///')" - logit "INFO" "Peer $peer found! Examining..." + _ak_log_info "Peer $peer found! Examining..." _ak_ipfs_cat /ipns/$peer/zlatest done < tmp_peers diff --git a/bin/ak-profile b/bin/ak-profile index 2fab750..1712575 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -43,9 +43,9 @@ source $AK_LIBDIR/_ak_zblock if [ ! -d $ZPROFILEDIR ]; then mkdir $ZPROFILEDIR cd $ZPROFILEDIR - logit "INFO" "zprofiledir created" + _ak_log_info "zprofiledir created" else - logit "INFO" "zprofiledir found" + _ak_log_info "zprofiledir found" fi # This is working with DATA blocks. DATA that matched profile/add ACTION @@ -56,7 +56,7 @@ fi _ak_modules_profile_show(){ if [ ! -z $1 ] then - logit "INFO" "Working with $1" + _ak_log_info "Working with $1" _ak_ipfs_cat $(echo $(_ak_ipfs_cat $1) | jq '.ipfs' -r) else echo "No DATA provided" diff --git a/bin/ak-sm-filejoiner b/bin/ak-sm-filejoiner index 3f3604c..9264a9a 100755 --- a/bin/ak-sm-filejoiner +++ b/bin/ak-sm-filejoiner @@ -74,7 +74,7 @@ then # We check if everything is okay sha512sum -c $MAPSDIR/$MAPSFILE if [ "$?" != "0" ]; then - logit "ERROR" "Error while checking sums" + _ak_log_error "Error while checking sums" exit 1 fi diff --git a/bin/ak-sm-files b/bin/ak-sm-files index ba4d851..d0514f8 100755 --- a/bin/ak-sm-files +++ b/bin/ak-sm-files @@ -14,14 +14,14 @@ if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR if [ $? == 0 ] then - logit "INFO" "Folder $ZFILESDIR created!" + _ak_log_info "Folder $ZFILESDIR created!" else - logit "ERROR" "Failed to create $ZFILESDIR folder" + _ak_log_error "Failed to create $ZFILESDIR folder" exit 1 fi cd $ZFILESDIR else - logit "INFO" "$ZFILESDIR found!" + _ak_log_info "$ZFILESDIR found!" fi usage(){ @@ -46,61 +46,61 @@ main(){ cd $TEMPASSIN echo "Adding $FILENAME" - logit "INFO" "Switching to tmp folder..." + _ak_log_info "Switching to tmp folder..." if [ $? == 0 ]; then - logit "INFO" "Success" + _ak_log_info "Success" else - logit "ERROR" "Error with tmp folder" + _ak_log_error "Error with tmp folder" exit 5 fi - logit "INFO" "Copying $1 to $TEMPASSIN" + _ak_log_info "Copying $1 to $TEMPASSIN" cp $CRP/$FILENAME $FILENAME if [ $? == 0 ]; then - logit "INFO" "Copied successfully" + _ak_log_info "Copied successfully" else - logit "ERROR" "Error copying..." + _ak_log_error "Error copying..." fi - logit "INFO" "Adding $FILENAME to IPFS..." + _ak_log_info "Adding $FILENAME to IPFS..." FILE_IPFS_HASH=$(_ak_ipfs_add $FILENAME) if [ $? == 0 ]; then - logit "INFO" "Added $FILENAME to IPFS" + _ak_log_info "Added $FILENAME to IPFS" else - logit "ERROR" "Error in adding the $FILENAME to IPFS" + _ak_log_error "Error in adding the $FILENAME to IPFS" fi - logit "INFO" "Adding $FILE to SHAMAPSYS..." + _ak_log_info "Adding $FILE to SHAMAPSYS..." FILEMAP_SHA512_HASH=$(ak-sm-filesplitter $FILENAME) if [ $? == 0 ]; then - logit "INFO" "Added $FILENAME to SHAMAPSYS" + _ak_log_info "Added $FILENAME to SHAMAPSYS" else - logit "ERROR" "Error in adding the $FILENAME to SHAMAPSYS" + _ak_log_error "Error in adding the $FILENAME to SHAMAPSYS" fi - logit "INFO" "Signing..." + _ak_log_info "Signing..." SIGN_FILE=$FILENAME".asc" _ak_gpg_sign_detached $SIGN_FILE $FILENAME if [ $? == 0 ]; then - logit "INFO" "Signed" + _ak_log_info "Signed" else - logit "ERROR" "Error while signing" + _ak_log_error "Error while signing" fi - logit "INFO" "Adding signature to IPFS" + _ak_log_info "Adding signature to IPFS" SIGNATURE=$(_ak_ipfs_add $SIGN_FILE) if [ $? == 0 ]; then - logit "INFO" "Added" + _ak_log_info "Added" else - logit "ERROR" "Error while adding" + _ak_log_error "Error while adding" fi - logit "INFO" "Adding signature to SHAMAPSYS" + _ak_log_info "Adding signature to SHAMAPSYS" SHAMAPSIGMAP=$(ak-sm-filesplitter $SIGN_FILE) if [ $? == 0 ]; then - logit "INFO" "Added" + _ak_log_info "Added" else - logit "ERROR" "Error while adding" + _ak_log_error "Error while adding" fi cat > data <> $stellarParticipants - logit "INFO" "Added $test" + _ak_log_info "Added $test" else - logit "INFO" "$test already there. Skipping..." + _ak_log_info "$test already there. Skipping..." fi i="$(expr $i + 1)" done @@ -103,9 +103,9 @@ do if [ "$flag" == "0" ] then echo $addressValuePair >> $stellarParticipantsOnline - logit "INFO" "$p is configured with $(echo $addressValuePair | awk '{ print $2 }'). Added to online participants." + _ak_log_info "$p is configured with $(echo $addressValuePair | awk '{ print $2 }'). Added to online participants." else - logit "INFO" "$(echo $addressValuePair | awk '{ print $2 }') is already in $stellarParticipantsOnline. Skipping..." + _ak_log_info "$(echo $addressValuePair | awk '{ print $2 }') is already in $stellarParticipantsOnline. Skipping..." fi fi done < $stellarParticipants diff --git a/bin/ak-tempassin b/bin/ak-tempassin index 20d1810..6831dc2 100755 --- a/bin/ak-tempassin +++ b/bin/ak-tempassin @@ -5,10 +5,10 @@ source $AK_LIBDIR/_ak_log if [ ! -d "$AK_TEMP" ] then - logit "ERROR" "Could not make $AK_TEMP directory to work in" + _ak_log_error "Could not make $AK_TEMP directory to work in" echo "Could not make $AK_TEMP directory to work in" exit 1 fi -logit "INFO" "$AK_TEMP created successfully" +_ak_log_info "$AK_TEMP created successfully" echo "$AK_TEMP" diff --git a/bin/ak-transactions b/bin/ak-transactions index f3bbf79..b23920a 100755 --- a/bin/ak-transactions +++ b/bin/ak-transactions @@ -13,7 +13,7 @@ source $AK_LIBDIR/_ak_gpg source $AK_LIBDIR/_ak_zblock _ak_modules_transactions_main(){ - logit "INFO" "$FROM_ADDRESS to $TO_ADDRESS value sent: $AMOUNT" + _ak_log_info "$FROM_ADDRESS to $TO_ADDRESS value sent: $AMOUNT" cat > transaction_file < tmp-zblock - logit "INFO" "ZBLOCK $zblock READ" + _ak_log_info "ZBLOCK $zblock READ" # Supposingly you are on a safe environment and you only have # access to your chain, I would consider mild secure to source # the files into your bash. # File an issue/pull request if you think it can be done better!! source tmp-zblock - logit "INFO" "ZBLOCK SOURCED" + _ak_log_info "ZBLOCK SOURCED" # Same as above applies to BLOCK and DATA subparts of each ZBLOCK # BLOCKS _ak_ipfs_cat $block | ak-json2bash > tmp-block source tmp-block - logit "INFO" "BLOCK $block SOURCED" + _ak_log_info "BLOCK $block SOURCED" touch $AK_BLOCKDIR/$block - logit "INFO" "BLOCK REFERENCED" + _ak_log_info "BLOCK REFERENCED" module="$(echo $action | sed -e 's/\// /g' | awk '{ print $1 }')" - logit "INFO" "DATA is $module module." + _ak_log_info "DATA is $module module." command="$(echo $action | sed -e 's/\// /g' | awk '{ print $2 }')" - logit "INFO" "COMMAND is $command" + _ak_log_info "COMMAND is $command" if [ ! -v $timestamp ] then echo "$timestamp : $zblock -> $block -> $previous" @@ -115,7 +115,7 @@ do # code 0 if [ -v $previous ] then - logit "ERROR" "Block $block has no previous zblock" + _ak_log_error "Block $block has no previous zblock" echo "Chain with no genesis" if [ "$fix" == "1" ] then @@ -138,12 +138,12 @@ do elif [ "$zblock" == "$seed" ] then echo "Chain is OK with GENESIS block = $seed" - logit "INFO" "Counter $counter" + _ak_log_info "Counter $counter" exit 0 fi # And finally, if nothing is there exit with error else - logit "ERROR" "Check not passed... No previous IPFS CID" + _ak_log_error "Check not passed... No previous IPFS CID" exit 1 fi done diff --git a/install.sh b/install.sh index f4a596d..062a3ce 100755 --- a/install.sh +++ b/install.sh @@ -34,50 +34,25 @@ packageManager="" installCommand="" dontAskFlag="" checkPkgManager(){ - printf "Searching for package manager..." - which dnf 2> /dev/null 1>&2 - if [ $? == 0 ] - then - printf "\tFound DNF\n" - packageManager="$(which dnf)" - installCommand="install" - dontAskFlag="-y" - fi - which apt 2> /dev/null 1>&2 - if [ $? == 0 ] - then - printf "\tFound APT\n" - packageManager="$(which apt)" - installCommand="install" - dontAskFlag="-y" - fi - which zypper 2> /dev/null 1>&2 - if [ $? == 0 ] - then - printf "\tFound ZYPPER\n" - packageManager="$(which zypper)" - installCommand="install" - dontAskFlag="-y" - fi - which pacman 2> /dev/null 1>&2 - if [ $? == 0 ] - then - printf "\tFound PACMAN\n" - packageManager="$(which pacman)" - installCommand="-S" - dontAskFlag="--noconfirm" - fi - which apk 2> /dev/null 1>&2 - if [ $? == 0 ] - then - printf "\tFound APK\n" - packageManager="$(which apk)" - installCommand="add" - dontAskFlag="-q" - fi + declare -a pkgmanagers=("dnf" "apt" "zypper" "pacman" "apk") + for pkgm in "${pkgmanagers[@]}" + do + printf "Searching for package manager..." + which $pkgm 2> /dev/null 1>&2 + if [ $? -eq 0 ] + then + printf '\tFound %s\n' "$pkgm" + packageManager="$(which $pkgm)" + installCommand="install" + dontAskFlag="-y" + break + fi + done if [ "$packageManager" == "" ] then printf "Could not find package manager\n" + printf "In case you missing a package, you will be informed to install \ + it manually.\n" fi } checkPkgManager @@ -104,7 +79,7 @@ do if [ "$packageManager" != "" ] then printf "\t Attempting installation..." - $sudoBin $packageManager $installCommand $dontAskFlag $dep 1> /dev/null 2>&1 + $sudoBin $packageManager $installCommand $dontAskFlag $dep > /dev/null 2>&1 if [ $? -ne 0 ] then printf "\t Failed to install!\n" @@ -112,7 +87,7 @@ do fi printf "\t installed!\n" else - printf "\t Don't know how to install!\n" + printf "\t Don't know how to install!\n\nInstall $dep manually!\n" exit 1 fi else @@ -125,7 +100,7 @@ which gpg2 if [ $? -ne 0 ] then which gpg - if [ $? == 0 ] + if [ $? -eq 0 ] then $sudoBin ln -s `which gpg` /usr/bin/gpg2 fi diff --git a/lib/_ak_fm b/lib/_ak_fm index 0d84fcd..cf1a14b 100755 --- a/lib/_ak_fm +++ b/lib/_ak_fm @@ -4,12 +4,12 @@ _ak_fm_remove_line_from_file(){ tempfile="$(mktemp)" if [ ! -f "$2" ] then - logit "ERROR" "$2 does not exist" + _ak_log_error "$2 does not exist" exit 1 fi grep "$1" "$2" > /dev/null 2>&1 if [ $? -ne 0 ] - logit "ERROR" "Could not find line: $1 in $2" + _ak_log_error "Could not find line: $1 in $2" exit 1 fi grep -v "$1" "$2" > $tempfile @@ -20,13 +20,13 @@ _ak_fm_remove_line_from_file(){ _ak_fm_sort_uniq_file(){ if [ ! -f "$1" ] then - logit "INFO" "No file to process" + _ak_log_info "No file to process" else - logit "INFO" "Sorting $1..." + _ak_log_info "Sorting $1..." tempfile="$(mktemp)" cat "$1" | sort | uniq > $tempfile cat $tempfile > $1 rm $tempfile - logit "INFO" "Sorting $1... Done!" + _ak_log_info "Sorting $1... Done!" fi } diff --git a/lib/_ak_gpg b/lib/_ak_gpg index b74d411..81229e1 100755 --- a/lib/_ak_gpg +++ b/lib/_ak_gpg @@ -9,17 +9,17 @@ _ak_gpg(){ _ak_gpg_key_import_from_file(){ if [ -z $1 ] then - logit "[ERROR]" "No argument given" + _ak_log_error "No argument given" exit 1 fi if [ ! -n "$1" ] then - logit "[ERROR]" "Empty argument given" + _ak_log_error "Empty argument given" exit 1 fi if [ ! -f "$1" ] then - logit "[ERROR]" "File not found" + _ak_log_error "File not found" exit 1 fi _ak_gpg --import $1 > /dev/null 2>&1 diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs index 1f2b5ce..35c38a5 100755 --- a/lib/_ak_ipfs +++ b/lib/_ak_ipfs @@ -71,7 +71,7 @@ _ak_ipfs_scanner(){ _ak_ipfs_add(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "no argument given" + _ak_log_error "no argument given" exit 1 fi # Receives a file @@ -79,7 +79,7 @@ _ak_ipfs_add(){ _ak_ipfs add -Qr "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to add $1" + _ak_log_error "Failed to add $1" exit 1 fi } @@ -87,13 +87,13 @@ _ak_ipfs_add(){ _ak_ipfs_block_stat(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "no argument given" + _ak_log_error "no argument given" exit 1 fi _ak_ipfs block stat "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to retrieve stat of block $1" + _ak_log_error "Failed to retrieve stat of block $1" exit 1 fi } @@ -101,13 +101,13 @@ _ak_ipfs_block_stat(){ _ak_ipfs_cat(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "no argument given" + _ak_log_error "no argument given" exit 1 fi _ak_ipfs --timeout=10s cat $1 if [ "$?" -ne "0" ] then - logit "ERROR" "Failed to cat $1" + _ak_log_error "Failed to cat $1" exit 1 fi @@ -116,18 +116,18 @@ _ak_ipfs_cat(){ _ak_ipfs_files_cp(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi if [ -z $2 ] || [ ! -n "$2" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs files cp "$1" "$2" if [ $? -ne 0 ] then - logit "ERROR" "Failed to copy $1 to $2" + _ak_log_error "Failed to copy $1 to $2" exit 1 fi } @@ -136,7 +136,7 @@ _ak_ipfs_files_ls(){ _ak_ipfs files ls "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to list $1" + _ak_log_error "Failed to list $1" exit 1 fi } @@ -144,13 +144,13 @@ _ak_ipfs_files_ls(){ _ak_ipfs_files_mkdir(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs files mkdir "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to mkdir $1" + _ak_log_error "Failed to mkdir $1" exit 1 fi } @@ -158,18 +158,18 @@ _ak_ipfs_files_mkdir(){ _ak_ipfs_files_mv(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi if [ -z $2 ] || [ ! -n "$2" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs files mv "$1" "$2" if [ $? -ne 0 ] then - logit "ERROR" "Failed to move $1 to $2" + _ak_log_error "Failed to move $1 to $2" exit 1 fi } @@ -177,13 +177,13 @@ _ak_ipfs_files_mv(){ _ak_ipfs_files_rm(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs files rm "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to remove $1" + _ak_log_error "Failed to remove $1" exit 1 fi } @@ -191,13 +191,13 @@ _ak_ipfs_files_rm(){ _ak_ipfs_files_stat(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs files stat "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to get file's stats $1" + _ak_log_error "Failed to get file's stats $1" exit 1 fi } @@ -205,13 +205,13 @@ _ak_ipfs_files_stat(){ _ak_ipfs_get(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs --timeout=10s get "$1" > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Failed to get $1" + _ak_log_error "Failed to get $1" exit 1 fi } @@ -219,13 +219,13 @@ _ak_ipfs_get(){ _ak_ipfs_key_gen(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs key gen "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to generate key $1" + _ak_log_error "Failed to generate key $1" exit 1 fi } @@ -234,7 +234,7 @@ _ak_ipfs_key_list(){ _ak_ipfs key list if [ $? -ne 0 ] then - logit "ERROR" "Failed to get key list" + _ak_log_error "Failed to get key list" exit 1 fi } @@ -243,7 +243,7 @@ _ak_ipfs_key_list_full(){ _ak_ipfs key list -l if [ $? -ne 0 ] then - logit "ERROR" "Failed to get key list" + _ak_log_error "Failed to get key list" exit 1 fi } @@ -251,18 +251,18 @@ _ak_ipfs_key_list_full(){ _ak_ipfs_name_publish(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi if [ -z $2 ] || [ ! -n "$2" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs name publish "$1" "$2" if [ $? -ne 0 ] then - logit "ERROR" "Failed to get $1" + _ak_log_error "Failed to get $1" exit 1 fi @@ -271,13 +271,13 @@ _ak_ipfs_name_publish(){ _ak_ipfs_name_resolve(){ if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi _ak_ipfs name resolve "$1" if [ $? -ne 0 ] then - logit "ERROR" "Failed to resolve $1" + _ak_log_error "Failed to resolve $1" exit 1 fi @@ -287,7 +287,7 @@ _ak_ipfs_swarm_peers(){ _ak_ipfs swarm peers if [ $? -ne 0 ] then - logit "ERROR" "Failed to get list of peers" + _ak_log_error "Failed to get list of peers" exit 1 fi } @@ -296,7 +296,7 @@ _ak_ipfs_starter(){ _ak_ipfs_daemon if [ $? -ne 0 ] then - logit "ERROR" "Failed to start IPFS daemon" + _ak_log_error "Failed to start IPFS daemon" exit 1 fi } @@ -307,11 +307,11 @@ _ak_ipns_resolve(){ rsld=$(_ak_ipfs_name_resolve $1) if [ $? -ne 0 ] then - logit "ERROR" "Failed to resolve $1" + _ak_log_error "Failed to resolve $1" exit 1 fi echo -n $rsld | sed -e 's/\/ipfs\///' - logit "INFO" "Resolved $1 to $rsld" + _ak_log_info "Resolved $1 to $rsld" else exit 1 fi @@ -321,43 +321,43 @@ _ak_ipfs_check(){ _ak_ipfs_files_ls /zarchive > /dev/null if [ $? != 0 ] then - logit "ERROR" "/zarchive is missing" + _ak_log_error "/zarchive is missing" else - logit "INFO" "/zarchive OK" + _ak_log_info "/zarchive OK" fi _ak_ipfs_files_ls /zlatest > /dev/null if [ $? != 0 ] then - logit "ERROR" "/zlatest is missing" + _ak_log_error "/zlatest is missing" else - logit "INFO" "/zlatest is OK" + _ak_log_info "/zlatest is OK" fi _ak_ipfs_key_list | grep zchain > /dev/null if [ $? != 0 ]; then - logit "WARNING" "zchain key is missing" + _ak_log_warning "zchain key is missing" _ak_ipfs_key_gen zchain > $ZCHAIN if [ $? != 0 ]; then - logit "ERROR" "zchain fails to create" + _ak_log_error "zchain fails to create" else - logit "INFO" "zchain created" + _ak_log_info "zchain created" fi else - logit "INFO" "zchain is there" + _ak_log_info "zchain is there" fi _ak_ipfs_key_list | grep ak-config > /dev/null if [ $? != 0 ]; then - logit "WARNING" "ak-config key is missing" + _ak_log_warning "ak-config key is missing" _ak_ipfs_key_gen ak-config if [ $? != 0 ]; then - logit "ERROR" "ak-config fails to create" + _ak_log_error "ak-config fails to create" else - logit "INFO" "ak-config created" + _ak_log_info "ak-config created" fi else - logit "INFO" "ak-config is there" + _ak_log_info "ak-config is there" fi } @@ -371,7 +371,7 @@ _ak_ipfs_init(){ } _ak_ipfs_download(){ - logit "INFO" "Attempting to install IPFS..." + _ak_log_info "Attempting to install IPFS..." IPFS_VERSION="$(curl \ --connect-timeout 3 \ -s https://dist.ipfs.tech/kubo/versions | tail -1)" @@ -387,12 +387,12 @@ _ak_ipfs_download(){ fi IPFS_TARGET_FILE="kubo_"$IPFS_VERSION"_linux-$ARCH.tar.gz" - logit "INFO" "Downloading ipfs $IPFS_VERSION" + _ak_log_info "Downloading ipfs $IPFS_VERSION" if [ ! -f $AK_ARCHIVESDIR/$IPFS_TARGET_FILE ] then wget -O $AK_ARCHIVESDIR/$IPFS_TARGET_FILE https://dist.ipfs.tech/kubo/$IPFS_VERSION/$IPFS_TARGET_FILE ; else - logit "INFO" "Already have the latest version" + _ak_log_info "Already have the latest version" exit 0 fi } @@ -400,16 +400,16 @@ _ak_ipfs_download(){ _ak_ipfs_cid_v0_check () { if [ -z $1 ] || [ ! -n "$1" ] then - logit "ERROR" "No argument given" + _ak_log_error "No argument given" exit 1 fi echo $1 | grep -e 'Qm.\{44\}' > /dev/null if [ "$?" -ne 0 ] then - logit "ERROR" "$1 is not an IPFS CIDv0 string" + _ak_log_error "$1 is not an IPFS CIDv0 string" exit 1 fi - logit "INFO" "$1 provided is an IPFS CIDv0 string" + _ak_log_info "$1 provided is an IPFS CIDv0 string" } _ak_ipfs_swarm_install() { @@ -417,13 +417,13 @@ _ak_ipfs_swarm_install() { if [ ! -f $AK_IPFS_REPO/swarm.key ] then - logit "INFO" "Downloading swarm key" + _ak_log_info "Downloading swarm key" wget -O $AK_IPFS_REPO/swarm.key https://arching-kaos.net/files/swarm.key elif [ -f $AK_IPFS_REPO/swarm.key ] && [ "$(sha512sum $AK_IPFS_REPO/swarm.key | awk '{ print $1 }')" == "$SWARMSHA512SUM" ] then - logit "INFO" "Congrats! You are already in our swarm" + _ak_log_info "Congrats! You are already in our swarm" else - logit "ERROR" "Found swarm.key but not ours" - logit "ERROR" "Visit https://arching-kaos.net/files/swarm.key and copy it to your ipfs folder" + _ak_log_error "Found swarm.key but not ours" + _ak_log_error "Visit https://arching-kaos.net/files/swarm.key and copy it to your ipfs folder" fi } diff --git a/lib/_ak_script b/lib/_ak_script index 3a7f635..9838c15 100755 --- a/lib/_ak_script +++ b/lib/_ak_script @@ -16,9 +16,9 @@ _ak_exit_program(){ # rm -rf $tempdir if [ $1 -ne 0 ] then - logit "ERROR" "$2 ($1)" + _ak_log_error "$2 ($1)" else - logit "EXIT" "$2" + _ak_log_message "EXIT" "$2" fi exit $1 } @@ -29,7 +29,7 @@ _ak_help(){ cat $fullprogrampath |grep '^##'| sed 's/^##//g;s/^ //g' 1>&2 exit 1 else - logit "ERROR" "fullprogrampath was not set" + _ak_log_error "fullprogrampath was not set" exit 1 fi } @@ -39,7 +39,7 @@ _ak_title_description(){ if [ ! -n "$descriptionString" ] then # Choose to exit with error to enforce standard - logit "ERROR" "No description string" + _ak_log_error "No description string" exit 1 # Alternative solution # full_title="$(printf '%s' "$PROGRAM")" diff --git a/lib/_ak_zblock b/lib/_ak_zblock index 0095c3d..b9fb91a 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -20,7 +20,7 @@ _ak_zblock_show(){ echo $1 | grep -e 'Qm.\{44\}' >/dev/null if [ $? -ne 0 ] then - logit "ERROR" "Argument provided ($1) was not an IPFS CIDv0 string" + _ak_log_error "Argument provided ($1) was not an IPFS CIDv0 string" exit 1 fi entrance="$1" @@ -38,7 +38,7 @@ _ak_zblock_show(){ # Reset timestamp since it's introduced later timestamp='' # Announce to logs which ZBLOCK is being read at the moment - logit "INFO" "Examining $zblock" + _ak_log_info "Examining $zblock" _ak_ipfs_cid_v0_check "$zblock" @@ -46,10 +46,10 @@ _ak_zblock_show(){ _ak_ipfs_cat $zblock | jq -c -M > $AK_ZBLOCKDIR/$zblock if [ "$?" -ne 0 ] then - logit "ERROR" "ZBLOCK $zblock READ failed" + _ak_log_error "ZBLOCK $zblock READ failed" exit 1 fi - logit "INFO" "ZBLOCK $zblock READ" + _ak_log_info "ZBLOCK $zblock READ" echo -n '{' # echo -n '"id":"'$counter'",' echo -n '"zblock":"'$zblock'",' @@ -58,11 +58,11 @@ _ak_zblock_show(){ cat $AK_ZBLOCKDIR/$zblock | jq -M > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "ZBLOCK $zblock is not JSON" + _ak_log_error "ZBLOCK $zblock is not JSON" cat /dev/null > $AK_ZBLOCKDIR/$zblock > /dev/null 2>&1 exit 1 fi - logit "INFO" "ZBLOCK $zblock is JSON" + _ak_log_info "ZBLOCK $zblock is JSON" # Be sure that there are the expected values # We need 'block' and 'block_signature' inside a 'zblock' @@ -70,20 +70,20 @@ _ak_zblock_show(){ block="$(cat $AK_ZBLOCKDIR/$zblock | jq -M -r .block)" if [ "$block" == "null" ] then - logit "ERROR" "ZBLOCK $zblock has no block" + _ak_log_error "ZBLOCK $zblock has no block" exit 1 fi _ak_ipfs_cid_v0_check "$block" - logit "INFO" "ZBLOCK $zblock has block" + _ak_log_info "ZBLOCK $zblock has block" block_signature="$(cat $AK_ZBLOCKDIR/$zblock | jq -M -r .block_signature)" if [ "$block_signature" == "null" ] then - logit "ERROR" "ZBLOCK $zblock doesn't contain a block_signature" + _ak_log_error "ZBLOCK $zblock doesn't contain a block_signature" exit 1 fi _ak_ipfs_cid_v0_check "$block_signature" - logit "INFO" "ZBLOCK $zblock contains a block_signature" + _ak_log_info "ZBLOCK $zblock contains a block_signature" # Same as above applies to BLOCK and DATA subparts of each ZBLOCK # BLOCKS @@ -92,24 +92,24 @@ _ak_zblock_show(){ cat $AK_BLOCKDIR/$block | jq -M > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "BLOCK $block READ failed" + _ak_log_error "BLOCK $block READ failed" exit 1 fi grep -e 'timestamp' -e 'gpg' -e 'data' -e 'action' -e 'detach' -e 'previous' $AK_BLOCKDIR/$block > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "BLOCK $block is NOT a valid block" + _ak_log_error "BLOCK $block is NOT a valid block" exit 1 fi - logit "INFO" "BLOCK $block is a block" + _ak_log_info "BLOCK $block is a block" action="$(cat $AK_BLOCKDIR/$block | jq -M -r .action)" module="$(echo $action | sed -e 's/\// /g' | awk '{ print $1 }')" - logit "INFO" "DATA is $module module." + _ak_log_info "DATA is $module module." command="$(echo $action | sed -e 's/\// /g' | awk '{ print $2 }')" - logit "INFO" "COMMAND is $command" + _ak_log_info "COMMAND is $command" timestamp="$(cat $AK_BLOCKDIR/$block | jq -M -r .timestamp)" if [ "$timestamp" != "null" ] @@ -134,39 +134,39 @@ _ak_zblock_show(){ _ak_ipfs_get $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not get GPG key: $gpg ." + _ak_log_error "Could not get GPG key: $gpg ." exit 1 fi _ak_gpg_key_import_from_file $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not import GPG key: $gpg ." + _ak_log_error "Could not import GPG key: $gpg ." exit 1 fi _ak_ipfs_get $block_signature > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Error while getting $block_signature for $block" + _ak_log_error "Error while getting $block_signature for $block" exit 1 fi mv $block_signature $block.asc - logit "INFO" "Block signature downloaded" + _ak_log_info "Block signature downloaded" _ak_ipfs_get $block > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not get $block block" + _ak_log_error "Could not get $block block" exit 1 fi - logit "INFO" "Downloaded block $block." + _ak_log_info "Downloaded block $block." _ak_gpg_verify_signature $block.asc $block > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not verify $block with GPG key $gpg." + _ak_log_error "Could not verify $block with GPG key $gpg." exit 1 fi - logit "GPG" "$gpg signature of $block is verified." + _ak_log_info "$gpg signature of $block is verified." fi data="$(cat $AK_BLOCKDIR/$block | jq -M -r .data)" @@ -174,7 +174,7 @@ _ak_zblock_show(){ ak-data-expand $data $gpg if [ "$?" -ne 0 ] then - logit "ERROR" "Failed on data signature verification [data: $data, gpg: $gpg, zblock: $zblock]" + _ak_log_error "Failed on data signature verification [data: $data, gpg: $gpg, zblock: $zblock]" exit 1 fi @@ -189,15 +189,15 @@ _ak_zblock_show(){ previous="$(cat $AK_BLOCKDIR/$block | jq -M -r .previous)" if [ -v $previous ] then - logit "WARNING" "Block $block has no previous zblock, appending pseudo genesis to exit with 2." + _ak_log_warning "Block $block has no previous zblock, appending pseudo genesis to exit with 2." echo -n '"previous":"'$seed'"},{"genesis":"genesis"}]' - logit "INFO" "Reached pseudo-genesis, counted $counter zblocks." + _ak_log_info "Reached pseudo-genesis, counted $counter zblocks." exit 2 # Otherwise, we inform of the sequence else #echo "$zblock after $previous" - logit "INFO" "Found a previous block for $zblock: $previous" + _ak_log_info "Found a previous block for $zblock: $previous" echo -n '"previous":"'$previous'"}' zblock=$previous fi @@ -207,7 +207,7 @@ _ak_zblock_show(){ elif [ "$zblock" == "$seed" ] then echo -n '{"genesis":"genesis"}]' - logit "INFO" "Reached $seed, counted $counter zblocks." + _ak_log_info "Reached $seed, counted $counter zblocks." exit 0 fi # And finally, if nothing is there exit with error @@ -265,7 +265,7 @@ _ak_zblock_show(){ # # main(){ # -# logit "INFO" "We are doing" $BLOCK_TO_ADD "with content" $PREVIOUS +# _ak_log_info "We are doing" $BLOCK_TO_ADD "with content" $PREVIOUS # # We add it to IPFS # MESSAGE_HASH=$(_ak_ipfs_add $MESSAGE) # @@ -369,7 +369,7 @@ _ak_zblock_gen_html(){ # Check if there are enough arguments if [ $# -lt 1 ] then - logit "ERROR" "Not enough arguments provided" + _ak_log_error "Not enough arguments provided" _ak_help exit 1 fi @@ -421,12 +421,12 @@ _ak_zblock_cache(){ # if [ "$(sha512sum $AK_ZBLOCKDIR/$1 | awk '{ print $1 }')" == "$(_ak_zblock_show $1 | sha512sum | awk '{ print $1 }')" ] if [ ! -f $FZBLOCKSDIR/$1 ] then - logit "INFO" "No cache found. Caching..." + _ak_log_info "No cache found. Caching..." _ak_zblock_show "$1" > $FZBLOCKSDIR/$1 fi if [ ! -f $FZBLOCKSDIR/$1 ] then - logit "INFO" "Caching failed..." + _ak_log_info "Caching failed..." exit 1 fi cat $FZBLOCKSDIR/$1 @@ -434,15 +434,15 @@ _ak_zblock_cache(){ _ak_zblock_show "$1" > $FZBLOCKSDIR/$1 if [ $? -ne "0" ] then - logit "ERROR" "_ak_zblock_show failed..." + _ak_log_error "_ak_zblock_show failed..." exit 2 fi - logit "ERROR" "Could not find zblock $1..." + _ak_log_error "Could not find zblock $1..." exit 1 fi exit 0 else - logit "ERROR" "No arguments..." + _ak_log_error "No arguments..." exit 1 fi @@ -462,13 +462,13 @@ _ak_zblock_pack(){ do if [ "$p" == "$TO_CHECK" ] then - logit "ERROR" "Value $TO_CHECK already mentioned on the zchain" + _ak_log_error "Value $TO_CHECK already mentioned on the zchain" exit 1 fi done < tempisalreadythere rm tempisalreadythere - logit "INFO" "We are doing $ACTION with content $MESSAGE" + _ak_log_info "We are doing $ACTION with content $MESSAGE" # We add it to IPFS MESSAGE_HASH=$(_ak_ipfs_add $MESSAGE) @@ -507,7 +507,7 @@ _ak_zblock_pack(){ ZBLOCK=$(_ak_ipfs_add $ZBL) echo $ZBLOCK else - logit "ERROR" "File does not exist. Aborting..." + _ak_log_error "File does not exist. Aborting..." exit 1 fi @@ -519,46 +519,46 @@ _ak_zblock_pack(){ _ak_ipfs_name_publish --key=zchain $ZBLOCK > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Failed publishing ZBLOCK: $ZBLOCK" + _ak_log_error "Failed publishing ZBLOCK: $ZBLOCK" exit 1 fi _ak_ipfs_files_ls /zarchive > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "WARNING" "/zarchive does not exist" + _ak_log_warning "/zarchive does not exist" _ak_ipfs_files_mkdir /zarchive > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not create /zarchive directory. Aborting." + _ak_log_error "Could not create /zarchive directory. Aborting." exit 1 fi fi _ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1) > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not back up previous /zlatest" + _ak_log_error "Could not back up previous /zlatest" exit 1 fi _ak_ipfs_files_rm /zlatest > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not remove previous /zlatest" + _ak_log_error "Could not remove previous /zlatest" exit 1 fi _ak_ipfs_files_cp /ipfs/$ZBLOCK /zlatest > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not copy $ZBLOCK to /zlatest" + _ak_log_error "Could not copy $ZBLOCK to /zlatest" exit 1 fi ak-config --publish if [ $? -ne 0 ] then - logit "ERROR" "Could not publish new configuration" + _ak_log_error "Could not publish new configuration" exit 1 fi else - logit "ERROR" "Not enough arguments" + _ak_log_error "Not enough arguments" exit 1 fi @@ -575,9 +575,9 @@ _ak_zblock_announce(){ 2>/dev/null | jq -M -c > /dev/null if [ $? -ne 0 ] then - logit "ERROR" "zblock $zblock announcement failed" + _ak_log_error "zblock $zblock announcement failed" else - logit "INFO" "zblock $zblock announced" + _ak_log_info "zblock $zblock announced" fi else curl \ @@ -588,9 +588,9 @@ _ak_zblock_announce(){ 2>/dev/null | jq -M -c > /dev/null if [ $? -ne 0 ] then - logit "ERROR" "zblock $zblock announcement failed" + _ak_log_error "zblock $zblock announcement failed" else - logit "INFO" "zblock $zblock announced" + _ak_log_info "zblock $zblock announced" fi fi } diff --git a/lib/_ak_zchain b/lib/_ak_zchain index a652a31..87fa5cf 100755 --- a/lib/_ak_zchain +++ b/lib/_ak_zchain @@ -31,7 +31,7 @@ _ak_zchain_reset(){ ak-config --publish if [ "$?" -ne 0 ] then - logit "ERROR" "Could not publish new configuration" + _ak_log_error "Could not publish new configuration" exit 1 fi @@ -70,7 +70,7 @@ _ak_zchain_rebase(){ ak-config --publish if [ "$?" -ne 0 ] then - logit "ERROR" "Could not publish new configuration" + _ak_log_error "Could not publish new configuration" exit 1 fi echo "Rebase was successful" diff --git a/modules/articles/main.sh b/modules/articles/main.sh index 382466b..29c1c34 100755 --- a/modules/articles/main.sh +++ b/modules/articles/main.sh @@ -22,9 +22,9 @@ TEMP="/tmp/aktmp" if [ ! -d $ZARTICLESDIR ]; then mkdir $ZARTICLESDIR cd $ZARTICLESDIR - logit "INFO" "zarticlesdir created" + _ak_log_info "zarticlesdir created" else - logit "INFO" "zarticlesdir found" + _ak_log_info "zarticlesdir found" fi _ak_modules_articles_create(){ @@ -33,18 +33,18 @@ _ak_modules_articles_create(){ export ARTICLES_FILE="$(date +%Y%m%d_%H%M%S)" if [ -z $EDITOR ] then - logit "ERROR" "No $EDITOR found. Exiting..." + _ak_log_error "No $EDITOR found. Exiting..." exit 1 fi $EDITOR $ARTICLES_FILE - logit "INFO" "Renaming..." + _ak_log_info "Renaming..." TITLE="$(head -n 1 $ARTICLES_FILE)" TO_FILE=$ARTICLES_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) IPFS_FILE=$(_ak_ipfs_add $ARTICLES_FILE) mv $ARTICLES_FILE $ZARTICLESDIR/$TO_FILE sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZARTICLESDIR/README _ak_modules_articles_add $ZARTICLESDIR/$TO_FILE - logit "INFO" "Adding to git repo..." + _ak_log_info "Adding to git repo..." cd $ZARTICLESDIR rm -rf $TEMP } diff --git a/modules/categories/main.sh b/modules/categories/main.sh index c0e1e77..82fc669 100755 --- a/modules/categories/main.sh +++ b/modules/categories/main.sh @@ -24,9 +24,9 @@ source $AK_LIBDIR/_ak_zblock if [ ! -d $AK_CATEGORIES ]; then mkdir $AK_CATEGORIES cd $AK_CATEGORIES - logit "INFO" "AK_CATEGORIES created" + _ak_log_info "AK_CATEGORIES created" else - logit "INFO" "AK_CATEGORIES found" + _ak_log_info "AK_CATEGORIES found" fi _ak_modules_categories_create(){ @@ -34,7 +34,7 @@ _ak_modules_categories_create(){ cd $TEMP export NEWS_FILE="$(date +%Y%m%d_%H%M%S)" vi $NEWS_FILE - logit "INFO" "Renaming..." + _ak_log_info "Renaming..." TITLE="$(head -n 1 $NEWS_FILE)" TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) IPFS_FILE=$(_ak_ipfs_add $NEWS_FILE) @@ -61,10 +61,10 @@ _ak_modules_categories_import(){ then if [ ! -d $1 ] then - logit "ERROR" "Folder does not exists" + _ak_log_error "Folder does not exists" exit 4 else - logit "INFO" "Folder $1 exists" + _ak_log_info "Folder $1 exists" fl="$(ls -1 $1)" for f in $fl do @@ -72,7 +72,7 @@ _ak_modules_categories_import(){ done fi else - logit "ERROR" "No value" + _ak_log_error "No value" exit 6 fi exit 224 @@ -82,7 +82,7 @@ _ak_modules_categories_add(){ cd $TEMP if [ -f $1 ]; then FILE="$1" - logit "INFO" "Adding news from " $FILE + _ak_log_info "Adding news from " $FILE DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') TITLE=$(head -n 1 $FILE) FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) @@ -99,15 +99,15 @@ _ak_modules_categories_add(){ } EOF else - logit "ERROR" "File $FILE doesn't exist"; + _ak_log_error "File $FILE doesn't exist"; exit 2 fi _ak_zblock_pack "news/add" $(pwd)/data if [ $? == 0 ] then - logit "INFO" "News added successfully" + _ak_log_info "News added successfully" else - logit "ERROR" "error??" + _ak_log_error "error??" exit 1 fi } diff --git a/modules/comments/main.sh b/modules/comments/main.sh index 6193e2f..f5ebabc 100755 --- a/modules/comments/main.sh +++ b/modules/comments/main.sh @@ -24,9 +24,9 @@ TEMP="/tmp/aktmp" if [ ! -d $ZCOMMENTSDIR ]; then mkdir $ZCOMMENTSDIR cd $ZCOMMENTSDIR - logit "INFO" "zcommentsdir created" + _ak_log_info "zcommentsdir created" else - logit "INFO" "zcommentsdir found" + _ak_log_info "zcommentsdir found" fi _ak_modules_comments_create(){ @@ -34,7 +34,7 @@ _ak_modules_comments_create(){ then REFER_TO="$1" else - logit "ERROR" "No reference given" + _ak_log_error "No reference given" echo "ERROR" "No reference given" exit 1 fi @@ -47,7 +47,7 @@ _ak_modules_comments_create(){ 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..." + _ak_log_info "Adding to git repo..." cd $ZCOMMENTSDIR if [ ! -z $REFER_TO ] then diff --git a/modules/files/main.sh b/modules/files/main.sh index 73c8219..a3202fe 100755 --- a/modules/files/main.sh +++ b/modules/files/main.sh @@ -19,15 +19,15 @@ if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR if [ $? == 0 ] then - logit "INFO" "Folder $ZFILESDIR created!" + _ak_log_info "Folder $ZFILESDIR created!" else - logit "ERROR" "Failed to create $ZFILESDIR folder" + _ak_log_error "Failed to create $ZFILESDIR folder" exit 1 fi cd $ZFILESDIR git init else - logit "INFO" "$ZFILESDIR found!" + _ak_log_info "$ZFILESDIR found!" fi _ak_modules_files_add(){ @@ -40,47 +40,47 @@ main(){ FILENAME="$1" CRP="$2" echo "Adding $FILENAME" - logit "INFO" "Switching to tmp folder..." + _ak_log_info "Switching to tmp folder..." TEMPASSIN="$(ak-tempassin)" cd $TEMPASSIN if [ $? == 0 ]; then - logit "INFO" "Success" + _ak_log_info "Success" else - logit "ERROR" "Error with tmp folder" + _ak_log_error "Error with tmp folder" exit 5 fi - logit "INFO" "Copying $1 to $TEMPASSIN" + _ak_log_info "Copying $1 to $TEMPASSIN" cp $2/$1 $TEMPASSIN/$1 if [ $? == 0 ]; then - logit "INFO" "Copied successfully" + _ak_log_info "Copied successfully" else - logit "ERROR" "Error copying..." + _ak_log_error "Error copying..." fi FILE="$TEMPASSIN/$1" - logit "INFO" "Adding $FILE to IPFS..." + _ak_log_info "Adding $FILE to IPFS..." FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) if [ $? == 0 ]; then - logit "INFO" "Added $FILE to IPFS" + _ak_log_info "Added $FILE to IPFS" else - logit "ERROR" "Error in adding the $FILE to IPFS" + _ak_log_error "Error in adding the $FILE to IPFS" fi - logit "INFO" "Signing..." + _ak_log_info "Signing..." SIGN_FILE=$FILENAME".asc" _ak_gpg_sign_detached $SIGN_FILE $FILE if [ $? == 0 ]; then - logit "INFO" "Signed" + _ak_log_info "Signed" else - logit "ERROR" "Error while signing" + _ak_log_error "Error while signing" fi - logit "INFO" "Adding signature to IPFS" + _ak_log_info "Adding signature to IPFS" SIGNATURE=$(_ak_ipfs_add $TEMPASSIN/$SIGN_FILE) if [ $? == 0 ]; then - logit "INFO" "Added" + _ak_log_info "Added" else - logit "ERROR" "Error while adding" + _ak_log_error "Error while adding" fi cat > $TEMPASSIN/data <