2019-11-27 11:27:14 +01:00
#!/bin/sh
2022-11-30 16:55:27 +01:00
# This script can optionally use a GitHub token to increase your request limit (for example, if using this script in a CI).
2022-11-30 16:55:32 +01:00
# To use a GitHub token, pass it through the GITHUB_PAT environment variable.
2022-11-30 14:14:46 +01:00
2022-10-14 15:32:59 +02:00
# GLOBALS
# 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
2022-10-14 15:32:59 +02:00
# Project name
PNAME = 'meilisearch'
2020-05-05 23:33:39 +02:00
2022-10-17 15:20:00 +02:00
# GitHub API address
2022-10-14 15:32:59 +02:00
GITHUB_API = 'https://api.github.com/repos/meilisearch/meilisearch/releases'
2022-10-17 15:20:00 +02:00
# GitHub Release address
2022-10-14 15:32:59 +02:00
GITHUB_REL = 'https://github.com/meilisearch/meilisearch/releases/download/'
2019-11-27 11:27:14 +01:00
2022-10-14 15:32:59 +02:00
# FUNCTIONS
2022-11-30 14:14:46 +01:00
# Gets the version of the latest stable version of Meilisearch by setting the $latest variable.
# Returns 0 in case of success, 1 otherwise.
2020-05-05 23:33:39 +02:00
get_latest( ) {
2022-10-14 15:32:59 +02:00
# temp_file is needed because the grep would start before the download is over
temp_file = $( mktemp -q /tmp/$PNAME .XXXXXXXXX)
2022-11-30 13:53:12 +01:00
latest_release = " $GITHUB_API /latest "
2022-10-14 15:32:59 +02:00
if [ $? -ne 0 ] ; then
2022-11-30 13:53:12 +01:00
echo " $0 : Can't create temp file. "
fetch_release_failure_usage
2022-10-14 15:32:59 +02:00
exit 1
fi
2021-10-16 17:23:50 +02:00
2022-02-07 16:00:50 +01:00
if [ -z " $GITHUB_PAT " ] ; then
2022-11-30 13:53:12 +01:00
curl -s " $latest_release " > " $temp_file " || return 1
2021-10-03 12:07:40 +02:00
else
2022-11-30 13:53:12 +01:00
curl -H " Authorization: token $GITHUB_PAT " -s " $latest_release " > " $temp_file " || return 1
2021-10-03 12:07:40 +02:00
fi
2022-11-30 13:53:12 +01:00
latest = " $( cat " $temp_file " | grep '"tag_name":' | cut -d ':' -f2 | tr -d '"' | tr -d ',' | tr -d ' ' ) "
2020-05-05 23:33:39 +02:00
rm -f " $temp_file "
2022-02-07 16:00:50 +01:00
return 0
2020-05-05 23:33:39 +02:00
}
2022-10-14 15:32:59 +02:00
# Gets the OS by setting the $os variable.
2020-05-05 16:59:30 +02:00
# 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'
; ;
2022-10-14 15:32:59 +02:00
'MINGW' *)
2021-08-31 05:04:21 +02:00
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
2024-02-01 21:34:20 +01:00
# Gets the C lib the system is using by setting the $c_lib variable.
# Returns 0 in case of success, 1 otherwise.
get_C_library( ) {
2024-02-05 10:59:54 +01:00
if ldd --version | grep -i glibc; then
2024-02-01 21:34:20 +01:00
c_lib = 'glibc'
2024-02-05 22:32:44 +01:00
elif ldd --version | grep -i eglibc; then
c_lib = 'eglibc'
2024-02-05 10:59:54 +01:00
elif ldd --version | grep -i musl; then
2024-02-01 21:34:20 +01:00
c_library_failure_usage
elif ldd --version | grep -i bionic; then
c_library_failure_usage
else
return 1
fi
return 0
}
2022-10-14 15:32:59 +02:00
# Gets the architecture by setting the $archi variable.
2020-05-05 16:59:30 +02:00
# 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-11-30 14:14:46 +01:00
# macOS M1/M2
2022-10-14 15:32:59 +02:00
if [ $os = 'macos' ] ; then
2022-11-30 14:14:46 +01:00
archi = 'apple-silicon'
2022-02-02 19:25:52 +01:00
else
archi = 'aarch64'
fi
; ;
2021-09-20 13:57:47 +02: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:'
2022-10-14 15:32:59 +02:00
echo " $ ./ $PNAME "
2019-11-27 11:27:14 +01:00
echo 'Usage:'
2022-10-14 15:32:59 +02:00
echo " $ ./ $PNAME --help "
2019-11-27 11:27:14 +01:00
}
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.'
2023-04-28 22:52:03 +02:00
echo 'Follow the steps at the page ("Source" tab): https://www.meilisearch.com/docs/learn/getting_started/installation'
2019-11-27 11:27:14 +01:00
}
2024-02-01 21:34:20 +01:00
c_library_failure_usage( ) {
2024-02-05 22:32:44 +01:00
printf " $RED %s\n $DEFAULT " 'ERROR: Meilisearch is designed to work with certain C libraries, such as glibc. Ensure that your system uses a compatible C library environment.'
2024-02-01 21:34:20 +01:00
echo ''
2024-02-05 22:32:44 +01:00
echo 'However, you can easily compile the binary from the source files or using the docker image'
echo 'Follow the steps at the page ("Source" tab): https://www.meilisearch.com/docs/learn/getting_started/installation#local-installation'
2024-02-01 21:34:20 +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'
2022-11-30 13:53:12 +01:00
echo ''
echo 'In the meantime, you can manually download the appropriate binary from the GitHub release assets here: https://github.com/meilisearch/meilisearch/releases/latest'
2022-02-07 16:00:50 +01:00
}
2022-10-14 15:32:59 +02:00
fill_release_variables( ) {
# Fill $latest variable.
if ! get_latest; then
fetch_release_failure_usage
exit 1
fi
if [ " $latest " = '' ] ; then
fetch_release_failure_usage
exit 1
fi
# Fill $os variable.
if ! get_os; then
not_available_failure_usage
exit 1
fi
# Fill $archi variable.
if ! get_archi; then
not_available_failure_usage
exit 1
fi
2024-02-01 21:34:20 +01:00
# Fill $c_lib variable.
if ! get_C_library; then
c_library_failure_usage
fi
2022-10-14 15:32:59 +02:00
}
2022-02-07 16:00:50 +01:00
2022-10-14 15:32:59 +02:00
download_binary( ) {
fill_release_variables
echo " Downloading Meilisearch binary $latest for $os , architecture $archi ... "
case " $os " in
'windows' )
release_file = " $PNAME - $os - $archi .exe "
binary_name = " $PNAME .exe "
; ;
*)
release_file = " $PNAME - $os - $archi "
binary_name = " $PNAME "
esac
# Fetch the Meilisearch binary.
curl --fail -OL " $GITHUB_REL / $latest / $release_file "
if [ $? -ne 0 ] ; then
fetch_release_failure_usage
exit 1
fi
mv " $release_file " " $binary_name "
chmod 744 " $binary_name "
success_usage
}
2021-08-31 05:04:21 +02:00
2022-10-14 15:32:59 +02:00
# MAIN
main( ) {
download_binary
}
main