From 27127f2d059e424796adbef91dc11fae94b5499b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Erbsh=C3=A4u=C3=9Fer?= Date: Sun, 7 Jun 2026 14:37:08 +0200 Subject: [PATCH] ease blog article upload --- tesoft.bash | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tesoft.bash b/tesoft.bash index 8f2e94e..2d1059a 100755 --- a/tesoft.bash +++ b/tesoft.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh cookie_path=./cookies.txt @@ -14,10 +14,10 @@ print_help() { echo "> $0 logout" echo "" echo "create a new blog article:" - echo "> $0 upload ./article.tar" + echo "> $0 upload ./article-dir" echo "" echo "update an existing blog article:" - echo "> $0 patch 123 ./article.tar" + echo "> $0 patch 123 ./article-dir" echo "" echo "publish an existing blog article:" echo "> $0 publish 123" @@ -56,15 +56,16 @@ logout() { upload() { if [ -z "$1" ]; then - echo "error: article file is not passed" >&2 + echo "error: article directory is not passed" >&2 exit 1 fi - if ! [ -f "$1" ]; then - echo "error: article file not found" >&2 + if ! [ -d "$1" ]; then + echo "error: article directory not found" >&2 exit 1 fi - out=$(curl -v -f -X PUT -F "file=@$1" "$URL/api/blog" -b "$cookie_path" 2>&1) + tar -C "$1" -cf /tmp/article.tar $(ls "$1") + out=$(curl -v -f -X PUT -F "file=@/tmp/article.tar" "$URL/api/blog" -b "$cookie_path" 2>&1) if [ $? -ne 0 ]; then echo "$out" >&2 exit 1 @@ -79,15 +80,16 @@ patch() { exit 1 fi if [ -z "$2" ]; then - echo "error: article file is not passed" >&2 + echo "error: article directory is not passed" >&2 exit 1 fi - if ! [ -f "$2" ]; then - echo "error: article file not found" >&2 + if ! [ -d "$2" ]; then + echo "error: article directory not found" >&2 exit 1 fi - out=$(curl -v -f -X PATCH -F "file=@$2" "$URL/api/blog/$1" -b "$cookie_path" 2>&1) + tar -C "$2" -cf /tmp/article.tar $(ls "$2") + out=$(curl -v -f -X PATCH -F "file=@/tmp/article.tar" "$URL/api/blog/$1" -b "$cookie_path" 2>&1) if [ $? -ne 0 ]; then echo "$out" >&2 exit 1