#!/bin/bash ZFILESDIR="$AK_WORKDIR/files" pwd > .pwd CRD=$(cat .pwd) PROGRAM="$(basename $0)" #set -xe logit(){ ak-logthis "$PROGRAM" "$1" "$2" } if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR if [ $? == 0 ] then logit "INFO" "Folder $ZFILESDIR created!" else logit "ERROR" "Failed to create $ZFILESDIR folder" exit 1 fi cd $ZFILESDIR else logit "INFO" "$ZFILESDIR found!" fi usage(){ echo "$PROGRAM - file" echo " -h, --help Prints this help message" echo " add Adds file to zchain as a zblock" echo " index List files" echo " full-index List all files" echo " ls-map-files List map files" } add(){ FILENAME="$1" main $FILENAME $CRD cat data | jq -M } main(){ FILENAME="$1" CRP="$2" TEMPASSIN="$(ak-tempassin)" cd $TEMPASSIN echo "Adding $FILENAME" logit "INFO" "Switching to tmp folder..." if [ $? == 0 ]; then logit "INFO" "Success" else logit "ERROR" "Error with tmp folder" exit 5 fi logit "INFO" "Copying $1 to $TEMPASSIN" cp $CRP/$FILENAME $FILENAME if [ $? == 0 ]; then logit "INFO" "Copied successfully" else logit "ERROR" "Error copying..." fi logit "INFO" "Adding $FILENAME to IPFS..." FILE_IPFS_HASH=$(ak-ipfs-add $FILENAME) if [ $? == 0 ]; then logit "INFO" "Added $FILENAME to IPFS" else logit "ERROR" "Error in adding the $FILENAME to IPFS" fi logit "INFO" "Adding $FILE to SHAMAPSYS..." FILEMAP_SHA512_HASH=$(ak-sm-filesplitter $FILENAME) if [ $? == 0 ]; then logit "INFO" "Added $FILENAME to SHAMAPSYS" else logit "ERROR" "Error in adding the $FILENAME to SHAMAPSYS" fi logit "INFO" "Signing..." SIGN_FILE=$FILENAME".asc" gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $SIGN_FILE $FILENAME if [ $? == 0 ]; then logit "INFO" "Signed" else logit "ERROR" "Error while signing" fi logit "INFO" "Adding signature to IPFS" SIGNATURE=$(ak-ipfs-add $SIGN_FILE) if [ $? == 0 ]; then logit "INFO" "Added" else logit "ERROR" "Error while adding" fi logit "INFO" "Adding signature to SHAMAPSYS" SHAMAPSIGMAP=$(ak-sm-filesplitter $SIGN_FILE) if [ $? == 0 ]; then logit "INFO" "Added" else logit "ERROR" "Error while adding" fi cat > data <