From 63b99b7bf3df73f571e8887e6303cdb1a3ade97a Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Thu, 15 Nov 2018 11:08:45 +0100 Subject: [PATCH] [confluence-tk] Improvements --- confluence-tk | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/confluence-tk b/confluence-tk index 130e83c..f21d571 100755 --- a/confluence-tk +++ b/confluence-tk @@ -13,14 +13,18 @@ Usage: ${0##*/} [-h] [-i PAGE_ID] [-m] -i PAGE_ID Page ID of page to operate on -l List used page ID's -m Print page as markdown - -o Out file (optional) - -c HTML out (optional) + -o FILE Out file (optional) + -c FILE HTML out (optional) -f Foce used page ID's rewrite + -d DESCRIPT Add page description to used page ID's list -h Help -- show this page and exit -v Vebose output Page content is *not* printed on stdout, tough that would be -preferred." +preferred. + +If \`-c\` (HTML out) is provided, then temporary files are not deleted +" example_page_id="46306514" example_page_id="46301431" @@ -35,9 +39,12 @@ action= v= curl_out_file="/tmp/${0##*/}-$$-curlout" html_out_file="/tmp/${0##*/}-$$-htmlout" +curl_login_out_file="/tmp/${0##*/}-$$-curlloginout" +html_login_out_file="/tmp/${0##*/}-$$-htmlloginout" html_save= force_rewrite= -while getopts hvlfmi:o:c: flag; do +page_description= +while getopts hvlfmi:o:c:d: flag; do case "$flag" in h) echoerr "$HELP" @@ -48,6 +55,8 @@ while getopts hvlfmi:o:c: flag; do output_file="$OPTARG" ;; f) force_rewrite="t" ;; + d) + page_description="$OPTARG" ;; c) html_save="t" html_out_file="$OPTARG" ;; @@ -128,11 +137,11 @@ elif grep -q "HTTP/1.1 302 Found" < "$curl_out_file" && --data "os_password=$password"\ --data "formname=loginform"\ --data "login='Log In'"\ - > /dev/null\ - 2> "$curl_out_file" + 1> "$html_login_out_file"\ + 2> "$curl_login_out_file" - if grep -q "HTTP/1.1 200 OK" < "$curl_out_file" && - grep -q "X-AUSERNAME: $username" < "$curl_out_file"; then + if grep -q "HTTP/1.1 200 OK" < "$curl_login_out_file" && + grep -q "X-AUSERNAME: $username" < "$curl_login_out_file"; then message="Login went through." if [ "$v" ]; then echoerr "${0##*/}: $message"; fi else @@ -185,14 +194,16 @@ esac # Visit sites file if [ "$v" ]; then echo "${0##*/}: Checks '$sites_csv'." 1>&2; fi if [ "$force_rewrite" ] || ! grep -q "${page_id}" "$sites_csv"; then - title_row=$(head -n 2 < "$html_out_file" | tail -n 1 | pandoc -f html -t markdown | head -n 1) + if [ -z "$page_description" ]; then + page_description=$(head -n 2 < "$html_out_file" | tail -n 1 | pandoc -f html -t markdown | head -n 1) + fi sed "/$page_id/ d" < "$sites_csv" > "${sites_csv}_"; mv -f "${sites_csv}_" "$sites_csv" - echo "$page_id,$output_file,$title_row" >> "$sites_csv" + echo "$page_id,$output_file,$page_description" >> "$sites_csv" if [ "$v" ]; then echo "${0##*/}: File '$sites_csv' modified." 1>&2; fi fi # Clean up if [ "$v" ]; then echo "${0##*/}: Cleans up and exits." 1>&2; fi -rm -f "$curl_out_file" +if [ -z "$html_save" ]; then rm -f "$curl_out_file"; fi if [ -z "$html_save" ]; then rm -f "$html_out_file"; fi exit 0 -- 2.39.2