bunteshaus.de/add_archive.sh

72 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
err() {
echo "${1}"
zenity --error --no-wrap --text "${1}"
exit 1
}
warn() {
echo "${1}"
zenity --warning --no-wrap --text "${1}"
}
set -x
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
for file in "${files[@]}"; do
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}"
if ! unzip -l "${file}"|grep -q "index.de.md"; then
err "maybe wrong archive, this is not compatible"
fi
if ! [ -d content ]; then
err "folder 'content' not found"
fi
mkdir -p "${folder}"
unzip -o -d "${folder}" "${file}"
git add "${folder}"
git commit -m "${fname}"
done
output_temp=""
for file in "${files[@]}"; do
banner="false"
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}"
for f in $(find "${folder}" -type f); do
if echo ${i}|grep -q "banner"; then
banner="true"
fi
done
if [ ${banner} == "false" ]; then
output_temp="${output_temp}banner missing\n "
fi
done
warn "${output_temp}"
zenity --info --text "Done"