~stormdragon2976/bashtml

a4f6440d83bf993eb919b2cc59b5f9b077b95681 — Storm Dragon 1 year, 7 months ago a2e7dbc
New as yet untested feature, sync, has been added.
1 files changed, 34 insertions(+), 0 deletions(-)

M bashtml.sh
M bashtml.sh => bashtml.sh +34 -0
@@ 5,6 5,7 @@ command=(
  h # help
  n # New post
  p # New post
  s # sync to server using rsync
)
htmlFile="$(mktemp -t html.XXXXXXXXXXXX)"
ifs="$IFS"


@@ 50,6 51,11 @@ declare -Ag settings=(
[gnuSocialURL]="https://2mb.social" # The GNU Social url used for tags in posts
[license]="CC BY-NC-ND"
[licenseURL]="https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode"
[rsyncAddress]="" # Server:path where files should be uploaded.
[rsyncDelete]="no" # Should files that do not exist on the local machine be deleted from the server during sync?
[rsyncExcludes]=".bashtmlrc *.md bashtml-plugins/" # Things rsync should not copy to the server.
[rsyncPasswordFile]="" # Full path to rsync password file, if not specified, you will be prompted.
[rsyncUser]="" # User rsync should sync as, e.g. http
)
EOF
  # Exit so configuration can be customized.


@@ 303,6 309,32 @@ show_help() {
    echo "for more in depth help, including the use of plugins, please see the README file."
}

sync_to_server() {
    # Minimal validation for settings.
    if [[ "${settings[rsyncAddress]}" == "" ]]; then
        echo "No address specified. Please edit your .bashtmlrc file and configure the rsync settings."
        exit 1
    fi
    if [[ "${settings[rsyncUser]}" == "" ]]; then
        echo "No user name specified. Please edit your .bashtmlrc file and configure the rsync settings."
        exit 1
    fi
    # Store arguments to rsync in a variable
    local rsyncArgs=('-hPrs')
    if [[ "${settings[rsyncPasswordFile]}" != "" ]]; then
        rsyncArgs+=("--password-file=${settings[rsyncPasswordFile]}")
    fi
    if [[ "${settings[rsyncDelete],,}" == "yes" ]]; then
        rsyncArgs+=("--delete")
    fi
    # Add any excludes to the arguments array.
    if [[ "${settings[rsyncExcludes]}" != "" ]]; then
        rsyncArgs+=("--exclude \"${settings[rsyncExcludes]// /\" --exclude \"}\"")
    fi
    # Sync the files to the server with the given settings.
    rsync ${rsyncArgs[@]} . ${settings[rsyncUser]}@${settings[rsyncAddress]}
}

add_header() {
# This function is left aligned so the cat command can be ended with EOF
local i


@@ 521,6 553,7 @@ for i in "$@"; do
  shift
  case "$i" in
    "--help") set -- "$@" "-h";;
    "--sync")   set -- "$@" "-s";;
    "--"new|post)   set -- "$@" "-p";;
    *)        set -- "$@" "$i"
  esac


@@ 532,6 565,7 @@ while getopts $(echo "${command[@]}" | tr -d '[:space:]') i ; do
  case "$i" in 
    h) show_help;;
    n|p) new_post;;
    s) sync_to_server;;
  esac
done
exit 0