Skip to content

Add Imaginary Docker for previews #2464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4bb587e
Create imaginary.sh
enoch85 Apr 1, 2023
ac1e56b
Add to NONO ports
enoch85 Apr 1, 2023
fde44ea
replace Imagick!
enoch85 Apr 1, 2023
146a25f
NC 24
enoch85 Apr 1, 2023
346a6d3
use a more updated image
enoch85 Apr 1, 2023
b07171e
add previewproviders
enoch85 Apr 1, 2023
7e9c0a4
fix spelling
enoch85 Apr 1, 2023
61c2a87
details!
enoch85 Apr 1, 2023
0accc0e
too tired now :sleeping:
enoch85 Apr 1, 2023
bc28731
only rebuild if previewgenerator was installed before
enoch85 Apr 1, 2023
fb6c37d
some more changes to Imaginary
enoch85 Apr 1, 2023
533584f
move to old
enoch85 Apr 1, 2023
9edf6c8
Create previewgenerator.sh
enoch85 Apr 1, 2023
62439d0
move to apps
enoch85 Apr 1, 2023
b2fa698
learn how to spell :)
enoch85 Apr 1, 2023
0b51e5a
change menu
enoch85 Apr 1, 2023
34ea2a7
typos
enoch85 Apr 1, 2023
10a37a6
update menu
enoch85 Apr 1, 2023
4633b15
more typos
enoch85 Apr 1, 2023
53f9cb9
cleanup testimage
enoch85 Apr 1, 2023
a87d2e3
improve docker prune
enoch85 Apr 1, 2023
475b9d8
update it!
enoch85 Apr 1, 2023
621deb5
change to docker run
enoch85 Apr 1, 2023
846517a
Merge branch 'master' into imaginary
enoch85 Apr 1, 2023
a796c74
only look for previews
enoch85 Apr 1, 2023
54b76d8
commit suggestion
enoch85 Apr 1, 2023
72fad48
SC
enoch85 Apr 1, 2023
332c6ab
remove custom config old
enoch85 Apr 1, 2023
2a3afba
add back providers and split preview generator uninstall
enoch85 Apr 1, 2023
b295dbb
tested and works!
enoch85 Apr 1, 2023
c6ddcac
commit suggestions
enoch85 Apr 1, 2023
4ecdd44
typo
enoch85 Apr 1, 2023
c804f9e
without this tha pp-data scan fails
enoch85 Apr 1, 2023
a66e6b7
fix preview removal
enoch85 Apr 1, 2023
8a7d2e8
remove more leftovers
enoch85 Apr 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions apps/imaginary.sh
Original file line number Diff line number Diff line change
@@ -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
Loading