aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_fs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/_ak_fs')
-rwxr-xr-xlib/_ak_fs79
1 files changed, 71 insertions, 8 deletions
diff --git a/lib/_ak_fs b/lib/_ak_fs
index 525b108..a0f5619 100755
--- a/lib/_ak_fs
+++ b/lib/_ak_fs
@@ -18,8 +18,9 @@
### along with this program. If not, see <http://www.gnu.org/licenses/>.
###
-source $AK_LIBDIR/_ak_log
-source $AK_LIBDIR/_ak_hash_exchange
+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
@@ -188,7 +189,7 @@ function _ak_fs_import(){
done
if [ -f level.1.map ]
then
- sha512sum level.1.map
+ # sha512sum level.1.map
sha512sum level.1.map >> $TEMPDIR/3rd_gen_map
else
ak_log_error "Got error an error, level.1.map is missing"
@@ -364,7 +365,7 @@ function _ak_fs_from_map_get_original_filename(){
then
if [ -f "$AK_MAPSDIR/$1" ]
then
- cat $AK_MAPSDIR/$1 | tr '\n' ' ' | awk '{ print $2 }'
+ cat $AK_MAPSDIR/$1 | sed -e 's/ / /g;' | tr '\n' ' ' | awk '{ print $2 }'
else
_ak_log_error "Map $1 was not found"
fi
@@ -428,7 +429,7 @@ function _ak_net_try_leaf(){
if [ "$(cat $1 | grep '^[0-9a-z]\{128\}$' | wc -l)" == 2 ]
then
_ak_log_info "File has two lines which are 2 hashes"
- cat $1
+ # cat $1
cp $1 ${AK_LEAFSDIR}/$1
exit
break
@@ -441,7 +442,7 @@ function _ak_net_try_leaf(){
rm $1
fi
else
- cat $1 | jq >&2
+ # cat $1 | jq >&2
_ak_log_warning "File $1 doesn't match expected hash: $(sha512sum $1 | awk '{print $1}')"
rm $1
fi
@@ -476,7 +477,7 @@ function _ak_net_try_chunk(){
if [ "$(cat $1 | grep -v '^[-A-Za-z0-9+/]*=\{0,3\}$')" == "" ]
then
_ak_log_info "File is base64"
- cat $1
+ # cat $1
cp $1 ${AK_CHUNKSDIR}/$1
exit
break
@@ -485,7 +486,7 @@ function _ak_net_try_chunk(){
rm $1
fi
else
- cat $1 | jq >&2
+ # cat $1 | jq >&2
_ak_log_warning "File $1 doesn't match expected hash: $(sha512sum $1 | awk '{print $1}')"
rm $1
fi
@@ -617,6 +618,21 @@ function _ak_fs_net_cat(){
fi
}
+function _ak_fs_net_get(){
+ if [ -z $1 ]
+ then
+ echo "Please provide a SHA512 hash"
+ exit 1
+ fi
+ echo $1 | grep "[0123456789abcdef]\{128\}" > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ echo "Look, I asked for a SHA512 hash, please try again"
+ exit 1
+ fi
+ _ak_fs_net_cat $1 $2 > $3
+}
+
function _ak_fs_from_map_net_get_original_hash(){
TEMPDIR=$(_ak_make_temp_directory)
cd $TEMPDIR
@@ -655,6 +671,44 @@ function _ak_fs_from_map_net_get_original_hash(){
fi
}
+function _ak_fs_from_map_net_get_original_filename(){
+ TEMPDIR=$(_ak_make_temp_directory)
+ cd $TEMPDIR
+ if _ak_fs_verify_input_is_hash "$1"
+ then
+ _ak_he_list_peers | while read peer
+ do
+ _ak_log_debug "Trying $(_ak_he_url_request_map_hash_from_peer ${peer} $1)..."
+ curl -s --connect-timeout 3 -o ${TEMPDIR}/peer_${peer}.reply $(_ak_he_url_request_map_hash_from_peer ${peer} $1)
+ done
+ find . -type f | while read reply
+ do
+ cat ${reply} | jq >/dev/null 2>&1
+ if [ $? -eq 0 ]
+ then
+ _ak_log_error "Found error in reply: $(cat ${reply} | jq -r '.error')"
+ else
+ if [ $(cat ${reply} | wc -l) -ne 2 ]
+ then
+ _ak_log_error "${reply} is not two lines long"
+ exit 1
+ else
+ _ak_log_info "${reply} is two lines long"
+ fi
+ if [ $(cat ${reply} | grep '^[0-9a-z]\{128\} ' | wc -l) -eq 2 ]
+ then
+ _ak_log_info "${reply} contains two hashes"
+ else
+ _ak_log_error "${reply} doesn't contain the appropriate info"
+ exit 1
+ fi
+ cat ${reply} | head -n 1 | awk '{print $2}'
+ break
+ fi
+ done
+ fi
+}
+
function _ak_fs_from_map_net_get_root_hash(){
TEMPDIR=$(_ak_make_temp_directory)
cd $TEMPDIR
@@ -693,9 +747,18 @@ function _ak_fs_from_map_net_get_root_hash(){
fi
}
+function _ak_fs_net_get_from_map_hash(){
+ if _ak_fs_verify_input_is_hash "$1"
+ then
+ _ak_fs_net_get `_ak_fs_from_map_net_get_root_hash $1` `_ak_fs_from_map_net_get_original_hash $1` `_ak_fs_from_map_get_original_filename $1`
+ fi
+}
+
function _ak_fs_net_cat_from_map_hash(){
if _ak_fs_verify_input_is_hash "$1"
then
_ak_fs_net_cat `_ak_fs_from_map_net_get_root_hash $1` `_ak_fs_from_map_net_get_original_hash $1`
fi
}
+
+_ak_log_debug "_ak_fs loaded $(caller)"