aboutsummaryrefslogtreecommitdiff
path: root/bin/ak-news
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2023-04-03 00:24:49 +0300
committerkaotisk <kaotisk@arching-kaos.org>2023-04-03 00:24:49 +0300
commit9606644a0beb4f2883e1e0f4c6c81b42ab40b3a1 (patch)
tree5f16ff3c7506b653862e0171d71163074f67c96e /bin/ak-news
parentfe1fb88889b2c3949383c254f3058da24ba5e3f2 (diff)
downloadarching-kaos-tools-9606644a0beb4f2883e1e0f4c6c81b42ab40b3a1.tar.gz
arching-kaos-tools-9606644a0beb4f2883e1e0f4c6c81b42ab40b3a1.tar.bz2
arching-kaos-tools-9606644a0beb4f2883e1e0f4c6c81b42ab40b3a1.zip
Renaming to prefix convention, introduced ipfs wrappers so it can be easier to maintain, changes in filesplitter and filejoiner as they move sm submodule namespace... like there are namespaces in bash or something
Diffstat (limited to 'bin/ak-news')
-rwxr-xr-xbin/ak-news54
1 files changed, 30 insertions, 24 deletions
diff --git a/bin/ak-news b/bin/ak-news
index 84f5ff8..1658065 100755
--- a/bin/ak-news
+++ b/bin/ak-news
@@ -1,19 +1,27 @@
#!/bin/bash
+PROGRAM=$(basename $0)
+
ZNEWSDIR="$AK_WORKDIR/news"
TEMP="/tmp/aktmp"
-echo $ZNEWSDIR
+
+logit(){
+ ak-logthis "<$PROGRAM>" "$1" "$2"
+}
+
if [ ! -d $ZNEWSDIR ]; then
mkdir $ZNEWSDIR
- cd $ZNEWSDIR
- git init
- echo "News repository" > README
- echo "Qmetc" >> README
- git add README
- git commit -m "Initiated news repository"
- echo "znewsdir created along with git repo"
+ if [ "$?" == 0 ]; then
+ logit "[INFO]" "$ZNEWSDIR created"
+ else
+ logit "[ERROR]" "$ZNEWSDIR couldn't be created"
+ exit 1
+ fi
else
- echo "znewsdir found"
+ logit "[INFO]" "$ZNEWSDIR found"
fi
+
+cd $ZNEWSDIR
+
tempassin(){
if [ ! -z $1 ]
then
@@ -27,6 +35,7 @@ tempassin(){
fi
cd $TEMPASSIN
}
+
create(){
tempassin $TEMP
curpath="$(pwd)"
@@ -35,15 +44,12 @@ create(){
echo "Renaming..."
TITLE="$(head -n 1 $NEWS_FILE)"
TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' )
- IPFS_FILE=$(ipfs add -q $NEWS_FILE)
+ IPFS_FILE=$(ak-ipfs-add $NEWS_FILE)
mv $NEWS_FILE $ZNEWSDIR/$TO_FILE
sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZNEWSDIR/README
add $TO_FILE
echo "Adding to git repo..."
cd $ZNEWSDIR
- git add $TO_FILE README
- git commit -m "Added $TO_FILE with $(head -n 1 $ZNEWSDIR/$TO_FILE)"
- git clean --force
# rm -rf $TEMP
}
index(){
@@ -53,13 +59,13 @@ index(){
do
DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
TITLE=$(head -n 1 $ZNEWSDIR/$FILE)
- echo $i \| $DATE \| $TITLE
+ IPFS_HASH=$(ak-ipfs-addn $ZNEWSDIR/$FILE)
+ echo $i \| $IPFS_HASH \| $DATE \| $TITLE
let i+=1
done
}
title(){
- echo ak-news-cli
- echo "--------------"
+ echo $PROGRAM
}
import(){
echo "#TODO"
@@ -93,10 +99,10 @@ add2(){
echo "Adding news from " $FILE
DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
TITLE=$(head -n 1 $FILE)
- FILE_IPFS_HASH=$(ipfs add -q $FILE)
+ FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
FILE_SIGN_FILE=$FILE".asc"
gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE
- FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE)
+ FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
cat > data <<EOF
{
"datetime":"$DATETIME",
@@ -110,7 +116,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- pack_z_block "news/add" data
+ ak-pack_z_block "news/add" data
if [ $? == 0 ]
then
echo "News added successfully"
@@ -126,10 +132,10 @@ add(){
echo "Adding news from " $FILE
DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
TITLE=$(head -n 1 $ZNEWSDIR/$FILE)
- FILE_IPFS_HASH=$(ipfs add -q $ZNEWSDIR/$FILE)
+ FILE_IPFS_HASH=$(ak-ipfs-add $ZNEWSDIR/$FILE)
FILE_SIGN_FILE=$FILE".asc"
gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $ZNEWSDIR/$FILE
- FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE)
+ FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
cat > data <<EOF
{
"datetime":"$DATETIME",
@@ -143,7 +149,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- pack_z_block "news/add" data
+ ak-pack_z_block "news/add" data
if [ $? == 0 ]
then
echo "News added successfully"
@@ -156,7 +162,7 @@ usage(){
echo "#TODO"
echo "All you need to know is that there are two options available:"
echo "help Prints this help message"
- echo "index Prints an indexed table of your news files"
+ echo "local-index Prints an indexed table of your news files"
echo "import <file> #TODO"
echo "add <file> Creates a data file from the news file you point to"
echo "create Vim is going to pop up, you will write and save your"
@@ -167,7 +173,7 @@ title
if [ ! -z $1 ]; then
case $1 in
help) usage; exit;;
- index) index; exit;;
+ local-index) index; exit;;
import) import $2; exit;;
add) add2 $2; exit;;
create) create; exit;;