From 66396b63caa9ca184dbcc96b8f8bdeb08ab9f845 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Fri, 5 Nov 2021 19:55:36 +0100 Subject: [PATCH] code update --- nextcloud/Dockerfile | 2 +- nextcloud/config.json | 1 + .../root/etc/cont-init.d/51-elasticsearch | 135 +++++++++--------- nextcloud/root/etc/cont-init.d/51-ocr | 28 +++- .../root/etc/cont-init.d/61-trusted_domains | 43 +++--- zzz_templates/00-bettercomments.sh | 8 ++ 6 files changed, 124 insertions(+), 93 deletions(-) create mode 100644 zzz_templates/00-bettercomments.sh diff --git a/nextcloud/Dockerfile b/nextcloud/Dockerfile index 575bf275e..b09e6f519 100644 --- a/nextcloud/Dockerfile +++ b/nextcloud/Dockerfile @@ -16,7 +16,7 @@ RUN \ ################## && echo "**** Install Bashio ****" \ && apk add --no-cache \ - curl jq \ + curl jq wget \ && curl -J -L -o /tmp/bashio.tar.gz \ "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" \ && mkdir /tmp/bashio \ diff --git a/nextcloud/config.json b/nextcloud/config.json index 51934e16b..bbda1b780 100644 --- a/nextcloud/config.json +++ b/nextcloud/config.json @@ -5,6 +5,7 @@ "upstream": "22.2.0", "slug": "nextcloud_ocr", "ingress": false, + "hassio_api": true, "ingress_port": 0, "arch": ["aarch64", "amd64", "armv7"], "description": "Nextcloud for Home Assistant", diff --git a/nextcloud/root/etc/cont-init.d/51-elasticsearch b/nextcloud/root/etc/cont-init.d/51-elasticsearch index b27373def..1cf5723f7 100644 --- a/nextcloud/root/etc/cont-init.d/51-elasticsearch +++ b/nextcloud/root/etc/cont-init.d/51-elasticsearch @@ -1,96 +1,93 @@ #!/usr/bin/with-contenv bashio +# Make sure there is an Nextcloud installation +if ! [ "$(occ -V)" ]; then + bashio::log.warning "It seems there is no Nextcloud server installed. Please restart the addon after initialization of the user." + exit 0 +fi + ############ # BASED ON # -############ -# https://raw.githubusercontent.com/nextcloud/vm/master/apps/fulltextsearch.sh -# T&M Hansson IT AB © - 2021, https://www.hanssonit.se/ -# SwITNet Ltd © - 2021, https://switnet.net/ +################################################################################# +# https://raw.githubusercontent.com/nextcloud/vm/master/apps/fulltextsearch.sh # +# T&M Hansson IT AB © - 2021, https://www.hanssonit.se/ # +# SwITNet Ltd © - 2021, https://switnet.net/ # +################################################################################# -# Download the script -source /sbin/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) +####################### +# Download the script # +####################### +#SCRIPT="/sbin/fetch_lib" +#wget -q -O $SCRIPT https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh +#source $SCRIPT -# Correct the script -sed -i "s|SCRIPTS=/var/scripts|SCRIPTS=/sbin|g" /sbin/fetch_lib.sh -sed -i "s|NCPATH=/var/www/nextcloud|/data/config/www/nextcloud|g" /sbin/fetch_lib.sh -sed -i "s|BACKUP=/mnt/NCBACKUP|BACKUP=/data/NCBACKUP|g" /sbin/fetch_lib.sh +###################### +# Correct the script # +###################### +#sed -i "s|SCRIPTS=/var/scripts|SCRIPTS=/sbin|g" $SCRIPT +#sed -i "s|NCPATH=/var/www/nextcloud|NCPATH=/data/config/www/nextcloud|g" $SCRIPT +#sed -i "s|BACKUP=/mnt/NCBACKUP|BACKUP=/data/NCBACKUP|g" $SCRIPT + +# Test RAM size (2GB min) + CPUs (min 2) +#ram_check 3 FullTextSearch +#cpu_check 2 FullTextSearch # Get all needed variables from the library -ncdb -nc_update -es_install +#ncdb +#nc_update +#es_install # Check for errors + debug code and abort if something isn't right # 1 = ON # 0 = OFF -DEBUG=0 -debug_mode +#DEBUG=0 +#debug_mode # Must be root -root_check +#root_check +# Nextcloud 18 is required. +#lowest_compatible_nc 18 -if [ bashio::config.is_true 'install_elasticsearch' ] && [ ! is_app_installed "fulltextsearch" ]; then +if bashio::config.true 'Full_Text_Search' && [ occ fulltextsearch:index ] &>/dev/null; then + echo "Full Text Search is already working" +else echo "Installing Full Text Search" - - true - SCRIPT_NAME="Full Text Search" - SCRIPT_EXPLAINER="Full Text Search provides Elasticsearch for Nextcloud, which makes it possible to search for text inside files." - : - # Make sure there is an Nextcloud installation - if ! [ "$(nextcloud_occ -V)" ]; then - echo "It seems there is no Nextcloud server installed, please check your installation." - exit 1 - fi - - # Install OCR if requested # Reset Full Text Search to be able to index again, and also remove the app to be able to install it again - nextcloud_occ_no_check fulltextsearch:reset + occ fulltextsearch:reset &>/dev/null || true APPS=(fulltextsearch fulltextsearch_elasticsearch files_fulltextsearch) for app in "${APPS[@]}"; do - if is_app_installed "$app"; then - nextcloud_occ app:remove "$app" - fi + # If app exists, remove it + [ ! -z $(occ app:getpath $app) ] && occ app:remove $app done - # Disable and remove Nextant + Solr - if is_app_installed nextant; then - # Remove Nextant - echo "We will now remove Nextant + Solr and replace it with Full Text Search" - nextcloud_occ app:remove nextant - - # Remove Solr - systemctl stop solr.service - rm -rf /var/solr - rm -rf /opt/solr* - rm /etc/init.d/solr - deluser --remove-home solr - deluser --group solr - fi - - # Check if the app is compatible with the current Nextcloud version - if ! install_and_enable_app fulltextsearch; then - exit 1 - fi - # Get Full Text Search app for nextcloud - echo "... installing apps : fulltextsearch" - install_and_enable_app fulltextsearch - echo "... installing apps : fulltextsearch_elasticsearch" - install_and_enable_app fulltextsearch_elasticsearch - echo "... installing apps : files_fulltextsearch" - install_and_enable_app files_fulltextsearch - echo "... updating permissions" - chown -R abc:abc $NC_APPS_PATH + for app in "${APPS[@]}"; do + echo "... installing apps : $app" + occ app:install $app >/dev/null + occ app:enable $app >/dev/null + done + chown -R abc:abc $NEXTCLOUD_PATH/apps # Final setup - echo "... creating base_config" - nextcloud_occ fulltextsearch:configure '{"search_platform":"OCA\\FullTextSearch_Elasticsearch\\Platform\\ElasticSearchPlatform"}' - nextcloud_occ fulltextsearch_elasticsearch:configure "{\"elastic_host\":\"http://${INDEX_USER}:${ROREST}@localhost:9200\",\"elastic_index\":\"${INDEX_USER}-index\"}" - nextcloud_occ files_fulltextsearch:configure "{\"files_pdf\":\"1\",\"files_office\":\"1\"}" - # Wait further for cache for index to work - countdown "Waiting for a few seconds before indexing starts..." "10" - if nextcloud_occ fulltextsearch:index /dev/null; then + # Wait further for cache for index to work + countdown "Waiting for a few seconds before indexing starts..." "10" + if occ fulltextsearch:index /dev/null || true + occ app:enable files_fulltextsearch_tesseract &>/dev/null || true + echo "Installing OCR" apk add --quiet --no-cache tesseract-ocr || apk add --quiet --no-cache tesseract-ocr@community # Install additional language if requested if bashio::config.has_value 'OCRLANG'; then LANG=$(bashio::config 'OCRLANG') - apk add --quiet --no-cache tesseract-ocr-data-$LANG || apk add --quiet --no-cache tesseract-ocr-data-$LANG@community \ - && bashio::log.info "OCR Language installed : $LANG" || bashio::log.fatal "Couldn't install OCR lang $LANG. Please check its format is conform" + apk add --quiet --no-cache tesseract-ocr-data-$LANG || apk add --quiet --no-cache tesseract-ocr-data-$LANG@community && \ + bashio::log.info "OCR Language installed : $LANG" || bashio::log.fatal "Couldn't install OCR lang $LANG. Please check its format is conform" + + # Downloading trainer data + cd /usr/share/tessdata + sudo rm -r $LANG.traineddata &>/dev/null || true + wget https://github.com/tesseract-ocr/tessdata/raw/main/$LANG.traineddata &>/dev/null + fi elif $(bashio::config 'OCR') = false; then bashio::log.info 'Removing OCR' - apk del tesseract-ocr.* || true + # Delete package + apk del tesseract-ocr.* &>/dev/null || true + # Remove app + occ app:disable files_fulltextsearch_tesseract &>/dev/null || true fi fi diff --git a/nextcloud/root/etc/cont-init.d/61-trusted_domains b/nextcloud/root/etc/cont-init.d/61-trusted_domains index a88673f5b..ab6b53bc6 100644 --- a/nextcloud/root/etc/cont-init.d/61-trusted_domains +++ b/nextcloud/root/etc/cont-init.d/61-trusted_domains @@ -1,28 +1,33 @@ #!/usr/bin/with-contenv bashio - #################### - # Initialization # - #################### +# Make sure there is an Nextcloud installation +if ! [ "$(nextcloud_occ -V)" ]; then + bashio::log.warning "It seems there is no Nextcloud server installed. Please restart the addon after initialization of the user." + exit 0 +fi + +#################### +# Initialization # +#################### if bashio::config.has_value 'trusted_domains'; then -LAUNCHER="sudo -u abc php /data/config/www/nextcloud/occ" || bashio::log.info "/data/config/www/nextcloud/occ not found" -if ! bashio::fs.file_exists '/data/config/www/nextcloud/occ'; then -LAUNCHER=`find / -name "occ" -print -quit` -fi || bashio::log.info "occ not found" + LAUNCHER="sudo -u abc php /data/config/www/nextcloud/occ" || bashio::log.info "/data/config/www/nextcloud/occ not found" + if ! bashio::fs.file_exists '/data/config/www/nextcloud/occ'; then + LAUNCHER=$(find / -name "occ" -print -quit) + fi || bashio::log.info "occ not found" -bashio::log.info "Currently set trusted domains :" -$LAUNCHER config:system:get trusted_domains || bashio::log.info "No trusted domain set yet. The first one will be set when doing initial configuration" + bashio::log.info "Currently set trusted domains :" + $LAUNCHER config:system:get trusted_domains || bashio::log.info "No trusted domain set yet. The first one will be set when doing initial configuration" - bashio::log.info "Trusted domains set in the configuration. Refreshing domains." && \ + bashio::log.info "Trusted domains set in the configuration. Refreshing domains." && \ ################################### # Remove previous trusted domains # ################################### bashio::log.info "... removing previously added trusted domain (except for first one created)" i=2 - until [ $i -gt 5 ] - do - $LAUNCHER config:system:delete trusted_domains $i && \ - ((i=i+1)) || exit + until [ $i -gt 5 ]; do + $LAUNCHER config:system:delete trusted_domains $i && \ + ((i = i + 1)) || exit done ########################### @@ -30,15 +35,13 @@ $LAUNCHER config:system:get trusted_domains || bashio::log.info "No trusted doma ########################### TRUSTEDDOMAINS=$(bashio::config 'trusted_domains') bashio::log.info "... alignement with trusted domains list : ${TRUSTEDDOMAINS}" - for domain in ${TRUSTEDDOMAINS//,/ } # Comma separated values - do + for domain in ${TRUSTEDDOMAINS//,/ }; do # Comma separated values bashio::log.info "... adding ${domain}" $LAUNCHER config:system:set trusted_domains $i --value=${domain} - i=$((i+1)) + i=$((i + 1)) done -bashio::log.info "Remaining configurated trusted domains :" -bashio::log.info "$($LAUNCHER config:system:get trusted_domains)" || exit + bashio::log.info "Remaining configurated trusted domains :" + bashio::log.info "$($LAUNCHER config:system:get trusted_domains)" || exit fi - diff --git a/zzz_templates/00-bettercomments.sh b/zzz_templates/00-bettercomments.sh new file mode 100644 index 000000000..c52e0660e --- /dev/null +++ b/zzz_templates/00-bettercomments.sh @@ -0,0 +1,8 @@ +#!bin/bash + +# Color comments +#! Red +#? Question +#// Done +#todo To do +#* Green