diff --git a/image_classifier.sh b/image_classifier.sh new file mode 100755 index 0000000..d6e8683 --- /dev/null +++ b/image_classifier.sh @@ -0,0 +1,10 @@ +#!/bin/bash +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +if [ ! -d "${script_dir}/.venv" ]; then + python -m venv "$script_dir/.venv" +fi +# shellcheck disable=1091 +source "$script_dir/.venv/bin/activate" +pip install -r "$script_dir/requirements.txt" > /dev/null +pip install "$script_dir/" > /dev/null +backup_imap.py "${@}" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..431b320 --- /dev/null +++ b/install.sh @@ -0,0 +1,29 @@ +#!/bin/bash +destination="/usr/local/bin" +while [ $# -gt 0 ] +do + case "$1" in + "--help"|"-h"|"-?") + usage + exit 0 + ;; + "--destination"|"-d") + shift + destination="${1}" + shift + ;; + *) + echo "Ignoring unknwon parameter '${1}'" + shift + ;; + esac +done + +if [ ! -e "${HOME}/.config/image_classifier.conf" ]; then + touch "${HOME}/.config/image_classifier.conf" +fi +chmod go-rwx "${HOME}/.config/image_classifier.conf" + +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +sed "s#__src_folder__#${script_dir}#g" wrapper.sh > "${destination}/image_classifier.sh" +chmod +x "${destination}/image_classifier.sh" diff --git a/wrapper.sh b/wrapper.sh new file mode 100644 index 0000000..de75c96 --- /dev/null +++ b/wrapper.sh @@ -0,0 +1,22 @@ +#!/bin/bash +if [ -z "${HOME}" ]; then + if [ "$(whoami)" == "root" ]; then + HOME="/root" + else + HOME=$(grep "$(whoami)" /etc/passwd | awk 'BEGIN {FS=":"} {print($6)}') + fi +fi + +CONFIG_FILE="${HOME}/.config/image_classifier.conf" +cd "__src_folder__" || exit 1 +if [ -r "${CONFIG_FILE}" ]; then + perms=$(stat -c %A "${CONFIG_FILE}") + if [ "${perms:4:6}" != '------' ]; then + echo "Permissions too open for config file '${CONFIG_FILE}' ($perms). Remove all permissions to group and others." + exit 1 + fi + config=(--config "${CONFIG_FILE}") +else + config=() +fi +"__src_folder__/image_classifier.sh" "${config[@]}" "${@}"