Merge pull request #4 from StevenSeifried/languagetool

Add LanguageTool
This commit is contained in:
Steven Seifried 2022-01-20 22:23:53 +01:00 committed by GitHub
commit 3a5f0ffc36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 275 additions and 1 deletions

View file

@ -189,7 +189,7 @@ ________________________________________________________________________________
<h1 align="center" id="heading"> jdownloader2 Server LXC </h1>
To create a new Jellyfin Server LXC, run the following in the Proxmox web shell.
To create a new jdownloader2 Server LXC, run the following in the Proxmox web shell.
```
bash -c "$(wget -qLO - https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/ct/jdownloader2_container.sh)"
@ -206,6 +206,25 @@ Run from the LXC console and follow the instructions:
sudo -u jdown2 java -jar /opt/jdown2/JDownloader.jar -norestart
```
____________________________________________________________________________________________
</details>
<details>
<summary markdown="span">Language Server LXC</summary>
<h1 align="center" id="heading"> LanguageTool Server LXC </h1>
To create a new LanguageTool Server LXC, run the following in the Proxmox web shell.
```
bash -c "$(wget -qLO - https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/ct/languagetool_container.sh)"
```
<h3 align="center" id="heading">Default Settings: 2GB RAM - 64GB Storage - 2vCPU</h3>
After the script completes, If you're dissatisfied with the default settings, click on the LXC, then on the **_Resources_** tab and change the **_Memory_**, **_Cores_** and **_Root D>
____________________________________________________________________________________________
</details>

View file

@ -0,0 +1 @@
languageModel=/opt/LanguageTool/ngrams/

View file

