Rename script to bashbird.sh
This commit is contained in:
195
bashbirds.sh
Executable file
195
bashbirds.sh
Executable file
@@ -0,0 +1,195 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION="v0.5b"
|
||||
### ChangeNotes: Notification template changes for: gotify(new), DSM(improved), SMTP(deprecation alternative).
|
||||
Github="https://github.com/bruno21/bashbirds"
|
||||
RawUrl="https://raw.githubusercontent.com/bruno21/bashbirds/main/dockcheck.sh"
|
||||
|
||||
### Variables for self updating
|
||||
ScriptArgs=( "$@" )
|
||||
ScriptPath="$(readlink -f "$0")"
|
||||
ScriptWorkDir="$(dirname "$ScriptPath")"
|
||||
|
||||
echo ScriptWorkDir
|
||||
|
||||
### 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")"
|
||||
|
||||
red="\033[1;31m"
|
||||
greenbold="\033[1;32m"
|
||||
green="\033[0;32m"
|
||||
yellow="\033[0;33m"
|
||||
bold="\033[1m"
|
||||
#bold_under="\033[1;4m"
|
||||
underline="\033[4m"
|
||||
reset="\033[0m"
|
||||
|
||||
search="$1"
|
||||
#echo "$search"
|
||||
|
||||
dir=$(dirname "$0")
|
||||
#echo $dir
|
||||
#file="liste_oiseaux.txt"
|
||||
#echo $file
|
||||
|
||||
req2() {
|
||||
f_md="liste_oiseaux.md"
|
||||
if [ -f "./$f_md" ]; then
|
||||
rm "./$f_md"
|
||||
fi
|
||||
read -p "Pause: " choice
|
||||
|
||||
query2="SELECT * FROM liste;"
|
||||
result2=$(sqlite3 ./birds_plus.db "$query2")
|
||||
#echo "$result2"
|
||||
|
||||
array=()
|
||||
while IFS='|' read -ra array;
|
||||
do
|
||||
fr="${array[0]}"
|
||||
aut="${array[1]}"
|
||||
lat="${array[2]}"
|
||||
en="${array[3]}"
|
||||
or="${array[4]}"
|
||||
fa="${array[5]}"
|
||||
ln="${array[6]}"
|
||||
[[ $aut != "" ]] && z="($aut)" || z=""
|
||||
|
||||
echo "| $fr $z |" >>"$f_md"
|
||||
echo "|--------------------------------------------------|" >>"$f_md"
|
||||
echo "| $lat |" >> "$f_md"
|
||||
echo "| $en |" >> "$f_md"
|
||||
echo "| $or |" >> "$f_md"
|
||||
echo "| $fa |" >> "$f_md"
|
||||
echo "| $ln |" >> "$f_md"
|
||||
echo "" >> "$f_md"
|
||||
|
||||
done <<< "$result2"
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
req1() {
|
||||
query1="SELECT * FROM liste WHERE francais LIKE \"%$1%\"";
|
||||
result1=$(sqlite3 ./birds_plus.db "$query1")
|
||||
#echo "$result1"
|
||||
|
||||
array2=()
|
||||
cmpt=1
|
||||
while IFS='|' read -ra array2;
|
||||
do
|
||||
fr2="${array2[0]}"
|
||||
aut2="${array2[1]}"
|
||||
lat2="${array2[2]}"
|
||||
en2="${array2[3]}"
|
||||
or2="${array2[4]}"
|
||||
fa2="${array2[5]}"
|
||||
lnk2="${array2[6]}"
|
||||
|
||||
tag2="$fr2,$lat2,$en2"
|
||||
if [ -n "$or2" ]; then
|
||||
tag2+=",$or2"
|
||||
fi
|
||||
if [ -n "$fa2" ]; then
|
||||
tag2+=",$fa2"
|
||||
fi
|
||||
#echo "${#fr2} ; ${#aut2} ; ${#lat2} ; ${#en2} ; ${#or2} ; ${#fa2} ; ${#lnk2}"
|
||||
|
||||
echo
|
||||
printf "| %-3s | %-25s | %-25s | %-25s | %-20s | %-20s \n" "$cmpt" "$fr2" "$lat2" "$en2" "$or2" "$fa2"
|
||||
printf "| %-3s | %-55s \n" "$cmpt" "$lnk2"
|
||||
printf "| %-3s | %-55s \n" "$cmpt" "$tag2"
|
||||
cmpt=$((cmpt+1))
|
||||
done <<< "$result1"
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
### Version check & initiate self update
|
||||
if [[ "$VERSION" != "$LatestRelease" ]] ; then
|
||||
printf "New version available! %b%s%b ⇒ %b%s%b \n Change Notes: %s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges"
|
||||
if [[ -z "$AutoUp" ]] ; then
|
||||
read -r -p "Would you like to update? y/[n]: " SelfUpdate
|
||||
[[ "$SelfUpdate" =~ [yY] ]] && self_update
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ -f ./birds_plus.db ]; then
|
||||
|
||||
#echo "$result"
|
||||
|
||||
#req2
|
||||
|
||||
echo
|
||||
|
||||
#req1 "$1"
|
||||
|
||||
else
|
||||
echo -e "${red}No database found !${reset}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### Help Function:
|
||||
Help() {
|
||||
echo "Syntax: birds.sh [OPTION]"
|
||||
echo "Example: birds.sh -b buse"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo "-b -b bird, -b all."
|
||||
echo "-h Print this Help."
|
||||
echo "-m Export markdown."
|
||||
echo "-v Prints current version."
|
||||
echo "-w Export html."
|
||||
}
|
||||
|
||||
while getopts "b:hm" options; do
|
||||
case "${options}" in
|
||||
b) Bird="${OPTARG}" ;;
|
||||
m) req2 ;;
|
||||
v) printf "%s\n" "$VERSION" ; exit 0 ;;
|
||||
h|*) Help ; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
shift "$((OPTIND-1))"
|
||||
|
||||
echo "bird: $Bird"
|
||||
read -p "Pause: " choice
|
||||
|
||||
if [ $Bird == "all" ]; then
|
||||
req1
|
||||
elif [ -n $Bird ]; then
|
||||
req1 "$Bird"
|
||||
fi
|
||||
87
bdd.sh
87
bdd.sh
@@ -1,87 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
red="\033[1;31m"
|
||||
greenbold="\033[1;32m"
|
||||
green="\033[0;32m"
|
||||
yellow="\033[0;33m"
|
||||
bold="\033[1m"
|
||||
#bold_under="\033[1;4m"
|
||||
underline="\033[4m"
|
||||
reset="\033[0m"
|
||||
|
||||
search="$1"
|
||||
echo "$search"
|
||||
|
||||
|
||||
req2() {
|
||||
query2="SELECT * FROM liste;"
|
||||
result2=$(sqlite3 ./birds.db "$query2")
|
||||
#echo "$result2"
|
||||
|
||||
array=()
|
||||
while IFS='|' read -ra array;
|
||||
do
|
||||
fr="${array[0]}"
|
||||
aut="${array[1]}"
|
||||
lat="${array[2]}"
|
||||
en="${array[3]}"
|
||||
ln="${array[4]}"
|
||||
[[ $aut != "" ]] && z="($aut)" || z=""
|
||||
|
||||
echo -e "${bold}$fr ${reset} $z"
|
||||
echo "$lat"
|
||||
echo "$en"
|
||||
echo "$ln"
|
||||
echo
|
||||
|
||||
done <<< "$result2"
|
||||
}
|
||||
|
||||
req1() {
|
||||
query1="SELECT * FROM liste WHERE francais LIKE \"%$1%\"";
|
||||
#query2="SELECT * FROM liste WHERE Francais LIKE '%Vautour%'";
|
||||
result1=$(sqlite3 ./birds.db "$query1")
|
||||
echo "$result1"
|
||||
array2=()
|
||||
cmpt=1
|
||||
while IFS='|' read -ra array2;
|
||||
do
|
||||
fr2="${array2[0]}"
|
||||
aut2="${array2[1]}"
|
||||
lat2="${array2[2]}"
|
||||
en2="${array2[3]}"
|
||||
lnk2="${array2[4]}"
|
||||
|
||||
echo ${#fr2}
|
||||
echo ${#aut2}
|
||||
echo ${#lat2}
|
||||
echo ${#en2}
|
||||
echo ${#lnk2}
|
||||
|
||||
#lnk2="https://www.oiseaux.net/oiseaux/vautour.africain.html"
|
||||
#echo "$cmpt $fr2 $aut2 $lat2 $en2 $lnk2"
|
||||
echo "$lnk2"
|
||||
|
||||
echo
|
||||
printf "| %-3s | %-30s | %-30s | %-30s | \n" "$cmpt" "$fr2" "$lat2" "$en2"
|
||||
printf "| %-3s | %-65s | \n" "$cmpt" "${lnk2}"
|
||||
echo
|
||||
#printf "| %-3s | %-55s |\n" "$cmpt" "$lnk"
|
||||
cmpt=$((cmpt+1))
|
||||
done <<< "$result1"
|
||||
}
|
||||
|
||||
if [ -f ./birds.db ]; then
|
||||
|
||||
#echo "$result"
|
||||
|
||||
#req2
|
||||
|
||||
echo
|
||||
|
||||
req1 "$1"
|
||||
|
||||
else
|
||||
echo -e "${red}No database found !${reset}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user