From 0d1777251dea7d35cd774518959b4377673e1cab Mon Sep 17 00:00:00 2001 From: kaotisk Date: Tue, 4 Jun 2024 18:07:39 +0300 Subject: Refactoring, modules directory introduced - All modules are now stored separately from the rest of the bin/ - You can run them now with `ak -m ` - Files affected: * bin/ak-articles -> modules/ak-articles * bin/ak-categories -> modules/ak-categories * bin/ak-comments -> modules/ak-comments * bin/ak-files -> modules/ak-files * bin/ak-folders -> modules/ak-folders * bin/ak-mixtapes -> modules/ak-mixtapes * bin/ak-news -> modules/ak-news * bin/ak-reference -> modules/ak-reference * bin/ak-repositories -> modules/ak-repositories * bin/ak-roadmap -> modules/ak-roadmap * bin/ak-todos -> modules/ak-todos --- bin/ak | 18 +-- bin/ak-articles | 139 --------------------- bin/ak-categories | 126 ------------------- bin/ak-comments | 105 ---------------- bin/ak-files | 116 ------------------ bin/ak-folders | 89 -------------- bin/ak-mixtapes | 86 ------------- bin/ak-news | 316 ----------------------------------------------- bin/ak-reference | 139 --------------------- bin/ak-repositories | 164 ------------------------- bin/ak-roadmap | 35 ------ bin/ak-todos | 134 -------------------- config.sh | 1 + init.sh | 23 ++++ install.sh | 1 + 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 ++++++++++++++++++++ update.sh | 11 ++ 27 files changed, 1496 insertions(+), 1457 deletions(-) delete mode 100755 bin/ak-articles delete mode 100755 bin/ak-categories delete mode 100755 bin/ak-comments delete mode 100755 bin/ak-files delete mode 100755 bin/ak-folders delete mode 100755 bin/ak-mixtapes delete mode 100755 bin/ak-news delete mode 100755 bin/ak-reference delete mode 100755 bin/ak-repositories delete mode 100755 bin/ak-roadmap delete mode 100755 bin/ak-todos create mode 100755 modules/ak-articles create mode 100755 modules/ak-categories create mode 100755 modules/ak-comments create mode 100755 modules/ak-files create mode 100755 modules/ak-folders create mode 100755 modules/ak-mixtapes create mode 100755 modules/ak-news create mode 100755 modules/ak-reference create mode 100755 modules/ak-repositories create mode 100755 modules/ak-roadmap create mode 100755 modules/ak-todos diff --git a/bin/ak b/bin/ak index c64ee44..a1bc85f 100755 --- a/bin/ak +++ b/bin/ak @@ -52,14 +52,16 @@ fi subcmd="$(echo $* | sed -e 's/ /-/g')" # Add functionality for separate modules directory -# case "$1" in -# -m|--module) -# shift -# subcmd="modules/$(echo $* | sed -e 's/ /-/g')" -# ;; -# esac -# -# echo $subcmd +case "$1" in + -m|--module) + shift + subcmd="$AK_MODULESDIR/$(echo $1 | sed -e 's/ /-/g')" + shift + subargs="$*" + $subcmd $subargs + _ak_exit_program $? "$subcmd module finished"; + ;; +esac if [ -f "$AK_BINDIR/ak-$subcmd" ] then diff --git a/bin/ak-articles b/bin/ak-articles deleted file mode 100755 index 97a8e8d..0000000 --- a/bin/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/bin/ak-files b/bin/ak-files deleted file mode 100755 index 73c8219..0000000 --- a/bin/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/bin/ak-mixtapes b/bin/ak-mixtapes deleted file mode 100755 index 712bb54..0000000 --- a/bin/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/bin/ak-news b/bin/ak-news deleted file mode 100755 index 5865d15..0000000 --- a/bin/ak-news +++ /dev/null @@ -1,316 +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 - -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/bin/ak-reference b/bin/ak-reference deleted file mode 100755 index 157b797..0000000 --- a/bin/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/bin/ak-repositories b/bin/ak-repositories deleted file mode 100755 index ffda701..0000000 --- a/bin/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/bin/ak-roadmap b/bin/ak-roadmap deleted file mode 100755 index a30894a..0000000 --- a/bin/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/bin/ak-todos b/bin/ak-todos deleted file mode 100755 index afe56f8..0000000 --- a/bin/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/config.sh b/config.sh index c122584..572041b 100755 --- a/config.sh +++ b/config.sh @@ -4,6 +4,7 @@ export AK_WORKDIR="$AK_ROOT/.arching-kaos" export AK_CONFIGDIR="$AK_WORKDIR/config" export AK_BINDIR="$AK_WORKDIR/bin" export AK_LIBDIR="$AK_WORKDIR/lib" +export AK_MODULESDIR="$AK_WORKDIR/modules" export AK_ZBLOCKDIR="$AK_WORKDIR/zblocks" export AK_BLOCKDIR="$AK_WORKDIR/blocks" export AK_DATADIR="$AK_WORKDIR/data" diff --git a/init.sh b/init.sh index 331c1ae..30532f9 100755 --- a/init.sh +++ b/init.sh @@ -97,6 +97,7 @@ do printf "\tOK!\n" fi done + # Find libs and create symlinks libfiles=$(ls -1 $(pwd)/lib) for b in $libfiles @@ -118,3 +119,25 @@ do printf "\tOK!\n" fi done +# +# Find modules and create symlinks +modfiles=$(ls -1 $(pwd)/modules) +for m in $modfiles +do + if [ ! -L $AK_MODULESDIR/$m ] + then + printf "Creating symlink to %s..." "$m" + ln -s $(pwd)/modules/$b $AK_MODULESDIR/$m + if [ $? -ne 0 ] + then + if [ -L $AK_MODULESDIR/$m ] + then + printf "\tAlready exists!\n" + exit 1 + fi + printf "\tFailed!\n" + exit 1 + fi + printf "\tOK!\n" + fi +done diff --git a/install.sh b/install.sh index 9d78acb..e05a634 100755 --- a/install.sh +++ b/install.sh @@ -147,6 +147,7 @@ fi if [ ! -d $AK_CONFIGDIR ] ; then mkdir $AK_CONFIGDIR ;fi if [ ! -d $AK_BINDIR ]; then mkdir $AK_BINDIR ;fi if [ ! -d $AK_LIBDIR ]; then mkdir $AK_LIBDIR ;fi +if [ ! -d $AK_MODULESDIR ]; then mkdir $AK_MODULESDIR ;fi if [ ! -d $AK_ZBLOCKDIR ]; then mkdir $AK_ZBLOCKDIR ;fi if [ ! -d $AK_BLOCKDIR ]; then mkdir $AK_BLOCKDIR ;fi if [ ! -d $AK_DATADIR ]; then mkdir $AK_DATADIR ;fi diff --git a/modules/ak-articles b/modules/ak-articles new file mode 100755 index 0000000..97a8e8d --- /dev/null +++ b/modules/ak-articles @@ -0,0 +1,139 @@ +#!/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 + #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 <<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/ak-categories b/modules/ak-categories new file mode 100755 index 0000000..c0e1e77 --- /dev/null +++ b/modules/ak-categories @@ -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/ak-comments b/modules/ak-comments new file mode 100755 index 0000000..6193e2f --- /dev/null +++ b/modules/ak-comments @@ -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/ak-files b/modules/ak-files new file mode 100755 index 0000000..73c8219 --- /dev/null +++ b/modules/ak-files @@ -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/ak-folders b/modules/ak-folders new file mode 100755 index 0000000..5aa82c7 --- /dev/null +++ b/modules/ak-folders @@ -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/ak-mixtapes b/modules/ak-mixtapes new file mode 100755 index 0000000..712bb54 --- /dev/null +++ b/modules/ak-mixtapes @@ -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_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 new file mode 100755 index 0000000..b015bd6 --- /dev/null +++ b/modules/ak-news @@ -0,0 +1,317 @@ +#!/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