Add Imaginary Docker for previews (#2464)

This commit is contained in:
Daniel Hansson 2023-04-01 23:07:56 +02:00 коммит произвёл GitHub
Родитель d5aa43c6f0
Коммит 64b69c9097
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 482 добавлений и 320 удалений

149
apps/imaginary.sh Normal file
Просмотреть файл

@ -0,0 +1,149 @@
#!/bin/bash
# T&M Hansson IT AB © - 2023, https://www.hanssonit.se/
# GNU General Public License v3.0
# https://github.com/nextcloud/vm/blob/master/LICENSE
true
SCRIPT_NAME="Imaginary Docker"
SCRIPT_EXPLAINER="This script will install Imaginary which is a replacement for the less secure Imagick.
It can speedup the loading of previews in Nextcloud a lot."
# shellcheck source=lib.sh
source /var/scripts/fetch_lib.sh
# Check for errors + debug code and abort if something isn't right
# 1 = ON
# 0 = OFF
DEBUG=0
debug_mode
# Check if root
root_check
# Check recources
ram_check 4
cpu_check 4
# Compatible with NC24 and above
lowest_compatible_nc 26
# Check if Imaginary is already installed
if ! does_this_docker_exist nextcloud/aio-imaginary
then
# Ask for installing
install_popup "$SCRIPT_NAME"
else
# Ask for removal or reinstallation
reinstall_remove_menu "$SCRIPT_NAME"
# Removal
if yesno_box_yes "Do you want to remove the Imaginary docker container and settings?"
then
# Remove docker container
docker_prune_this 'nextcloud/aio-imaginary'
# reset the preview formats
nextcloud_occ config:system:delete "preview_imaginary_url"
nextcloud_occ config:system:delete "enabledPreviewProviders"
nextcloud_occ config:system:delete "preview_max_x"
nextcloud_occ config:system:delete "preview_max_y"
nextcloud_occ config:system:delete "jpeg_quality"
nextcloud_occ config:system:delete "preview_max_memory"
nextcloud_occ config:system:delete "enable_previews"
nextcloud_occ config:system:delete "preview_concurrency_new"
nextcloud_occ config:system:delete "preview_concurrency_all"
# Remove FFMPEG
if is_this_installed ffmpeg && ! is_app_installed integration_whiteboard
then
apt-get purge ffmpeg -y
apt-get autoremove -y
fi
# Show successful uninstall if applicable
removal_popup "$SCRIPT_NAME"
fi
fi
# Remove everything that is related to previewgenerator
if is_app_enabled previewgenerator
then
if yesno_box_yes "We noticed that you have Preview Generator enabled. Imagniary replaces this, and the old app Preview Generator is now legacy. We recommend you to remove it. Do you want to do that?"
then
# Remove the app
nextcloud_occ app:remove previewgenerator
# Reset the cronjob
crontab -u www-data -l | grep -v 'preview:pre-generate' | crontab -u www-data -
# Remove apps
APPS=(php-imagick php"$PHPVER"-imagick libmagickcore-6.q16-3-extra imagemagick-6.q16-extra)
for app in "${APPS[@]}"
do
if is_this_installed "$app"
then
apt-get purge "$app" -y
fi
done
# Remove custom config
rm -rf /etc/ImageMagick-6
# Remove previews
if yesno_box_yes "Do you want to remove all previews that were generated until now?
This will most likely clear a lot of space! Also, pre-generated previews are not needed anymore once Imaginary are installed."
then
countdown "Removing the preview folder. This can take a while..." "5"
rm -rfv "$NCDATA"/appdata_*/preview/*
print_text_in_color "$ICyan" "Scanning Nextclouds appdata directory after removing all previews. \
This can take a while..."
nextcloud_occ files:scan-app-data preview -vvv
msg_box "All previews were successfully removed."
fi
# Remove log
rm -f "$VMLOGS"/previewgenerator.log
fi
fi
# Install Docker
install_docker
# Pull and start
docker pull nextcloud/aio-imaginary:latest
docker run -t -d -p 127.0.0.1:9000:9000 --restart always --name imaginary nextcloud/aio-imaginary -concurrency 50 -enable-url-source -log-level debug
# Test if imaginary is working
countdown "Testing if it works in 3 sedonds" "3"
if curl -O "http://127.0.0.1:9000/crop?width=500&height=400&url=https://raw.githubusercontent.com/h2non/imaginary/master/testdata/large.jpg"
then
print_text_in_color "$IGreen" "imaginary seems to be working OK!"
rm -f large.jpg
else
msg_box "Test failed, please report this to: $ISSUES"
exit
fi
# Install dependencies
check_php
install_if_not php"$PHPVER"-sysvsem
install_if_not ffmpeg
# Set default limits
# https://github.com/nextcloud/server/pull/18210/files#diff-3bbe91e1f85eec5dbd0031642dfb0ad6749b550fc3b94af7aa68a98210b78738R1121
nextcloud_occ config:system:set preview_concurrency_all --value="8"
nextcloud_occ config:system:set preview_concurrency_new --value="4"
# Set providers (https://github.com/nextcloud/server/blob/master/lib/private/Preview/Imaginary.php#L60)
# https://github.com/nextcloud/vm/pull/2464#discussion_r1155074227
nextcloud_occ config:system:set enabledPreviewProviders 0 --value="OC\\Preview\\Imaginary"
nextcloud_occ config:system:set enabledPreviewProviders 1 --value="OC\\Preview\\Image"
nextcloud_occ config:system:set enabledPreviewProviders 2 --value="OC\\Preview\\MarkDown"
nextcloud_occ config:system:set enabledPreviewProviders 3 --value="OC\\Preview\\MP3"
nextcloud_occ config:system:set enabledPreviewProviders 4 --value="OC\\Preview\\TXT"
nextcloud_occ config:system:set enabledPreviewProviders 5 --value="OC\\Preview\\OpenDocument"
nextcloud_occ config:system:set enabledPreviewProviders 6 --value="OC\\Preview\\Movie"
nextcloud_occ config:system:set preview_imaginary_url --value="http://127.0.0.1:9000"
# Set general values
nextcloud_occ config:system:set preview_max_x --value="2048"
nextcloud_occ config:system:set preview_max_y --value="2048"
nextcloud_occ config:system:set jpeg_quality --value="60"
nextcloud_occ config:system:set preview_max_memory --value="256"
if docker logs imaginary
then
msg_box "Imaginary was successfully installed!"
else
msg_box "It seems that something is wrong. Please post the full installation output to $ISSUES"
fi

Просмотреть файл

@ -2,300 +2,6 @@
# T&M Hansson IT AB © - 2023, https://www.hanssonit.se/
true
SCRIPT_NAME="Preview Generator"
SCRIPT_EXPLAINER="This script will install the Preview Generator.
It can speedup the loading of previews in Nextcloud a lot."
# shellcheck source=lib.sh
source /var/scripts/fetch_lib.sh
####### TEMPORARY 2023-04-01 #######
# Check for errors + debug code and abort if something isn't right
# 1 = ON
# 0 = OFF
DEBUG=0
debug_mode
# Check if root
root_check
# PHP 7.x is needed
if is_this_installed php5.6-common || is_this_installed php5.5-common
then
msg_box "At least PHP 7.X is required, please upgrade your PHP version: \
https://shop.hanssonit.se/product/upgrade-php-version-including-dependencies/"
exit
fi
# Encryption may not be enabled
if is_app_enabled encryption || is_app_enabled end_to_end_encryption
then
msg_box "It seems like you have encryption enabled which is unsupported when using the Preview Generator"
exit
fi
# Check if previewgenerator is already installed
if ! is_app_installed previewgenerator
then
# Ask for installing
install_popup "$SCRIPT_NAME"
else
# Ask for removal or reinstallation
reinstall_remove_menu "$SCRIPT_NAME"
# Removal
nextcloud_occ app:remove previewgenerator
# reset the preview formats
nextcloud_occ_no_check config:system:delete "enabledPreviewProviders"
nextcloud_occ config:system:delete preview_max_x
nextcloud_occ config:system:delete preview_max_y
nextcloud_occ config:system:delete jpeg_quality
nextcloud_occ config:system:delete preview_max_memory
nextcloud_occ config:system:delete enable_previews
# reset the cronjob
crontab -u www-data -l | grep -v 'preview:pre-generate' | crontab -u www-data -
# Remove apps
APPS=(php-imagick libmagickcore-6.q16-3-extra imagemagick-6.q16-extra)
for app in "${APPS[@]}"
do
if is_this_installed "$app"
then
apt-get purge "$app" -y
fi
done
if is_this_installed ffmpeg && ! is_app_installed integration_whiteboard
then
apt-get purge ffmpeg -y
fi
apt-get autoremove -y
if yesno_box_no "Do you want to remove all previews that were generated until now?
This will most likely clear a lot of space but your server will need to re-generate the previews \
if you should opt to re-enable previews again."
then
countdown "Removing the preview folder. This can take a while..." "5"
rm -rfv "$NCDATA"/appdata_*/preview
print_text_in_color "$ICyan" "Scanning Nextclouds appdata directory after removing all previews. \
This can take a while..."
nextcloud_occ files:scan-app-data -vvv
msg_box "All previews were successfully removed."
fi
# Show successful uninstall if applicable
removal_popup "$SCRIPT_NAME"
fi
# Install preview generator
install_and_enable_app previewgenerator
# check if the previewgenerator is installed and enabled
if is_app_enabled previewgenerator
then
# enable previews
nextcloud_occ config:system:set enable_previews --value=true --type=boolean
# install needed dependency for movies
install_if_not ffmpeg
else
exit
fi
msg_box "In the next step you can choose to install a package called imagick \
to speed up the generation of previews and add support for more filetypes.
The currently supported filetypes are:
* PNG
* JPEG
* GIF
* BMP
* MarkDown
* MP3
* TXT
* Movie
* Photoshop (needs imagick)
* SVG (needs imagick)
* TIFF (needs imagick)"
msg_box "IMPORTANT NOTE!!
Imagick will put your server at risk as it's is known to have several flaws.
You can check this issue to understand why: https://github.com/nextcloud/vm/issues/743
Please note: If you choose not to install imagick, it will get removed now."
if yesno_box_no "Do you want to install imagick?"
then
check_php
# Install imagick
install_if_not php"$PHPVER"-imagick
if version 22.04 "$DISTRO" 22.04.10
then
install_if_not libmagickcore-6.q16-6-extra
elif version 20.04 "$DISTRO" 20.04.10
then
install_if_not libmagickcore-6.q16-3-extra
fi
# Memory tuning
sed -i 's|policy domain="resource" name="memory" value=.*|policy domain="resource" name="memory" value="512MiB"|g' /etc/ImageMagick-6/policy.xml
sed -i 's|policy domain="resource" name="map" value=.*|policy domain="resource" name="map" value="1024MiB"|g' /etc/ImageMagick-6/policy.xml
sed -i 's|policy domain="resource" name="area" value=.*|policy domain="resource" name="area" value="256MiB"|g' /etc/ImageMagick-6/policy.xml
sed -i 's|policy domain="resource" name="disk" value=.*|policy domain="resource" name="disk" value="8GiB"|g' /etc/ImageMagick-6/policy.xml
# Choose file formats fo the case when imagick is installed.
# for additional previews please look at the Nextcloud documentation. But these probably won't work.
choice=$(whiptail --title "$TITLE - Choose file formats" --checklist \
"Now you can choose for which file formats you would like to generate previews for
$CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"PNG" "" ON \
"JPEG" "" ON \
"GIF" "" ON \
"BMP" "" ON \
"MarkDown" "" ON \
"MP3" "" ON \
"TXT" "" ON \
"Movie" "" ON \
"Photoshop" "" ON \
"SVG" "" ON \
"TIFF" "" ON 3>&1 1>&2 2>&3)
case "$choice" in
*"PNG"*)
nextcloud_occ config:system:set enabledPreviewProviders 0 --value="OC\\Preview\\PNG"
;;&
*"JPEG"*)
nextcloud_occ config:system:set enabledPreviewProviders 1 --value="OC\\Preview\\JPEG"
;;&
*"GIF"*)
nextcloud_occ config:system:set enabledPreviewProviders 2 --value="OC\\Preview\\GIF"
;;&
*"BMP"*)
nextcloud_occ config:system:set enabledPreviewProviders 3 --value="OC\\Preview\\BMP"
;;&
*"MarkDown"*)
nextcloud_occ config:system:set enabledPreviewProviders 4 --value="OC\\Preview\\MarkDown"
;;&
*"MP3"*)
nextcloud_occ config:system:set enabledPreviewProviders 5 --value="OC\\Preview\\MP3"
;;&
*"TXT"*)
nextcloud_occ config:system:set enabledPreviewProviders 6 --value="OC\\Preview\\TXT"
;;&
*"Movie"*)
nextcloud_occ config:system:set enabledPreviewProviders 7 --value="OC\\Preview\\Movie"
;;&
*"Photoshop"*)
nextcloud_occ config:system:set enabledPreviewProviders 8 --value="OC\\Preview\\Photoshop"
;;&
*"SVG"*)
nextcloud_occ config:system:set enabledPreviewProviders 9 --value="OC\\Preview\\SVG"
;;&
*"TIFF"*)
nextcloud_occ config:system:set enabledPreviewProviders 10 --value="OC\\Preview\\TIFF"
;;&
*)
;;
esac
else
# check if imagick is installed and remove it
if is_this_installed php-imagick
then
apt-get purge php-imagick -y
elif is_this_installed php"$PHPVER"-imagick
then
apt-get purge php"$PHPVER"-imagick -y
fi
# check if libmagickcore is installed and remove it
if is_this_installed libmagickcore-6.q16-3-extra
then
apt-get purge libmagickcore-6.q16-3-extra -y
fi
# Choose file formats fo the case when imagick is not installed.
# for additional previews please look at the Nextcloud documentation. But these probably won't work.
choice=$(whiptail --title "$TITLE - Choose file formats" --checklist \
"Now you can choose for which file formats you would like to generate previews for
$CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"PNG" "" ON \
"JPEG" "" ON \
"GIF" "" ON \
"BMP" "" ON \
"MarkDown" "" ON \
"MP3" "" ON \
"TXT" "" ON \
"Movie" "" ON 3>&1 1>&2 2>&3)
case "$choice" in
*"PNG"*)
nextcloud_occ config:system:set enabledPreviewProviders 11 --value="OC\\Preview\\PNG"
;;&
*"JPEG"*)
nextcloud_occ config:system:set enabledPreviewProviders 12 --value="OC\\Preview\\JPEG"
;;&
*"GIF"*)
nextcloud_occ config:system:set enabledPreviewProviders 13 --value="OC\\Preview\\GIF"
;;&
*"BMP"*)
nextcloud_occ config:system:set enabledPreviewProviders 14 --value="OC\\Preview\\BMP"
;;&
*"MarkDown"*)
nextcloud_occ config:system:set enabledPreviewProviders 15 --value="OC\\Preview\\MarkDown"
;;&
*"MP3"*)
nextcloud_occ config:system:set enabledPreviewProviders 16 --value="OC\\Preview\\MP3"
;;&
*"TXT"*)
nextcloud_occ config:system:set enabledPreviewProviders 17 --value="OC\\Preview\\TXT"
;;&
*"Movie"*)
nextcloud_occ config:system:set enabledPreviewProviders 18 --value="OC\\Preview\\Movie"
;;&
*)
;;
esac
fi
# Set aspect ratio
nextcloud_occ config:app:set previewgenerator squareSizes --value="32 256"
nextcloud_occ config:app:set previewgenerator widthSizes --value="256 384"
nextcloud_occ config:app:set previewgenerator heightSizes --value="256"
nextcloud_occ config:system:set preview_max_x --value="2048"
nextcloud_occ config:system:set preview_max_y --value="2048"
nextcloud_occ config:system:set jpeg_quality --value="60"
nextcloud_occ config:system:set preview_max_memory --value="128"
nextcloud_occ config:app:set preview jpeg_quality --value="60"
# Add crontab for www-data
if ! crontab -u www-data -l | grep -q 'preview:pre-generate'
then
print_text_in_color "$ICyan" "Adding crontab for $SCRIPT_NAME"
crontab -u www-data -l | { cat; echo "*/10 * * * * php -f $NCPATH/occ preview:pre-generate >> $VMLOGS/previewgenerator.log"; } | crontab -u www-data -
touch "$VMLOGS"/previewgenerator.log
chown www-data:www-data "$VMLOGS"/previewgenerator.log
fi
msg_box "In the last step you can define a specific Nextcloud user for \
which will be the user that runs the Preview Generation.
The default behavior (just hit [ENTER]) is to run with the \
system user 'www-data' which will generate previews for all users.
If you on the other hand choose to use a specific user, previews will ONLY be generated for that specific user."
if ! yesno_box_no "Do you want to choose a specific Nextcloud user to generate previews?"
then
print_text_in_color "$ICyan" "Using www-data (all Nextcloud users) for generating previews..."
# Pre generate everything
nextcloud_occ preview:generate-all
else
while :
do
PREVIEW_USER=$(input_box "Enter the Nextcloud user for \
which you want to run the Preview Generation (as a scheduled task)")
if [ -z "$(nextcloud_occ user:list | grep "$PREVIEW_USER" | awk '{print $3}')" ]
then
msg_box "It seems like the user you entered ($PREVIEW_USER) doesn't exist, please try again."
else
break
fi
done
# Pre generate everything
nextcloud_occ preview:generate-all "$PREVIEW_USER"
fi
msg_box "Previewgenerator was successfully installed."
run_script APPS imaginary

