aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/_ak_checks45
-rwxr-xr-xlib/_ak_cjdns64
-rwxr-xr-xlib/_ak_coin24
-rwxr-xr-xlib/_ak_config41
-rwxr-xr-xlib/_ak_datetime46
-rwxr-xr-xlib/_ak_fm31
-rwxr-xr-xlib/_ak_fs653
-rwxr-xr-xlib/_ak_gpg106
-rwxr-xr-xlib/_ak_hash_exchange79
-rwxr-xr-xlib/_ak_html30
-rwxr-xr-xlib/_ak_ipfs176
-rwxr-xr-xlib/_ak_irc10
-rwxr-xr-xlib/_ak_lib_load32
-rwxr-xr-xlib/_ak_log153
-rwxr-xr-xlib/_ak_maintainance86
-rwxr-xr-xlib/_ak_network399
-rwxr-xr-xlib/_ak_network_cjdns217
-rwxr-xr-xlib/_ak_network_incoming95
-rwxr-xr-xlib/_ak_network_ipfs39
-rwxr-xr-xlib/_ak_network_stellar163
-rwxr-xr-xlib/_ak_network_utils81
-rwxr-xr-xlib/_ak_network_yggdrasil119
-rwxr-xr-xlib/_ak_node32
-rwxr-xr-xlib/_ak_ns202
-rwxr-xr-xlib/_ak_pkg231
-rwxr-xr-xlib/_ak_sblock28
-rwxr-xr-xlib/_ak_schain41
-rwxr-xr-xlib/_ak_script160
-rwxr-xr-xlib/_ak_settings46
-rwxr-xr-xlib/_ak_sh67
-rwxr-xr-xlib/_ak_smfiles65
-rwxr-xr-xlib/_ak_wallet28
-rwxr-xr-xlib/_ak_yggdrasil228
-rwxr-xr-xlib/_ak_zblock240
-rwxr-xr-xlib/_ak_zchain130
35 files changed, 3310 insertions, 877 deletions
diff --git a/lib/_ak_checks b/lib/_ak_checks
new file mode 100755
index 0000000..97b3d8a
--- /dev/null
+++ b/lib/_ak_checks
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_log
+
+function _ak_checks_example_check_for_base64_strings(){
+
+ if [ ! -z $1 ] && [ -n "$1" ]
+ then
+ cat $1 | base64 | while read line
+ do
+ if [ $(echo "$line" | tr -d $'\n' | wc -c) -lt 77 ]
+ then
+ if [ $(echo "$line" | tr -d $'\n' | sed -e 's/[0-9A-Za-z]//g; s/[=\/+]//g' | wc -c) -gt 0 ]
+ then
+ echo "$line"
+ _ak_log_error "Not a base64 line"
+ fi
+ else
+ _ak_log_error "Not a base64 line"
+ fi
+ done
+ else
+ _ak_log_error "No argument given"
+ fi
+}
+
+_ak_log_debug "_ak_checks loaded $(caller)"
diff --git a/lib/_ak_cjdns b/lib/_ak_cjdns
index 4328c65..51832d3 100755
--- a/lib/_ak_cjdns
+++ b/lib/_ak_cjdns
@@ -1,13 +1,32 @@
-#!/bin/bash
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_log
+_ak_lib_load _ak_network
-source $AK_LIBDIR/_ak_log
-source $AK_LIBDIR/_ak_network
rust_sh_install_url="https://sh.rustup.rs"
cjdns_src_git_repo_url="https://github.com/cjdelisle/cjdns"
cjdnstoolspath="$HOME/cjdns/tools"
cargo_env="$HOME/.cargo/env"
-_ak_cjdns_check_availability(){
+function _ak_cjdns_check_availability(){
declare -a cjdns_bins=("cjdroute" "makekeys" "mkpasswd" "privatetopublic" "publictoip6" "randombytes" "sybilsim")
for cbin in "${cjdns_bins[@]}"
do
@@ -22,19 +41,20 @@ _ak_cjdns_check_availability(){
done
}
-_ak_cargo_rust_check_install(){
- if [ ! -f $cargo_env ]
+function _ak_cargo_rust_check_install(){
+ if [ ! -f ${cargo_env} ]
then
- curl --proto '=https' --tlsv1.2 -sSf $rust_sh_install_url | sh
+ curl --proto '=https' --tlsv1.2 -sSf ${rust_sh_install_url} | sh
fi
- source $cargo_env
+ source ${cargo_env}
}
-_ak_cjdns_install(){
+function _ak_cjdns_install(){
_ak_cargo_rust_check_install
- git clone $cjdns_src_git_repo_url
+ git clone ${cjdns_src_git_repo_url}
+ cjdns_install_script="./do"
cd cjdns
- sh do
+ sh ${cjdns_install_script}
if [ $? -ne 0 ]
then
_ak_log_error "Failed to compile cjdns"
@@ -48,25 +68,24 @@ _ak_cjdns_install(){
sudo cp cjdns/target/release/publictoip6 /usr/bin/publictoip6
sudo cp cjdns/target/release/randombytes /usr/bin/randombytes
sudo cp cjdns/target/release/sybilsim /usr/bin/sybilsim
- ln -s "$(realpath cjdns/tools/dumpLinks)" $HOME/.arching-kaos/bin/dumpLinks
- ln -s "$(realpath cjdns/tools/cexec)" $HOME/.arching-kaos/bin/cjdns-cexec
- ln -s "$(realpath cjdns/tools/peerStats)" $HOME/.arching-kaos/bin/peerStats
+ ln -s "$(realpath cjdns/tools/dumpLinks)" ${HOME}/.arching-kaos/bin/dumpLinks
+ ln -s "$(realpath cjdns/tools/cexec)" ${HOME}/.arching-kaos/bin/cjdns-cexec
+ ln -s "$(realpath cjdns/tools/peerStats)" ${HOME}/.arching-kaos/bin/peerStats
which systemctl 2> /dev/null 1>&2
if [ $? -ne 0 ]
then
_ak_log_error "Systemctl not found... TODO"
else
- sudo cp "$(realpath cjdns/contrib/systemd/cjdns.service)" /etc/systemd/system/cjdns.service
- sudo cp "$(realpath cjdns/contrib/systemd/cjdns-resume.service)" /etc/systemd/system/cjdns-resume.service
+ sudo cp cjdns/contrib/systemd/cjdns.service /etc/systemd/system/cjdns.service
+ sudo cp cjdns/contrib/systemd/cjdns-resume.service /etc/systemd/system/cjdns-resume.service
sudo systemctl enable --now cjdns.service
fi
}
-_ak_cjdns_read_peers_to_vars_with_jq(){
+function _ak_cjdns_read_peers_to_vars_with_jq(){
totalpeers="$(jq '. | length' < $peersfile)"
number="0"
interface="0"
-
while [ $number -lt $totalpeers ]
do
address="$(jq -r '.['$number'].address' < $peersfile)"
@@ -85,7 +104,7 @@ _ak_cjdns_read_peers_to_vars_with_jq(){
done
}
-_ak_cjdns_read_peers_to_vars_natively(){
+function _ak_cjdns_read_peers_to_vars_natively(){
number=-1
cat $peersfile | tr -d $'\n' | sed -e 's/]$/\n/g' | tr -d ' ' | sed -e 's/"//g; s/,/,\n/g; s/}//g; s/,//g' | while read line
do
@@ -132,8 +151,7 @@ _ak_cjdns_read_peers_to_vars_natively(){
rm peerfile
}
-
-_ak_cjdns_connect_peers(){
+function _ak_cjdns_connect_peers(){
_ak_network_cjdns_connect
exit $?
#
@@ -169,7 +187,7 @@ _ak_cjdns_connect_peers(){
fi
}
-_ak_cjdns_get_ip(){
+function _ak_cjdns_get_ip(){
which ip > /dev/null 2>&1
if [ $? -ne 0 ]
then
@@ -181,3 +199,5 @@ _ak_cjdns_get_ip(){
awk '{print $2}' | \
cut -d'/' -f1
}
+
+_ak_log_debug "_ak_cjdns loaded $(caller)"
diff --git a/lib/_ak_coin b/lib/_ak_coin
index fda3bc0..413d575 100755
--- a/lib/_ak_coin
+++ b/lib/_ak_coin
@@ -1,4 +1,22 @@
-#!/bin/bash
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
# coin max is 10,000.0000000
# but we count in integer to avoid floating point arithmetic :P
#
@@ -8,7 +26,9 @@ COINBASE=100000000000
GENESIS="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
-_ak_coin_stats(){
+function _ak_coin_stats(){
echo "Coinbase: $COINBASE"
echo "Genesis: $GENESIS"
}
+
+_ak_log_debug "_ak_coin loaded $(caller)"
diff --git a/lib/_ak_config b/lib/_ak_config
index 45d0112..6c71e9c 100755
--- a/lib/_ak_config
+++ b/lib/_ak_config
@@ -1,7 +1,26 @@
-#!/bin/bash
-source $AK_LIBDIR/_ak_node
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_node
-_ak_config_show(){
+function _ak_config_show(){
# We will be using our public key also to put it in the block later
KEY="self.pub"
ak-gpg --export-key-self-to-file
@@ -9,31 +28,35 @@ _ak_config_show(){
GPG_PUB_KEY=$(_ak_ipfs_add $KEY)
rm $KEY
profile="$(ak-profile -l)"
-
echo '
{
"profile":'$profile',
"genesis":"'$(cat $AK_WORKDIR/config/zgenesis)'",
- "gpg":"'$GPG_PUB_KEY'",
+ "gpg":{
+ "ipfs":"'$GPG_PUB_KEY'",
+ "fingerprint":"'$(ak gpg --get-key-fingerprint-from-ipfs $GPG_PUB_KEY)'"
+ },
"zchain":"'$(cat $AK_WORKDIR/config/zchain)'",
"zlatest":"'$(ak zchain --get-latest)'"
}'| jq;
}
-_ak_config_publish(){
+function _ak_config_publish(){
_ak_config_show | jq -c -M > tmpfile
ipfs_hash="$(_ak_ipfs_add tmpfile)"
_ak_ipfs_config_publish $ipfs_hash
if [ $? != 0 ]
then
- echo -e "\033[0;34mError on publishing\033[0;0m\nYour information:\n"
- cat tmpfile
+ _ak_log_error "Error on publishing"
+ _ak_log_debug "Your information:"
+ cat tmpfile | while read line; do _ak_log_debug "$line"; done
exit 1
fi
rm tmpfile
}
-_ak_config_published(){
+function _ak_config_published(){
_ak_ipfs_cat $(_ak_node_info_ipfs_hash) | jq
}
+_ak_log_debug "_ak_config loaded $(caller)"
diff --git a/lib/_ak_datetime b/lib/_ak_datetime
new file mode 100755
index 0000000..a25696f
--- /dev/null
+++ b/lib/_ak_datetime
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+
+function _ak_datetime_unix(){
+ date -u +%s | tr -d '\n'
+}
+
+function _ak_datetime_unix_nanosecs(){
+ date -u +%s.%N | tr -d '\n'
+}
+
+function _ak_datetime_human(){
+ date -u +%Y%m%d_%H%M%S
+}
+
+function _ak_datetime_human_date_only(){
+ date -u +%Y%m%d
+}
+
+function _ak_datetime_human_date_only_yesterday(){
+ date --date=yesterday -u +%Y%m%d 2>/dev/null || date -v -1d -u +%Y%m%d 2>/dev/null
+}
+
+function _ak_datetime_unix_to_human(){
+ if [ ! -z $1 ] && [ -n "$1" ] && [ "$(echo $1 | sed -e 's/[0-9]\{10\}//g')" == "" ]
+ then
+ date --date=@$1 +%Y%m%d_%H%M%S 2>/dev/null || date -r $1 +%Y%m%d_%H%M%S 2>/dev/null
+ fi
+}
diff --git a/lib/_ak_fm b/lib/_ak_fm
index deefb6d..5971a88 100755
--- a/lib/_ak_fm
+++ b/lib/_ak_fm
@@ -1,6 +1,28 @@
-#!/bin/bash
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
-_ak_fm_remove_line_from_file(){
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_log
+_ak_lib_load _ak_script
+
+function _ak_fm_remove_line_from_file(){
tempfile="$(_ak_make_temp_file)"
if [ ! -f "$2" ]
then
@@ -9,6 +31,7 @@ _ak_fm_remove_line_from_file(){
fi
grep "$1" "$2" > /dev/null 2>&1
if [ $? -ne 0 ]
+ then
_ak_log_error "Could not find line: $1 in $2"
exit 1
fi
@@ -17,7 +40,7 @@ _ak_fm_remove_line_from_file(){
rm $tempfile
}
-_ak_fm_sort_uniq_file(){
+function _ak_fm_sort_uniq_file(){
if [ ! -f "$1" ]
then
_ak_log_info "No file to process"
@@ -30,3 +53,5 @@ _ak_fm_sort_uniq_file(){
_ak_log_info "Sorting $1... Done!"
fi
}
+
+_ak_log_debug "_ak_fm loaded $(caller)"
diff --git a/lib/_ak_fs b/lib/_ak_fs
index f55e58e..a0f5619 100755
--- a/lib/_ak_fs
+++ b/lib/_ak_fs
@@ -1,18 +1,46 @@
-#!/bin/bash
-
-source $AK_LIBDIR/_ak_log
+#!/usr/bin/env bash
+###
+### arching-kaos-tools
+### Tools to interact and build an Arching Kaos Infochain
+### Copyright (C) 2021 - 2025 kaotisk
+###
+### This program is free software: you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program. If not, see <http://www.gnu.org/licenses/>.
+###
+
+source $AK_LIBDIR/_ak_lib_load
+_ak_lib_load _ak_log
+_ak_lib_load _ak_hash_exchange
+
+function _ak_fs_dir_init_setup(){
+ _ak_check_and_create_dir $AK_MAPSDIR
+ _ak_check_and_create_dir $AK_CHUNKSDIR
+ _ak_check_and_create_dir $AK_LEAFSDIR
+}
-_ak_fs_return_hash_path(){
- hashpath="$(echo -n "$1" |sed 's/./&\//g;s/\/$//g')"
- echo -n "$hashpath"
+function _ak_fs_return_hash_path(){
+ #hashpath="$(echo -n "$1" |sed 's/./&\//g;s/\/$//g')"
+ #hashpath="$(echo -n "$1" | fold -w 4 | tr $'\n' '/')"
+ echo -n "$1"
}
-_ak_fs_return_hash_dir(){
- hashdir="$(echo -n "$1" | sed -e 's/./&\//g' | grep '\(./\)\{128\}' | sed -e 's/..$//')"
- echo -n "$hashdir"
+function _ak_fs_return_hash_dir(){
+ #hashdir="$(_ak_fs_return_hash_path $1 | sed -e 's/.....$//')"
+ #echo -n "$hashdir"
+ echo -n "$1"
}
-_ak_fs_verify_input_is_hash(){
+function _ak_fs_verify_input_is_hash(){
if [ ! -z "$1" ] && echo "$1" | grep '[0123456789abcdef]\{128\}' > /dev/null 2>&1
then
return 0
@@ -22,7 +50,7 @@ _ak_fs_verify_input_is_hash(){
fi
}
-_ak_fs_create_dir_for_hash(){
+function _ak_fs_create_dir_for_hash(){
_ak_fs_verify_input_is_hash $2
if [ ! -z $1 ] && [ ! -z $2 ] && [ -n "$1" ] && [ -n "$2" ]
then
@@ -31,14 +59,16 @@ _ak_fs_create_dir_for_hash(){
}
# Append last chk if not even number
-_ak_fs_appendLastIfNotEven(){
+function _ak_fs_appendLastIfNotEven(){
if [ "$(( $(wc -l "$1" | awk '{ print $1 }') % 2))" -ne 0 ]
then
- tail -n 1 "$1" >> "$1"
+ tail -n 1 "$1" >> "$1.temp"
+ cat "$1.temp" >> "$1"
+ rm $1.temp
fi
}
-_ak_fs_import(){
+function _ak_fs_import(){
#
# The concept is bit more complicated now
#
@@ -59,77 +89,16 @@ _ak_fs_import(){
#
# 6. We are done!
#
-
# A temporary root dir to work on
- TEMPORARYDIR="$(_ak_make_temp_directory)"
+ TEMPDIR="$(_ak_make_temp_directory)"
# A subdir to split the files there
- TECHDIR="$TEMPORARYDIR/chks"
+ TCHKDIR="$TEMPDIR/chks"
# A pin point to return from where we came from
CURRENTDIR="$(pwd)"
-
# Checking directories and create them if necessary
- # rm -rf $TEMPORARYDIR
-
- # TECHDIR
- if [ ! -d "$TECHDIR" ]
- then
- mkdir -p "$TECHDIR"
- if [ $? -eq 0 ]
- then
- _ak_log_info "Folder $TECHDIR created!"
- else
- _ak_log_error "Problem occured while creating $TECHDIR"
- exit 1
- fi
- else
- _ak_log_debug "Temp dir found"
- fi
-
- # AK_MAPSDIR
- if [ ! -d "$AK_MAPSDIR" ]
- then
- mkdir -p "$AK_MAPSDIR"
- if [ $? -eq 0 ]
- then
- _ak_log_debug "Folder $AK_MAPSDIR created!"
- else
- _ak_log_error "Problem occured while creating $AK_MAPSDIR"
- exit 1
- fi
- else
- _ak_log_debug "Mapsdir found"
- fi
-
- # AK_CHUNKSDIR
- if [ ! -d "$AK_CHUNKSDIR" ]
- then
- mkdir -p "$AK_CHUNKSDIR"
- if [ $? -eq 0 ]
- then
- _ak_log_info "Folder $AK_CHUNKSDIR created!"
- else
- _ak_log_error "Problem occured while creating $AK_CHUNKSDIR"
- exit 1
- fi
- else
- _ak_log_debug "Workdir found"
- fi
-
- # AK_LEAFSDIR
- if [ ! -d "$AK_LEAFSDIR" ]
- then
- mkdir -p "$AK_LEAFSDIR"
- if [ $? -eq 0 ]
- then
- _ak_log_info "Folder $AK_LEAFSDIR created!"
- else
- _ak_log_error "Problem occured while creating $AK_LEAFSDIR"
- echo "ERROR Can't create $AK_LEAFSDIR"
- exit 1
- fi
- else
- _ak_log_debug "Workdir found"
- fi
+ # rm -rf $TEMPDIR
+ _ak_check_and_create_dir $TCHKDIR
+ _ak_fs_dir_init_setup
if [ ! -f "$1" ]
then
_ak_log_error "File $1 not found"
@@ -142,21 +111,19 @@ _ak_fs_import(){
# sha256sum as quick pointer to root of the tree
#
_ak_log_info "Storing original hash of $1 along with its name"
- sha512sum "$1" > $TEMPORARYDIR/3rd_gen_map
+ sha512sum "$1" > $TEMPDIR/3rd_gen_map
_ak_log_info "Encoding to base64"
base64 $1 > file
FILE="file"
fi
-
# Uncomment next line in case you want to debug the resulting script as well
- # echo 'set -xe' > $TEMPORARYDIR/cmd_queue.sh
-
+ # echo 'set -xe' > $TEMPDIR/cmd_queue.sh
# We get the SHA512 hash for the $FILE given
CHECKSUM=$(sha512sum "$FILE"|awk '{print $1}')
- FILE_SIZE="$(du -b $FILE | awk '{ print $1 }')"
+ FILE_SIZE="$( (du -b $FILE||stat -f %z $FILE)2>/dev/null | awk '{ print $1 }')"
if [ $FILE_SIZE -lt 4097 ]
then
- cp $FILE "$TECHDIR/$(basename "$FILE")-00000000000000000000000000000000000000000000000000.chk"
+ cp $FILE "$TCHKDIR/chunk-0000000000000"
else
FACTOR=1024
while [ $(( $FILE_SIZE / $FACTOR )) -gt 250 ]
@@ -165,23 +132,24 @@ _ak_fs_import(){
done
_ak_log_info "Gonna split in $FACTOR size"
sleep 3
- # 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")-"
+ # We split the file into 4*1024 bytes and output the chunks into TCHKDIR
+ split -a 13 -b $FACTOR -d "$FILE" "$TCHKDIR/chunk-"
fi
_ak_log_info "File done splitting"
-
# We go over there...
- cd $TECHDIR
+ cd $TCHKDIR
#set -xe
# We get every chunks' SHA512 and we craft a script to rename the chunks and
# move them to AK_CHUNKSDIR
- for file in $TEMPORARYDIR/chks/*
+ for file in *
do
- sha512sum $file >> $TEMPORARYDIR/map
+ _ak_log_debug "Hashing ${file}..."
+ sha512sum $file >> $TEMPDIR/map
+ _ak_log_debug "Hashing of ${file} completed"
done
- _ak_fs_appendLastIfNotEven "$TEMPORARYDIR/map"
+ _ak_fs_appendLastIfNotEven "$TEMPDIR/map"
# Figure out how many times we need to pack
- totalChunks=`grep 'chk' $TEMPORARYDIR/map | wc -l`
+ totalChunks=`grep 'chunk-' $TEMPDIR/map | wc -l`
temp="$totalChunks"
timesRan=0
while [ $temp -ne 1 ]
@@ -191,8 +159,7 @@ _ak_fs_import(){
done
_ak_log_debug "Ran $timesRan times"
_ak_log_debug "Total chunks $totalChunks"
-
- workingIndex="$TEMPORARYDIR/map"
+ workingIndex="$TEMPDIR/map"
c=$timesRan
while [ $c -ne 0 ]
do
@@ -220,61 +187,49 @@ _ak_fs_import(){
totalChunks=`cat $workingIndex | wc -l`
c=`expr $c - 1`
done
-
if [ -f level.1.map ]
then
- sha512sum level.1.map
- sha512sum level.1.map >> $TEMPORARYDIR/3rd_gen_map
+ # sha512sum level.1.map
+ sha512sum level.1.map >> $TEMPDIR/3rd_gen_map
else
- echo error
+ ak_log_error "Got error an error, level.1.map is missing"
exit 1
fi
-
# Reset file with uniq
- cat $TEMPORARYDIR/map | uniq > $TEMPORARYDIR/map2
- cat $TEMPORARYDIR/map2 > $TEMPORARYDIR/map
- rm $TEMPORARYDIR/map2
-
+ cat $TEMPDIR/map | uniq > $TEMPDIR/map2
+ cat $TEMPDIR/map2 > $TEMPDIR/map
+ rm $TEMPDIR/map2
counter=0
while IFS="" read -r p || [ -n "$p" ]
do
-# printf "mv %s %s/%s\n" "$(echo $p | awk '{ print $2 }')" "$AK_CHUNKSDIR" "$(echo $p | awk '{ print $1 }')" >> $TEMPORARYDIR/cmd_queue.sh
+# printf "mv %s %s/%s\n" "$(echo $p | awk '{ print $2 }')" "$AK_CHUNKSDIR" "$(echo $p | awk '{ print $1 }')" >> $TEMPDIR/cmd_queue.sh
#mkdir -p $AK_CHUNKSDIR/$(echo $p | awk '{ print $1 }')
cp $(echo $p | awk '{ print $2 }') $AK_CHUNKSDIR/$(echo $p | awk '{ print $1 }')
counter=`expr "$counter" + 1`
- done < $TEMPORARYDIR/map
-
+ done < $TEMPDIR/map
# We run the crafted script
-# sh $TEMPORARYDIR/cmd_queue.sh
-
+# sh $TEMPDIR/cmd_queue.sh
# and we delete it
-# rm $TEMPORARYDIR/cmd_queue.sh
-
+# rm $TEMPDIR/cmd_queue.sh
# We inform the map about the original $FILE name and SHA512
-# echo "$CHECKSUM $(basename "$FILE")" >> $TEMPORARYDIR/map
-
+# echo "$CHECKSUM $(basename "$FILE")" >> $TEMPDIR/map
# We get the SHA512 hash of the resulted map file
-# MAPFILEHASH="$(sha512sum $TEMPORARYDIR/map | awk '{ print $1 }')"
-
+# MAPFILEHASH="$(sha512sum $TEMPDIR/map | awk '{ print $1 }')"
# and we rename it with it and move it to AK_MAPSDIR
-# `sha512sum $TEMPORARYDIR/map | awk '{print "mv " $2 " '$AK_MAPSDIR/'" $1}'`
-
- mp512p="$(sha512sum $TEMPORARYDIR/3rd_gen_map | awk '{print $1}')"
- mv $TEMPORARYDIR/3rd_gen_map $AK_MAPSDIR/$mp512p
-
- # We remove the TEMPORARYDIR
- rm -rf $TEMPORARYDIR
-
+# `sha512sum $TEMPDIR/map | awk '{print "mv " $2 " '$AK_MAPSDIR/'" $1}'`
+ mp512p="$(sha512sum $TEMPDIR/3rd_gen_map | awk '{print $1}')"
+ cp $TEMPDIR/3rd_gen_map $AK_MAPSDIR/$mp512p
+ # We remove the TEMPDIR
+ rm -rf $TEMPDIR
# and print the MAPFILEHASH
echo "$mp512p"
-
}
-_ak_fs_find_depth(){
+function _ak_fs_find_depth(){
currentNode="$1"
#pathToNode="$AK_LEAFSDIR/$(_ak_fs_return_hash_path $currentNode)"
pathToNode="$AK_LEAFSDIR/$currentNode"
- if [ -f $pathToNode ] && [ "$(du -b $pathToNode | awk '{print $1}')" == "258" ]
+ if [ -f $pathToNode ] && [ "$( (du -b $pathToNode||stat -f %z $pathToNode)2>/dev/null | awk '{print $1}')" == "258" ]
then
fileHead="$(head -n 1 $pathToNode)"
counter="$(expr $counter + 1)"
@@ -285,7 +240,7 @@ _ak_fs_find_depth(){
else
exit 111
# Try to download stuff
- # wget -s $remoteMrk/$currentNode -O $AK_LEAFSDIR/$currentNode
+ # curl -s $remoteMrk/$currentNode -o $AK_LEAFSDIR/$currentNode
# if [ $? -ne 0 ]
# then
# exit 111
@@ -294,29 +249,29 @@ _ak_fs_find_depth(){
fi
}
-_ak_fs_cat(){
+function _ak_fs_cat(){
if [ -z $1 ]
then
echo "Please provide a SHA512 hash"
exit 1
fi
- echo $1 | grep "[0123456789abcdef]\{128\}"
+ echo $1 | grep "[0123456789abcdef]\{128\}" > /dev/null 2>&1
if [ $? -ne 0 ]
then
- echo "Look, I asked for a SHA512 hash, please try again"
+ _ak_log_error "Look, I asked for a SHA512 hash, please try again"
exit 1
fi
treeRootHash="$1"
# Enter temp folder
- TEMPASSIN="$(_ak_make_temp_directory)"
- cd $TEMPASSIN
+ TEMPDIR="$(_ak_make_temp_directory)"
+ cd $TEMPDIR
currentNode="$treeRootHash"
counter=0
printf "%s" "$currentNode" > workspace.0
_ak_fs_find_depth "$currentNode"
depth="$(expr `cat depth` + 1)"
counter="0"
- printf "%s" "$depth"
+ # printf "%s" "$depth"
if [ -f output ]
then
rm output
@@ -330,7 +285,7 @@ _ak_fs_cat(){
nextLevel="$(expr $counter + 1)"
if [ "$p" == "" ]
then
- echo hi
+ _ak_log_debug "Got empty line"
else
#expectedPath="$AK_LEAFSDIR/$(_ak_fs_return_hash_path $p)"
expectedPath="$AK_LEAFSDIR/$p"
@@ -352,12 +307,11 @@ _ak_fs_cat(){
done < workspace.$counter
counter="$(expr $counter + 1)"
done
-
base64 -d output
_ak_log_info "Recreation of $treeRootHash succeeded!"
}
-_ak_fs_export(){
+function _ak_fs_export(){
if [ -z $1 ]
then
_ak_log_error "Please provide a SHA512 hash"
@@ -369,21 +323,21 @@ _ak_fs_export(){
exit 2
fi
outputFilename="$2"
- echo $1 | grep "[0123456789abcdef]\{128\}"
+ echo $1 | grep "[0123456789abcdef]\{128\}" > /dev/null 2>&1
if [ $? -ne 0 ]
then
_ak_log_error "Look, I asked for a SHA512 hash, please try again"
exit 1
fi
- _ak_fs_export "$1" > $outputFilename
+ _ak_fs_cat "$1" > $outputFilename
}
-_ak_fs_list(){
+function _ak_fs_list(){
if [ -d "${AK_MAPSDIR}" ]
then
find $AK_MAPSDIR -type f | while read fina
do
- cat $fina | tr $'\n' ' ' | awk '{ print $2 " " $3 }'
+ cat $fina | tr '\n' ' ' | awk '{ print "'$(basename ${fina})' " $3 " " $2 }'
done
else