239 lines
7.2 KiB
Bash
Executable File
239 lines
7.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
VERSION="v0.4.7"
|
|
### ChangeNotes: Notification template changes for: gotify(new), DSM(improved), SMTP(deprecation alternative).
|
|
Github="https://github.com/mag37/dockcheck"
|
|
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
|
|
|
### Variables for self updating
|
|
ScriptArgs=( "$@" )
|
|
ScriptPath="$(readlink -f "$0")"
|
|
ScriptWorkDir="$(dirname "$ScriptPath")"
|
|
|
|
### Check if there's a new release of the script:
|
|
LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
|
LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNotes: //p")"
|
|
|
|
### Styles
|
|
reset="\033[0m"
|
|
|
|
bold="\033[1m"
|
|
dim="\033[2m"
|
|
italic="\033[3m"
|
|
underline="\033[4m"
|
|
bold_underline="\033[1;4m"
|
|
italic_underline="\033[3;4m"
|
|
#reverse="\033[7" !!Bug
|
|
#strikethrough="\033[9" !!Bug
|
|
moverline="\033[53"
|
|
|
|
echo -e "${bold}bold${reset}"
|
|
echo -e "${dim}dim${reset}"
|
|
echo -e "${italic}italic${reset}"
|
|
echo -e "${underline}underline${reset}"
|
|
echo -e "${bold_underline}bold_underline${reset}"
|
|
echo -e "${italic_underline}italic_underline${reset}"
|
|
#echo -e "${reverse}reverse${reset}"
|
|
#echo -e "${strikethrough}strikethrough${reset}"
|
|
echo -e "${moverline}moverline${reset}"
|
|
|
|
### Colors
|
|
red="\033[0;31m"
|
|
redbold="\033[1;31m"
|
|
green="\033[0;32m"
|
|
greenbold="\033[1;32m"
|
|
yellow="\033[0;33m"
|
|
yellowbold="\033[1;33m"
|
|
cyan="\033[0;36m"
|
|
|
|
echo -e "${red}red${reset}"
|
|
echo -e "${redbold}redbold${reset}"
|
|
echo -e "${green}green${reset}"
|
|
echo -e "${greenbold}greenbold${reset}"
|
|
echo -e "${yellow}yellow${reset}"
|
|
echo -e "${yellowbold}yellowbold${reset}"
|
|
echo -e "${cyan}cyan${reset}"
|
|
|
|
bur="\033[1;4;31m"
|
|
echo -e "${bur}bold_underline_red${reset}"
|
|
|
|
### Background
|
|
cyanbackgrd="\033[0;46m"
|
|
redbackgrd="\033[1;41m"
|
|
|
|
echo -e "${cyanbackgrd}cyanbackgrd${reset}"
|
|
echo -e "${redbackgrd}redbackgrd${reset}"
|
|
|
|
printf "\e[3;4;33mjaune,italic,souligné\n\e[0m"
|
|
|
|
fzf_bin=0
|
|
if (! type fzf > /dev/null 2>&1); then
|
|
echo -e "Install ${bold}fzf${reset} for a better experience !"
|
|
echo -e "${italic}brew install fzf${reset}"
|
|
fzf_bin=0
|
|
else fzf_bin=1
|
|
fi
|
|
|
|
if ! command -v mediainfo &> /dev/null; then
|
|
echo -e "Install ${bold}mediainfo${reset} to display media tags !"
|
|
echo -e "${italic}brew install mediainfo${reset}"
|
|
mediainfo=false
|
|
else
|
|
mediainfo=true
|
|
fi
|
|
|
|
# Test if variable is an integer
|
|
function _is_int() { test "$@" -eq "$@" 2> /dev/null; }
|
|
|
|
_sanitize() {
|
|
local s="${1?need a string}" # 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
|
|
echo "${s,,}" # convert to lowercase
|
|
}
|
|
|
|
# Trim variable
|
|
_trim () {
|
|
read -rd '' $1 <<<"${!1}"
|
|
}
|
|
|
|
dotenv () {
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
[ -f "$HOME/.env" ] && . "$HOME/.env" || echo -e "${red}\nNo .env file found ! Googlemaps reverse geocode not working.${reset}"
|
|
set +a
|
|
}
|
|
|
|
showHelp() {
|
|
echo -e "${greenbold}keywords2insta${reset} v3.1"
|
|
echo -e "Bruno <bruno<clicclac.info>"
|
|
echo -e "Read exif and keywords from an image file, and copy them to the clipboard, "
|
|
echo -e " ready for Instagram, Flickr and 500px."
|
|
echo
|
|
echo -e "${yellow}USAGE:${reset}"
|
|
echo -e "${green}keyword2insta [-Options...] -f <file>${reset}"
|
|
echo -e "If no option (except gps and copyright) is chosen, all tags are added (default)."
|
|
echo
|
|
echo -e "If the gps and coypright options are selected, the images files will be modified."
|
|
echo
|
|
echo -e "${yellow}OPTIONS:${reset}"
|
|
echo -e " ${green}-f${reset}, ${green}--file <file>${reset} Image file"
|
|
echo -e " ${green}-l${reset}, ${green}--lens${reset} Add lens exif"
|
|
echo -e " ${green}-m${reset}, ${green}--model${reset} Add APN model exif"
|
|
echo -e " ${green}-n${reset}, ${green}--nature${reset} Add nature related keywords"
|
|
echo
|
|
echo -e "${yellow}REQUIEREMENTS:${reset}"
|
|
echo -e " -${underline}exiftool${reset} for extract exifs ${bold}(requis)${reset}"
|
|
echo -e " brew install exiftool"
|
|
echo
|
|
echo -e "${yellow}EXAMPLES:${reset}"
|
|
echo -e " keyword2insta -f image.jpg"
|
|
echo -e " keyword2insta -lm -f image.jpg"
|
|
echo
|
|
echo -e "${yellow}EXIT CODES:${reset}"
|
|
echo -e " 0: Success !"
|
|
echo -e " 1: Exiftool could not be found."
|
|
echo -e " 2: No image file."
|
|
echo -e " 3: Unknown long option."
|
|
echo -e " 4: Unknown short option."
|
|
echo -e " 5: No Keywords found in image file."
|
|
echo
|
|
echo -e "${yellow}Changelog:${reset}"
|
|
echo -e " v3.0: support 500px"
|
|
echo -e " v3.1: display thumb"
|
|
}
|
|
|
|
self_update_curl() {
|
|
cp "$ScriptPath" "$ScriptPath".bak
|
|
if [[ $(builtin type -P curl) ]]; then
|
|
curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath"
|
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
|
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
|
|
exit 1 # exit the old instance
|
|
elif [[ $(builtin type -P wget) ]]; then
|
|
wget $RawUrl -O "$ScriptPath" ; chmod +x "$ScriptPath"
|
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
|
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
|
|
exit 1 # exit the old instance
|
|
else
|
|
printf "curl/wget not available - download the update manually: %s \n" "$Github"
|
|
fi
|
|
}
|
|
|
|
self_update() {
|
|
cd "$ScriptWorkDir" || { printf "Path error, skipping update.\n" ; return ; }
|
|
if [[ $(builtin type -P git) ]] && [[ "$(git ls-remote --get-url 2>/dev/null)" =~ .*"mag37/dockcheck".* ]] ; then
|
|
printf "\n%s\n" "Pulling the latest version."
|
|
git pull --force || { printf "Git error, manually pull/clone.\n" ; return ; }
|
|
printf "\n%s\n" "--- starting over with the updated version ---"
|
|
cd - || { printf "Path error.\n" ; return ; }
|
|
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
|
|
exit 1 # exit the old instance
|
|
else
|
|
cd - || { printf "Path error.\n" ; return ; }
|
|
self_update_curl
|
|
fi
|
|
}
|
|
|
|
|
|
dotenv
|
|
|
|
# https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options
|
|
# le 1er : de $optspec supprime le message d'erreur
|
|
|
|
optspec=":wnrcf:t:mlh-:"
|
|
while getopts "$optspec" opt
|
|
do
|
|
case $opt in
|
|
-) case "${OPTARG}" in
|
|
help) showHelp; exit;;
|
|
wildlife) opt_wildlife=true;;
|
|
file)
|
|
file="${!OPTIND}"; OPTIND=$(( OPTIND + 1 ))
|
|
;;
|
|
file=*)
|
|
file=${OPTARG#*=}
|
|
#opt=${OPTARG%=$file}
|
|
opt="$(printf "%s\n" "${OPTARG}" | cut -d'=' -f1 )" ; file="$(printf "%s\n" "${OPTARG}" | cut -d'=' -f2-)"
|
|
;;
|
|
model) opt_model=true;;
|
|
lens) opt_lens=true;;
|
|
*)
|
|
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" = ":" ]; then
|
|
echo "Unknown option --${OPTARG}" >&2
|
|
fi
|
|
exit 3
|
|
;;
|
|
esac;;
|
|
w) opt_wildlife=true;;
|
|
n) opt_nature=true;;
|
|
r) opt_region=true;;
|
|
c) opt_copyright=true;;
|
|
f) file="${OPTARG}";;
|
|
t) tags=("$OPTARG")
|
|
until [[ $(eval "echo \${$OPTIND}") =~ ^-.* ]] || [ -z $(eval "echo \${$OPTIND}") ]; do
|
|
tags+=($(eval "echo \${$OPTIND}"))
|
|
OPTIND=$((OPTIND + 1))
|
|
done
|
|
;;
|
|
m) opt_model=true;;
|
|
h)
|
|
showHelp
|
|
exit 0
|
|
;;
|
|
*)
|
|
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
|
|
echo "Non-option argument: '-${OPTARG}'" >&2
|
|
fi
|
|
exit 4
|
|
;;
|
|
esac
|
|
done
|
|
shift "$((OPTIND-1))"
|
|
|
|
: <<'END_COMMENT'
|
|
|
|
bla
|
|
END_COMMENT |