41
lib.sh
Просмотреть файл

@ -70,7 +70,7 @@ INTERNET_DNS="9.9.9.9"
# Default Quad9 DNS servers, overwritten by the systemd global DNS defined servers, if set
DNS1="9.9.9.9"
DNS2="149.112.112.112"
NONO_PORTS=(22 25 53 80 443 1024 3012 3306 5178 5179 5432 7867 7983 8983 10000 8081 8443 9443)
NONO_PORTS=(22 25 53 80 443 1024 3012 3306 5178 5179 5432 7867 7983 8983 10000 8081 8443 9443 9000 9980)
use_global_systemd_dns() {
if [ -f "/etc/systemd/resolved.conf" ]
then
@ -1654,7 +1654,7 @@ is_image_present() {
}
# Check if old docker exists
# FULL NAME e.g. ark74/nc_fts or containrrr/watchtower or collabora/code
# FULL NAME e.g. ark74/nc_fts or containrrr/watchtower or collabora/code or 'nextcloud/aio-imaginary'
does_this_docker_exist() {
is_docker_running && is_image_present "$1";
}
@ -1691,30 +1691,33 @@ print_text_in_color "$ICyan" "Checking if there are any old images and removing
DOCKERPS=$(docker ps -a | grep -v "$1" | awk 'NR>1 {print $1}')
if [ "$DOCKERPS" != "" ]
then
msg_box "Removing old Docker instance(s)... ($DOCKERPS)
Please note that we will not remove $1 ($2).
You will be given the option to abort when you hit OK."
any_key "Press any key to continue. Press CTRL+C to abort"
docker stop "$(docker ps -a | grep -v "$1" | awk 'NR>1 {print $1}')"
docker container prune -f
docker image prune -a -f
docker volume prune -f
if yesno_box_yes "Do you want to remove old Docker instance(s)... ($DOCKERPS)? Please note that we will not remove $1 ($2)."
then
docker stop "$(docker ps -a | grep -v "$1" | awk 'NR>1 {print $1}')"
docker container prune -f
docker image prune -a -f
docker volume prune -f
else
msg_box "OK, this script will now exit, but there's still leftovers to cleanup. You can run it again at any time."
exit
fi
fi
}
# Remove selected Docker image
# docker_prune_this 'collabora/code' 'onlyoffice/documentserver' 'ark74/nc_fts'
# docker_prune_this 'collabora/code' 'onlyoffice/documentserver' 'ark74/nc_fts' 'nextcloud/aio-imaginary'
docker_prune_this() {
if does_this_docker_exist "$1"
then
msg_box "Removing old Docker image: $1
You will be given the option to abort when you hit OK."
any_key "Press any key to continue. Press CTRL+C to abort"
docker stop "$(docker container ls -a | grep "$1" | awk '{print $1}' | tail -1)"
docker rm "$(docker container ls -a | grep "$1" | awk '{print $1}' | tail -1)" --volumes
docker image prune -a -f
if yesno_box_yes "Do you want to remove $1?"
then
docker stop "$(docker container ls -a | grep "$1" | awk '{print $1}' | tail -1)"
docker rm "$(docker container ls -a | grep "$1" | awk '{print $1}' | tail -1)" --volumes
docker image prune -a -f
else
msg_box "OK, this script will now exit, but there's still leftovers to cleanup. You can run it again at any time."
exit
fi
fi
}

