mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-12-18 08:27:03 +02:00
95 lines
2.2 KiB
Bash
Executable File
95 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -eo pipefail
|
|
__dirname=$(cd "$(dirname "$0")"; pwd -P)
|
|
cd "${__dirname}"
|
|
|
|
platform="Linux" # Assumed
|
|
uname=$(uname)
|
|
case $uname in
|
|
"Darwin")
|
|
platform="MacOS / OSX"
|
|
;;
|
|
MINGW*)
|
|
platform="Windows"
|
|
;;
|
|
esac
|
|
|
|
if [[ $platform = "Windows" ]]; then
|
|
export COMPOSE_CONVERT_WINDOWS_PATHS=1
|
|
fi
|
|
|
|
# define realpath replacement function
|
|
if [[ $platform = "MacOS / OSX" ]]; then
|
|
realpath() {
|
|
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
|
}
|
|
fi
|
|
|
|
usage(){
|
|
echo "Usage: $0 [--port N]"
|
|
echo
|
|
echo "Run LibreTranslate using docker."
|
|
echo
|
|
exit
|
|
}
|
|
|
|
export LT_PORT=5000
|
|
|
|
# Parse args for overrides
|
|
ARGS=()
|
|
while [[ $# -gt 0 ]]
|
|
do
|
|
key="$1"
|
|
case $key in
|
|
--port)
|
|
export LT_PORT="$2"
|
|
ARGS+=("$1")
|
|
ARGS+=("$2") # save it in an array for later
|
|
shift # past argument
|
|
shift # past value
|
|
;;
|
|
--debug)
|
|
export LT_DEBUG=YES
|
|
ARGS+=("$1")
|
|
shift # past argument
|
|
;;
|
|
--help)
|
|
usage
|
|
;;
|
|
*) # unknown option
|
|
ARGS+=("$1")
|
|
shift # past argument
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# $1 = command | $2 = help_text | $3 = install_command (optional)
|
|
check_command(){
|
|
hash "$1" 2>/dev/null || not_found=true
|
|
if [[ $not_found ]]; then
|
|
check_msg_prefix="Checking for $1... "
|
|
|
|
# Can we attempt to install it?
|
|
if [[ -n "$3" ]]; then
|
|
echo -e "$check_msg_prefix \033[93mnot found, we'll attempt to install\033[39m"
|
|
$3 || sudo $3
|
|
|
|
# Recurse, but don't pass the install command
|
|
check_command "$1" "$2"
|
|
else
|
|
check_msg_result="\033[91m can't find $1! Check that the program is installed and that you have added the proper path to the program to your PATH environment variable before launching WebODM. If you change your PATH environment variable, remember to close and reopen your terminal. $2\033[39m"
|
|
fi
|
|
fi
|
|
|
|
echo -e "$check_msg_prefix $check_msg_result"
|
|
if [[ $not_found ]]; then
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
environment_check(){
|
|
check_command "docker" "https://www.docker.com/"
|
|
}
|
|
|
|
environment_check
|
|
docker run -ti --rm --entrypoint bash -p $LT_PORT:$LT_PORT -v lt-share:/home/libretranslate/.local/share libretranslate/libretranslate #${ARGS[@]} |