From 8054e74052c8a9fdc88231e5aa42655f86250bbb Mon Sep 17 00:00:00 2001 From: teldra Date: Sun, 26 Jun 2022 19:42:17 +0200 Subject: [PATCH] small fixes --- add_archive.sh | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/add_archive.sh b/add_archive.sh index 87ddb81..137a5e2 100755 --- a/add_archive.sh +++ b/add_archive.sh @@ -1,70 +1,86 @@ #!/bin/bash +# define folder for content +PATH="content/posts" + +# define an error function err() { echo "${1}" zenity --error --no-wrap --text "${1}" exit 1 } +#define a warn function warn() { echo "${1}" zenity --warning --no-wrap --text "${1}" } -set -x + +#check if unzip installed if ! command -v unzip &> /dev/null then err "'unzip' could not be found" fi -if [ ${#@} -eq 0 ]; then - # no arguments - IFS=$'\n' files=($(zenity --file-selection --multiple --separator=$'\n' --title="Choose files")) -else - # arguments - echo "" -fi +# choose files to process +IFS=$'\n' files=($(zenity --file-selection --multiple --separator=$'\n' --title="Choose files")) +# check and extract files to destination path for file in "${files[@]}"; do + # sanitize filename s="$(basename ${file%.*})" # receive input in first argument s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to - s="${s//+(-)/-}" # convert multiple - to single - s="${s/#-}" # remove - from start s="${s/%-}" # remove - from end fname="${s,,}" # convert to lowercase - folder="content/posts/${fname}" + folder="${PATH}/${fname}" + + # check if file is compatible by checking if 'index.de.md' available if ! unzip -l "${file}"|grep -q "index.de.md"; then - err "maybe wrong archive, this is not compatible" + err "Maybe wrong archive? This is not compatible." fi - if ! [ -d content ]; then - err "folder 'content' not found" + + #check if folder '${PATH}' available + if ! [ -d "${PATH}" ]; then + err "Folder 'content' not found." fi + # create folder mkdir -p "${folder}" + # deflate zip file unzip -o -d "${folder}" "${file}" + # add folder for next commit git add "${folder}" + # commit that folder git commit -m "${fname}" done - +# make a couple of lints for the archives output_temp="" - for file in "${files[@]}"; do banner="false" + # sanitize filename s="$(basename ${file%.*})" # receive input in first argument s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to - s="${s//+(-)/-}" # convert multiple - to single - s="${s/#-}" # remove - from start s="${s/%-}" # remove - from end fname="${s,,}" # convert to lowercase - folder="content/posts/${fname}" + folder="${PATH}/${fname}" + # get a list of files in folder for f in $(find "${folder}" -type f); do + # check if a file called 'banner*' exists if echo ${i}|grep -q "banner"; then banner="true" fi done + # compile missing or worng things if [ ${banner} == "false" ]; then output_temp="${output_temp}banner missing\n " fi done - +# print missing or wrongg things warn "${output_temp}" + +# completed.. and tell it! zenity --info --text "Done"