Просмотреть файл

@ -42,9 +42,10 @@ $CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"Bitwarden" "(External password manager)" OFF \
"Fail2ban " "(Extra Bruteforce protection)" "$STARTUP_SWITCH" \
"Recognize" "(Use [local] AI on your photos in Nextcloud)" OFF \
"PreviewGenerator" "(Pre-generate previews for Nextcloud)" OFF \
"Imaginary" "(Generate image previews for Nextcloud) [4GB RAM + 4 CPU]" "$STARTUP_SWITCH" \
"Webmin" "(Server GUI like Cpanel)" OFF \
"Talk" "(Video calls and chat for Nextcloud)" "$STARTUP_SWITCH" \
"Talk" "(Video calls and chat for Nextcloud - requires port 3478)" "$STARTUP_SWITCH" \
"SMB-mount" "(Mount SMB-shares from your local network)" OFF \
"Adminer" "(PostgreSQL GUI)" OFF \
"LDAP" "(Windows Active directory for Nextcloud)" OFF \
"Notify Push" "(High Performance Files Backend for Nextcloud)" OFF \
@ -56,7 +57,6 @@ $CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"Pico CMS" "(Lightweight CMS integration in Nextcloud)" OFF \
"Whiteboard" "(Whiteboard for Nextcloud)" OFF \
"Extract" "(Archive extraction for Nextcloud)" OFF \
"SMB-mount" "(Mount SMB-shares from your local network)" OFF \
"PDF Annotations" "(Annotate PDF files in Nextcloud)" OFF 3>&1 1>&2 2>&3)
case "$choice" in
@ -104,8 +104,8 @@ case "$choice" in
print_text_in_color "$ICyan" "Downloading the Pico CMS script..."
run_script APP pico_cms
;;&
*"PreviewGenerator"*)
print_text_in_color "$ICyan" "Downloading the PreviewGenerator script..."
*"Imaginary"*)
print_text_in_color "$ICyan" "Downloading the Imaginary script..."
run_script APP previewgenerator
;;&
*"Notify Push"*)

