diff options
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/ak-articles | 139 | ||||
-rwxr-xr-x | modules/ak-categories | 126 | ||||
-rwxr-xr-x | modules/ak-comments | 105 | ||||
-rwxr-xr-x | modules/ak-files | 116 | ||||
-rwxr-xr-x | modules/ak-folders | 89 | ||||
-rwxr-xr-x | modules/ak-mixtapes | 86 | ||||
-rwxr-xr-x | modules/ak-news | 317 | ||||
-rwxr-xr-x | modules/ak-reference | 139 | ||||
-rwxr-xr-x | modules/ak-repositories | 164 | ||||
-rwxr-xr-x | modules/ak-roadmap | 35 | ||||
-rwxr-xr-x | modules/ak-todos | 134 |
11 files changed, 1450 insertions, 0 deletions
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 $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 new file mode 100755 index 0000000..157b797 --- /dev/null +++ b/modules/ak-reference @@ -0,0 +1,139 @@ +#!/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 ] |