From ba1173c9ec87b14a6ba6772d5ebfaafb81c7f888 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sun, 9 Jun 2024 06:52:03 +0300 Subject: Refactoring --- bin/ak | 2 +- bin/ak-config | 16 ++- bin/ak-ipfs-starter | 3 +- bin/ak-node-info | 14 +- bin/ak-profile | 6 +- bin/ak-startup | 14 +- lib/_ak_ipfs | 7 +- lib/_ak_node | 14 ++ modules/ak-articles | 139 ------------------- modules/ak-categories | 126 ----------------- modules/ak-comments | 105 -------------- modules/ak-files | 116 ---------------- modules/ak-folders | 89 ------------ modules/ak-mixtapes | 86 ------------ modules/ak-news | 317 ------------------------------------------- modules/ak-reference | 139 ------------------- modules/ak-repositories | 164 ---------------------- modules/ak-roadmap | 35 ----- modules/ak-todos | 134 ------------------ modules/articles/main.sh | 132 ++++++++++++++++++ modules/categories/main.sh | 126 +++++++++++++++++ modules/comments/main.sh | 105 ++++++++++++++ modules/files/main.sh | 116 ++++++++++++++++ modules/folders/main.sh | 89 ++++++++++++ modules/mixtapes/main.sh | 86 ++++++++++++ modules/news/main.sh | 317 +++++++++++++++++++++++++++++++++++++++++++ modules/reference/main.sh | 139 +++++++++++++++++++ modules/repositories/main.sh | 164 ++++++++++++++++++++++ modules/roadmap/main.sh | 35 +++++ modules/todos/main.sh | 134 ++++++++++++++++++ update.sh | 9 ++ 31 files changed, 1496 insertions(+), 1482 deletions(-) create mode 100755 lib/_ak_node delete mode 100755 modules/ak-articles delete mode 100755 modules/ak-categories delete mode 100755 modules/ak-comments delete mode 100755 modules/ak-files delete mode 100755 modules/ak-folders delete mode 100755 modules/ak-mixtapes delete mode 100755 modules/ak-news delete mode 100755 modules/ak-reference delete mode 100755 modules/ak-repositories delete mode 100755 modules/ak-roadmap delete mode 100755 modules/ak-todos create mode 100755 modules/articles/main.sh create mode 100755 modules/categories/main.sh create mode 100755 modules/comments/main.sh create mode 100755 modules/files/main.sh create mode 100755 modules/folders/main.sh create mode 100755 modules/mixtapes/main.sh create mode 100755 modules/news/main.sh create mode 100755 modules/reference/main.sh create mode 100755 modules/repositories/main.sh create mode 100755 modules/roadmap/main.sh create mode 100755 modules/todos/main.sh diff --git a/bin/ak b/bin/ak index c9f960e..539176a 100755 --- a/bin/ak +++ b/bin/ak @@ -64,7 +64,7 @@ case "$1" in exit 1 fi subargs="$*" - $subcmd $subargs + $subcmd/main.sh $subargs _ak_exit_program $? "$subcmd module finished"; ;; esac diff --git a/bin/ak-config b/bin/ak-config index 1655593..bda8564 100755 --- a/bin/ak-config +++ b/bin/ak-config @@ -17,6 +17,7 @@ descriptionString="Arching Kaos Configuration Tool" source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_gpg source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_node _ak_config_show(){ # We will be using our public key also to put it in the block later @@ -29,9 +30,9 @@ _ak_config_show(){ echo ' { "profile":'$profile', - "genesis":"'$(cat $HOME/.arching-kaos/config/zgenesis)'", + "genesis":"'$(cat $AK_WORKDIR/config/zgenesis)'", "gpg":"'$GPG_PUB_KEY'", - "zchain":"'$(cat $HOME/.arching-kaos/config/zchain)'", + "zchain":"'$(cat $AK_WORKDIR/config/zchain)'", "zlatest":"'$(ak-get-zlatest)'" }'| jq; } @@ -39,12 +40,12 @@ _ak_config_show(){ _ak_config_publish(){ _ak_config_show | jq -c -M > tmpfile _ak_ipfs key list | grep ak-config 2> /dev/null 1>&2 - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then - _ak_ipfs key gen ak-config + _ak_ipfs_key_gen ak-config fi _ak_ipfs_name_publish --key=ak-config /ipfs/$(_ak_ipfs_add tmpfile) - if [ "$?" != 0 ] + if [ $? != 0 ] then echo -e "\033[0;34mError on publishing\033[0;0m\nYour information:\n" cat tmpfile @@ -54,10 +55,11 @@ _ak_config_publish(){ } _ak_config_published(){ - _ak_ipfs_cat $(ak-node-info --ipfs) | jq + _ak_ipfs_cat $(_ak_node_info_ipfs_hash) | jq } -if [ ! -z $1 ]; then +if [ ! -z $1 ] && [ -n "$1" ] +then case $1 in --help| -h) _ak_usage;exit;; --show) _ak_config_show;exit;; diff --git a/bin/ak-ipfs-starter b/bin/ak-ipfs-starter index ae483f8..6b63c3c 100755 --- a/bin/ak-ipfs-starter +++ b/bin/ak-ipfs-starter @@ -2,8 +2,9 @@ PROGRAM="$(basename $0)" source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_ipfs -screen -dmS akipfsd ak-ipfs-daemon +screen -dmS akipfsd _ak_ipfs_daemon if [ $? -ne 0 ] then logit "ERROR" "Failed to start IPFS daemon" diff --git a/bin/ak-node-info b/bin/ak-node-info index b667fd3..42f6822 100755 --- a/bin/ak-node-info +++ b/bin/ak-node-info @@ -15,19 +15,7 @@ PROGRAM=$(basename $0) descriptionString="Quick description" source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -# Resolves the IPNS key "ak-config" to its current IPFS value -# Return IPFS CIDv0 without /ipfs/ prefix -_ak_node_info_ipfs_hash(){ - _ak_ipfs_name_resolve /ipns/$(_ak_node_info_ipns_key) | sed -e 's/\/ipfs\///' -} - -# Finds ak-config ipns key -# Returns IPNS key -_ak_node_info_ipns_key(){ - _ak_ipfs_key_list_full | grep ak-config | awk '{print $1}' -} - +source $AK_LIBDIR/_ak_node if [ ! -z "$1" ] then diff --git a/bin/ak-profile b/bin/ak-profile index d513c9a..2fab750 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -81,7 +81,7 @@ _ak_modules_profile_propget(){ fi } -propwrite(){ +_ak_modules_profile_propwrite(){ cat > $ZPROPERTY_FILE << EOF { "$ZPROPERTY_KEY":"${ZPROPERTY_VALUE}" @@ -113,7 +113,7 @@ _ak_modules_profile_propset(){ then touch $ZPROPERTY_FILE echo "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE" - propwrite #"$ZPROPERTY_FILE" "${ZPROPERTY_VALUE}" + _ak_modules_profile_propwrite #"$ZPROPERTY_FILE" "${ZPROPERTY_VALUE}" else echo "No value for $1" fi @@ -123,7 +123,7 @@ _ak_modules_profile_propset(){ ZPROPERTY_VALUE="$2" read -p "Overwrite $1 with ${ZPROPERTY_VALUE} ? " yn case $yn in - [Yy]* ) propwrite;;# "$ZPROPERTY_" "${ZPROPERTY_VALUE}";; + [Yy]* ) _ak_modules_profile_propwrite;;# "$ZPROPERTY_" "${ZPROPERTY_VALUE}";; [Nn]* ) exit 130;; * ) echo "Answer please";; esac diff --git a/bin/ak-startup b/bin/ak-startup index 7a67e58..87d1fe3 100755 --- a/bin/ak-startup +++ b/bin/ak-startup @@ -1,12 +1,14 @@ #!/bin/bash -PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:$HOME/bin:$HOME/.arching-kaos/bin -#screen -dmS ipfs-daemon ipfs daemon source $HOME/.arching-kaos/rc -ak-ipfs-starter -ak-log-rotate -# screen -dmS akdaemon +PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:$HOME/bin:$AK_WORKDIR/bin + +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_log +_ak_ipfs_starter +_ak_log_rotate + ak-daemon > $AK_WORKDIR/akd.log 2>&1 & printf '%s' "$!" > $AK_WORKDIR/akd.pid if [ ! -z $1 ] && [ -n "$1" ] && [ "$1" == "--podman" ] then - ak log follow + _ak_log_follow fi diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs index 8780f51..1f2b5ce 100755 --- a/lib/_ak_ipfs +++ b/lib/_ak_ipfs @@ -6,6 +6,11 @@ _ak_ipfs(){ export IPFS_PATH=$AK_IPFS_REPO; ipfs $* } +_ak_ipfs_daemon(){ + _ak_ipfs daemon --routing=dht --migrate & + printf '%s' "$!" > $AK_WORKDIR/akipfsd.pid +} + _ak_ipfs_get_peers(){ _ak_ipfs swarm peers 1> /dev/null 2>&1 if [ $? == 0 ] @@ -288,7 +293,7 @@ _ak_ipfs_swarm_peers(){ } _ak_ipfs_starter(){ - _ak_ipfs daemon --routing=dht --migrate + _ak_ipfs_daemon if [ $? -ne 0 ] then logit "ERROR" "Failed to start IPFS daemon" diff --git a/lib/_ak_node b/lib/_ak_node new file mode 100755 index 0000000..c1436d9 --- /dev/null +++ b/lib/_ak_node @@ -0,0 +1,14 @@ +#!/bin/bash +source $AK_LIBDIR/_ak_ipfs + +# Resolves the IPNS key "ak-config" to its current IPFS value +# Return IPFS CIDv0 without /ipfs/ prefix +_ak_node_info_ipfs_hash(){ + _ak_ipfs_name_resolve /ipns/$(_ak_node_info_ipns_key) | sed -e 's/\/ipfs\///' +} + +# Finds ak-config ipns key +# Returns IPNS key +_ak_node_info_ipns_key(){ + _ak_ipfs_key_list_full | grep ak-config | awk '{print $1}' +} diff --git a/modules/ak-articles b/modules/ak-articles deleted file mode 100755 index 97a8e8d..0000000 --- a/modules/ak-articles +++ /dev/null @@ -1,139 +0,0 @@ -#!/bin/bash -## -## -h, --help Prints this help message -## index Prints an indexed table of your articles files -## import TODO -## add Creates a data file from the articles file you point to -## create Vim is going to pop up, you will write and save your -## articlesletter and it's going to be saved -## -fullprogrampath="$(realpath $0)" -PROGRAM=$(basename $0) -descriptionString="Articles module for Arching Kaos" - -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock - -ZARTICLESDIR="$AK_WORKDIR/articles" -TEMP="/tmp/aktmp" -if [ ! -d $ZARTICLESDIR ]; then - mkdir $ZARTICLESDIR - cd $ZARTICLESDIR - #git init - echo "Articles repository" > README - echo "Qmetc" >> README - #git add README - #git commit -m "Initiated articles repository" - logit "INFO" "zarticlesdir created" -else - logit "INFO" "zarticlesdir found" -fi - -_ak_modules_articles_create(){ - TEMP="$(ak-tempassin)" - cd $TEMP - export ARTICLES_FILE="$(date +%Y%m%d_%H%M%S)" - if [ -z $EDITOR ] - then - logit "ERROR" "No $EDITOR found. Exiting..." - exit 1 - fi - $EDITOR $ARTICLES_FILE - logit "INFO" "Renaming..." - TITLE="$(head -n 1 $ARTICLES_FILE)" - TO_FILE=$ARTICLES_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(_ak_ipfs_add $ARTICLES_FILE) - mv $ARTICLES_FILE $ZARTICLESDIR/$TO_FILE - sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZARTICLESDIR/README - _ak_modules_articles_add $ZARTICLESDIR/$TO_FILE - logit "INFO" "Adding to git repo..." - cd $ZARTICLESDIR - # git add $TO_FILE README - # git commit -m "Added $TO_FILE with $(head -n 1 $ZARTICLESDIR/$TO_FILE)" - # git clean --force - rm -rf $TEMP -} -_ak_modules_articles_index(){ - FILES="$(ls -1 $ZARTICLESDIR)" - i=0 - for FILE in $FILES - do - DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $ZARTICLESDIR/$FILE) - echo $i \| $DATE \| $TITLE - let i+=1 - done -} -_ak_modules_articles_title(){ - description -} -_ak_modules_articles_import(){ - echo "#TODO" - if [ ! -z $1 ] - then - if [ ! -d $1 ] - then - echo "Folder does not exists" - exit 4 - else - echo "Folder $1 exists" - fl="$(ls -1 $1)" - for f in $fl - do - _ak_modules_articles_add $1/$f - done - fi - else - echo "No value" - exit 6 - fi - exit 224 -} -_ak_modules_articles_add(){ - TEMP="$(ak-tempassin)" - cd $TEMP - if [ -f $1 ]; then - FILE="$1" - echo "Adding articles from " $FILE - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) - FILE_SIGN_FILE=$FILE".asc" - _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) - cat > data < #TODO" -## -## add Creates a data file from the news file you point to" -## -## create Vim is going to pop up, you will write and save your" -## newsletter and it's going to be saved" -## -AK_CATEGORIES="$AK_WORKDIR/categories" -PROGRAM="$(basename $0)" -descriptionString="A module for adding and refering zblocks to categories" - -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock - -if [ ! -d $AK_CATEGORIES ]; then - mkdir $AK_CATEGORIES - cd $AK_CATEGORIES - logit "INFO" "AK_CATEGORIES created" -else - logit "INFO" "AK_CATEGORIES found" -fi - -_ak_modules_categories_create(){ - TEMP="$(ak-tempassin)" - cd $TEMP - export NEWS_FILE="$(date +%Y%m%d_%H%M%S)" - vi $NEWS_FILE - logit "INFO" "Renaming..." - TITLE="$(head -n 1 $NEWS_FILE)" - TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(_ak_ipfs_add $NEWS_FILE) - mv $NEWS_FILE $AK_CATEGORIES/$TO_FILE - sed -e 's,Qm.*,'"$IPFS_FILE"',g' $AK_CATEGORIES/README - _ak_modules_categories_add $AK_CATEGORIES/$TO_FILE - cd $AK_CATEGORIES -} -_ak_modules_categories_index(){ - FILES="$(ls -1 $AK_CATEGORIES)" - i=0 - for FILE in $FILES - do - DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $AK_CATEGORIES/$FILE) - echo $i \| $DATE \| $TITLE - let i+=1 - done -} - -_ak_modules_categories_import(){ - echo "#TODO" - if [ ! -z $1 ] - then - if [ ! -d $1 ] - then - logit "ERROR" "Folder does not exists" - exit 4 - else - logit "INFO" "Folder $1 exists" - fl="$(ls -1 $1)" - for f in $fl - do - _ak_modules_categories_add $1/$f - done - fi - else - logit "ERROR" "No value" - exit 6 - fi - exit 224 -} -_ak_modules_categories_add(){ - TEMP="$(ak-tempassin)" - cd $TEMP - if [ -f $1 ]; then - FILE="$1" - logit "INFO" "Adding news from " $FILE - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) - FILE_SIGN_FILE=$FILE".asc" - _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) - cat > data < Creates a data file from the comments file you point to" -## -## create Vim is going to pop up, you will write and save your" -## commentsletter and it's going to be saved" -## -fullprogrampath="$(realpath $0)" -PROGRAM="$(basename $0)" -descriptionString="Comments module for Arching Kaos" - -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock - -ZCOMMENTSDIR="$AK_WORKDIR/comments" -TEMP="/tmp/aktmp" -if [ ! -d $ZCOMMENTSDIR ]; then - mkdir $ZCOMMENTSDIR - cd $ZCOMMENTSDIR - logit "INFO" "zcommentsdir created" -else - logit "INFO" "zcommentsdir found" -fi - -_ak_modules_comments_create(){ - if [ ! -z $1 ] - then - REFER_TO="$1" - else - logit "ERROR" "No reference given" - echo "ERROR" "No reference given" - exit 1 - fi - TEMP="$(ak-tempassin)" - cd $TEMP - export COMMENTS_FILE="$(date -u +%s)" - vi $COMMENTS_FILE - echo "Renaming..." - TO_FILE=$COMMENTS_FILE - IPFS_FILE=$(_ak_ipfs_add $COMMENTS_FILE) - mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE - _ak_modules_comments_add $TO_FILE - logit "INFO" "Adding to git repo..." - cd $ZCOMMENTSDIR - if [ ! -z $REFER_TO ] - then - ak-reference create $REFERENCE $REFER_TO - fi -} - -_ak_modules_comments_index(){ - FILES="$(ls -1 $ZCOMMENTSDIR)" - i=0 - for FILE in $FILES - do - DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $ZCOMMENTSDIR/$FILE) - echo $i \| $DATE \| $TITLE - let i+=1 - done -} - -_ak_modules_comments_add(){ - TEMP="$(ak-tempassin)" - cd $TEMP - if [ -f "$ZCOMMENTSDIR/$1" ]; then - FILE=$ZCOMMENTSDIR/$1 - echo "Adding comments from " $FILE - DATETIME="$1" - FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) - FILE_SIGN_FILE=$FILE".asc" - _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) - printf '{"datetime":"%s","ipfs":"%s","detach":"%s"}' $DATETIME $FILE_IPFS_HASH $FILE_SIGNATURE > data - else - echo "File $FILE doesn't exist"; - exit 2 - fi - REFERENCE="$(_ak_zblock_pack "comments/add" $(pwd)/data)" - if [ $? == 0 ] - then - echo "Comment added successfully" - else - echo "error??" - exit 1 - fi -} - -if [ ! -z $1 ]; then - case $1 in - -h | --help) _ak_usage; exit;; - index) _ak_modules_comments_index; exit;; - add) _ak_modules_comments_add $2 $3; exit;; - create) _ak_modules_comments_create $2; exit;; - * ) _ak_usage;; - esac -else _ak_usage -fi diff --git a/modules/ak-files b/modules/ak-files deleted file mode 100755 index 73c8219..0000000 --- a/modules/ak-files +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash -## -## The following creates a files data message -## -## -h, --help Prints this help message -## -fullprogrampath="$(realpath $0)" -PROGRAM=$(basename $0) -descriptionString="Module for adding files" -ZFILESDIR="$AK_WORKDIR/files" -TEMP="/tmp/aktmp" -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock - -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 - git init -else - logit "INFO" "$ZFILESDIR found!" -fi - -_ak_modules_files_add(){ - CRP="$(pwd)" - FILENAME="$1" - main $FILENAME $CRP - cat $TEMPASSIN/data | jq -M -} -main(){ - FILENAME="$1" - CRP="$2" - echo "Adding $FILENAME" - logit "INFO" "Switching to tmp folder..." - TEMPASSIN="$(ak-tempassin)" - cd $TEMPASSIN - if [ $? == 0 ]; then - logit "INFO" "Success" - else - logit "ERROR" "Error with tmp folder" - exit 5 - fi - logit "INFO" "Copying $1 to $TEMPASSIN" - cp $2/$1 $TEMPASSIN/$1 - if [ $? == 0 ]; then - logit "INFO" "Copied successfully" - else - logit "ERROR" "Error copying..." - fi - - FILE="$TEMPASSIN/$1" - - logit "INFO" "Adding $FILE to IPFS..." - FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) - if [ $? == 0 ]; then - logit "INFO" "Added $FILE to IPFS" - else - logit "ERROR" "Error in adding the $FILE to IPFS" - fi - logit "INFO" "Signing..." - SIGN_FILE=$FILENAME".asc" - _ak_gpg_sign_detached $SIGN_FILE $FILE - if [ $? == 0 ]; then - logit "INFO" "Signed" - else - logit "ERROR" "Error while signing" - fi - - logit "INFO" "Adding signature to IPFS" - SIGNATURE=$(_ak_ipfs_add $TEMPASSIN/$SIGN_FILE) - if [ $? == 0 ]; then - logit "INFO" "Added" - else - logit "ERROR" "Error while adding" - fi - - cat > $TEMPASSIN/data < Try ak-folders add -## -fullprogrampath="$(realpath $0)" -PROGRAM="$(basename $0)" -descriptionString="Module for adding folders" -ZFOLDERSDIR="$AK_WORKDIR/folders" -TEMP="/tmp/aktmp" - -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_zblock - -if [ ! -d $ZFOLDERSDIR ]; then - mkdir $ZFOLDERSDIR - logit "ERROR" "error $ZFOLDERSDIR not found or/and could not be created" -else - logit "INFO" "Found $ZFOLDERSDIR" - exit 1 -fi -TEMPASSIN="$(ak-tempassin)" -cd $TEMPASSIN - - -_ak_modules_folders_add(){ - CRP="$(pwd)" - FOLDERNAME="$1" - _ak_modules_folders_main $FOLDERNAME $CRP - cat data | jq -M -} - -_ak_modules_folders_main(){ - FOLDERNAME="$1" - CRP="$2" - echo "Adding $FOLDERNAME" - logit "INFO" "Copying $1 to temporary folder" - cp -r $2/$1 $1 - if [ $? == 0 ]; then - logit "INFO" "Copied successfully" - else - logit "ERROR" "Error copying..." - fi - - FOLDER="$1" - - logit "INFO" "Adding $FOLDER to IPFS..." - FOLDER_IPFS_HASH=$(_ak_ipfs_add $FOLDER) - if [ $? == 0 ]; then - logit "INFO" "done" - else - logit "ERROR" "error" - fi - logit "WARNING" "Folders are not signing..." - - printf '{"timestamp":"%s","foldername":"%s","ipfs":"%s"}' $(date -u +%s) $FOLDERNAME $FOLDER_IPFS_HASH - - echo "Printing data..." - cat data - echo "Publishing..." - - _ak_zblock_pack folders/add $(pwd)/data - if [ $? == 0 ] - then - echo "cool" - else - echo "not?" - exit 2 - fi -} - -_ak_modules_folders_title(){ - echo "$PROGRAM - Folder block creator" -} - -if [ ! -z $1 ]; then - case $1 in - -h | --help) _ak_usage; exit;; - add) _ak_modules_folders_add $2; exit;; - *) _ak_usage; exit;; - esac -else _ak_usage -fi diff --git a/modules/ak-mixtapes b/modules/ak-mixtapes deleted file mode 100755 index 712bb54..0000000 --- a/modules/ak-mixtapes +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash -## -## The following creates a mixtape data message -## -## Usage: -## -## -a <file> Adds a file with tags artist and title -## -## -h , --help -## -## -s , --specs -## -# We can extend it by calling the _ak_zblock_pack.sh mixtape/add data ## ORIGINAL LINE -fullprogrampath="$(realpath $0)" -PROGRAM="$(basename $0)" -descriptionString="AK mixtape block creator" -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock - -_ak_modules_mixtapes_specs(){ - datetime_mask=$(printf '^[0-9]\{8\}_[0-9]\{6\}$' | xxd -p) - ipfs_mask=$(printf '^Qm[a-zA-Z0-9]\{44\}$' | xxd -p) - text_dash_underscore_space_mask=$(printf '^[a-zA-Z0-9][a-zA-Z0-9[:space:]\_]\{1,128\}$' | xxd -p -c 64) - echo ' - { - "datetime": "'$datetime_mask'", - "artist": "'$text_dash_underscore_space_mask'", - "title": "'$text_dash_underscore_space_mask'", - "ipfs": "'$ipfs_mask'", - "detach": "'$ipfs_mask'" - }' | jq -} - -_ak_modules_mixtapes_add(){ - if [ ! -z $3 ]; - then - echo $1 - PWD="$(pwd)" - MIXTAPE_ARTIST="$1" - MIXTAPE_TITLE="$2" - MIXTAPE_FILE="$PWD/$3" - _ak_modules_mixtapes_main $1 - cat $PWD/data | jq -M - _ak_zblock_pack mixtape/add $PWD/data - fi -} - -_ak_modules_mixtapes_main(){ - echo $MIXTAPE_FILE "by" $MIXTAPE_ARTIST "named as" $MIXTAPE_TITLE - - MIXTAPE_IPFS_HASH=$(_ak_ipfs_add $MIXTAPE_FILE) - - MIXTAPE_SIGN_FILE=$MIXTAPE_FILE".asc" - _ak_gpg_sign_detached $MIXTAPE_SIGN_FILE $MIXTAPE_FILE - - MIXTAPE_SIGNATURE=$(_ak_ipfs_add $MIXTAPE_SIGN_FILE) - - cat > data <<EOF -{ - "timestamp":"$(date -u +%s)", - "artist":"$MIXTAPE_ARTIST", - "title":"$MIXTAPE_TITLE", - "ipfs":"$MIXTAPE_IPFS_HASH", - "detach":"$MIXTAPE_SIGNATURE" -} -EOF - -} - -if [ ! -z $1 ]; then - case $1 in - -h | --help) _ak_usage; exit;; - -l | --local-index) _ak_modules_mixtapes_index; exit;; - -i | --import) _ak_modules_mixtapes_import $2; exit;; - -a | --add) _ak_modules_mixtapes_add_from_file $2 $3 $4; exit;; - -c | --create) _ak_modules_mixtapes_create; exit;; - -r | --read) _ak_modules_mixtapes_read $2; exit;; - -s | --specs) _ak_modules_mixtapes_specs $2; exit;; - -x | --html) _ak_modules_mixtapes_html $2; exit;; - * ) _ak_usage;; - esac -else _ak_usage -fi diff --git a/modules/ak-news b/modules/ak-news deleted file mode 100755 index b015bd6..0000000 --- a/modules/ak-news +++ /dev/null @@ -1,317 +0,0 @@ -#!/bin/bash -## -## -h, --help Prints this help message -## -## -l, --local-index Prints an indexed table of your news files -## -## -i, --import <file> TODO -## -## -a, --add <file> Creates a data file from the news file you -## point to -## -## -r, --read <zblock> Reads a zblock as a news data -## -## -c, --create Vim is going to pop up, you will write and -## save your newsletter and it's going to bei -## saved -## -## -s, --specs Print specs of data block -## -## -x, --html <zblock> Returns an appropriate html element from a -## NEWS zblock -## -fullprogrampath="$(realpath $0)" -PROGRAM=$(basename $0) -descriptionString="Module to read, create and add zblocks" - -ZNEWSDIR="$AK_WORKDIR/news" -TEMP="/tmp/aktmp" - -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock -source $AK_LIBDIR/_ak_zchain - -if [ ! -d $ZNEWSDIR ]; then - mkdir $ZNEWSDIR - if [ $? -ne 0 ]; then - logit "ERROR" "$ZNEWSDIR couldn't be created" - exit 1 - fi - logit "INFO" "$ZNEWSDIR created" -else - logit "INFO" "$ZNEWSDIR found" -fi - -cd $ZNEWSDIR - -_ak_modules_news_create(){ - TEMP="$(ak-tempassin)" - cd $TEMP - cd - curpath="$(pwd)" - export NEWS_FILE="$(date +%Y%m%d_%H%M%S)" - vi $NEWS_FILE - echo "Renaming..." - TITLE="$(head -n 1 $NEWS_FILE)" - TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(_ak_ipfs_add $NEWS_FILE) - mv $NEWS_FILE $ZNEWSDIR/$TO_FILE - sed -i -e 's,Qm.*,'"$IPFS_FILE"',g' $ZNEWSDIR/README - _ak_modules_news_add $TO_FILE - cd $ZNEWSDIR - # rm -rf $TEMP -} - -_ak_modules_news_index(){ - FILES="$(ls -1 $ZNEWSDIR)" - i=0 - _ak_zchain_extract_cids | sort | uniq > temp - for FILE in $FILES - do - DATE="$(echo $FILE | cut -d - -f 1 | awk '{print $1}')" - TITLE="$(head -n 1 $ZNEWSDIR/$FILE)" - IPFS_HASH="$(ipfs add -nQ $ZNEWSDIR/$FILE)" - ONLINE="offzchain" - grep "$IPFS_HASH" temp > /dev/null 2>&1 - if [ $? -eq 0 ] - then - ONLINE="on-zchain" - fi - printf "%3d | %5s | %52s | %10s | %56s \n"\ - "$i" "$ONLINE" "$IPFS_HASH" "$DATE" "$TITLE" - let i+=1 - done - rm temp -} - -_ak_modules_news_import(){ - echo "#TODO" - if [ ! -z $1 ] - then - if [ ! -d "$1" ] - then - echo $1 - echo "Folder does not exist" - exit 4 - else - echo "Folder $1 exists" - fl="$(ls -1 $1)" - for f in $fl - do - echo $1 $f - _ak_modules_news_add_from_file "$1/$f" - done - fi - else - echo "No value" - exit 6 - fi - exit 224 -} - -_ak_modules_news_add_from_file(){ - TEMP="$(ak-tempassin)" - if [ -f "$1" ]; then - FILE="$(realpath $1)" - cp $FILE $ZNEWSDIR - cp $FILE $TEMP - FILE="$(basename $1)" - cd $TEMP - logit "INFO" "Adding news from " $FILE - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) - FILE_SIGN_FILE=$FILE".asc" - _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) - cat > data <<EOF -{ - "datetime":"$DATETIME", - "title":"$TITLE", - "filename":"$(basename $FILE)", - "ipfs":"$FILE_IPFS_HASH", - "detach":"$FILE_SIGNATURE" -} -EOF - else - logit "ERROR" "File $FILE doesn't exist"; - exit 2 - fi - _ak_zblock_pack "news/add" $(pwd)/data - if [ $? == 0 ] - then - logit "INFO" "News added successfully" - else - logit "ERROR" "Failed to pack zblock" - exit 1 - fi - rm -rf $TEMP -} - -_ak_modules_news_add(){ - TEMP="$(ak-tempassin)" - cd $TEMP - if [ -f $ZNEWSDIR/$1 ]; then - FILE="$1" - logit "INFO" "Adding news from " $FILE - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $ZNEWSDIR/$FILE) - FILE_IPFS_HASH=$(_ak_ipfs_add $ZNEWSDIR/$FILE) - FILE_SIGN_FILE=$FILE".asc" - _ak_gpg_sign_detached $FILE_SIGN_FILE $ZNEWSDIR/$FILE - FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) - cat > data <<EOF -{ - "datetime":"$DATETIME", - "title":"$TITLE", - "filename":"$FILE", - "ipfs":"$FILE_IPFS_HASH", - "detach":"$FILE_SIGNATURE" -} -EOF - else - logit "ERROR" "File $1 doesn't exist"; - exit 2 - fi - _ak_zblock_pack "news/add" $(pwd)/data - if [ $? == 0 ] - then - logit "INFO" "News added successfully" - else - logit "ERROR" "error??" - exit 1 - fi -} - -_ak_modules_news_read(){ - ak-enter -l 1 $1 > temp - if [ $? -ne 0 ] - then - echo error - exit 22 - fi - module="`cat temp | jq -r '.[].module'`" - action="`cat temp | jq -r '.[].action'`" - data="`cat temp | jq -r '.[].data'`" - linkToText="`cat temp | jq -r ".[].$data.ipfs"`" - - if [ "$module" == "news" ] && [ "$action" == "add" ] - then - - _ak_ipfs_cat $linkToText - else - logit "ERROR" "Not a news block." - echo "ERROR Not a news block." - exit 1 - fi - rm temp -} - -_ak_modules_news_html(){ - ak-enter -l 1 $1 > temp - if [ $? -ne 0 ] - then - logit "ERROR" "Failed to retrieve zblock $1" - exit 22 - fi - module="`cat temp | jq -r '.[].module'`" - action="`cat temp | jq -r '.[].action'`" - data="`cat temp | jq -r '.[].data'`" - linkToText="`cat temp | jq -r ".[].$data.ipfs"`" - zfilename="`cat temp | jq -r ".[].$data.filename"`" - ztitle="`cat temp | jq -r ".[].$data.title"`" - zdatetime="`cat temp | jq -r ".[].$data.datetime"`" - - if [ "$module" == "news" ] && [ "$action" == "add" ] - then - echo "<table>" - echo " <tr>" - echo " <td>" - echo " <pre>⌚ Date/Time</pre>" - echo " </td>" - echo " <td>" - echo " <pre>$zdatetime</pre>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>✍️ Title</pre>" - echo " </td>" - echo " <td>" - echo " <pre>$ztitle</pre>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>📄 Filename</pre>" - echo " </td>" - echo " <td>" - echo " <pre>$zfilename</pre>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>📄 Content</pre>" - echo " </td>" - echo " <td>" - echo " <style>" - echo " .body * {" - echo " border: 0;" - echo " margin: 0;" - echo " padding: 0;" - echo " }" - echo " .body a {" - echo " color: #042746;" - echo " background-color: lightyellow;" - echo " border: 0;" - echo " margin: 0;" - echo " padding: 0;" - echo " }" - echo " .body p {" - echo " border: 0;" - echo " margin: 0;" - echo " padding: 1vh 1vw;" - echo " }" - echo " </style>" - _ak_ipfs_cat $linkToText | txt2tags -t html -H --infile=- --outfile=- - echo " </td>" - echo " </tr>" - echo '</table>' - else - logit "ERROR" "Not a news block." - exit 1 - fi - rm temp -} - -_ak_modules_news_specs(){ - datetime_mask=$(printf '^[0-9]\{8\}_[0-9]\{6\}$' | xxd -p) - ipfs_mask=$(printf '^Qm[a-zA-Z0-9]\{44\}$' | xxd -p) - text_mask=$(printf '^[a-zA-Z0-9_\-]\{1,128\}$' | xxd -p) - echo ' - { - "datetime":"'$datetime_mask'", - "title": "'$text_mask'", - "filename": "'$text_mask'", - "ipfs": "'$ipfs_mask'", - "detach": "'$ipfs_mask'" - }' | jq -} - -if [ ! -z $1 ]; then - case $1 in - -h | --help) _ak_usage; exit;; - -l | --local-index) _ak_modules_news_index; exit;; - -i | --import) _ak_modules_news_import $2; exit;; - -a | --add) _ak_modules_news_add_from_file $2; exit;; - -c | --create) _ak_modules_news_create; exit;; - -r | --read) _ak_modules_news_read $2; exit;; - -s | --specs) _ak_modules_news_specs $2; exit;; - -x | --html) _ak_modules_news_html $2; exit;; - * ) _ak_usage;; - esac -else _ak_usage -fi diff --git a/modules/ak-reference b/modules/ak-reference deleted file mode 100755 index 157b797..0000000 --- a/modules/ak-reference +++ /dev/null @@ -1,139 +0,0 @@ -#!/bin/bash -## #TODO -## All you need to know is that there are two options available: -## -h, --help Prints this help message -## index Prints an indexed table of your references files -## import <file> #TODO -## add <file> Creates a data file from the references file you point to -## create [ref] [to] Vim is going to pop up, you will write and save your -## referencesletter and it's going to be saved -fullprogrampath="$(realpath $0)" -PROGRAM=$(basename $0) -descriptionString="Quick description" - - -ZREFERENCESDIR="$AK_WORKDIR/references" -TEMP="/tmp/aktmp" - -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock - -if [ ! -d $ZREFERENCESDIR ]; then - mkdir $ZREFERENCESDIR - cd $ZREFERENCESDIR - logit "INFO" "zreferencesdir created" -else - logit "INFO" "zreferencesdir found" -fi - -_ak_modules_reference_create(){ - TEMP="$(ak-tempassin)" - cd $TEMP - export REFERENCEFILE="$(date -u +%s)" - if [ ! -z $1 ] && [ ! -z $2 ] - then - TO_FILE="$(date -u +%s)-$1-$2" - cat > $REFERENCEFILE << EOF -$1 -$2 -EOF - - else - vi $REFERENCEFILE - fi - REFERENCE="$(head -n 1 $REFERENCEFILE)" - REFER_TO="$(tail -n 1 $REFERENCEFILE)" - TO_FILE="$REFERENCEFILE-$REFERENCE-$REFER_TO" - mv $REFERENCEFILE $ZREFERENCESDIR/$TO_FILE - echo $TO_FILE - IPFS_FILE=$(_ak_ipfs_add $ZREFERENCESDIR/$TO_FILE) - sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZREFERENCESDIR/README - _ak_modules_reference_add $ZREFERENCESDIR/$TO_FILE - cd $ZREFERENCESDIR -} - -_ak_modules_reference_index(){ - FILES="$(ls -1 $ZREFERENCESDIR)" - i=0 - for FILE in $FILES - do - DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $ZREFERENCESDIR/$FILE) - REFE=$(tail -n 1 $ZREFERENCESDIR/$FILE) - echo $i \| $DATE \| $TITLE \| $REFE - let i+=1 - done -} - -_ak_modules_reference_import(){ - echo "#TODO" - if [ ! -z $1 ] - then - if [ ! -d $1 ] - then - echo "Folder does not exists" - exit 4 - else - echo "Folder $1 exists" - fl="$(ls -1 $1)" - for f in $fl - do - _ak_modules_reference_add $1/$f - done - fi - else - echo "No value" - exit 6 - fi - exit 224 -} - -_ak_modules_reference_add(){ - TEMP="$(ak-tempassin)" - cd $TEMP - if [ ! -f $1 ]; then - echo "File $FILE doesn't exist"; - exit 2 - fi - FILE="$1" - echo "Adding references from " $FILE - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) - FILE_SIGN_FILE=$FILE".asc" - _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) - cat > data <<EOF -{ - "datetime":"$(date -u +%s)", - "reference":"$REFERENCE", - "refer_to":"$REFER_TO", - "ipfs":"$FILE_IPFS_HASH", - "detach":"$FILE_SIGNATURE" -} -EOF - cat data | jq -M -c > tmp - cat tmp > data - rm tmp - _ak_zblock_pack "references/add" $(pwd)/data - if [ $? != 0 ] - then - echo "error??" - exit 1 - fi - echo "References added successfully" -} - -if [ ! -z $1 ]; then - case $1 in - -h | --help) _ak_usage; exit;; - index) _ak_modules_reference_index; exit;; - import) _ak_modules_reference_import $2; exit;; - add) _ak_modules_reference_add $2; exit;; - create) _ak_modules_reference_create $2 $3; exit;; - * ) _ak_usage;; - esac -else _ak_usage -fi diff --git a/modules/ak-repositories b/modules/ak-repositories deleted file mode 100755 index ffda701..0000000 --- a/modules/ak-repositories +++ /dev/null @@ -1,164 +0,0 @@ -#!/bin/bash -source $AK_LIBDIR/_ak_zblock -REPODIR="$HOME/projects" -BAREDIR="$HOME/bare" -REPOSTORE="$HOME/.arching-kaos/repostore" -if [ ! -d $BAREDIR ]; then mkdir $BAREDIR; fi -if [ ! -d $REPODIR ]; then echo "no $REPODIR" && exit; fi -if [ ! -f $REPOSTORE ]; then touch $REPOSTORE; fi -import(){ - REPOS="$(ls -1 $REPODIR)" - for PROJECT in $REPOS - do - cd $BAREDIR - # Can be as well be - # git clone --bare $REPODIR/$PROJECT/.git - # or whatever form git let's you use - git clone --bare http://git.h.kaotisk-hund.com/$PROJECT/.git - if [ $? == 0 ] - then - cd $PROJECT.git - git repack -a - IPFS="$(_ak_ipfs_add .)" - _ak_ipfs_key_gen "$PROJECT.git" - _ak_ipfs_name_publish --key="$PROJECT.git" /ipfs/$IPFS - cd $HOME/bare - else - echo "$PROJECT not a git repo" - fi - done -} - -update(){ - if [ ! -z $1 ] - then - USING="$1" - REPO="$REPODIR/$1/.git" - BARE="$BAREDIR/$1.git" - BARENAME="$1.git" - if [ -d $BARE ] - then - cd $BARE - git pull - git repack -a - IPFS="$(_ak_ipfs_add .)" - _ak_ipfs_name_publish --key="$BARENAME" /ipfs/$IPFS - echo "DONE" - else - echo "NO BARE TO UPDATE" - echo "updating all..." - fi - else - BARES="$(ls -1 $BAREDIR)" - cd $BAREDIR - for PROJECT in $BARES - do - cd "$PROJECT" - git pull - git repack -a - IPFS="$(_ak_ipfs_add .)" - _ak_ipfs_name_publish --key="$PROJECT" /ipfs/$IPFS - cd $BAREDIR - done - fi -} - -append-if-needed(){ - under="$1" - file="$HOME/.arching-kaos/repos" - lines="$(cat $file)" - found="no" - for line in $lines - do - if [ $found == "yes" ] - then - echo "found $found" - break - else - if [ "$line" == "$under" ] - then - found="yes" - echo "found $found" - break - fi - fi - done - if [ $found == "no" ] - then - echo $under > $file - fi -} - -add(){ - PROJECT="$1" - PROJECTDIR="$REPODIR/$PROJECT" - BAREGITDIR="$BAREDIR/$PROJECT.git" - if [ -d $PROJECTDIR ] - then - cd $HOME/bare - git clone --bare $PROJECTDIR/.git - if [ $? == 0 ] - then - cd $BAREGITDIR - git repack -a - IPFS="$(_ak_ipfs_add .)" - try=_ak_ipfs_key_gen "$PROJECT.git" - if [ $? == 0 ] - then - _ak_ipfs_name_publish --key="$PROJECT.git" /ipfs/$IPFS - printf '{"project":"%s.git","ipns":"%s"}' $PROJECT $try > data - _ak_zblock_pack "repos/add" $PWD/data - echo "Done" - fi - fi - else - echo "$PROJECT not a git repo" - fi -} - -index(){ - _ak_ipfs_key_list_full | grep -e '\.git' -} - -set-as-profile(){ - IPFS=$(_ak_ipfs_add $REPOSTORE) - if [ $? == 0 ] - then - profile set repositories $IPFS - else - echo error - fi -} - -publish(){ - if [ ! -z $1 ] - then - echo "Filtering for $1..." - index | grep "$1" > $REPOSTORE - set-as-profile - else - echo "Publishing all..." - index > $REPOSTORE - set-as-profile - fi -} - -usage(){ - echo "-h, --help" - echo "index | add | publish | update" - exit -} - -if [ ! -z $1 ] -then - case $1 in - -h | --help) usage; exit;; - index) index; exit;; - add) add "$2"; exit;; - publish) publish "$2"; exit;; - update) update "$2"; exit;; - *) echo "No command $1";usage; exit;; - esac -else - usage -fi diff --git a/modules/ak-roadmap b/modules/ak-roadmap deleted file mode 100755 index a30894a..0000000 --- a/modules/ak-roadmap +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -echo "$(basename $0) - Not implemented" -exit 1 - -title(){ - echo "AK Roadmap tool" -} - -usage(){ - title -} - -search(){ - cd $HOME/projects - PRJS="$(ls -1 .)" - for prj in $PRJS - do - if [ -f $prj/ROADMAP.md ]; - then - echo " - Roadmap found in $prj" - fi - done -} - -if [ ! -z $1 ]; -then - case $1 in - -h | --help) usage; exit;; - search) search; exit;; - *) usage; exit;; - esac -else - usage - exit 0 -fi diff --git a/modules/ak-todos b/modules/ak-todos deleted file mode 100755 index afe56f8..0000000 --- a/modules/ak-todos +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/bash -## -## Brief description -## -## Usage: -## -## -h, --help Prints this help message -## -## index Prints an indexed table of your todos files -## -## import <file> #TODO -## -## add <file> Creates a data file from the todos file you point to -## -## create Vim is going to pop up, you will write and save your -## todosletter and it's going to be saved -## -fullprogrampath="$(realpath $0)" -PROGRAM=$(basename $0) -descriptionString="Quick description" -PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_zblock - -ZTODOSDIR="$AK_WORKDIR/todos" -TEMP="/tmp/aktmp" -if [ ! -d $ZTODOSDIR ]; then - mkdir $ZTODOSDIR - cd $ZTODOSDIR - logit "INFO" "ztodosdir created along with git repo" -else - logit "INFO" "ztodosdir found" -fi - -_ak_modules_todos_create(){ - TEMP="$(ak-tempassin)" - cd $TEMP - export TODOS_FILE="$(date -u +%s)" - vi $TODOS_FILE - logit "INFO" "Renaming..." - TITLE="$(head -n 1 $TODOS_FILE)" - TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(_ak_ipfs_add $TODOS_FILE) - mv $TODOS_FILE $ZTODOSDIR/$TO_FILE - _ak_modules_todos_add $ZTODOSDIR/$TO_FILE - logit "INFO" "Adding to git repo..." - cd $ZTODOSDIR - # rm -rf $TEMP -} - -_ak_modules_todos_index(){ - FILES="$(ls -1 $ZTODOSDIR)" - i=0 - for FILE in $FILES - do - DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $ZTODOSDIR/$FILE) - echo $i \| $DATE \| $TITLE - let i+=1 - done -} - -_ak_modules_todos_import(){ - echo "#TODO" - if [ ! -z $1 ] - then - if [ ! -d $1 ] - then - echo "Folder does not exists" - exit 4 - else - echo "Folder $1 exists" - fl="$(ls -1 $1)" - for f in $fl - do - _ak_modules_todos_add $1/$f - done - fi - else - echo "No value" - exit 6 - fi - exit 224 -} - -_ak_modules_todos_add(){ - TEMP="$(ak-tempassin)" - cd $TEMP - if [ -f $1 ]; then - FILE="$1" - logit "INFO" "Adding todos from $FILE" - DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') - TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) - FILE_SIGN_FILE=$FILE".asc" - _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) - cat > data <<EOF -{ - "datetime":"$TODOS_FILE", - "title":"$TITLE", - "filename":"$FILE", - "ipfs":"$FILE_IPFS_HASH", - "detach":"$FILE_SIGNATURE" -} -EOF - else - logit "ERROR" "File $FILE doesn't exist"; - exit 2 - fi - _ak_zblock_pack "todos/add" $(pwd)/data - if [ $? == 0 ] - then - logit "INFO" "Todos added successfully" - else - logit "ERROR" "error?? _ak_zblock_pack failed" - exit 1 - fi -} - -if [ ! -z $1 ]; then - case $1 in - -h | --help) _ak_usage; exit;; - index) _ak_modules_todos_index; exit;; - import) _ak_modules_todos_import $2; exit;; - add) _ak_modules_todos_add $2; exit;; - create) _ak_modules_todos_create; exit;; - * ) _ak_usage;; - esac -else _ak_usage -fi diff --git a/modules/articles/main.sh b/modules/articles/main.sh new file mode 100755 index 0000000..382466b --- /dev/null +++ b/modules/articles/main.sh @@ -0,0 +1,132 @@ +#!/bin/bash +## +## -h, --help Prints this help message +## index Prints an indexed table of your articles files +## import <file> TODO +## add <file> Creates a data file from the articles file you point to +## create Vim is going to pop up, you will write and save your +## articlesletter and it's going to be saved +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Articles module for Arching Kaos" + +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_zblock + +ZARTICLESDIR="$AK_WORKDIR/articles" +TEMP="/tmp/aktmp" +if [ ! -d $ZARTICLESDIR ]; then + mkdir $ZARTICLESDIR + cd $ZARTICLESDIR + logit "INFO" "zarticlesdir created" +else + logit "INFO" "zarticlesdir found" +fi + +_ak_modules_articles_create(){ + TEMP="$(ak-tempassin)" + cd $TEMP + export ARTICLES_FILE="$(date +%Y%m%d_%H%M%S)" + if [ -z $EDITOR ] + then + logit "ERROR" "No $EDITOR found. Exiting..." + exit 1 + fi + $EDITOR $ARTICLES_FILE + logit "INFO" "Renaming..." + TITLE="$(head -n 1 $ARTICLES_FILE)" + TO_FILE=$ARTICLES_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) + IPFS_FILE=$(_ak_ipfs_add $ARTICLES_FILE) + mv $ARTICLES_FILE $ZARTICLESDIR/$TO_FILE + sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZARTICLESDIR/README + _ak_modules_articles_add $ZARTICLESDIR/$TO_FILE + logit "INFO" "Adding to git repo..." + cd $ZARTICLESDIR + rm -rf $TEMP +} + +_ak_modules_articles_index(){ + FILES="$(ls -1 $ZARTICLESDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZARTICLESDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done +} + +_ak_modules_articles_import(){ + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + echo "Folder does not exists" + exit 4 + else + echo "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + _ak_modules_articles_add $1/$f + done + fi + else + echo "No value" + exit 6 + fi + exit 224 +} + +_ak_modules_articles_add(){ + TEMP="$(ak-tempassin)" + cd $TEMP + if [ -f $1 ]; then + FILE="$1" + echo "Adding articles from " $FILE + DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $FILE) + FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) + FILE_SIGN_FILE=$FILE".asc" + _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE + FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) + cat > data <<EOF +{ + "datetime":"$DATETIME", + "title":"$TITLE", + "filename":"$FILE", + "ipfs":"$FILE_IPFS_HASH", + "detach":"$FILE_SIGNATURE" +} +EOF + else + echo "File $FILE doesn't exist"; + exit 2 + fi + _ak_zblock_pack "articles/add" $(pwd)/data + if [ $? == 0 ] + then + echo "Articles added successfully" + else + echo "error??" + exit 1 + fi +} + +if [ ! -z $1 ]; then + case $1 in + -h | --help) _ak_usage; exit;; + index) _ak_modules_articles_index; exit;; + import) _ak_modules_articles_import $2; exit;; + add) _ak_modules_articles_add $2; exit;; + create) _ak_modules_articles_create; exit;; + * ) _ak_usage;; + esac +else _ak_usage +fi diff --git a/modules/categories/main.sh b/modules/categories/main.sh new file mode 100755 index 0000000..c0e1e77 --- /dev/null +++ b/modules/categories/main.sh @@ -0,0 +1,126 @@ +#!/bin/bash +## +## -h, --help Prints this help message" +## +## index Prints an indexed table of your news files" +## +## import <file> #TODO" +## +## add <file> Creates a data file from the news file you point to" +## +## create Vim is going to pop up, you will write and save your" +## newsletter and it's going to be saved" +## +AK_CATEGORIES="$AK_WORKDIR/categories" +PROGRAM="$(basename $0)" +descriptionString="A module for adding and refering zblocks to categories" + +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_zblock + +if [ ! -d $AK_CATEGORIES ]; then + mkdir $AK_CATEGORIES + cd $AK_CATEGORIES + logit "INFO" "AK_CATEGORIES created" +else + logit "INFO" "AK_CATEGORIES found" +fi + +_ak_modules_categories_create(){ + TEMP="$(ak-tempassin)" + cd $TEMP + export NEWS_FILE="$(date +%Y%m%d_%H%M%S)" + vi $NEWS_FILE + logit "INFO" "Renaming..." + TITLE="$(head -n 1 $NEWS_FILE)" + TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) + IPFS_FILE=$(_ak_ipfs_add $NEWS_FILE) + mv $NEWS_FILE $AK_CATEGORIES/$TO_FILE + sed -e 's,Qm.*,'"$IPFS_FILE"',g' $AK_CATEGORIES/README + _ak_modules_categories_add $AK_CATEGORIES/$TO_FILE + cd $AK_CATEGORIES +} +_ak_modules_categories_index(){ + FILES="$(ls -1 $AK_CATEGORIES)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $AK_CATEGORIES/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done +} + +_ak_modules_categories_import(){ + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + logit "ERROR" "Folder does not exists" + exit 4 + else + logit "INFO" "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + _ak_modules_categories_add $1/$f + done + fi + else + logit "ERROR" "No value" + exit 6 + fi + exit 224 +} +_ak_modules_categories_add(){ + TEMP="$(ak-tempassin)" + cd $TEMP + if [ -f $1 ]; then + FILE="$1" + logit "INFO" "Adding news from " $FILE + DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $FILE) + FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) + FILE_SIGN_FILE=$FILE".asc" + _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE + FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) + cat > data <<EOF +{ + "datetime":"$DATETIME", + "title":"$TITLE", + "filename":"$FILE", + "ipfs":"$FILE_IPFS_HASH", + "detach":"$FILE_SIGNATURE" +} +EOF + else + logit "ERROR" "File $FILE doesn't exist"; + exit 2 + fi + _ak_zblock_pack "news/add" $(pwd)/data + if [ $? == 0 ] + then + logit "INFO" "News added successfully" + else + logit "ERROR" "error??" + exit 1 + fi +} + + +if [ ! -z $1 ]; then + case $1 in + -h | --help) _ak_usage; exit;; + index) _ak_modules_categories_index; exit;; + import) _ak_modules_categories_import $2; exit;; + add) _ak_modules_categories_add $2; exit;; + create) _ak_modules_categories_create; exit;; + * ) _ak_usage;; + esac +else _ak_usage +fi diff --git a/modules/comments/main.sh b/modules/comments/main.sh new file mode 100755 index 0000000..6193e2f --- /dev/null +++ b/modules/comments/main.sh @@ -0,0 +1,105 @@ +#!/bin/bash +## +## -h, --help Prints this help message" +## +## index Prints an indexed table of your comments files" +## +## add <file> <refer_to> Creates a data file from the comments file you point to" +## +## create <refer_to> Vim is going to pop up, you will write and save your" +## commentsletter and it's going to be saved" +## +fullprogrampath="$(realpath $0)" +PROGRAM="$(basename $0)" +descriptionString="Comments module for Arching Kaos" + +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_zblock + +ZCOMMENTSDIR="$AK_WORKDIR/comments" +TEMP="/tmp/aktmp" +if [ ! -d $ZCOMMENTSDIR ]; then + mkdir $ZCOMMENTSDIR + cd $ZCOMMENTSDIR + logit "INFO" "zcommentsdir created" +else + logit "INFO" "zcommentsdir found" +fi + +_ak_modules_comments_create(){ + if [ ! -z $1 ] + then + REFER_TO="$1" + else + logit "ERROR" "No reference given" + echo "ERROR" "No reference given" + exit 1 + fi + TEMP="$(ak-tempassin)" + cd $TEMP + export COMMENTS_FILE="$(date -u +%s)" + vi $COMMENTS_FILE + echo "Renaming..." + TO_FILE=$COMMENTS_FILE + IPFS_FILE=$(_ak_ipfs_add $COMMENTS_FILE) + mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE + _ak_modules_comments_add $TO_FILE + logit "INFO" "Adding to git repo..." + cd $ZCOMMENTSDIR + if [ ! -z $REFER_TO ] + then + ak-reference create $REFERENCE $REFER_TO + fi +} + +_ak_modules_comments_index(){ + FILES="$(ls -1 $ZCOMMENTSDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZCOMMENTSDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done +} + +_ak_modules_comments_add(){ + TEMP="$(ak-tempassin)" + cd $TEMP + if [ -f "$ZCOMMENTSDIR/$1" ]; then + FILE=$ZCOMMENTSDIR/$1 + echo "Adding comments from " $FILE + DATETIME="$1" + FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) + FILE_SIGN_FILE=$FILE".asc" + _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE + FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) + printf '{"datetime":"%s","ipfs":"%s","detach":"%s"}' $DATETIME $FILE_IPFS_HASH $FILE_SIGNATURE > data + else + echo "File $FILE doesn't exist"; + exit 2 + fi + REFERENCE="$(_ak_zblock_pack "comments/add" $(pwd)/data)" + if [ $? == 0 ] + then + echo "Comment added successfully" + else + echo "error??" + exit 1 + fi +} + +if [ ! -z $1 ]; then + case $1 in + -h | --help) _ak_usage; exit;; + index) _ak_modules_comments_index; exit;; + add) _ak_modules_comments_add $2 $3; exit;; + create) _ak_modules_comments_create $2; exit;; + * ) _ak_usage;; + esac +else _ak_usage +fi diff --git a/modules/files/main.sh b/modules/files/main.sh new file mode 100755 index 0000000..73c8219 --- /dev/null +++ b/modules/files/main.sh @@ -0,0 +1,116 @@ +#!/bin/bash +## +## The following creates a files data message +## +## -h, --help Prints this help message +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Module for adding files" +ZFILESDIR="$AK_WORKDIR/files" +TEMP="/tmp/aktmp" +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_zblock + +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 + git init +else + logit "INFO" "$ZFILESDIR found!" +fi + +_ak_modules_files_add(){ + CRP="$(pwd)" + FILENAME="$1" + main $FILENAME $CRP + cat $TEMPASSIN/data | jq -M +} +main(){ + FILENAME="$1" + CRP="$2" + echo "Adding $FILENAME" + logit "INFO" "Switching to tmp folder..." + TEMPASSIN="$(ak-tempassin)" + cd $TEMPASSIN + if [ $? == 0 ]; then + logit "INFO" "Success" + else + logit "ERROR" "Error with tmp folder" + exit 5 + fi + logit "INFO" "Copying $1 to $TEMPASSIN" + cp $2/$1 $TEMPASSIN/$1 + if [ $? == 0 ]; then + logit "INFO" "Copied successfully" + else + logit "ERROR" "Error copying..." + fi + + FILE="$TEMPASSIN/$1" + + logit "INFO" "Adding $FILE to IPFS..." + FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) + if [ $? == 0 ]; then + logit "INFO" "Added $FILE to IPFS" + else + logit "ERROR" "Error in adding the $FILE to IPFS" + fi + logit "INFO" "Signing..." + SIGN_FILE=$FILENAME".asc" + _ak_gpg_sign_detached $SIGN_FILE $FILE + if [ $? == 0 ]; then + logit "INFO" "Signed" + else + logit "ERROR" "Error while signing" + fi + + logit "INFO" "Adding signature to IPFS" + SIGNATURE=$(_ak_ipfs_add $TEMPASSIN/$SIGN_FILE) + if [ $? == 0 ]; then + logit "INFO" "Added" + else + logit "ERROR" "Error while adding" + fi + + cat > $TEMPASSIN/data <<EOF +{ + "timestamp":"$(date -u +%s)", + "filename":"$FILENAME", + "ipfs":"$FILE_IPFS_HASH", + "detach":"$SIGNATURE" +} +EOF + +echo "Printing data..." +cat $TEMPASSIN/data +echo "Publishing..." + + _ak_zblock_pack files/add $PWD/data + if [ $? == 0 ] + then + echo "cool" + else + echo "not?" + exit 2 + fi +} + +if [ ! -z $1 ]; then + case $1 in + -h | --help) _ak_usage; exit;; + add) _ak_modules_files_add $2; exit;; + *) _ak_usage; exit;; + esac +else _ak_usage +fi diff --git a/modules/folders/main.sh b/modules/folders/main.sh new file mode 100755 index 0000000..5aa82c7 --- /dev/null +++ b/modules/folders/main.sh @@ -0,0 +1,89 @@ +#!/bin/bash +## The following creates a folder data message +## +## +## -h, --help Prints this help message +## +## +## add <folder> Try ak-folders add <folder> +## +fullprogrampath="$(realpath $0)" +PROGRAM="$(basename $0)" +descriptionString="Module for adding folders" +ZFOLDERSDIR="$AK_WORKDIR/folders" +TEMP="/tmp/aktmp" + +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_zblock + +if [ ! -d $ZFOLDERSDIR ]; then + mkdir $ZFOLDERSDIR + logit "ERROR" "error $ZFOLDERSDIR not found or/and could not be created" +else + logit "INFO" "Found $ZFOLDERSDIR" + exit 1 +fi +TEMPASSIN="$(ak-tempassin)" +cd $TEMPASSIN + + +_ak_modules_folders_add(){ + CRP="$(pwd)" + FOLDERNAME="$1" + _ak_modules_folders_main $FOLDERNAME $CRP + cat data | jq -M +} + +_ak_modules_folders_main(){ + FOLDERNAME="$1" + CRP="$2" + echo "Adding $FOLDERNAME" + logit "INFO" "Copying $1 to temporary folder" + cp -r $2/$1 $1 + if [ $? == 0 ]; then + logit "INFO" "Copied successfully" + else + logit "ERROR" "Error copying..." + fi + + FOLDER="$1" + + logit "INFO" "Adding $FOLDER to IPFS..." + FOLDER_IPFS_HASH=$(_ak_ipfs_add $FOLDER) + if [ $? == 0 ]; then + logit "INFO" "done" + else + logit "ERROR" "error" + fi + logit "WARNING" "Folders are not signing..." + + printf '{"timestamp":"%s","foldername":"%s","ipfs":"%s"}' $(date -u +%s) $FOLDERNAME $FOLDER_IPFS_HASH + + echo "Printing data..." + cat data + echo "Publishing..." + + _ak_zblock_pack folders/add $(pwd)/data + if [ $? == 0 ] + then + echo "cool" + else + echo "not?" + exit 2 + fi +} + +_ak_modules_folders_title(){ + echo "$PROGRAM - Folder block creator" +} + +if [ ! -z $1 ]; then + case $1 in + -h | --help) _ak_usage; exit;; + add) _ak_modules_folders_add $2; exit;; + *) _ak_usage; exit;; + esac +else _ak_usage +fi diff --git a/modules/mixtapes/main.sh b/modules/mixtapes/main.sh new file mode 100755 index 0000000..712bb54 --- /dev/null +++ b/modules/mixtapes/main.sh @@ -0,0 +1,86 @@ +#!/bin/bash +## +## The following creates a mixtape data message +## +## Usage: +## +## -a <artist> <title> <file> Adds a file with tags artist and title +## +## -h , --help +## +## -s , --specs +## +# We can extend it by calling the _ak_zblock_pack.sh mixtape/add data ## ORIGINAL LINE +fullprogrampath="$(realpath $0)" +PROGRAM="$(basename $0)" +descriptionString="AK mixtape block creator" +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script +source $AK_LIBD