aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.com>2021-12-14 03:50:02 +0200
committerkaotisk <kaotisk@arching-kaos.com>2021-12-14 03:50:02 +0200
commit03a0fd66bd696a5cbf9cd91dde242df60e4a6f96 (patch)
treefc1100ce3736f536ab1c7a0a0927c18bd0d2ae07
parente93bc58da017610d6f92d68b40f908d09d529d53 (diff)
downloadarching-kaos-tools-03a0fd66bd696a5cbf9cd91dde242df60e4a6f96.tar.gz
arching-kaos-tools-03a0fd66bd696a5cbf9cd91dde242df60e4a6f96.tar.bz2
arching-kaos-tools-03a0fd66bd696a5cbf9cd91dde242df60e4a6f96.zip
As far as I 've been
-rwxr-xr-xconfig.sh18
-rwxr-xr-xgetlatest.sh2
-rwxr-xr-xinit.sh36
-rwxr-xr-xinstall.sh37
-rwxr-xr-xipfs-check-install-setup-init-update57
-rwxr-xr-xipfs-starter2
-rwxr-xr-xpack_z_block111
7 files changed, 263 insertions, 0 deletions
diff --git a/config.sh b/config.sh
new file mode 100755
index 0000000..672b369
--- /dev/null
+++ b/config.sh
@@ -0,0 +1,18 @@
+export IPFS="$(which ipfs)"
+export ROOT=$HOME
+export WORKDIR="$ROOT/.arching-kaos"
+export CONFIGDIR="$WORKDIR/config"
+export BINDIR="$WORKDIR/bin"
+export ARCHIVESDIR="$WORKDIR/archives"
+export GENESIS="$CONFIGDIR/genesis"
+export GENESISASC="$CONFIGDIR/genesis.asc"
+export ZGENESIS="$CONFIGDIR/zgenesis"
+export ZGENESISASC="$CONFIGDIR/zgenesisasc"
+export ZCHAIN="$CONFIGDIR/zchain"
+export ZCHAINASC="$CONFIGDIR/zchain.asc"
+export ZZCHAIN="$CONFIGDIR/zzchain"
+export ZLIST="$WORKDIR/zlist"
+export ZLATEST="$WORKDIR/zlatest"
+export LOGSFILE="$WORKDIR/logs"
+export FINGERPRINT="$(gpg2 --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')"
+
diff --git a/getlatest.sh b/getlatest.sh
new file mode 100755
index 0000000..f28ffbe
--- /dev/null
+++ b/getlatest.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+ipfs files stat /ZLATEST | head -n 1
diff --git a/init.sh b/init.sh
new file mode 100755
index 0000000..3c9912b
--- /dev/null
+++ b/init.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#source ./config.sh
+echo "INIT started"
+#echo This is our work dir: $WORKDIR
+if [[ ! -d $WORKDIR ]] ; then mkdir $WORKDIR ;fi
+if [[ ! -d $CONFIGDIR ]] ; then mkdir $CONFIGDIR ;fi
+if [[ ! -d $BINDIR ]]; then mkdir $BINDIR ;fi
+if [[ ! -d $ARCHIVESDIR ]]; then mkdir $ARCHIVESDIR ;fi
+if [[ ! -f $GENESIS ]] ; then touch $GENESIS;fi
+if [[ ! -f $ZGENESIS ]] ; then echo "$(ipfs add -q $GENESIS)" > $ZGENESIS;fi
+if [[ ! -f $ZCHAIN ]] ; then echo "$(ipfs key gen zchain)" > $ZCHAIN;fi
+if [[ ! -f $ZLATEST ]] ; then cp $ZGENESIS $ZLATEST;fi
+if [[ ! -f $ZCHAINASC ]] ; then gpg2 -bao $ZCHAINASC $ZCHAIN;fi
+if [[ ! -f $ZZCHAIN ]] ; then echo $(ipfs add -q $ZCHAINASC) > $ZZCHAIN;fi
+if [[ ! -f $GENESISASC ]] ; then gpg2 -bao $GENESISASC $GENESIS;fi
+if [[ ! -f $ZGENESISASC ]] ; then echo $(ipfs add -q $GENESISASC) > $ZGENESISASC;fi
+ipfs files ls /zarchive > /dev/null 2>&1
+if [ $? != 0 ]; then
+ ipfs files mkdir /zarchive
+fi
+ipfs files stat /ZLATEST > /dev/null 2>&1
+if [ $? != 0 ]; then
+ ipfs files cp /ipfs/$(cat $ZGENESIS) /ZLATEST
+fi
+
+# TODO GPG/PGP setup
+# eg gpg2 --full-key-generate and/or gpg2 --set-default key
+# or just question the user if they are going to use their
+# existing one if any.
+
+
+
+# TODO The thing is done, we are sitting on a genesis.
+# We also have an IPNS name to use.
+
+
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..e2102b7
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+logthis(){
+ logger -t arching-kaos $1
+}
+HAK=".arching-kaos"
+logthis "Searching for $HAK folder and files"
+if [ ! -d $HOME/$HAK ]; then
+ mkdir $HOME/$HAK
+ logthis "$HAK created in $HOME";
+fi
+logthis "Searching for rc"
+if [ ! -f $HOME/$HAK/rc ]; then
+ echo export PATH=$PATH:$HOME/$HAK/bin > $HOME/$HAK/rc
+ cat config.sh >> $HOME/$HAK/rc
+ logthis "New rc export to file";
+fi
+logthis "Searching for shell"
+if [ $SHELL == "/usr/bin/zsh" ]; then
+ SHELLRC=".zshrc"
+ logthis "ZSH found";
+elif [ $SHELL == "/usr/bin/bash" ]; then
+ SHELLRC='.bashrc'
+ logthis "BASH found";
+else
+ logthis "Unknown shell... skipping installation"
+ exit;
+fi
+logthis "Searching if rc is already there"
+grep "source ~/$HAK/rc" $HOME/$SHELLRC > /dev/null 2>&1
+if [ $? == 0 ]; then
+ logthis "Already installed";
+else
+ echo "source ~/$HAK/rc" >> $HOME/$SHELLRC
+ logthis "$HAK installed at $HOME and sourced it in $SHELLRC";
+fi
+sh init.sh
+sh ipfs-check-install-setup-init-update
diff --git a/ipfs-check-install-setup-init-update b/ipfs-check-install-setup-init-update
new file mode 100755
index 0000000..28e2799
--- /dev/null
+++ b/ipfs-check-install-setup-init-update
@@ -0,0 +1,57 @@
+#!/bin/bash
+# I will be using journal for logs
+# To follow logs write
+# journalctl -f -t arching-kaos
+# Change to stdout easily:
+# cat ipfs-check-install-setup-init | sed -e 's/logthis(){//' | sed -e 's/.*logger.*$//' | sed -e 's/}//' | sed -e 's/\n\n\n//' | sed -e 's/logthis/echo/g' > ipfs-check-install-setup-init-logstdout
+# or whatever...
+
+logthis(){
+ logger -t arching-kaos $1
+}
+install(){
+ logthis "ipfs-check-install-setup-init"
+ IPFS_VERSION="$(curl https://github.com/ipfs/go-ipfs/releases/latest | sed -e 's/.*releases//g' | sed -e 's/".*//' | sed -e 's/\/tag\///')"
+ SWARMSHA512SUM="7001e37412758c43d372a969e977ca11511e034c8c1e233a58dc3ce1c6f3c1aa7d2da8cba9944a5eabaa8885742bfe6cc6794224c146b7129da8f633b53b9cfc"
+ IPFS_TARGET_FILE="go-ipfs_"$IPFS_VERSION"_linux-amd64.tar.gz"
+ AKBIN="$BINDIR"
+ AKAR="$ARCHIVESDIR"
+ if [ ! -d $AKAR ]; then
+ mkdir $AKAR
+ if [ $? != 0 ]; then
+ logthis "Problem creating directory"
+ exit 1;
+ fi
+ fi
+ logthis "Downloading ipfs $IPFS_VERSION"
+ if [ ! -f $AKAR/$IPFS_TARGET_FILE ]; then
+ wget -O $AKAR/$IPFS_TARGET_FILE https://dist.ipfs.io/go-ipfs/$IPFS_VERSION/$IPFS_TARGET_FILE ;
+ fi
+ logthis "Making temp files"
+ TIMESTAMP="$(date -u +%s)"
+ TEMPASSIN="/tmp/aktmp_$TIMESTAMP"
+ if [ ! -d $TEMPASSIN ]; then
+ mkdir $TEMPASSIN
+ cd $TEMPASSIN
+ tar xf $AKAR/$IPFS_TARGET_FILE
+ cp go-ipfs/ipfs $AKBIN
+ fi
+ logthis "ipfs installed on $AKBIN"
+ if [ ! -d $HOME/.ipfs ]; then
+ mkdir $HOME/.ipfs
+ $AKBIN/ipfs init ;
+ fi
+ if [ ! -f $HOME/.ipfs/swarm.key ]; then
+ wget -O $HOME/.ipfs/swarm.key https://arching-kaos.net/files/swarm.key ;
+ elif [ "$(sha512sum $HOME/.ipfs/swarm.key | awk '{ print $1 }')" == "$SWARMSHA512SUM" ]; then
+ logthis "Congrats! You are already in our swarm" ;
+ else
+ logthis "Error: Found swarm.key but not ours"
+ logthis "Visit https\:\/\/arching-kaos.net\/files\/swarm.key and copy it to your ipfs folder" ;
+ fi
+}
+which ipfs > /dev/null 2>&1
+if [ $? != 0 ]; then
+ install
+else logthis "Found IPFS"
+fi
diff --git a/ipfs-starter b/ipfs-starter
new file mode 100755
index 0000000..5cab1c3
--- /dev/null
+++ b/ipfs-starter
@@ -0,0 +1,2 @@
+#!/bin/bash
+screen -dmS ipfs-daemon ipfs daemon
diff --git a/pack_z_block b/pack_z_block
new file mode 100755
index 0000000..a323ddf
--- /dev/null
+++ b/pack_z_block
@@ -0,0 +1,111 @@
+#!/bin/bash
+# This file describe the structure of the ArchingKaos messages in their basis.
+#
+# As previously thought, we exchange one IPFS hash through whatever means we can.
+#
+# GPG is mentioned as a signing algorithm for encryption, decryption and signing.
+# Let's say we have a file named as `example`
+#
+# We can extend this with calling the encoder and further send the transaction
+#
+
+#FINGERPRINT="CHANGE THIS TO YOUR DEFAULT FINGERPRINT"
+# We acquire the GPG fingerprint by email address
+# The following example finds kaos@kaos.kaos' GPG fingerprint like this
+FINGERPRINT="$(gpg2 --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')"
+
+# Below, the usage information
+usage(){
+ echo "$0 - action data_file"
+ echo "Creates and publishes a ZBLOCK based on ACTION and DATA file."
+ echo ""
+ echo "action An action for the render to grasp"
+ echo "data_file A data file that according to the action is valid"
+}
+
+main(){
+
+ echo "We are doing" $ACTION "with content" $MESSAGE
+ # We add it to IPFS
+ MESSAGE_HASH=$(ipfs add -q $MESSAGE)
+
+ # We create a detached and armor signature of it
+ MESSAGE_SIGN_FILE=$MESSAGE".asc"
+ gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $MESSAGE_SIGN_FILE $MESSAGE
+
+ # We add the signature to IPFS
+ MESSAGE_SIGNATURE=$(ipfs add -q $MESSAGE_SIGN_FILE)
+
+ # We will be using our public key also to put it in the block later
+ KEY="gpg.pub"
+ gpg2 --armour --output $KEY --export $FINGERPRINT
+ GPG_PUB_KEY=$(ipfs add -q $KEY)
+
+ # Acquire last block of information, to chain this one with previous posted
+ PREVIOUS=$(ipfs files stat /ZLATEST | head -n 1)
+
+ # We create a block of json like this:
+ cat > block <<EOF
+{
+ "action":"$ACTION",
+ "data":"$MESSAGE_HASH",
+ "detach":"$MESSAGE_SIGNATURE",
+ "gpg":"$GPG_PUB_KEY",
+ "previous":"$PREVIOUS"
+}
+EOF
+ BLOCK="block"
+ BLOCK_SIG=$BLOCK".asc"
+ # We have a block now, so we sign it
+ gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $BLOCK_SIG $BLOCK
+
+ # We now add the signature to IPFS
+ BLOCK_SIGNATURE=$(ipfs add -q $BLOCK_SIG)
+
+ # We also add the block!
+ BLOCK=$(ipfs add -q $BLOCK)
+
+ # So we now do the think almost again
+ cat > zblock << EOF
+{
+ "block":"$BLOCK",
+ "block_signature":"$BLOCK_SIGNATURE"
+}
+EOF
+ ZBL="zblock"
+ # and we add it on IPFS
+ ZBLOCK=$(ipfs add -q $ZBL)
+ echo $ZBLOCK
+}
+
+title(){
+ echo "AK zblock creator from ACTION and FILE"
+ echo "======================================"
+}
+
+title
+if [ ! -z $2 ];
+then
+ PWD="$(pwd)"
+ MESSAGE="$PWD/$2"
+ ACTION="$1"
+ if [ -f "$MESSAGE" ]; then
+ main
+ else
+ echo "File does not exist. Aborting..."
+ usage
+ fi
+
+ # cat $PWD/zblock | json_pp
+ # Optional or extending with
+ # python send_as_ak_tx $ZBLOCK
+ # or for "offline" use
+ ipfs name publish --key=zchain $ZBLOCK
+ ipfs files mkdir /zarchive
+ ipfs files cp /ZLATEST /zarchive/$(date -u +%s)-$(head -n 1 $(ipfs files stat /ZLATEST))
+ ipfs files rm /ZLATEST
+ ipfs files cp /ipfs/$ZBLOCK /ZLATEST
+else
+ usage
+fi
+