@ -0,0 +1,157 @@
#!/usr/bin/env bash
while true; do
read -p "This will create a new LanguageTool LXC Container. Proceed (y/n)?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
shopt -s expand_aliases
alias die='EXIT=$? LINE=$LINENO error_exit'
trap die ERR
CHECKMARK='\033[0;32m\xE2\x9C\x94\033[0m'
trap cleanup EXIT
function error_exit() {
trap - ERR
local DEFAULT='Unknown failure occured.'
local REASON="\e[97m${1:-$DEFAULT}\e[39m"
local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE"
msg "$FLAG $REASON"
[ ! -z ${CTID-} ] && cleanup_ctid
exit $EXIT
}
function warn() {
local REASON="\e[97m$1\e[39m"
local FLAG="\e[93m[WARNING]\e[39m"
msg "$FLAG $REASON"
}
function info() {
local REASON="$1"
local FLAG="\e[36m[INFO]\e[39m"
msg "$FLAG $REASON"
}
function msg() {
local TEXT="$1"
echo -e "$TEXT"
}
function cleanup_ctid() {
if [ ! -z ${MOUNT+x} ]; then
pct unmount $CTID
fi
if $(pct status $CTID &>/dev/null); then
if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then
pct stop $CTID
fi
pct destroy $CTID
elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then
pvesm free $ROOTFS
fi
}
function cleanup() {
popd >/dev/null
rm -rf $TEMP_DIR
}
function load_module() {
if ! $(lsmod | grep -Fq $1); then
modprobe $1 &>/dev/null || \
die "Failed to load '$1' module."
fi
MODULES_PATH=/etc/modules
if ! $(grep -Fxq "$1" $MODULES_PATH); then
echo "$1" >> $MODULES_PATH || \
die "Failed to add '$1' module to load at boot."
fi
}
TEMP_DIR=$(mktemp -d)
pushd $TEMP_DIR >/dev/null
wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/setup_files/languagetool_setup.sh
load_module overlay
while read -r line; do
TAG=$(echo $line | awk '{print $1}')
TYPE=$(echo $line | awk '{printf "%-10s", $2}')
FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}')
ITEM=" Type: $TYPE Free: $FREE "
OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
fi
STORAGE_MENU+=( "$TAG" "$ITEM" "OFF" )
done < <(pvesm status -content rootdir | awk 'NR>1')
if [ $((${#STORAGE_MENU[@]}/3)) -eq 0 ]; then
warn "'Container' needs to be selected for at least one storage location."
die "Unable to detect valid storage location."
elif [ $((${#STORAGE_MENU[@]}/3)) -eq 1 ]; then
STORAGE=${STORAGE_MENU[0]}
else
while [ -z "${STORAGE:+x}" ]; do
STORAGE=$(whiptail --title "Storage Pools" --radiolist \
"Which storage pool you would like to use for the container?\n\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit
done
fi
info "Using '$STORAGE' for Storage Location."
CTID=$(pvesh get /cluster/nextid)
info "Container ID is $CTID."
echo -e "${CHECKMARK} \e[1;92m Updating LXC Template List... \e[0m"
pveam update >/dev/null
echo -e "${CHECKMARK} \e[1;92m Downloading LXC Template... \e[0m"
OSTYPE=debian
OSVERSION=${OSTYPE}-11
mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($OSVERSION.*\)/\1/p" | sort -t - -k 2 -V)
TEMPLATE="${TEMPLATES[-1]}"
pveam download local $TEMPLATE >/dev/null ||
die "A problem occured while downloading the LXC template."
STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}')
case $STORAGE_TYPE in
dir|nfs)
DISK_EXT=".raw"
DISK_REF="$CTID/"
;;
zfspool)
DISK_PREFIX="subvol"
DISK_FORMAT="subvol"
;;
esac
DISK=${DISK_PREFIX:-vm}-${CTID}-disk-0${DISK_EXT-}
ROOTFS=${STORAGE}:${DISK_REF-}${DISK}
echo -e "${CHECKMARK} \e[1;92m Creating LXC Container... \e[0m"
DISK_SIZE=64G
pvesm alloc $STORAGE $CTID $DISK $DISK_SIZE --format ${DISK_FORMAT:-raw} >/dev/null
if [ "$STORAGE_TYPE" == "zfspool" ]; then
warn "Some containers may not work properly due to ZFS not supporting 'fallocate'."
else
mkfs.ext4 $(pvesm path $ROOTFS) &>/dev/null
fi
ARCH=$(dpkg --print-architecture)
HOSTNAME=languagetool
TEMPLATE_STRING="local:vztmpl/${TEMPLATE}"
pct create $CTID $TEMPLATE_STRING -arch $ARCH -features nesting=1 \
-hostname $HOSTNAME -net0 name=eth0,bridge=vmbr0,ip=dhcp -onboot 1 -cores 2 -memory 2048\
-ostype $OSTYPE -rootfs $ROOTFS,size=$DISK_SIZE -storage $STORAGE >/dev/null
MOUNT=$(pct mount $CTID | cut -d"'" -f 2)
ln -fs $(readlink /etc/localtime) ${MOUNT}/etc/localtime
pct unmount $CTID && unset MOUNT
echo -e "${CHECKMARK} \e[1;92m Starting LXC Container... \e[0m"
pct start $CTID
pct push $CTID languagetool_setup.sh /languagetool_setup.sh -perms 755
pct exec $CTID /languagetool_setup.sh
IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
info "Successfully created a LanguageTool LXC Container to $CTID at IP Address ${IP}:8081/v2"

View file

@ -0,0 +1,81 @@
#!/usr/bin/env bash
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
shopt -s expand_aliases
alias die='EXIT=$? LINE=$LINENO error_exit'
trap die ERR
CHECKMARK='\033[0;32m\xE2\x9C\x94\033[0m'
trap 'die "Script interrupted."' INT
function error_exit() {
trap - ERR
local DEFAULT='Unknown failure occured.'
local REASON="\e[97m${1:-$DEFAULT}\e[39m"
local FLAG="\e[91m[ERROR:LXC] \e[93m$EXIT@$LINE"
msg "$FLAG $REASON"
exit $EXIT
}
function msg() {
local TEXT="$1"
echo -e "$TEXT"
}
echo -e "${CHECKMARK} \e[1;92m Setting up Container OS... \e[0m"
sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
locale-gen >/dev/null
apt-get -y purge openssh-{client,server} >/dev/null
apt-get autoremove >/dev/null
echo -e "${CHECKMARK} \e[1;92m Updating Container OS... \e[0m"
apt-get update &>/dev/null
apt-get -qqy upgrade &>/dev/null
echo -e "${CHECKMARK} \e[1;92m Installing Prerequisites... \e[0m"
apt-get -qqy install \
default-jre-headless \
unzip \
sudo \
wget \
apt-transport-https \
hunspell \
hunspell-de-de \
hunspell-en-us &>/dev/null
echo -e "${CHECKMARK} \e[1;92m Installing LanguageTool Server... \e[0m"
wget https://languagetool.org/download/LanguageTool-stable.zip &>/dev/null
unzip LanguageTool-stable.zip &>/dev/null
sudo mv LanguageTool-*.*/ /opt/LanguageTool &>/dev/null
rm LanguageTool-stable.zip &>/dev/null
sudo mkdir /opt/LanguageTool/ngrams &>/dev/null
wget https://languagetool.org/download/ngram-data/ngrams-de-20150819.zip &>/dev/null
wget https://languagetool.org/download/ngram-data/ngrams-en-20150817.zip &>/dev/null
sudo unzip ngrams-de-20150819.zip -d /opt/LanguageTool/ngrams &>/dev/null
sudo unzip ngrams-en-20150817.zip -d /opt/LanguageTool/ngrams &>/dev/null
rm ngrams-de-20150819.zip &>/dev/null
rm ngrams-en-20150817.zip &>/dev/null
wget -O /opt/LanguageTool/languagetool.cfg https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/config_files/languagetool.cfg &>/dev/null
wget -O /etc/systemd/system/languagetool.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/systemd_files/languagetool.service &>/dev/null
sudo adduser --system --no-create-home languagetool &>/dev/null
sudo systemctl daemon-reload &>/dev/null
sudo systemctl enable --now languagetool &>/dev/null
echo -e "${CHECKMARK} \e[1;92m Customizing Container... \e[0m"
rm /etc/motd
rm /etc/update-motd.d/10-uname
touch ~/.hushlogin
GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
mkdir -p $(dirname $GETTY_OVERRIDE)
cat << EOF > $GETTY_OVERRIDE
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
EOF
systemctl daemon-reload
systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
echo -e "${CHECKMARK} \e[1;92m Cleanup... \e[0m"
rm -rf /jellyfin_setup.sh /var/{cache,log}/* /var/lib/apt/lists/*

View file

@ -0,0 +1,16 @@
[Unit]
Description=LanguageTool
After=syslog.target
After=network.target
[Service]
Type=simple
User=languagetool
Group=nogroup
WorkingDirectory=/opt/LanguageTool
ExecStart=/usr/bin/java -cp /opt/LanguageTool/languagetool-server.jar org.languagetool.server.HTTPServer --config languagetool.cfg --port 8081 --allow-origin "*" --public
Restart=always
#Environment=USER= HOME=/opt/LanguageTool
[Install]
WantedBy=multi-user.target