You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
buha.de/add_archive.linux.sh

92 lines
2.4 KiB

#!/bin/bash
# define folder for content
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}"
}
#check if unzip installed
if ! command -v unzip &> /dev/null
then
err "'unzip' could not be found"
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_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."
fi
#check if folder '${PATH}' available
if ! [ -d "${CONTENT_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}" && \
git commit -m "${fname}" # commit that folder
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_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"