#!/bin/bash # The following creates a mixtape data message # We can extend it by calling the pack_z_block.sh mixtape/add data ZFILESDIR="$WORKDIR/files" TEMP="/tmp/aktmp" if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR cd $ZFILESDIR git init else logthis "error $ZFILESDIR not found" fi tempassin(){ if [ ! -z $1 ]; then TEMPASSIN="$1" else TIMESTAMP="$(date -u +%s)" TEMPASSIN="/tmp/aktmp_$TIMESTAMP" fi if [ ! -d $TEMPASSIN ]; then mkdir $TEMPASSIN fi cd $TEMPASSIN echo "$TEMPASSIN" } usage(){ title echo "$0 - file" } add(){ CRP="$(pwd)" FILENAME="$1" main $FILENAME $CRP cat $TEMPASSIN/data | json_pp } main(){ FILENAME="$1" CRP="$2" echo "Adding $FILENAME" logthis "Switching to tmp folder..." TEMPASSIN="$(tempassin)" cd $TEMPASSIN if [ $? == 0 ]; then logthis "Success" else logthis "Error with tmp folder" exit 5 fi logthis "Copying $1 to $TEMPASSIN" cp $2/$1 $TEMPASSIN/$1 if [ $? == 0 ]; then logthis "Copied successfully" else logthis "Error copying..." fi FILE="$TEMPASSIN/$1" logthis "Adding $FILE to IPFS..." FILE_IPFS_HASH=$(ipfs add -q $FILE) if [ $? == 0 ]; then logthis "done" else logthis "error" fi logthis "Signing..." SIGN_FILE=$FILE".asc" gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $SIGN_FILE $FILE SIGNATURE=$(ipfs add -q $SIGN_FILE) cat > $TEMPASSIN/data <