Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/vm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorszaimen <42591237+szaimen@users.noreply.github.com>2020-01-02 13:31:19 +0300
committerDaniel Hansson <github@hanssonit.se>2020-01-02 13:31:19 +0300
commita87ee843bd003ca38d6b54ac75065ebe091a1648 (patch)
tree0fa7ee22aad8fdab76ca8b89f879b67a052839fc /apps/previewgenerator.sh
parent155a21191128e5f8c0837527394370affbb521a4 (diff)
Refactor and improve Previewgenerator (#1002)
Diffstat (limited to 'apps/previewgenerator.sh')
-rw-r--r--apps/previewgenerator.sh291
1 files changed, 240 insertions, 51 deletions
diff --git a/apps/previewgenerator.sh b/apps/previewgenerator.sh
index 83a5b0fe..7111f56f 100644
--- a/apps/previewgenerator.sh
+++ b/apps/previewgenerator.sh
@@ -16,67 +16,256 @@ debug_mode
# Check if root
root_check
-msg_box "Please note that this will put your server at risk as it will install a package called 'imagick' which is known to have several flaws.
-
-You can check this issue to understand why: https://github.com/nextcloud/vm/issues/743
+# PHP 7.x is needed
+if is_this_installed php5.6-common
+then
+ msg_box "At least PHP 7.X is supported, please upgrade your PHP version: https://shop.hanssonit.se/product/upgrade-php-version-including-dependencies/"
+ exit
+elif is_this_installed php5.5-common
+then
+ msg_box "At least PHP 7.X is supported, please upgrade your PHP version: https://shop.hanssonit.se/product/upgrade-php-version-including-dependencies/"
+ exit
+fi
-You can choose to cancel installing this in the next step."
-if [[ "no" == $(ask_yes_or_no "Do you still want to continue?") ]]
+# Encryption may not be enabled
+if [ -n "$(occ_command app:list | grep encryption | awk '{print $3}')" ]
then
+ msg_box "It seems like you have encryption enabled which is unsupported when using the Preview Generator"
exit
+fi
+
+msg_box "This script will install the Preview Generator.
+
+It can speedup the loading of previews in Nextcloud a lot.
+
+Please note: If you continue, all your current Preview Generator settings will be lost, if any."
+if [[ "yes" == $(ask_yes_or_no "Do you want to install the Preview Generator?") ]]
+then
+ # Install preview generator
+ print_text_in_color "$ICyan" "Installing the Preview Generator..."
+ install_and_enable_app previewgenerator
+
+ # check if the previewgenerator is installed and enabled
+ if [ -d "$NC_APPS_PATH/previewgenerator" ]
+ then
+ # enable previews
+ occ_command config:system:set enable_previews --value=true --type=boolean
+
+ # install needed dependency for movies
+ install_if_not ffmpeg
+
+ # reset the preview formats
+ occ_command config:system:delete "enabledPreviewProviders"
+
+ # reset the cronjob
+ print_text_in_color "$ICyan" "Resetting the cronjob for the preview-generation"
+ crontab -u www-data -l | grep -v 'preview:pre-generate' | crontab -u www-data -
+ else
+ exit
+ fi
else
- sleep 1
+ exit
fi
-# Install preview generator
-install_and_enable_app previewgenerator
+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
-# Run the first preview generation and add crontab
-if [ -d "$NC_APPS_PATH/previewgenerator" ]
+Please note: If you choose not to install imagick, it will get removed now."
+if [[ "yes" == $(ask_yes_or_no "Do you want to install imagick?") ]]
then
- # Enable previews (remove the # to enable the specific preview)
- occ_command config:system:set enable_previews --value=true --type=boolean
- occ_command config:system:set preview_libreoffice_path --value="/usr/bin/libreoffice"
-# occ_command config:system:set enabledPreviewProviders 0 --value="OC\\Preview\\PNG"
-# occ_command config:system:set enabledPreviewProviders 1 --value="OC\\Preview\\JPEG"
-# occ_command config:system:set enabledPreviewProviders 2 --value="OC\\Preview\\GIF"
-# occ_command config:system:set enabledPreviewProviders 3 --value="OC\\Preview\\BMP"
-# occ_command config:system:set enabledPreviewProviders 4 --value="OC\\Preview\\XBitmap"
-# occ_command config:system:set enabledPreviewProviders 5 --value="OC\\Preview\\MarkDown"
-# occ_command config:system:set enabledPreviewProviders 6 --value="OC\\Preview\\MP3"
-# occ_command config:system:set enabledPreviewProviders 7 --value="OC\\Preview\\TXT"
-# occ_command config:system:set enabledPreviewProviders 8 --value="OC\\Preview\\Illustrator"
-# occ_command config:system:set enabledPreviewProviders 9 --value="OC\\Preview\\Movie"
-# occ_command config:system:set enabledPreviewProviders 10 --value="OC\\Preview\\MSOffice2003"
-# occ_command config:system:set enabledPreviewProviders 11 --value="OC\\Preview\\MSOffice2007"
-# occ_command config:system:set enabledPreviewProviders 12 --value="OC\\Preview\\MSOfficeDoc"
-# occ_command config:system:set enabledPreviewProviders 13 --value="OC\\Preview\\OpenDocument"
-# occ_command config:system:set enabledPreviewProviders 14 --value="OC\\Preview\\PDF"
-# occ_command config:system:set enabledPreviewProviders 15 --value="OC\\Preview\\Photoshop"
-# occ_command config:system:set enabledPreviewProviders 16 --value="OC\\Preview\\Postscript"
-# occ_command config:system:set enabledPreviewProviders 17 --value="OC\\Preview\\StarOffice"
-# occ_command config:system:set enabledPreviewProviders 18 --value="OC\\Preview\\SVG"
-# occ_command config:system:set enabledPreviewProviders 19 --value="OC\\Preview\\TIFF"
-# occ_command config:system:set enabledPreviewProviders 20 --value="OC\\Preview\\Font"
-
- # Set aspect ratio
- occ_command config:app:set --value="32 64 1024" previewgenerator squareSizes
- occ_command config:app:set --value="64 128 1024" previewgenerator widthSizes
- occ_command config:app:set --value="64 256 1024" previewgenerator heightSizes
-
- # Add crotab
- crontab -u www-data -l | { cat; echo "@daily php -f $NCPATH/occ preview:pre-generate >> /var/log/previewgenerator.log"; } | crontab -u www-data -
- touch /var/log/previewgenerator.log
- chown www-data:www-data /var/log/previewgenerator.log
-
- # Install needed dependencies
- install_if_not ffmpeg
- install_if_not libreoffice
+ # Install imagick
install_if_not php-imagick
install_if_not libmagickcore-6.q16-3-extra
-
+
+ # 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.
+ whiptail --title "Choose file formats" --checklist --separate-output "Now you can choose for which file formats you would like to generate previews for\nSelect or unselect by pressing the spacebar" "$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 2>results
+
+ while read -r -u 11 choice
+ do
+ case $choice in
+ "PNG")
+ occ_command config:system:set enabledPreviewProviders 0 --value="OC\\Preview\\PNG"
+ ;;
+
+ "JPEG")
+ occ_command config:system:set enabledPreviewProviders 1 --value="OC\\Preview\\JPEG"
+ ;;
+
+ "GIF")
+ occ_command config:system:set enabledPreviewProviders 2 --value="OC\\Preview\\GIF"
+ ;;
+
+ "BMP")
+ occ_command config:system:set enabledPreviewProviders 3 --value="OC\\Preview\\BMP"
+ ;;
+
+ "MarkDown")
+ occ_command config:system:set enabledPreviewProviders 4 --value="OC\\Preview\\MarkDown"
+ ;;
+
+ "MP3")
+ occ_command config:system:set enabledPreviewProviders 5 --value="OC\\Preview\\MP3"
+ ;;
+
+ "TXT")
+ occ_command config:system:set enabledPreviewProviders 6 --value="OC\\Preview\\TXT"
+ ;;
+
+ "Movie")
+ occ_command config:system:set enabledPreviewProviders 7 --value="OC\\Preview\\Movie"
+ ;;
+
+ "Photoshop")
+ occ_command config:system:set enabledPreviewProviders 8 --value="OC\\Preview\\Photoshop"
+ ;;
+
+ "SVG")
+ occ_command config:system:set enabledPreviewProviders 9 --value="OC\\Preview\\SVG"
+ ;;
+
+ "TIFF")
+ occ_command config:system:set enabledPreviewProviders 10 --value="OC\\Preview\\TIFF"
+ ;;
+
+ *)
+ ;;
+ esac
+ done 11< results
+ rm -f results
+else
+ # check if imagick ist installed and remove it
+ if is_this_installed php-imagick
+ then
+ apt purge php-imagick -y
+ fi
+ # check if libmagickcore is installed and remove it
+ if is_this_installed libmagickcore-6.q16-3-extra
+ then
+ apt 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.
+ whiptail --title "Choose file formats" --checklist --separate-output "Now you can choose for which file formats you would like to generate previews for\nSelect or unselect by pressing the spacebar" "$WT_HEIGHT" "$WT_WIDTH" 4 \
+ "PNG" "" ON \
+ "JPEG" "" ON \
+ "GIF" "" ON \
+ "BMP" "" ON \
+ "MarkDown" "" ON \
+ "MP3" "" ON \
+ "TXT" "" ON \
+ "Movie" "" ON 2>results
+
+ while read -r -u 8 choice
+ do
+ case $choice in
+ "PNG")
+ occ_command config:system:set enabledPreviewProviders 11 --value="OC\\Preview\\PNG"
+ ;;
+
+ "JPEG")
+ occ_command config:system:set enabledPreviewProviders 12 --value="OC\\Preview\\JPEG"
+ ;;
+
+ "GIF")
+ occ_command config:system:set enabledPreviewProviders 13 --value="OC\\Preview\\GIF"
+ ;;
+
+ "BMP")
+ occ_command config:system:set enabledPreviewProviders 14 --value="OC\\Preview\\BMP"
+ ;;
+
+ "MarkDown")
+ occ_command config:system:set enabledPreviewProviders 15 --value="OC\\Preview\\MarkDown"
+ ;;
+
+ "MP3")
+ occ_command config:system:set enabledPreviewProviders 16 --value="OC\\Preview\\MP3"
+ ;;
+
+ "TXT")
+ occ_command config:system:set enabledPreviewProviders 17 --value="OC\\Preview\\TXT"
+ ;;
+
+ "Movie")
+ occ_command config:system:set enabledPreviewProviders 18 --value="OC\\Preview\\Movie"
+ ;;
+
+ *)
+ ;;
+ esac
+ done 8< results
+ rm -f results
+fi
+
+# Set aspect ratio
+occ_command config:app:set previewgenerator squareSizes --value="32 256"
+occ_command config:app:set previewgenerator widthSizes --value="256 384"
+occ_command config:app:set previewgenerator heightSizes --value="256"
+occ_command config:system:set preview_max_x --value="2048"
+occ_command config:system:set preview_max_y --value="2048"
+occ_command config:system:set jpeg_quality --value="60"
+occ_command config:app:set preview jpeg_quality --value="60"
+
+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 behaviour (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 [[ "no" == $(ask_yes_or_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..."
+ # Add crontab for www-data
+ crontab -u www-data -l | { cat; echo "0 4 * * * 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
+
# Pre generate everything
occ_command preview:generate-all
-fi
+else
+ while true
+ do
+ PREVIEW_USER=$(whiptail --inputbox "Enter the Nextcloud user for which you want to run the preview-generation" "$WT_HEIGHT" "$WT_WIDTH" 3>&1 1>&2 2>&3)
+ if [ -z "$(occ_command 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
+ # Add crontab for $PREVIEW_USER
+ crontab -u www-data -l | { cat; echo "0 4 * * * php -f $NCPATH/occ preview:pre-generate $PREVIEW_USER >> $VMLOGS/previewgenerator.log"; } | crontab -u www-data -
+ touch "$VMLOGS"/previewgenerator.log
+ chown www-data:www-data "$VMLOGS"/previewgenerator.log
-exit
+ # Pre generate everything
+ occ_command preview:generate-all "$PREVIEW_USER"
+fi