bunteshaus.de/add_archive.sh
2022-06-26 18:54:28 +02:00

66 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
err() {
echo "${1}"
zenity --error --no-wrap --text "${1}"
}
warn() {
echo "${1}"
zenity --warning --no-wrap --text "${1}"
}
if ! command -v unzip &> /dev/null
then
err "'unzip' could not be found"
exit 1
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
fname="$(basename ${file%.*})"
folder="content/posts/${fname}"
if ! unzip -l "${file}"|grep -q "index.de.md"; then
err "maybe wrong archive, this is not compatible"
exit 1
fi
if ! [ -d content ]; then
err "folder 'content' not found"
exit 1
fi
set -x
mkdir -p "${folder}"
unzip -d "${folder}" "${file}"
git add "${folder}"
git commit -m "${fname}"
done
output="Done."
output_temp=""
for file in "${files[@]}"; do
banner="false"
fname="$(basename ${file%.*})"
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}"