Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 11bad4f0cd | |||
| ddb25adba3 | |||
| 54532c7f23 | |||
| 9debf8e7f9 | |||
| 9166fe0e8b | |||
| bdb26651b1 | |||
| 9e9a58ff9f | |||
| 1e25f72eff | |||
| c4de3d61bb | |||
| 391e4c1267 | |||
| 84568c355f |
36
README.md
Normal file
36
README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# bashbird
|
||||
|
||||
Script that queries a SQLite database about a bird and returns various information (vernacular name, English name, family, order and links to [oiseaux.net](https://oiseaux.net)).
|
||||
|
||||
|
||||
|
||||
#### 1) bashbirds.sh
|
||||
|
||||
<u>Usage</u>:
|
||||
|
||||
./bashbird.sh -b etourneau
|
||||
|
||||
<u>Others files</u>:
|
||||
|
||||
- Oiseaux europe.xlsm: export from Oiseaux.net website
|
||||
- Oiseaux europe.csv:same as format .csv
|
||||
- insert.sh: script to create birds.db database from .csv export (Usage: ./insert.sh)
|
||||
- birds.db: SQLite database
|
||||
- liste_oiseaux.html: html export
|
||||
- liste_oiseaux.md: markdown export
|
||||
- Transparent300px.png: usefull for markdown export (table width)
|
||||
|
||||
<u>Options</u>:
|
||||
|
||||
- -b \< bird \>: a bird to search (-b etourneau)
|
||||
- -b all: search for all birds
|
||||
- -m: export markdown
|
||||
- -w: export html
|
||||
- -h: help
|
||||
|
||||
Notes:
|
||||
|
||||
- insert.sh deletes and recreates the database each time it is launched (no update)
|
||||
|
||||
|
||||
|
||||
120
bashbirds.sh
120
bashbirds.sh
@@ -1,6 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION="v1.0"
|
||||
VERSION="v1.1.4"
|
||||
|
||||
### Variables for self updating
|
||||
ScriptArgs=( "$@" )
|
||||
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
|
||||
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
|
||||
|
||||
dotenv () {
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
[ -f "$ScriptWorkDir/.env" ] && . "$ScriptWorkDir/.env" || echo -e "${red}\nNo .env file found ! Could'nt get update from Github.'.${reset}"
|
||||
set +a
|
||||
}
|
||||
|
||||
dotenv
|
||||
|
||||
### ChangeNotes: 1.1.4 curl 2ko
|
||||
### ChangeNotes: 1.1.3 Won't display Changes notes
|
||||
### ChangeNotes: 1.1.1 Bugfix .env path
|
||||
### ChangeNotes: 1.1 Bugfix when script was run with symlink
|
||||
### ChangeNotes: 1.0 Minor corrections.
|
||||
|
||||
Github="https://github.com/bruno21/bashbirds"
|
||||
# Public Repo:
|
||||
#RawUrl="https://raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
|
||||
# Private Repo:
|
||||
RawUrl="https://x-access-token:$GITHUB_TOKEN@raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
|
||||
|
||||
### 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-2000 $RawUrl | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
|
||||
LatestChanges="$(curl -s -r 0-2000 $RawUrl | grep "^### ChangeNotes:" | sed 's/### ChangeNotes://g')"
|
||||
|
||||
#[[ $LatestRelease != $VERSION ]] && new="($LatestRelease)" || new=""
|
||||
|
||||
#echo "$LatestRelease"
|
||||
#echo "$LatestChanges"
|
||||
|
||||
red="\033[1;31m"
|
||||
greenbold="\033[1;32m"
|
||||
@@ -8,39 +44,28 @@ green="\033[0;32m"
|
||||
yellow="\033[0;33m"
|
||||
yellowbold="\033[1;33m"
|
||||
bold="\033[1m"
|
||||
italic="\033[3m"
|
||||
#bold_under="\033[1;4m"
|
||||
underline="\033[4m"
|
||||
reset="\033[0m"
|
||||
|
||||
dotenv () {
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
[ -f ".env" ] && . ".env" || echo -e "${red}\nNo .env file found ! Could'nt get update from Github.'.${reset}"
|
||||
set +a
|
||||
}
|
||||
|
||||
dotenv
|
||||
|
||||
### ChangeNotes: Minor corrections.
|
||||
Github="https://github.com/bruno21/bashbirds"
|
||||
# Repo normal:
|
||||
#RawUrl="https://raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
|
||||
# Repo privé:
|
||||
RawUrl="https://x-access-token:$GITHUB_TOKEN@raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
|
||||
|
||||
### Variables for self updating
|
||||
ScriptArgs=( "$@" )
|
||||
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
|
||||
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
|
||||
|
||||
### 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")"
|
||||
#[[ $LatestRelease != $VERSION ]] && new="($LatestRelease)" || new=""
|
||||
|
||||
echo -e "${yellowbold}Bashbird${reset} $VERSION\n"
|
||||
|
||||
|
||||
### 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."
|
||||
}
|
||||
|
||||
req2() {
|
||||
option=$1
|
||||
|
||||
@@ -57,9 +82,8 @@ req2() {
|
||||
#read -p "Pause: " choice
|
||||
|
||||
|
||||
#query2="SELECT * FROM liste;"
|
||||
query2="SELECT Francais, Autres, Latin, Anglais, Ordre, Famille, Liens FROM liste;"
|
||||
result2=$(sqlite3 ./birds.db "$query2")
|
||||
result2=$(sqlite3 "$ScriptWorkDir/birds.db" "$query2")
|
||||
#echo "$result2"
|
||||
|
||||
i=1
|
||||
@@ -76,9 +100,6 @@ req2() {
|
||||
ln="${array[6]}"
|
||||
|
||||
|
||||
#echo "$ln"
|
||||
#read -r -p "Would you like to update? y/[n]: " SelfUpdate
|
||||
|
||||
[[ $aut != "" ]] && z="($aut)" || z=""
|
||||
|
||||
if [ $ext = ".md" ]; then
|
||||
@@ -139,7 +160,7 @@ req2() {
|
||||
html
|
||||
elif [ $ext = ".md" ]; then
|
||||
|
||||
echo -e "${yellow}Exporting markdown file...${reset}"
|
||||
echo -e "${yellow}Exporting markdown file ${italic}$ScriptWorkDir/liste_oiseaux$ext !${reset}"
|
||||
bird=$(echo "$birds" | sed 's/\
|
||||
//g')
|
||||
echo -e "$bird" > "liste_oiseaux$ext"
|
||||
@@ -149,7 +170,7 @@ req2() {
|
||||
}
|
||||
|
||||
html() {
|
||||
|
||||
|
||||
echo -e "${yellow}Exporting html file ${italic}$ScriptWorkDir/liste_oiseaux.html !${reset}"
|
||||
|
||||
cat > liste_oiseaux.html << EOF
|
||||
@@ -254,7 +275,7 @@ req1() {
|
||||
|
||||
request=$(echo "$request" | sed 'y/áàâäçéèêëîïìôöóùúüñÂÀÄÇÉÈÊËÎÏÔÖÙÜÑ/aaaaceeeeiiiooouuunAAACEEEEIIOOUUN/')
|
||||
|
||||
query1="SELECT * FROM liste WHERE Fra LIKE \"%$request%\" OR Aut LIKE \"%$request%\" OR Latin LIKE \"%$request%\"";
|
||||
query1="SELECT * FROM liste WHERE Fra LIKE \"%$request%\" OR Aut LIKE \"%$request%\" OR Latin LIKE \"%$request%\"";
|
||||
result1=$(sqlite3 "$ScriptWorkDir/birds.db" "$query1")
|
||||
|
||||
if [ -n "$result1" ]; then
|
||||
@@ -321,7 +342,7 @@ 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 ---"
|
||||
printf "\n%s\n" "--- starting over with the updated version ---"
|
||||
exec "$ScriptPath" "${ScriptArgs[@]}" >/dev/null # run the new script with old arguments
|
||||
exit 1 # exit the old instance
|
||||
elif [[ $(builtin type -P wget) ]]; then
|
||||
@@ -350,31 +371,28 @@ self_update() {
|
||||
}
|
||||
|
||||
### Version check & initiate self update
|
||||
if [[ "$VERSION" != "$LatestRelease" ]] ; then
|
||||
if [[ "$VERSION" != "$LatestRelease" ]] ; then
|
||||
printf "New version available! %b%s%b ⇒ %b%s%b \nChange Notes:\n%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
|
||||
|
||||
|
||||
|
||||
### Database is present or not ?
|
||||
if [ ! -f "$ScriptWorkDir/birds.db" ]; then
|
||||
echo -e "${red}No database found !${reset}"
|
||||
exit 1
|
||||
exit 1
|
||||
|
||||
### 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."
|
||||
|
||||
else
|
||||
query="SELECT COUNT(Francais) FROM liste";
|
||||
result5=$(sqlite3 "$ScriptWorkDir/birds.db" "$query")
|
||||
|
||||
if [ -n "$result5" ]; then
|
||||
echo -e "\n${bold}A birds database that return keywords for Lightroom.${reset}"
|
||||
echo -e "$result5 birds founds in database...\n"
|
||||
Help
|
||||
fi
|
||||
fi
|
||||
|
||||
while getopts "b:hmw" options; do
|
||||
|
||||
Reference in New Issue
Block a user