init docker
This commit is contained in:
@@ -1,37 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Update the user and group IDs as per environment variables
|
||||
if [ ! -z "$PUID" ] && [ "$PUID" != "$(id -u stirlingpdfuser)" ]; then
|
||||
usermod -o -u "$PUID" stirlingpdfuser || true
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -z "$PGID" ] && [ "$PGID" != "$(getent group stirlingpdfgroup | cut -d: -f3)" ]; then
|
||||
groupmod -o -g "$PGID" stirlingpdfgroup || true
|
||||
fi
|
||||
umask "$UMASK" || true
|
||||
|
||||
if [[ "$INSTALL_BOOK_AND_ADVANCED_HTML_OPS" == "true" && "$FAT_DOCKER" != "true" ]]; then
|
||||
echo "issue with calibre in current version, feature currently disabled on Stirling-PDF"
|
||||
#apk add --no-cache calibre@testing
|
||||
fi
|
||||
|
||||
if [[ "$FAT_DOCKER" != "true" ]]; then
|
||||
/scripts/download-security-jar.sh
|
||||
/scripts/download-security-jar.sh
|
||||
fi
|
||||
|
||||
if [[ -n "$LANGS" ]]; then
|
||||
/scripts/installFonts.sh $LANGS
|
||||
/scripts/installFonts.sh $LANGS
|
||||
fi
|
||||
|
||||
echo "Setting permissions and ownership for necessary directories..."
|
||||
# Attempt to change ownership of directories and files
|
||||
if chown -R stirlingpdfuser:stirlingpdfgroup $HOME /logs /scripts /usr/share/fonts/opentype/noto /configs /customFiles /pipeline /app.jar; then
|
||||
chmod -R 755 /logs /scripts /usr/share/fonts/opentype/noto /configs /customFiles /pipeline /app.jar || true
|
||||
# If chown succeeds, execute the command as stirlingpdfuser
|
||||
exec su-exec stirlingpdfuser "$@"
|
||||
else
|
||||
# If chown fails, execute the command without changing the user context
|
||||
echo "[WARN] Chown failed, running as host user"
|
||||
exec "$@"
|
||||
fi
|
||||
exec "$@"
|
||||
@@ -1,31 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copy the original tesseract-ocr files to the volume directory without overwriting existing files
|
||||
echo "Copying original files without overwriting existing files"
|
||||
mkdir -p /usr/share/tessdata
|
||||
cp -rn /usr/share/tessdata-original/* /usr/share/tessdata
|
||||
cp -rn /usr/share/tessdata-original/* /usr/share/tessdata 2>/dev/null || true
|
||||
|
||||
# Copy additional tessdata if available
|
||||
if [ -d /usr/share/tesseract-ocr/4.00/tessdata ]; then
|
||||
cp -r /usr/share/tesseract-ocr/4.00/tessdata/* /usr/share/tessdata || true;
|
||||
cp -rn /usr/share/tesseract-ocr/4.00/tessdata/* /usr/share/tessdata 2>/dev/null || true
|
||||
fi
|
||||
|
||||
if [ -d /usr/share/tesseract-ocr/5/tessdata ]; then
|
||||
cp -r /usr/share/tesseract-ocr/5/tessdata/* /usr/share/tessdata || true;
|
||||
cp -rn /usr/share/tesseract-ocr/5/tessdata/* /usr/share/tessdata 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Check if TESSERACT_LANGS environment variable is set and is not empty
|
||||
if [[ -n "$TESSERACT_LANGS" ]]; then
|
||||
# Convert comma-separated values to a space-separated list
|
||||
LANGS=$(echo $TESSERACT_LANGS | tr ',' ' ')
|
||||
pattern='^[a-zA-Z]{2,4}(_[a-zA-Z]{2,4})?$'
|
||||
# Install each language pack
|
||||
for LANG in $LANGS; do
|
||||
if [[ $LANG =~ $pattern ]]; then
|
||||
apk add --no-cache "tesseract-ocr-data-$LANG"
|
||||
else
|
||||
echo "Skipping invalid language code"
|
||||
fi
|
||||
done
|
||||
# Convert comma-separated values to a space-separated list
|
||||
TES_LANGS=$(echo $TESSERACT_LANGS | tr ',' ' ')
|
||||
pattern='^[a-zA-Z]{2,4}(_[a-zA-Z]{2,4})?$'
|
||||
|
||||
# Log available languages
|
||||
echo "Currently installed languages:"
|
||||
tesseract --list-langs
|
||||
|
||||
echo "Requested additional languages: $TES_LANGS"
|
||||
|
||||
# Instead of apk add, download language files from a known source
|
||||
for LANG in $TES_LANGS; do
|
||||
if [[ $LANG =~ $pattern ]]; then
|
||||
# Download to user-writable directory
|
||||
wget -P /usr/share/tessdata/ "https://github.com/tesseract-ocr/tessdata/raw/main/${LANG}.traineddata" || \
|
||||
echo "Failed to download language pack for ${LANG}"
|
||||
else
|
||||
echo "Skipping invalid language code"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
/scripts/init-without-ocr.sh "$@"
|
||||
@@ -1,67 +1,156 @@
|
||||
#!/bin/bash
|
||||
|
||||
LANGS=$1
|
||||
FONT_DIR="$HOME/.local/share/fonts"
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
|
||||
# Function to install a font package
|
||||
install_font() {
|
||||
echo "Installing font package: $1"
|
||||
if ! apk add "$1" --no-cache; then
|
||||
echo "Failed to install $1"
|
||||
fi
|
||||
# Create fonts directory if it doesn't exist
|
||||
mkdir -p "$FONT_DIR"
|
||||
|
||||
# Function to get latest GitHub release
|
||||
get_latest_release() {
|
||||
local repo=$1
|
||||
local api_url="https://api.github.com/repos/$repo/releases/latest"
|
||||
curl --silent "$api_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
|
||||
}
|
||||
|
||||
# Install common fonts used across many languages
|
||||
#common_fonts=(
|
||||
# font-terminus
|
||||
# font-dejavu
|
||||
# font-noto
|
||||
# font-noto-cjk
|
||||
# font-awesome
|
||||
# font-noto-extra
|
||||
#)
|
||||
#
|
||||
#for font in "${common_fonts[@]}"; do
|
||||
# install_font $font
|
||||
#done
|
||||
# Function to download and install a font
|
||||
install_font() {
|
||||
local font_name=$1
|
||||
echo "Installing font package: $font_name"
|
||||
|
||||
# Map font package names to actual font URLs and installation methods
|
||||
case $font_name in
|
||||
"font-dejavu")
|
||||
local version=$(get_latest_release "dejavu-fonts/dejavu-fonts")
|
||||
version=${version#version_} # Remove 'version_' prefix
|
||||
local url="https://github.com/dejavu-fonts/dejavu-fonts/releases/download/version_${version}/dejavu-fonts-ttf-${version}.tar.bz2"
|
||||
wget -q "$url" -P "$TEMP_DIR" && \
|
||||
tar xjf "$TEMP_DIR/dejavu-fonts-ttf-${version}.tar.bz2" -C "$TEMP_DIR" && \
|
||||
find "$TEMP_DIR" -name "*.ttf" -exec cp {} "$FONT_DIR/" \;
|
||||
;;
|
||||
|
||||
"font-noto")
|
||||
# Base Noto Sans and Serif
|
||||
wget -q "https://noto-website-2.storage.googleapis.com/pkgs/NotoSans-hinted.zip" -P "$TEMP_DIR" && \
|
||||
wget -q "https://noto-website-2.storage.googleapis.com/pkgs/NotoSerif-hinted.zip" -P "$TEMP_DIR" && \
|
||||
unzip -q "$TEMP_DIR/NotoSans-hinted.zip" -d "$TEMP_DIR/noto-sans" && \
|
||||
unzip -q "$TEMP_DIR/NotoSerif-hinted.zip" -d "$TEMP_DIR/noto-serif" && \
|
||||
cp "$TEMP_DIR/noto-sans"/*.ttf "$FONT_DIR/" && \
|
||||
cp "$TEMP_DIR/noto-serif"/*.ttf "$FONT_DIR/"
|
||||
;;
|
||||
|
||||
"font-noto-cjk")
|
||||
# Noto CJK
|
||||
wget -q "https://github.com/notofonts/noto-cjk/raw/main/Sans/OTF/Japanese/NotoSansCJKjp-Regular.otf" -P "$FONT_DIR"
|
||||
wget -q "https://github.com/notofonts/noto-cjk/raw/main/Sans/OTF/Korean/NotoSansCJKkr-Regular.otf" -P "$FONT_DIR"
|
||||
wget -q "https://github.com/notofonts/noto-cjk/raw/main/Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Regular.otf" -P "$FONT_DIR"
|
||||
wget -q "https://github.com/notofonts/noto-cjk/raw/main/Sans/OTF/TraditionalChinese/NotoSansCJKtc-Regular.otf" -P "$FONT_DIR"
|
||||
;;
|
||||
|
||||
"font-noto-arabic")
|
||||
wget -q "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoNaskhArabic/NotoNaskhArabic-Regular.ttf" -P "$FONT_DIR"
|
||||
wget -q "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoKufiArabic/NotoKufiArabic-Regular.ttf" -P "$FONT_DIR"
|
||||
;;
|
||||
|
||||
"font-noto-devanagari")
|
||||
wget -q "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSansDevanagari/NotoSansDevanagari-Regular.ttf" -P "$FONT_DIR"
|
||||
wget -q "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSerifDevanagari/NotoSerifDevanagari-Regular.ttf" -P "$FONT_DIR"
|
||||
;;
|
||||
|
||||
"font-noto-thai")
|
||||
wget -q "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSansThai/NotoSansThai-Regular.ttf" -P "$FONT_DIR"
|
||||
wget -q "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSerifThai/NotoSerifThai-Regular.ttf" -P "$FONT_DIR"
|
||||
;;
|
||||
|
||||
"font-noto-hebrew")
|
||||
wget -q "https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSansHebrew/NotoSansHebrew-Regular.ttf" -P "$FONT_DIR"
|
||||
;;
|
||||
|
||||
"font-awesome")
|
||||
local version=$(get_latest_release "FortAwesome/Font-Awesome")
|
||||
wget -q "https://use.fontawesome.com/releases/v${version}/fontawesome-free-${version}-desktop.zip" -P "$TEMP_DIR" && \
|
||||
unzip -q "$TEMP_DIR/fontawesome-free-${version}-desktop.zip" -d "$TEMP_DIR" && \
|
||||
cp "$TEMP_DIR/fontawesome-free-${version}-desktop/otfs"/*.otf "$FONT_DIR/"
|
||||
;;
|
||||
|
||||
"font-source-code-pro")
|
||||
local version=$(get_latest_release "adobe-fonts/source-code-pro")
|
||||
wget -q "https://github.com/adobe-fonts/source-code-pro/releases/download/${version}/TTF-source-code-pro-${version}.zip" -P "$TEMP_DIR" && \
|
||||
unzip -q "$TEMP_DIR/TTF-source-code-pro-${version}.zip" -d "$TEMP_DIR/source-code-pro" && \
|
||||
cp "$TEMP_DIR/source-code-pro"/*.ttf "$FONT_DIR/"
|
||||
;;
|
||||
|
||||
"font-vollkorn")
|
||||
wget -q "https://github.com/FAlthausen/Vollkorn-Typeface/raw/main/fonts/TTF/Vollkorn-Regular.ttf" -P "$FONT_DIR"
|
||||
;;
|
||||
|
||||
"font-liberation")
|
||||
wget -q "https://github.com/liberationfonts/liberation-fonts/files/7261482/liberation-fonts-ttf-2.1.5.tar.gz" -P "$TEMP_DIR" && \
|
||||
tar xzf "$TEMP_DIR/liberation-fonts-ttf-2.1.5.tar.gz" -C "$TEMP_DIR" && \
|
||||
cp "$TEMP_DIR/liberation-fonts-ttf-2.1.5"/*.ttf "$FONT_DIR/"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Completed installation attempt for $font_name"
|
||||
}
|
||||
|
||||
# Map languages to specific font packages
|
||||
# Enhanced language-specific font mappings
|
||||
declare -A language_fonts=(
|
||||
["ar_AR"]="font-noto-arabic"
|
||||
["zh_CN"]="font-isas-misc"
|
||||
["zh_TW"]="font-isas-misc"
|
||||
["ja_JP"]="font-noto font-noto-thai font-noto-tibetan font-ipa font-sony-misc font-jis-misc"
|
||||
["ru_RU"]="font-vollkorn font-misc-cyrillic font-mutt-misc font-screen-cyrillic font-winitzki-cyrillic font-cronyx-cyrillic"
|
||||
["sr_LATN_RS"]="font-vollkorn font-misc-cyrillic font-mutt-misc font-screen-cyrillic font-winitzki-cyrillic font-cronyx-cyrillic"
|
||||
["uk_UA"]="font-vollkorn font-misc-cyrillic font-mutt-misc font-screen-cyrillic font-winitzki-cyrillic font-cronyx-cyrillic"
|
||||
["ko_KR"]="font-noto font-noto-thai font-noto-tibetan"
|
||||
["zh_CN"]="font-noto-cjk"
|
||||
["zh_TW"]="font-noto-cjk"
|
||||
["ja_JP"]="font-noto font-noto-cjk"
|
||||
["ru_RU"]="font-noto font-liberation font-vollkorn"
|
||||
["sr_LATN_RS"]="font-noto font-liberation"
|
||||
["uk_UA"]="font-noto font-liberation"
|
||||
["ko_KR"]="font-noto font-noto-cjk"
|
||||
["el_GR"]="font-noto"
|
||||
["hi_IN"]="font-noto-devanagari"
|
||||
["bg_BG"]="font-vollkorn font-misc-cyrillic"
|
||||
["GENERAL"]="font-terminus font-dejavu font-noto font-noto-cjk font-awesome font-noto-extra"
|
||||
["bg_BG"]="font-noto font-liberation"
|
||||
["th_TH"]="font-noto-thai"
|
||||
["he_IL"]="font-noto-hebrew"
|
||||
["GENERAL"]="font-noto font-dejavu font-liberation font-source-code-pro font-awesome"
|
||||
)
|
||||
|
||||
# Install fonts for other languages which generally do not need special packages beyond 'font-noto'
|
||||
other_langs=("en_GB" "en_US" "de_DE" "fr_FR" "es_ES" "ca_CA" "it_IT" "pt_BR" "nl_NL" "sv_SE" "pl_PL" "ro_RO" "hu_HU" "tr_TR" "id_ID" "eu_ES")
|
||||
# Install fonts based on specified languages
|
||||
if [[ $LANGS == "ALL" ]]; then
|
||||
# Install all fonts from the language_fonts map
|
||||
declare -A installed_fonts
|
||||
for fonts in "${language_fonts[@]}"; do
|
||||
for font in $fonts; do
|
||||
install_font $font
|
||||
if [[ -z "${installed_fonts[$font]}" ]]; then
|
||||
install_font "$font"
|
||||
installed_fonts[$font]=1
|
||||
fi
|
||||
done
|
||||
done
|
||||
else
|
||||
# Split comma-separated languages and install necessary fonts
|
||||
declare -A installed_fonts
|
||||
IFS=',' read -ra LANG_CODES <<< "$LANGS"
|
||||
for code in "${LANG_CODES[@]}"; do
|
||||
if [[ " ${other_langs[@]} " =~ " ${code} " ]]; then
|
||||
install_font font-noto
|
||||
else
|
||||
fonts_to_install=${language_fonts[$code]}
|
||||
if [ ! -z "$fonts_to_install" ]; then
|
||||
for font in $fonts_to_install; do
|
||||
install_font $font
|
||||
done
|
||||
fi
|
||||
fonts_to_install=${language_fonts[$code]}
|
||||
if [ ! -z "$fonts_to_install" ]; then
|
||||
for font in $fonts_to_install; do
|
||||
if [[ -z "${installed_fonts[$font]}" ]]; then
|
||||
install_font "$font"
|
||||
installed_fonts[$font]=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
# Update font cache
|
||||
if command -v fc-cache >/dev/null; then
|
||||
fc-cache -f "$FONT_DIR"
|
||||
echo "Font cache updated"
|
||||
else
|
||||
echo "Warning: fc-cache not found. You may need to manually update your font cache"
|
||||
fi
|
||||
|
||||
echo "Font installation completed. Fonts installed in: $FONT_DIR"
|
||||
Reference in New Issue
Block a user