Просмотреть файл

@ -625,6 +625,8 @@ If you need help, please get support here: https://shop.hanssonit.se/product/pre
docker-compose_update 'fts_os-node' 'Full Text Search' "$OPNSDIR"
# Plex
docker_update_specific 'plex' "Plex Media Server"
# Imaginary
docker_update_specific 'imaginary' "Imaginary"
fi
# Fix Collabora change too coolwsd

302
old/previewgenerator.sh Normal file
Просмотреть файл

@ -0,0 +1,302 @@
#!/bin/bash
# T&M Hansson IT AB © - 2023, https://www.hanssonit.se/
true
SCRIPT_NAME="Preview Generator"
SCRIPT_EXPLAINER="This script will install the Preview Generator.
It can speedup the loading of previews in Nextcloud a lot."
# shellcheck source=lib.sh
source /var/scripts/fetch_lib.sh
# Check for errors + debug code and abort if something isn't right
# 1 = ON
# 0 = OFF
DEBUG=0
debug_mode
# Check if root
root_check
# PHP 7.x is needed
if is_this_installed php5.6-common || is_this_installed php5.5-common
then
msg_box "At least PHP 7.X is required, please upgrade your PHP version: \
https://shop.hanssonit.se/product/upgrade-php-version-including-dependencies/"
exit
fi
# Encryption may not be enabled
if is_app_enabled encryption || is_app_enabled end_to_end_encryption
then
msg_box "It seems like you have encryption enabled which is unsupported when using the Preview Generator"
exit
fi
# Check if previewgenerator is already installed
if ! is_app_installed previewgenerator
then
# Ask for installing
install_popup "$SCRIPT_NAME"
else
# Ask for removal or reinstallation
reinstall_remove_menu "$SCRIPT_NAME"
# Removal
nextcloud_occ app:remove previewgenerator
# reset the preview formats
nextcloud_occ_no_check config:system:delete "enabledPreviewProviders"
nextcloud_occ config:system:delete preview_max_x
nextcloud_occ config:system:delete preview_max_y
nextcloud_occ config:system:delete jpeg_quality
nextcloud_occ config:system:delete preview_max_memory
nextcloud_occ config:system:delete enable_previews
# reset the cronjob
crontab -u www-data -l | grep -v 'preview:pre-generate' | crontab -u www-data -
# Remove apps
APPS=(php-imagick libmagickcore-6.q16-3-extra imagemagick-6.q16-extra)
for app in "${APPS[@]}"
do
if is_this_installed "$app"
then
apt-get purge "$app" -y
fi
done
if is_this_installed ffmpeg && ! is_app_installed integration_whiteboard
then
apt-get purge ffmpeg -y
fi
apt-get autoremove -y
rm -rf /etc/ImageMagick-6
if yesno_box_no "Do you want to remove all previews that were generated until now?
This will most likely clear a lot of space but your server will need to re-generate the previews \
if you should opt to re-enable previews again."
then
countdown "Removing the preview folder. This can take a while..." "5"
rm -rfv "$NCDATA"/appdata_*/preview
print_text_in_color "$ICyan" "Scanning Nextclouds appdata directory after removing all previews. \
This can take a while..."
nextcloud_occ files:scan-app-data -vvv
msg_box "All previews were successfully removed."
fi
# Show successful uninstall if applicable
removal_popup "$SCRIPT_NAME"
fi
# Install preview generator
install_and_enable_app previewgenerator
# check if the previewgenerator is installed and enabled
if is_app_enabled previewgenerator
then
# enable previews
nextcloud_occ config:system:set enable_previews --value=true --type=boolean
# install needed dependency for movies
install_if_not ffmpeg
else
exit
fi
msg_box "In the next step you can choose to install a package called imagick \
to speed up the generation of previews and add support for more filetypes.
The currently supported filetypes are:
* PNG
* JPEG
* GIF
* BMP
* MarkDown
* MP3
* TXT
* Movie
* Photoshop (needs imagick)
* SVG (needs imagick)
* TIFF (needs imagick)"
msg_box "IMPORTANT NOTE!!
Imagick will put your server at risk as it's is known to have several flaws.
You can check this issue to understand why: https://github.com/nextcloud/vm/issues/743
Please note: If you choose not to install imagick, it will get removed now."
if yesno_box_no "Do you want to install imagick?"
then
check_php
# Install imagick
install_if_not php"$PHPVER"-imagick
if version 22.04 "$DISTRO" 22.04.10
then
install_if_not libmagickcore-6.q16-6-extra
elif version 20.04 "$DISTRO" 20.04.10
then
install_if_not libmagickcore-6.q16-3-extra
fi
# Memory tuning
sed -i 's|policy domain="resource" name="memory" value=.*|policy domain="resource" name="memory" value="512MiB"|g' /etc/ImageMagick-6/policy.xml
sed -i 's|policy domain="resource" name="map" value=.*|policy domain="resource" name="map" value="1024MiB"|g' /etc/ImageMagick-6/policy.xml
sed -i 's|policy domain="resource" name="area" value=.*|policy domain="resource" name="area" value="256MiB"|g' /etc/ImageMagick-6/policy.xml
sed -i 's|policy domain="resource" name="disk" value=.*|policy domain="resource" name="disk" value="8GiB"|g' /etc/ImageMagick-6/policy.xml
# Choose file formats fo the case when imagick is installed.
# for additional previews please look at the Nextcloud documentation. But these probably won't work.
choice=$(whiptail --title "$TITLE - Choose file formats" --checklist \
"Now you can choose for which file formats you would like to generate previews for
$CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"PNG" "" ON \
"JPEG" "" ON \
"GIF" "" ON \
"BMP" "" ON \
"MarkDown" "" ON \
"MP3" "" ON \
"TXT" "" ON \
"Movie" "" ON \
"Photoshop" "" ON \
"SVG" "" ON \
"TIFF" "" ON 3>&1 1>&2 2>&3)
case "$choice" in
*"PNG"*)
nextcloud_occ config:system:set enabledPreviewProviders 0 --value="OC\\Preview\\PNG"
;;&
*"JPEG"*)
nextcloud_occ config:system:set enabledPreviewProviders 1 --value="OC\\Preview\\JPEG"
;;&
*"GIF"*)
nextcloud_occ config:system:set enabledPreviewProviders 2 --value="OC\\Preview\\GIF"
;;&
*"BMP"*)
nextcloud_occ config:system:set enabledPreviewProviders 3 --value="OC\\Preview\\BMP"
;;&
*"MarkDown"*)
nextcloud_occ config:system:set enabledPreviewProviders 4 --value="OC\\Preview\\MarkDown"
;;&
*"MP3"*)
nextcloud_occ config:system:set enabledPreviewProviders 5 --value="OC\\Preview\\MP3"
;;&
*"TXT"*)
nextcloud_occ config:system:set enabledPreviewProviders 6 --value="OC\\Preview\\TXT"
;;&
*"Movie"*)
nextcloud_occ config:system:set enabledPreviewProviders 7 --value="OC\\Preview\\Movie"
;;&
*"Photoshop"*)
nextcloud_occ config:system:set enabledPreviewProviders 8 --value="OC\\Preview\\Photoshop"
;;&
*"SVG"*)
nextcloud_occ config:system:set enabledPreviewProviders 9 --value="OC\\Preview\\SVG"
;;&
*"TIFF"*)
nextcloud_occ config:system:set enabledPreviewProviders 10 --value="OC\\Preview\\TIFF"
;;&
*)
;;
esac
else
# check if imagick is installed and remove it
if is_this_installed php-imagick
then
apt-get purge php-imagick -y
elif is_this_installed php"$PHPVER"-imagick
then
apt-get purge php"$PHPVER"-imagick -y
fi
# check if libmagickcore is installed and remove it
if is_this_installed libmagickcore-6.q16-3-extra
then
apt-get purge libmagickcore-6.q16-3-extra -y
fi
# Choose file formats fo the case when imagick is not installed.
# for additional previews please look at the Nextcloud documentation. But these probably won't work.
choice=$(whiptail --title "$TITLE - Choose file formats" --checklist \
"Now you can choose for which file formats you would like to generate previews for
$CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"PNG" "" ON \
"JPEG" "" ON \
"GIF" "" ON \
"BMP" "" ON \
"MarkDown" "" ON \
"MP3" "" ON \
"TXT" "" ON \
"Movie" "" ON 3>&1 1>&2 2>&3)
case "$choice" in
*"PNG"*)
nextcloud_occ config:system:set enabledPreviewProviders 11 --value="OC\\Preview\\PNG"
;;&
*"JPEG"*)
nextcloud_occ config:system:set enabledPreviewProviders 12 --value="OC\\Preview\\JPEG"
;;&
*"GIF"*)
nextcloud_occ config:system:set enabledPreviewProviders 13 --value="OC\\Preview\\GIF"
;;&
*"BMP"*)
nextcloud_occ config:system:set enabledPreviewProviders 14 --value="OC\\Preview\\BMP"
;;&
*"MarkDown"*)
nextcloud_occ config:system:set enabledPreviewProviders 15 --value="OC\\Preview\\MarkDown"
;;&
*"MP3"*)
nextcloud_occ config:system:set enabledPreviewProviders 16 --value="OC\\Preview\\MP3"
;;&
*"TXT"*)
nextcloud_occ config:system:set enabledPreviewProviders 17 --value="OC\\Preview\\TXT"
;;&
*"Movie"*)
nextcloud_occ config:system:set enabledPreviewProviders 18 --value="OC\\Preview\\Movie"
;;&
*)
;;
esac
fi
# Set aspect ratio
nextcloud_occ config:app:set previewgenerator squareSizes --value="32 256"
nextcloud_occ config:app:set previewgenerator widthSizes --value="256 384"
nextcloud_occ config:app:set previewgenerator heightSizes --value="256"
nextcloud_occ config:system:set preview_max_x --value="2048"
nextcloud_occ config:system:set preview_max_y --value="2048"
nextcloud_occ config:system:set jpeg_quality --value="60"
nextcloud_occ config:system:set preview_max_memory --value="128"
nextcloud_occ config:app:set preview jpeg_quality --value="60"
# Add crontab for www-data
if ! crontab -u www-data -l | grep -q 'preview:pre-generate'
then
print_text_in_color "$ICyan" "Adding crontab for $SCRIPT_NAME"
crontab -u www-data -l | { cat; echo "*/10 * * * * php -f $NCPATH/occ preview:pre-generate >> $VMLOGS/previewgenerator.log"; } | crontab -u www-data -
touch "$VMLOGS"/previewgenerator.log
chown www-data:www-data "$VMLOGS"/previewgenerator.log
fi
msg_box "In the last step you can define a specific Nextcloud user for \
which will be the user that runs the Preview Generation.
The default behavior (just hit [ENTER]) is to run with the \
system user 'www-data' which will generate previews for all users.
If you on the other hand choose to use a specific user, previews will ONLY be generated for that specific user."
if ! yesno_box_no "Do you want to choose a specific Nextcloud user to generate previews?"
then
print_text_in_color "$ICyan" "Using www-data (all Nextcloud users) for generating previews..."
# Pre generate everything
nextcloud_occ preview:generate-all
else
while :
do
PREVIEW_USER=$(input_box "Enter the Nextcloud user for \
which you want to run the Preview Generation (as a scheduled task)")
if [ -z "$(nextcloud_occ user:list | grep "$PREVIEW_USER" | awk '{print $3}')" ]
then
msg_box "It seems like the user you entered ($PREVIEW_USER) doesn't exist, please try again."
else
break
fi
done
# Pre generate everything
nextcloud_occ preview:generate-all "$PREVIEW_USER"
fi
msg_box "Previewgenerator was successfully installed."