From 4217dc0560bf40b4fa7ae6a6f964bd56b418712e Mon Sep 17 00:00:00 2001 From: kaotisk Date: Fri, 14 Jun 2024 22:36:12 +0300 Subject: Refactoring --- modules/articles/main.sh | 10 +++++----- modules/categories/main.sh | 20 ++++++++++---------- modules/comments/main.sh | 8 ++++---- modules/files/main.sh | 36 ++++++++++++++++++------------------ modules/folders/main.sh | 18 +++++++++--------- modules/news/main.sh | 28 ++++++++++++++-------------- modules/reference/main.sh | 4 ++-- modules/todos/main.sh | 16 ++++++++-------- 8 files changed, 70 insertions(+), 70 deletions(-) (limited to 'modules') diff --git a/modules/articles/main.sh b/modules/articles/main.sh index 382466b..29c1c34 100755 --- a/modules/articles/main.sh +++ b/modules/articles/main.sh @@ -22,9 +22,9 @@ TEMP="/tmp/aktmp" if [ ! -d $ZARTICLESDIR ]; then mkdir $ZARTICLESDIR cd $ZARTICLESDIR - logit "INFO" "zarticlesdir created" + _ak_log_info "zarticlesdir created" else - logit "INFO" "zarticlesdir found" + _ak_log_info "zarticlesdir found" fi _ak_modules_articles_create(){ @@ -33,18 +33,18 @@ _ak_modules_articles_create(){ export ARTICLES_FILE="$(date +%Y%m%d_%H%M%S)" if [ -z $EDITOR ] then - logit "ERROR" "No $EDITOR found. Exiting..." + _ak_log_error "No $EDITOR found. Exiting..." exit 1 fi $EDITOR $ARTICLES_FILE - logit "INFO" "Renaming..." + _ak_log_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..." + _ak_log_info "Adding to git repo..." cd $ZARTICLESDIR rm -rf $TEMP } diff --git a/modules/categories/main.sh b/modules/categories/main.sh index c0e1e77..82fc669 100755 --- a/modules/categories/main.sh +++ b/modules/categories/main.sh @@ -24,9 +24,9 @@ source $AK_LIBDIR/_ak_zblock if [ ! -d $AK_CATEGORIES ]; then mkdir $AK_CATEGORIES cd $AK_CATEGORIES - logit "INFO" "AK_CATEGORIES created" + _ak_log_info "AK_CATEGORIES created" else - logit "INFO" "AK_CATEGORIES found" + _ak_log_info "AK_CATEGORIES found" fi _ak_modules_categories_create(){ @@ -34,7 +34,7 @@ _ak_modules_categories_create(){ cd $TEMP export NEWS_FILE="$(date +%Y%m%d_%H%M%S)" vi $NEWS_FILE - logit "INFO" "Renaming..." + _ak_log_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) @@ -61,10 +61,10 @@ _ak_modules_categories_import(){ then if [ ! -d $1 ] then - logit "ERROR" "Folder does not exists" + _ak_log_error "Folder does not exists" exit 4 else - logit "INFO" "Folder $1 exists" + _ak_log_info "Folder $1 exists" fl="$(ls -1 $1)" for f in $fl do @@ -72,7 +72,7 @@ _ak_modules_categories_import(){ done fi else - logit "ERROR" "No value" + _ak_log_error "No value" exit 6 fi exit 224 @@ -82,7 +82,7 @@ _ak_modules_categories_add(){ cd $TEMP if [ -f $1 ]; then FILE="$1" - logit "INFO" "Adding news from " $FILE + _ak_log_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) @@ -99,15 +99,15 @@ _ak_modules_categories_add(){ } EOF else - logit "ERROR" "File $FILE doesn't exist"; + _ak_log_error "File $FILE doesn't exist"; exit 2 fi _ak_zblock_pack "news/add" $(pwd)/data if [ $? == 0 ] then - logit "INFO" "News added successfully" + _ak_log_info "News added successfully" else - logit "ERROR" "error??" + _ak_log_error "error??" exit 1 fi } diff --git a/modules/comments/main.sh b/modules/comments/main.sh index 6193e2f..f5ebabc 100755 --- a/modules/comments/main.sh +++ b/modules/comments/main.sh @@ -24,9 +24,9 @@ TEMP="/tmp/aktmp" if [ ! -d $ZCOMMENTSDIR ]; then mkdir $ZCOMMENTSDIR cd $ZCOMMENTSDIR - logit "INFO" "zcommentsdir created" + _ak_log_info "zcommentsdir created" else - logit "INFO" "zcommentsdir found" + _ak_log_info "zcommentsdir found" fi _ak_modules_comments_create(){ @@ -34,7 +34,7 @@ _ak_modules_comments_create(){ then REFER_TO="$1" else - logit "ERROR" "No reference given" + _ak_log_error "No reference given" echo "ERROR" "No reference given" exit 1 fi @@ -47,7 +47,7 @@ _ak_modules_comments_create(){ 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..." + _ak_log_info "Adding to git repo..." cd $ZCOMMENTSDIR if [ ! -z $REFER_TO ] then diff --git a/modules/files/main.sh b/modules/files/main.sh index 73c8219..a3202fe 100755 --- a/modules/files/main.sh +++ b/modules/files/main.sh @@ -19,15 +19,15 @@ if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR if [ $? == 0 ] then - logit "INFO" "Folder $ZFILESDIR created!" + _ak_log_info "Folder $ZFILESDIR created!" else - logit "ERROR" "Failed to create $ZFILESDIR folder" + _ak_log_error "Failed to create $ZFILESDIR folder" exit 1 fi cd $ZFILESDIR git init else - logit "INFO" "$ZFILESDIR found!" + _ak_log_info "$ZFILESDIR found!" fi _ak_modules_files_add(){ @@ -40,47 +40,47 @@ main(){ FILENAME="$1" CRP="$2" echo "Adding $FILENAME" - logit "INFO" "Switching to tmp folder..." + _ak_log_info "Switching to tmp folder..." TEMPASSIN="$(ak-tempassin)" cd $TEMPASSIN if [ $? == 0 ]; then - logit "INFO" "Success" + _ak_log_info "Success" else - logit "ERROR" "Error with tmp folder" + _ak_log_error "Error with tmp folder" exit 5 fi - logit "INFO" "Copying $1 to $TEMPASSIN" + _ak_log_info "Copying $1 to $TEMPASSIN" cp $2/$1 $TEMPASSIN/$1 if [ $? == 0 ]; then - logit "INFO" "Copied successfully" + _ak_log_info "Copied successfully" else - logit "ERROR" "Error copying..." + _ak_log_error "Error copying..." fi FILE="$TEMPASSIN/$1" - logit "INFO" "Adding $FILE to IPFS..." + _ak_log_info "Adding $FILE to IPFS..." FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) if [ $? == 0 ]; then - logit "INFO" "Added $FILE to IPFS" + _ak_log_info "Added $FILE to IPFS" else - logit "ERROR" "Error in adding the $FILE to IPFS" + _ak_log_error "Error in adding the $FILE to IPFS" fi - logit "INFO" "Signing..." + _ak_log_info "Signing..." SIGN_FILE=$FILENAME".asc" _ak_gpg_sign_detached $SIGN_FILE $FILE if [ $? == 0 ]; then - logit "INFO" "Signed" + _ak_log_info "Signed" else - logit "ERROR" "Error while signing" + _ak_log_error "Error while signing" fi - logit "INFO" "Adding signature to IPFS" + _ak_log_info "Adding signature to IPFS" SIGNATURE=$(_ak_ipfs_add $TEMPASSIN/$SIGN_FILE) if [ $? == 0 ]; then - logit "INFO" "Added" + _ak_log_info "Added" else - logit "ERROR" "Error while adding" + _ak_log_error "Error while adding" fi cat > $TEMPASSIN/data < temp if [ $? -ne 0 ] then - logit "ERROR" "Failed to retrieve zblock $1" + _ak_log_error "Failed to retrieve zblock $1" exit 22 fi module="`cat temp | jq -r '.[].module'`" @@ -281,7 +281,7 @@ _ak_modules_news_html(){ echo " " echo '' else - logit "ERROR" "Not a news block." + _ak_log_error "Not a news block." exit 1 fi rm temp diff --git a/modules/reference/main.sh b/modules/reference/main.sh index 157b797..e6c06d3 100755 --- a/modules/reference/main.sh +++ b/modules/reference/main.sh @@ -24,9 +24,9 @@ source $AK_LIBDIR/_ak_zblock if [ ! -d $ZREFERENCESDIR ]; then mkdir $ZREFERENCESDIR cd $ZREFERENCESDIR - logit "INFO" "zreferencesdir created" + _ak_log_info "zreferencesdir created" else - logit "INFO" "zreferencesdir found" + _ak_log_info "zreferencesdir found" fi _ak_modules_reference_create(){ diff --git a/modules/todos/main.sh b/modules/todos/main.sh index afe56f8..299bcb0 100755 --- a/modules/todos/main.sh +++ b/modules/todos/main.sh @@ -30,9 +30,9 @@ TEMP="/tmp/aktmp" if [ ! -d $ZTODOSDIR ]; then mkdir $ZTODOSDIR cd $ZTODOSDIR - logit "INFO" "ztodosdir created along with git repo" + _ak_log_info "ztodosdir created along with git repo" else - logit "INFO" "ztodosdir found" + _ak_log_info "ztodosdir found" fi _ak_modules_todos_create(){ @@ -40,13 +40,13 @@ _ak_modules_todos_create(){ cd $TEMP export TODOS_FILE="$(date -u +%s)" vi $TODOS_FILE - logit "INFO" "Renaming..." + _ak_log_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..." + _ak_log_info "Adding to git repo..." cd $ZTODOSDIR # rm -rf $TEMP } @@ -91,7 +91,7 @@ _ak_modules_todos_add(){ cd $TEMP if [ -f $1 ]; then FILE="$1" - logit "INFO" "Adding todos from $FILE" + _ak_log_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) @@ -108,15 +108,15 @@ _ak_modules_todos_add(){ } EOF else - logit "ERROR" "File $FILE doesn't exist"; + _ak_log_error "File $FILE doesn't exist"; exit 2 fi _ak_zblock_pack "todos/add" $(pwd)/data if [ $? == 0 ] then - logit "INFO" "Todos added successfully" + _ak_log_info "Todos added successfully" else - logit "ERROR" "error?? _ak_zblock_pack failed" + _ak_log_error "error?? _ak_zblock_pack failed" exit 1 fi } -- cgit v1.2.3