mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-27 02:11:00 +00:00
lt.sh helper script
This commit is contained in:
parent
c4d1b05b27
commit
10f82d9a3e
3 changed files with 98 additions and 6 deletions
|
@ -24,7 +24,7 @@ FROM python:3.8.14-slim-bullseye
|
||||||
ARG with_models=false
|
ARG with_models=false
|
||||||
ARG models=
|
ARG models=
|
||||||
|
|
||||||
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate
|
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate && mkdir -p /home/libretranslate/.local && chown -R libretranslate:libretranslate /home/libretranslate/.local
|
||||||
USER libretranslate
|
USER libretranslate
|
||||||
|
|
||||||
COPY --from=builder --chown=1032:1032 /app /app
|
COPY --from=builder --chown=1032:1032 /app /app
|
||||||
|
|
|
@ -130,11 +130,8 @@ Then open a web browser to http://localhost:5000
|
||||||
|
|
||||||
### Run with Docker
|
### Run with Docker
|
||||||
|
|
||||||
Simply run:
|
Linux/MacOS: `./lt.sh`
|
||||||
|
Windows: double-click `lt.bat`
|
||||||
```bash
|
|
||||||
docker run -ti --rm -p 5000:5000 libretranslate/libretranslate
|
|
||||||
```
|
|
||||||
|
|
||||||
Then open a web browser to http://localhost:5000
|
Then open a web browser to http://localhost:5000
|
||||||
|
|
||||||
|
|
95
lt.sh
Executable file
95
lt.sh
Executable file
|
@ -0,0 +1,95 @@
|
||||||
|
#!/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[@]}
|
Loading…
Reference in a new issue