bunteshaus.de/add_archive.sh

61 lines
1.1 KiB
Bash
Raw Normal View History

2022-06-26 15:04:39 +02:00
#!/bin/bash
err() {
echo "${1}"
zenity --error --no-wrap --text "${1}"
2022-06-26 19:14:13 +02:00
exit 1
2022-06-26 15:04:39 +02:00
}
warn() {
echo "${1}"
zenity --warning --no-wrap --text "${1}"
}
2022-06-26 19:16:55 +02:00
set -x
2022-06-26 15:04:39 +02:00
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
2022-06-26 18:53:44 +02:00
for file in "${files[@]}"; do
fname="$(basename ${file%.*})"
folder="content/posts/${fname}"
if ! unzip -l "${file}"|grep -q "index.de.md"; then
2022-06-26 15:04:39 +02:00
err "maybe wrong archive, this is not compatible"
fi
if ! [ -d content ]; then
err "folder 'content' not found"
fi
2022-06-26 18:53:44 +02:00
mkdir -p "${folder}"
2022-06-26 19:20:24 +02:00
unzip -o -d "${folder}" "${file}"
2022-06-26 18:53:44 +02:00
git add "${folder}"
2022-06-26 18:54:28 +02:00
git commit -m "${fname}"
2022-06-26 15:04:39 +02:00
done
2022-06-26 18:53:44 +02:00
2022-06-26 15:04:39 +02:00
output_temp=""
2022-06-26 18:53:44 +02:00
for file in "${files[@]}"; do
banner="false"
fname="$(basename ${file%.*})"
2022-06-26 15:04:39 +02:00
folder="content/posts/${fname}"
2022-06-26 18:53:44 +02:00
for f in $(find "${folder}" -type f); do
if echo ${i}|grep -q "banner"; then
banner="true"
fi
done
if [ ${banner} == "false" ]; then
2022-06-26 15:04:39 +02:00
output_temp="${output_temp}banner missing\n "
fi
done
warn "${output_temp}"
2022-06-26 19:14:13 +02:00
zenity --info --text "Done"