2019-11-27 11:27:14 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# COLORS
|
2019-12-09 14:48:08 +01:00
|
|
|
RED='\033[31m'
|
|
|
|
GREEN='\033[32m'
|
|
|
|
DEFAULT='\033[0m'
|
2019-11-27 11:27:14 +01:00
|
|
|
|
|
|
|
# GLOBALS
|
2020-05-05 23:33:39 +02:00
|
|
|
GREP_SEMVER_REGEXP='v\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)$' # i.e. v[number].[number].[number]
|
|
|
|
|
|
|
|
# FUNCTIONS
|
2019-11-27 11:27:14 +01:00
|
|
|
|
|
|
|
# semverParseInto and semverLT from https://github.com/cloudflare/semver_bash/blob/master/semver.sh
|
|
|
|
|
|
|
|
# usage: semverParseInto version major minor patch special
|
|
|
|
# version: the string version
|
|
|
|
# major, minor, patch, special: will be assigned by the function
|
|
|
|
semverParseInto() {
|
|
|
|
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
|
|
|
|
#MAJOR
|
|
|
|
eval $2=`echo $1 | sed -e "s#$RE#\1#"`
|
|
|
|
#MINOR
|
|
|
|
eval $3=`echo $1 | sed -e "s#$RE#\2#"`
|
2021-06-05 16:45:13 +02:00
|
|
|
#PATCH
|
2019-11-27 11:27:14 +01:00
|
|
|
eval $4=`echo $1 | sed -e "s#$RE#\3#"`
|
|
|
|
#SPECIAL
|
|
|
|
eval $5=`echo $1 | sed -e "s#$RE#\4#"`
|
|
|
|
}
|
|
|
|
|
|
|
|
# usage: semverLT version1 version2
|
|
|
|
semverLT() {
|
|
|
|
local MAJOR_A=0
|
|
|
|
local MINOR_A=0
|
|
|
|
local PATCH_A=0
|
|
|
|
local SPECIAL_A=0
|
|
|
|
|
|
|
|
local MAJOR_B=0
|
|
|
|
local MINOR_B=0
|
|
|
|
local PATCH_B=0
|
|
|
|
local SPECIAL_B=0
|
|
|
|
|
|
|
|
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
|
|
|
|
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
|
|
|
|
|
|
|
|
if [ $MAJOR_A -lt $MAJOR_B ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ $MAJOR_A -le $MAJOR_B ] && [ $MINOR_A -lt $MINOR_B ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ $MAJOR_A -le $MAJOR_B ] && [ $MINOR_A -le $MINOR_B ] && [ $PATCH_A -lt $PATCH_B ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2021-10-16 17:36:50 +02:00
|
|
|
if [ "_$SPECIAL_A" == '_' ] && [ "_$SPECIAL_B" == '_' ] ; then
|
2019-11-27 11:27:14 +01:00
|
|
|
return 1
|
|
|
|
fi
|
2021-10-16 17:36:50 +02:00
|
|
|
if [ "_$SPECIAL_A" == '_' ] && [ "_$SPECIAL_B" != '_' ] ; then
|
2019-11-27 11:27:14 +01:00
|
|
|
return 1
|
|
|
|
fi
|
2021-10-16 17:36:50 +02:00
|
|
|
if [ "_$SPECIAL_A" != '_' ] && [ "_$SPECIAL_B" == '_' ] ; then
|
2019-11-27 11:27:14 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ "_$SPECIAL_A" < "_$SPECIAL_B" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2021-10-03 13:07:40 +03:00
|
|
|
# Get a token from https://github.com/settings/tokens to increasae rate limit (from 60 to 5000), make sure the token scope is set to 'public_repo'
|
|
|
|
# Create GITHUB_PAT enviroment variable once you aquired the token to start using it
|
2020-05-05 23:33:39 +02:00
|
|
|
# Returns the tag of the latest stable release (in terms of semver and not of release date)
|
|
|
|
get_latest() {
|
|
|
|
temp_file='temp_file' # temp_file needed because the grep would start before the download is over
|
2021-10-16 17:23:50 +02:00
|
|
|
|
2022-02-07 16:00:50 +01:00
|
|
|
if [ -z "$GITHUB_PAT" ]; then
|
2022-01-26 17:56:18 +01:00
|
|
|
curl -s 'https://api.github.com/repos/meilisearch/meilisearch/releases' > "$temp_file" || return 1
|
2021-10-03 13:07:40 +03:00
|
|
|
else
|
2022-01-26 17:56:18 +01:00
|
|
|
curl -H "Authorization: token $GITHUB_PAT" -s 'https://api.github.com/repos/meilisearch/meilisearch/releases' > "$temp_file" || return 1
|
2021-10-03 13:07:40 +03:00
|
|
|
fi
|
|
|
|
|
2020-05-05 23:33:39 +02:00
|
|
|
releases=$(cat "$temp_file" | \
|
2021-12-07 16:37:22 +01:00
|
|
|
grep -E '"tag_name":|"draft":|"prerelease":' \
|
2020-05-05 23:33:39 +02:00
|
|
|
| tr -d ',"' | cut -d ':' -f2 | tr -d ' ')
|
|
|
|
# Returns a list of [tag_name draft_boolean prerelease_boolean ...]
|
|
|
|
# Ex: v0.10.1 false false v0.9.1-rc.1 false true v0.9.0 false false...
|
|
|
|
|
|
|
|
i=0
|
2021-10-16 17:36:50 +02:00
|
|
|
latest=''
|
|
|
|
current_tag=''
|
2020-05-05 23:33:39 +02:00
|
|
|
for release_info in $releases; do
|
|
|
|
if [ $i -eq 0 ]; then # Cheking tag_name
|
|
|
|
if echo "$release_info" | grep -q "$GREP_SEMVER_REGEXP"; then # If it's not an alpha or beta release
|
|
|
|
current_tag=$release_info
|
|
|
|
else
|
2021-10-16 17:36:50 +02:00
|
|
|
current_tag=''
|
2020-05-05 23:33:39 +02:00
|
|
|
fi
|
|
|
|
i=1
|
|
|
|
elif [ $i -eq 1 ]; then # Checking draft boolean
|
2021-10-16 17:36:50 +02:00
|
|
|
if [ "$release_info" = 'true' ]; then
|
|
|
|
current_tag=''
|
2020-05-05 23:33:39 +02:00
|
|
|
fi
|
|
|
|
i=2
|
|
|
|
elif [ $i -eq 2 ]; then # Checking prerelease boolean
|
2021-10-16 17:36:50 +02:00
|
|
|
if [ "$release_info" = 'true' ]; then
|
|
|
|
current_tag=''
|
2020-05-05 23:33:39 +02:00
|
|
|
fi
|
|
|
|
i=0
|
2021-10-16 17:36:50 +02:00
|
|
|
if [ "$current_tag" != '' ]; then # If the current_tag is valid
|
|
|
|
if [ "$latest" = '' ]; then # If there is no latest yet
|
2020-05-05 23:33:39 +02:00
|
|
|
latest="$current_tag"
|
|
|
|
else
|
|
|
|
semverLT $current_tag $latest # Comparing latest and the current tag
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
latest="$current_tag"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -f "$temp_file"
|
2022-02-07 16:00:50 +01:00
|
|
|
return 0
|
2020-05-05 23:33:39 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 16:59:30 +02:00
|
|
|
# Gets the OS by setting the $os variable
|
|
|
|
# Returns 0 in case of success, 1 otherwise.
|
2020-05-05 23:33:39 +02:00
|
|
|
get_os() {
|
|
|
|
os_name=$(uname -s)
|
|
|
|
case "$os_name" in
|
|
|
|
'Darwin')
|
|
|
|
os='macos'
|
|
|
|
;;
|
2020-05-05 16:59:30 +02:00
|
|
|
'Linux')
|
2020-05-05 23:33:39 +02:00
|
|
|
os='linux'
|
|
|
|
;;
|
2021-08-31 08:34:21 +05:30
|
|
|
'MINGW'*)
|
|
|
|
os='windows'
|
|
|
|
;;
|
2020-05-05 23:33:39 +02:00
|
|
|
*)
|
2020-05-05 16:59:30 +02:00
|
|
|
return 1
|
2020-05-05 23:33:39 +02:00
|
|
|
esac
|
2020-05-05 16:59:30 +02:00
|
|
|
return 0
|
|
|
|
}
|
2020-05-05 23:33:39 +02:00
|
|
|
|
2020-05-05 16:59:30 +02:00
|
|
|
# Gets the architecture by setting the $archi variable
|
|
|
|
# Returns 0 in case of success, 1 otherwise.
|
|
|
|
get_archi() {
|
|
|
|
architecture=$(uname -m)
|
|
|
|
case "$architecture" in
|
2022-02-02 19:25:52 +01:00
|
|
|
'x86_64' | 'amd64' )
|
2020-05-05 16:59:30 +02:00
|
|
|
archi='amd64'
|
|
|
|
;;
|
2022-02-02 19:25:52 +01:00
|
|
|
'arm64')
|
2022-02-07 13:53:30 +01:00
|
|
|
if [ $os = 'macos' ]; then # MacOS M1
|
2022-02-02 19:25:52 +01:00
|
|
|
archi='amd64'
|
|
|
|
else
|
|
|
|
archi='aarch64'
|
|
|
|
fi
|
|
|
|
;;
|
2021-09-20 20:57:47 +09:00
|
|
|
'aarch64')
|
2022-02-02 19:25:52 +01:00
|
|
|
archi='aarch64'
|
2020-05-05 16:59:30 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return 1
|
|
|
|
esac
|
|
|
|
return 0
|
2020-05-05 23:33:39 +02:00
|
|
|
}
|
|
|
|
|
2019-11-27 11:27:14 +01:00
|
|
|
success_usage() {
|
2022-01-26 17:43:16 +01:00
|
|
|
printf "$GREEN%s\n$DEFAULT" "Meilisearch $latest binary successfully downloaded as '$binary_name' file."
|
2019-11-27 11:27:14 +01:00
|
|
|
echo ''
|
|
|
|
echo 'Run it:'
|
|
|
|
echo ' $ ./meilisearch'
|
|
|
|
echo 'Usage:'
|
|
|
|
echo ' $ ./meilisearch --help'
|
|
|
|
}
|
|
|
|
|
2022-02-07 16:00:50 +01:00
|
|
|
not_available_failure_usage() {
|
2022-01-26 17:43:16 +01:00
|
|
|
printf "$RED%s\n$DEFAULT" 'ERROR: Meilisearch binary is not available for your OS distribution or your architecture yet.'
|
2019-11-27 11:27:14 +01:00
|
|
|
echo ''
|
|
|
|
echo 'However, you can easily compile the binary from the source files.'
|
2021-09-01 15:57:11 +02:00
|
|
|
echo 'Follow the steps at the page ("Source" tab): https://docs.meilisearch.com/learn/getting_started/installation.html'
|
2019-11-27 11:27:14 +01:00
|
|
|
}
|
|
|
|
|
2022-02-07 16:00:50 +01:00
|
|
|
fetch_release_failure_usage() {
|
|
|
|
echo ''
|
|
|
|
printf "$RED%s\n$DEFAULT" 'ERROR: Impossible to get the latest stable version of Meilisearch.'
|
|
|
|
echo 'Please let us know about this issue: https://github.com/meilisearch/meilisearch/issues/new/choose'
|
|
|
|
}
|
|
|
|
|
2020-05-05 23:33:39 +02:00
|
|
|
# MAIN
|
2022-02-07 16:00:50 +01:00
|
|
|
|
|
|
|
# Fill $latest variable
|
|
|
|
if ! get_latest; then
|
|
|
|
fetch_release_failure_usage # TO CHANGE
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-30 23:48:23 -03:00
|
|
|
|
2021-10-16 17:36:36 +02:00
|
|
|
if [ "$latest" = '' ]; then
|
2022-02-07 16:00:50 +01:00
|
|
|
fetch_release_failure_usage
|
2021-10-16 17:36:36 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-02-07 16:00:50 +01:00
|
|
|
# Fill $os variable
|
2020-10-30 23:48:23 -03:00
|
|
|
if ! get_os; then
|
2022-02-07 16:00:50 +01:00
|
|
|
not_available_failure_usage
|
2020-05-05 16:59:30 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-30 23:48:23 -03:00
|
|
|
|
2022-02-07 16:00:50 +01:00
|
|
|
# Fill $archi variable
|
2020-10-30 23:48:23 -03:00
|
|
|
if ! get_archi; then
|
2022-02-07 16:00:50 +01:00
|
|
|
not_available_failure_usage
|
2020-05-05 16:59:30 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-30 23:48:23 -03:00
|
|
|
|
2022-01-26 17:43:16 +01:00
|
|
|
echo "Downloading Meilisearch binary $latest for $os, architecture $archi..."
|
2021-08-31 08:34:21 +05:30
|
|
|
case "$os" in
|
|
|
|
'windows')
|
|
|
|
release_file="meilisearch-$os-$archi.exe"
|
2022-02-07 16:00:50 +01:00
|
|
|
binary_name='meilisearch.exe'
|
2021-08-31 08:34:21 +05:30
|
|
|
|
|
|
|
;;
|
2022-02-07 16:00:50 +01:00
|
|
|
*)
|
|
|
|
release_file="meilisearch-$os-$archi"
|
|
|
|
binary_name='meilisearch'
|
2021-08-31 08:34:21 +05:30
|
|
|
|
|
|
|
esac
|
2022-02-07 16:00:50 +01:00
|
|
|
|
|
|
|
# Fetch the Meilisearch binary
|
2022-01-26 17:56:18 +01:00
|
|
|
link="https://github.com/meilisearch/meilisearch/releases/download/$latest/$release_file"
|
2022-02-08 16:17:53 +01:00
|
|
|
curl --fail -OL "$link"
|
2022-02-07 16:05:48 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
2022-02-07 16:00:50 +01:00
|
|
|
fetch_release_failure_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-10-16 17:23:50 +02:00
|
|
|
mv "$release_file" "$binary_name"
|
|
|
|
chmod 744 "$binary_name"
|
2019-11-27 11:27:14 +01:00
|
|
|
success_usage
|