From 50074253d03d2f8568d44fd931b84ce212156be9 Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 12 Jun 2023 04:02:07 +0100 Subject: add install script to install --- install.sh | 8 ++++++++ src/shblg | 48 ------------------------------------------------ src/shblg.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/test.sh | 18 ------------------ 4 files changed, 56 insertions(+), 66 deletions(-) create mode 100755 install.sh delete mode 100755 src/shblg create mode 100755 src/shblg.sh delete mode 100755 src/test.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..9c8a653 --- /dev/null +++ b/install.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# installs m2html and shblg to the system path + +PREFIX=${PREFIX:-/usr} + +install -m755 src/md2html.sh ${PREFIX}/bin/md2html +install -m755 src/shblg.sh ${PREFIX}/bin/shblg diff --git a/src/shblg b/src/shblg deleted file mode 100755 index 226216c..0000000 --- a/src/shblg +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -INPUT_DIR=blog -OUTPUT_DIR=dist -PAGE_TEMPLATE=blog/template.html - -while getopts ":o:i:t:" opt; do - case "$opt" in - o) - OUTPUT_DIR=$OPTARG/ - mkdir -p $OUTPUT_DIR - OUTPUT_DIR=$(realpath $OUTPUT_DIR) - ;; - i) - INPUT_DIR=$(realpath $OPTARG) - ;; - t) - PAGE_TEMPLATE=$(realpath $OPTARG) - ;; - esac -done - -# process a file to -process () { - path="${1#$INPUT_DIR}" - dirpath="${1%${1##*/}}" - out_file="${OUTPUT_DIR}${path}" - - [ -d "$1" ] && { - mkdir -p "$out_file" - for f in "$1"/*; do - process "$f" - done - return 0 - } || [ -x "$1" ] && { - # execute the file - cd $dirpath - "$1" > "${out_file%.*}.html" - cd - - return 0 - } || { - # just output the file as is - while IFS= read -r line; do printf "%s\n" "$line"; done < "$1" > "$out_file" - return 0 - } -} - -process "$INPUT_DIR" diff --git a/src/shblg.sh b/src/shblg.sh new file mode 100755 index 0000000..226216c --- /dev/null +++ b/src/shblg.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +INPUT_DIR=blog +OUTPUT_DIR=dist +PAGE_TEMPLATE=blog/template.html + +while getopts ":o:i:t:" opt; do + case "$opt" in + o) + OUTPUT_DIR=$OPTARG/ + mkdir -p $OUTPUT_DIR + OUTPUT_DIR=$(realpath $OUTPUT_DIR) + ;; + i) + INPUT_DIR=$(realpath $OPTARG) + ;; + t) + PAGE_TEMPLATE=$(realpath $OPTARG) + ;; + esac +done + +# process a file to +process () { + path="${1#$INPUT_DIR}" + dirpath="${1%${1##*/}}" + out_file="${OUTPUT_DIR}${path}" + + [ -d "$1" ] && { + mkdir -p "$out_file" + for f in "$1"/*; do + process "$f" + done + return 0 + } || [ -x "$1" ] && { + # execute the file + cd $dirpath + "$1" > "${out_file%.*}.html" + cd - + return 0 + } || { + # just output the file as is + while IFS= read -r line; do printf "%s\n" "$line"; done < "$1" > "$out_file" + return 0 + } +} + +process "$INPUT_DIR" diff --git a/src/test.sh b/src/test.sh deleted file mode 100755 index 84c5405..0000000 --- a/src/test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - - -line="hell o world" -# replace tabs with spaces -l="$line" -line= -while [ "$l" ]; do - c="${l%*${l#?}}" - case "$c" in - "\t") line="$line ";; - *) line="$line$c" ;; - esac - l="${l#?}" - printf "%s\n" "$c" -done -printf "%s\n" "$line" - -- cgit v1.2.1