aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-06-30 22:39:50 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-06-30 22:39:50 +0300
commitde53c55383ed07e0b65f69d33f5284a31d791664 (patch)
treef1e426c88a5d0a48ca463eccd21c1d12524d8f3a /bin
parent9531bcdffff4e44e8aadb000f0b577d59a32ea3f (diff)
downloadarching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.tar.gz
arching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.tar.bz2
arching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.zip
Refactoring
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ak-config2
-rwxr-xr-xbin/ak-follow102
-rwxr-xr-xbin/ak-following13
-rwxr-xr-xbin/ak-mempool15
-rwxr-xr-xbin/ak-miner-script2
-rwxr-xr-xbin/ak-profile58
-rwxr-xr-xbin/ak-schain28
-rwxr-xr-xbin/ak-schain-latest-cached9
-rwxr-xr-xbin/ak-unfollow30
-rwxr-xr-xbin/ak-zchain10
10 files changed, 167 insertions, 102 deletions
diff --git a/bin/ak-config b/bin/ak-config
index 24db38f..6be3f8c 100755
--- a/bin/ak-config
+++ b/bin/ak-config
@@ -31,7 +31,7 @@ _ak_config_show(){
_ak_gpg_key_self_export $KEY
GPG_PUB_KEY=$(_ak_ipfs_add $KEY)
rm $KEY
- profile="$(ak-profile --index)"
+ profile="$(ak-profile -l)"
echo '
{
diff --git a/bin/ak-follow b/bin/ak-follow
index c289b0f..d8461b8 100755
--- a/bin/ak-follow
+++ b/bin/ak-follow
@@ -1,26 +1,96 @@
#!/bin/bash
-FOLLOWING="$HOME/.arching-kaos/following"
-PROGRAM="$(basename $0)"
+##
+## You can maintain a list of friendly zchains or ids
+##
+## Usage:
+##
+## -h, --help Prints this help message
+##
+## -f, --follow Adds a ... to your follow list
+##
+## -l, --list Shows a list of your followings
+##
+## -u, --unfollow Unfollows a ...
+##
+fullprogrampath="$(realpath $0)"
+PROGRAM=$(basename $0)
+descriptionString="Following stuff"
+
source $AK_LIBDIR/_ak_log
+source $AK_LIBDIR/_ak_script
source $AK_LIBDIR/_ak_ipfs
-if [ ! -z $1 ]
-then
- grep $1 $FOLLOWING
- if [ $? == 0 ]
+FOLLOWING="$HOME/.arching-kaos/following"
+
+_ak_follow_follow(){
+ if [ ! -z $1 ]
then
- _ak_log_error "Already exists"
- exit 1
+ grep $1 $FOLLOWING
+ if [ $? == 0 ]
+ then
+ _ak_log_error "Already exists"
+ exit 1
+ fi
+ echo $1 >> $FOLLOWING
+ IPFS=$(_ak_ipfs_add $FOLLOWING)
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "Addition failed"
+ exit 1
+ fi
+ ak-profile set following $IPFS
+ exit 0
fi
- echo $1 >> $FOLLOWING
- IPFS=$(_ak_ipfs_add $FOLLOWING)
- if [ $? != 0 ]
+ printf "Usage:\n\t%s <AKID_IPFS_CID_v0>\n" $PROGRAM
+ exit 1
+}
+
+_ak_follow_list(){
+ if [ -f $FOLLOWING ]
+ then
+ cat $FOLLOWING
+ else
+ _ak_log_info "No following file, creating"
+ touch $FOLLOWING
+ echo "None found"
+ fi
+}
+
+_ak_follow_unfollow(){
+ FOLLOWING="$HOME/.arching-kaos/following"
+ fentries="$(cat $FOLLOWING)"
+ if [ ! -z $1 ]
then
- _ak_log_error "Addition failed"
+ search="$1"
+ sed -i -e 's,'"$search"',,g' $FOLLOWING
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "sed didn't found $search"
+ exit 1
+ fi
+ IPFS="$(_ak_ipfs_add $FOLLOWING)"
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "IPFS problem"
+ exit 1
+ fi
+ ak-profile set repositories "$IPFS"
+ exit 0
+ else
+ echo "Who to unfollow?"
+ echo "Type following to see them"
exit 1
fi
- ak-profile set following $IPFS
- exit 0
+}
+
+if [ ! -z $1 ]
+then
+ case $1 in
+ -h | --help) _ak_usage; exit;;
+ -f | --follow) _ak_follow_follow $2; exit;;
+ -l | --list) _ak_follow_list $2; exit;;
+ -u | --unfollow) _ak_follow_unfollow $2; exit;;
+ * ) _ak_usage;;
+ esac
+else _ak_usage
fi
-printf "Usage:\n\t%s <AKID_IPFS_CID_v0>\n" $PROGRAM
-exit 1
diff --git a/bin/ak-following b/bin/ak-following
deleted file mode 100755
index 734f6ed..0000000
--- a/bin/ak-following
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-PROGRAM="$(basename $0)"
-source $AK_LIBDIR/_ak_log
-
-FOLLOWING="$HOME/.arching-kaos/following"
-if [ -f $FOLLOWING ]
-then
- cat $FOLLOWING
-else
- _ak_log_info "No following file, creating"
- touch $FOLLOWING
- echo "None found"
-fi
diff --git a/bin/ak-mempool b/bin/ak-mempool
index bcf56ad..4e796fb 100755
--- a/bin/ak-mempool
+++ b/bin/ak-mempool
@@ -1,11 +1,24 @@
#!/bin/bash
+##
+## Brief description
+##
+## Usage:
+##
+## -h, --help Prints this help message
+##
+fullprogrampath="$(realpath $0)"
+PROGRAM=$(basename $0)
+descriptionString="Quick description"
+
+# At least these
+source $AK_LIBDIR/_ak_log
+source $AK_LIBDIR/_ak_script
# Assumptions:
# I suppose each ak node is connected to some IP.
# They also run IPFS.
# They also are a part of our swarm.
# So should we ask for our peers?
-source $AK_LIBDIR/_ak_log
source $AK_LIBDIR/_ak_ipfs
_ak_ipfs_swarm_peers > tmp_peers
diff --git a/bin/ak-miner-script b/bin/ak-miner-script
index 9119b0c..ae9f7a8 100755
--- a/bin/ak-miner-script
+++ b/bin/ak-miner-script
@@ -43,7 +43,7 @@ proofofwork(){
usage(){
echo "$PROGRAM <somethings> <previous> <miner_address>"
- echo " hit ak-enter after that !!! "
+ echo " hit 'ak-zchain --crawl' after that."
}
if [ -z "$1" ] ;
diff --git a/bin/ak-profile b/bin/ak-profile
index f4051eb..67b67d1 100755
--- a/bin/ak-profile
+++ b/bin/ak-profile
@@ -7,7 +7,7 @@
##
## -h, --help Prints this help message
##
-## -i, --index Show current status
+## -l, --local-index Show current status
##
## --show <data IPFS CIDv0> Show profile entry from specified DATA
## IPFS CIDv0
@@ -29,9 +29,7 @@ fullprogrampath="$(realpath $0)"
PROGRAM=$(basename $0)
descriptionString="Profile module"
ZPROFILEDIR="$AK_WORKDIR/profile"
-TEMP="/tmp/aktmp"
-# Outputs to log file in the classic format :)
source $AK_LIBDIR/_ak_log
source $AK_LIBDIR/_ak_script
source $AK_LIBDIR/_ak_ipfs
@@ -40,14 +38,16 @@ source $AK_LIBDIR/_ak_zblock
# Whatever the command is, we check if $ZPROFILEDIR is there.
# If NOT we create it and we change dir there.
-if [ ! -d $ZPROFILEDIR ]; then
+if [ ! -d $ZPROFILEDIR ]
+then
mkdir $ZPROFILEDIR
- cd $ZPROFILEDIR
_ak_log_info "zprofiledir created"
else
_ak_log_info "zprofiledir found"
fi
+cd $ZPROFILEDIR
+
# This is working with DATA blocks. DATA that matched profile/add ACTION
#
# The profile settings/configuration is part of the blockchain produced.
@@ -59,7 +59,7 @@ _ak_modules_profile_show(){
_ak_log_info "Working with $1"
_ak_ipfs_cat $(echo $(_ak_ipfs_cat $1) | jq '.ipfs' -r)
else
- echo "No DATA provided"
+ _ak_log_error "No DATA provided"
exit 1
fi
}
@@ -71,12 +71,12 @@ _ak_modules_profile_propget(){
then
if [ ! -f $ZPROFILEDIR/$1 ]
then
- echo "property not found"
+ _ak_log_error "property not found $1"
else
cat $ZPROFILEDIR/$1
fi
else
- echo "No particular property... indexing"
+ _ak_log_error "No particular property... indexing"
_ak_modules_profile_index
fi
}
@@ -89,13 +89,13 @@ _ak_modules_profile_propwrite(){
EOF
if [ $? == 0 ]
then
- echo "Added successfully... proceeding"
+ _ak_log_info "Added successfully... proceeding"
IPFS_FILE=$(_ak_ipfs_add $ZPROPERTY_FILE)
- echo "Prop writting,,, $IPFS_FILE"
+ _ak_log_info "Prop writting,,, $IPFS_FILE"
_ak_modules_profile_add $ZPROPERTY_KEY
cd $ZPROFILEDIR
else
- echo "Couldn't write to file $ZPROFILEDIR/$TO_FILE"
+ _ak_log_error "Couldn't write to file $ZPROFILEDIR/$TO_FILE"
exit 1
fi
}
@@ -107,19 +107,19 @@ _ak_modules_profile_propset(){
ZPROPERTY_KEY="$1"
if [ ! -f $ZPROPERTY_FILE ]
then
- echo "No such property: $ZPROPERTY_KEY ... creating"
+ _ak_log_warning "No such property: $ZPROPERTY_KEY ... creating"
ZPROPERTY_VALUE="$2"
if [ ! -z "$ZPROPERTY_VALUE" ]
then
touch $ZPROPERTY_FILE
- echo "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE"
+ _ak_log_debug "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE"
_ak_modules_profile_propwrite #"$ZPROPERTY_FILE" "${ZPROPERTY_VALUE}"
else
- echo "No value for $1"
+ _ak_log_error "No value for $1"
fi
else
- echo found $ZPROPERTY_FILE
- echo "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE"
+ _ak_log_info "found $ZPROPERTY_FILE"
+ _ak_log_debug "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE"
ZPROPERTY_VALUE="$2"
read -p "Overwrite $1 with ${ZPROPERTY_VALUE} ? " yn
case $yn in
@@ -127,11 +127,11 @@ _ak_modules_profile_propset(){
[Nn]* ) exit 130;;
* ) echo "Answer please";;
esac
- echo $IPFS_FILE
+ _ak_log_debug $IPFS_FILE
_ak_modules_profile_show $IPFS_FILE
fi
else
- echo "conditions unmet"
+ _ak_log_error "conditions unmet"
exit 244
fi
}
@@ -159,10 +159,10 @@ _ak_modules_profile_import(){
then
if [ ! -d $1 ]
then
- echo "Profile folder check: Folder $1 does not exist. Stopping..."
+ _ak_log_error "Profile folder check: Folder $1 does not exist. Stopping..."
exit 4
else
- echo "Profile folder check: Folder $1 exists."
+ _ak_log_info "Profile folder check: Folder $1 exists."
fl="$(ls -1 $1)"
for f in $fl
do
@@ -170,7 +170,7 @@ _ak_modules_profile_import(){
done
fi
else
- echo "No value"
+ _ak_log_error "No value"
exit 6
fi
exit 224
@@ -178,11 +178,11 @@ _ak_modules_profile_import(){
# Adds a file as a profile/add ACTION on the zchain.
_ak_modules_profile_add(){
- TEMP="$(_ak_make_temp_directory)"
- cd $TEMP
+ TEMPASSIN="$(_ak_make_temp_directory)"
+ cd $TEMPASSIN
if [ -f $ZPROFILEDIR/$1 ]; then
FILE="$ZPROFILEDIR/$1"
- echo "Adding from " $FILE
+ _ak_log_info "Adding from " $FILE
FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
FILE_SIGN_FILE=$(pwd)/$1".asc"
_ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
@@ -195,26 +195,26 @@ _ak_modules_profile_add(){
}
EOF
else
- echo "File $FILE doesn't exist";
+ _ak_log_error "File $FILE doesn't exist"
exit 2
fi
_ak_zblock_pack "profile/add" $(pwd)/data
if [ $? -ne 0 ]
then
- echo "error??"
+ _ak_log_error "Error while packing"
exit 1
fi
- echo "Profile added successfully"
+ _ak_log_info "Profile zblock added successfully"
cd $ZPROFILEDIR
- rm -rf "$TEMPASSIN"
+ rm -rf $TEMPASSIN
}
if [ ! -z $1 ]; then
case $1 in
-h | --help) _ak_usage; exit;;
- -i | --index) _ak_modules_profile_index; exit;;
+ -l | --local-index) _ak_modules_profile_index; exit;;
--show) _ak_modules_profile_show $2; exit;;
-i | --import) _ak_modules_profile_import $2; exit;;
-a | --add) _ak_modules_profile_add $2; exit;;
diff --git a/bin/ak-schain b/bin/ak-schain
new file mode 100755
index 0000000..1221274
--- /dev/null
+++ b/bin/ak-schain
@@ -0,0 +1,28 @@
+#!/bin/bash
+##
+## Various tools for schains
+##
+## Usage:
+##
+## -h, --help Prints this help message
+##
+## -c, --crawl Crawl an schain or latest known
+##
+fullprogrampath="$(realpath $0)"
+PROGRAM=$(basename $0)
+descriptionString="Schain tools"
+
+source $AK_LIBDIR/_ak_log
+source $AK_LIBDIR/_ak_script
+source $AK_LIBDIR/_ak_schain
+
+# Flags to run
+if [ ! -z $1 ]
+then
+ case $1 in
+ -h | --help) _ak_usage; exit;;
+ -c | --crawl) _ak_schain_crawl_interface $*; exit;;
+ * ) _ak_usage;;
+ esac
+else _ak_usage
+fi
diff --git a/bin/ak-schain-latest-cached b/bin/ak-schain-latest-cached
deleted file mode 100755
index 18ac1df..0000000
--- a/bin/ak-schain-latest-cached
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-
-PROGRAM="$(basename $0)"
-source $AK_LIBDIR/_ak_log
-if [ ! -f $AK_WORKDIR/schain.latest ]
-then
- ak-find-latest-mined-sblock > $AK_WORKDIR/schain.latest
-fi
-cat $AK_WORKDIR/schain.latest
diff --git a/bin/ak-unfollow b/bin/ak-unfollow
deleted file mode 100755
index c23aeef..0000000
--- a/bin/ak-unfollow
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-PROGRAM="$(basename $0)"
-source $AK_LIBDIR/_ak_config
-source $AK_LIBDIR/_ak_ipfs
-FOLLOWING="$HOME/.arching-kaos/following"
-fentries="$(cat $FOLLOWING)"
-if [ ! -z $1 ]
-then
- search="$1"
- sed -i -e 's,'"$search"',,g' $FOLLOWING
- if [ $? != 0 ]
- then
- _ak_log_error "sed didn't found $search"
- exit 1
- fi
- IPFS="$(_ak_ipfs_add $FOLLOWING)"
- if [ $? != 0 ]
- then
- _ak_log_error "IPFS problem"
- exit 1
- fi
- ak-profile set repositories "$IPFS"
- exit 0
-else
- echo "Who to unfollow?"
- echo "Type following to see them"
- exit 1
-fi
-
-
diff --git a/bin/ak-zchain b/bin/ak-zchain
index c2ecbc6..df73e7c 100755
--- a/bin/ak-zchain
+++ b/bin/ak-zchain
@@ -34,6 +34,9 @@
##
## --calculate-size Calculates the size of a zchain
##
+## --crawl Crawls zchains ( --crawl --help for more
+## options)
+##
## --crawl-self Crawls the local zchain
##
## --crawl-remote-ipfs Crawls a remote zchain
@@ -44,9 +47,11 @@ fullprogrampath="$(realpath $0)"
PROGRAM=$(basename $0)
descriptionString="Zchain tools"
-# At least these
source $AK_LIBDIR/_ak_log
source $AK_LIBDIR/_ak_script
+source $AK_LIBDIR/_ak_ipfs
+source $AK_LIBDIR/_ak_gpg
+source $AK_LIBDIR/_ak_zblock
source $AK_LIBDIR/_ak_zchain
# Flags to run
@@ -55,10 +60,11 @@ if [ ! -z $1 ]; then
-h | --help) _ak_usage; exit;;
-r | --reset) _ak_zchain_reset; exit;;
--rebase) if [ ! -z $2 ]; then _ak_zchain_rebase $2; else exit 1; fi; exit;;
- --rebase-back-one) _ak_zchain_rebase "`ak-enter -l 2 | jq -r '.[1].zblock'`" ; exit ;;
+ --rebase-back-one) _ak_zchain_rebase "`_ak_zchain_crawl -l 2 | jq -r '.[1].zblock'`" ; exit ;;
--extract-cids) _ak_zchain_extract_cids $2; exit;;
--extract-data-cids) _ak_zchain_extract_data_cids $2; exit;;
--calculate-size) _ak_zchain_calculate_size $2; exit;;
+ --crawl) shift; _ak_zchain_crawl $*; exit;;
--crawl-self) _ak_zchain_crawl_self; exit;;
--crawl-remote-ipfs) _ak_zchain_crawl_remote_ipfs $2; exit;;
--crawl-remote-ipns) _ak_zchain_crawl_remote_ipns $2; exit;;