mirror of
https://github.com/skoobasteeve/skoobasteeve.github.io.2.git
synced 2026-03-20 07:58:57 +00:00
nextlcoud-photos post finished
This commit is contained in:
@@ -21,7 +21,7 @@ If you're not familiar with Systemd unit files and how they work, I would highly
|
|||||||
|
|
||||||
You'll need to create dedicated folders on your machine where the shares will be mounted.
|
You'll need to create dedicated folders on your machine where the shares will be mounted.
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo mkdir -p /mnt/smb/sambashare
|
$ sudo mkdir -p /mnt/smb/sambashare
|
||||||
$ sudo mkdir -p /mnt/nfs/nfsshare
|
$ sudo mkdir -p /mnt/nfs/nfsshare
|
||||||
```
|
```
|
||||||
@@ -30,7 +30,7 @@ $ sudo mkdir -p /mnt/nfs/nfsshare
|
|||||||
|
|
||||||
If your Samba server uses authentication, you'll need to create a file with your login details that Systemd can use to connect. These should be saved in a safe location with restricted permissions.
|
If your Samba server uses authentication, you'll need to create a file with your login details that Systemd can use to connect. These should be saved in a safe location with restricted permissions.
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo nano /etc/samba/smbcreds
|
$ sudo nano /etc/samba/smbcreds
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ username=[USERNAME]
|
|||||||
password=[PASSWORD]
|
password=[PASSWORD]
|
||||||
```
|
```
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo chmod 600 /etc/samba/smbcreds
|
$ sudo chmod 600 /etc/samba/smbcreds
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -47,13 +47,13 @@ $ sudo chmod 600 /etc/samba/smbcreds
|
|||||||
|
|
||||||
#### Samba
|
#### Samba
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo apt install samba cifs-utils
|
$ sudo apt install samba cifs-utils
|
||||||
```
|
```
|
||||||
|
|
||||||
#### NFS
|
#### NFS
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo apt install nfs-common
|
$ sudo apt install nfs-common
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ To make this work, we need (2) unit files for each connection: the **mount** uni
|
|||||||
|
|
||||||
The below instructions assume your samba share is located at `//example.server/sambafiles`.
|
The below instructions assume your samba share is located at `//example.server/sambafiles`.
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo nano /etc/systemd/system/mnt-smb-sambashare.mount
|
$ sudo nano /etc/systemd/system/mnt-smb-sambashare.mount
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -86,13 +86,14 @@ WantedBy=multi-user.target
|
|||||||
```
|
```
|
||||||
|
|
||||||
A few notes on the above file:
|
A few notes on the above file:
|
||||||
|
|
||||||
* `vers=2.1` - adjust this based on the version of samba running on your server
|
* `vers=2.1` - adjust this based on the version of samba running on your server
|
||||||
* `uid=1000` - adjust this based on your local user ID to avoid permissions problems. This is usually 1000 on a desktop system.
|
* `uid=1000` - adjust this based on your local user ID to avoid permissions problems. This is usually 1000 on a desktop system.
|
||||||
|
|
||||||
\
|
\
|
||||||
Next we need to create the automount file in the same location.
|
Next we need to create the automount file in the same location.
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo nano /etc/systemd/system/mnt-smb-sambashare.automount
|
$ sudo nano /etc/systemd/system/mnt-smb-sambashare.automount
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ WantedBy=multi-user.target
|
|||||||
|
|
||||||
The below instructions assume your NFS share is located at `example.server:/srv/nfsfiles`.
|
The below instructions assume your NFS share is located at `example.server:/srv/nfsfiles`.
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo nano /etc/systemd/system/mnt-nfs-nfssahre.mount
|
$ sudo nano /etc/systemd/system/mnt-nfs-nfssahre.mount
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -134,7 +135,7 @@ WantedBy=multi-user.target
|
|||||||
\
|
\
|
||||||
Same as before, we need to create the automount file in the same location.
|
Same as before, we need to create the automount file in the same location.
|
||||||
|
|
||||||
``` bash
|
```bash
|
||||||
$ sudo nano /etc/systemd/system/mnt-smb-nfsshare.automount
|
$ sudo nano /etc/systemd/system/mnt-smb-nfsshare.automount
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -14,19 +14,24 @@ The good news is that because Nextcloud is a wonderful piece of FOSS that we're
|
|||||||
- [Preview Generator](https://apps.nextcloud.com/apps/previewgenerator) (Nextcloud app)
|
- [Preview Generator](https://apps.nextcloud.com/apps/previewgenerator) (Nextcloud app)
|
||||||
- [exiftool](https://exiftool.org/) (Linux app)
|
- [exiftool](https://exiftool.org/) (Linux app)
|
||||||
|
|
||||||
Let's dive in!
|
Both are freely available from Nextcloud and your distro's package manager, respectively. Let's dive in!
|
||||||
|
|
||||||
# Previews and Thumbnails
|
# Previews and Thumbnails
|
||||||
|
|
||||||
First we need to fix our preview generation. By default, Nextcloud generates photo previews and thumbnails on-demand, leading to slow load times. To fix this, we're going to use the Preview Generator app for Nextcloud to pre-generate these previews on a regular basis. That way, your photos are ready to view as soon as you open the folder.
|
First we need to fix Nextcloud's preview generation. By default, Nextcloud generates photo previews and thumbnails on-demand, leading to slow load times. To fix this, we're going to use the Preview Generator app for Nextcloud to pre-generate previews on a regular basis. That way, your photos are ready to view as soon as you open the folder.
|
||||||
|
|
||||||
1. **Install the Preview Generator app for Nextcloud**. From a Nextcloud account with admin permissions, navigate to the Apps section and locate Preview Generator under the Multimedia category. Click Download and enable.
|
1. **Install the Preview Generator app for Nextcloud**. From a Nextcloud account with admin permissions, navigate to the Apps section and locate Preview Generator under the Multimedia category. Click Download and enable.
|
||||||
|
|
||||||
2. **Configure preview and thumbnail settings.** While the default settings work well from a performance standpoint, they cause Nextcloud to generate a huge number of previews and thumbnails for each photo. Once you add a lot of photos, you'll notice that these previews eat into your storage significantly. Fortunately, Preview Generator is highly configurable.
|
{:class="img-responsive" .align-center}
|
||||||
|
|
||||||
|
|
||||||
|
2. **Configure preview and thumbnail settings.** While the default settings work well from a performance standpoint, they cause Nextcloud to generate a huge number of previews and thumbnails for each photo. Once you add a lot of photos, you'll notice that these previews eat into your storage significantly (sometimes more than the photos themselves). Fortunately, Preview Generator is highly configurable.
|
||||||
|
|
||||||
|
SSH into your Nextcloud server and follow the instructions below.
|
||||||
|
|
||||||
**Note:** I've found that the below settings provide a good balance of resolution, performance, and storage usage for my environment, but you can tweak them depending on your needs.
|
**Note:** I've found that the below settings provide a good balance of resolution, performance, and storage usage for my environment. You can tweak them depending on your needs.
|
||||||
|
|
||||||
Choose default thumbnail sizes:
|
Set the default thumbnail sizes by using the following occ commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo -u www-data php /var/www/nextcloud/occ config:app:set --value="32 256" previewgenerator squareSizes
|
sudo -u www-data php /var/www/nextcloud/occ config:app:set --value="32 256" previewgenerator squareSizes
|
||||||
@@ -36,10 +41,10 @@ First we need to fix our preview generation. By default, Nextcloud generates pho
|
|||||||
|
|
||||||
Next, edit your config.php to specify the maximum preview size for images. This is going to effect the appearance and load time of images when you click on them.
|
Next, edit your config.php to specify the maximum preview size for images. This is going to effect the appearance and load time of images when you click on them.
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo nano /var/www/nextcloud/config/config.php
|
sudo nano /var/www/nextcloud/config/config.php
|
||||||
```
|
```
|
||||||
|
|
||||||
Find the below lines toward the end of the file. If they don't exist, add them to the block.
|
Find the below lines toward the end of the file. If they don't exist, add them to the block.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@@ -47,7 +52,7 @@ First we need to fix our preview generation. By default, Nextcloud generates pho
|
|||||||
'preview_max_y' => '2048',
|
'preview_max_y' => '2048',
|
||||||
'jpeg_quality' => '60',
|
'jpeg_quality' => '60',
|
||||||
```
|
```
|
||||||
|
|
||||||
Save the file and restart the web server.
|
Save the file and restart the web server.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -55,8 +60,7 @@ First we need to fix our preview generation. By default, Nextcloud generates pho
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
3. **Generate initial previews.** Open a terminal on your Nextcloud server and run the following command:
|
||||||
3. **Generate initial previews.** Open a terminal on your Nextcloud host machine and run the following command:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo -u www-data php /var/www/nextcloud/occ preview:generate-all -vvv
|
sudo -u www-data php /var/www/nextcloud/occ preview:generate-all -vvv
|
||||||
@@ -66,7 +70,8 @@ First we need to fix our preview generation. By default, Nextcloud generates pho
|
|||||||
|
|
||||||
**NOTE:** Depending on the amount of photos you have, this could take a while to complete and use a high amount of resources. If you have users beyond yourself, it's probably best to run it during a low-activity period.
|
**NOTE:** Depending on the amount of photos you have, this could take a while to complete and use a high amount of resources. If you have users beyond yourself, it's probably best to run it during a low-activity period.
|
||||||
|
|
||||||
4. **Add a cron job.** To avoid problems, you should edit the crontab of the web server user:
|
|
||||||
|
4. **Add a cron job.** This allows Preview Generator to run continuously generate previews as new photos are added to Nextcloud. To avoid permissions problems, we'll edit the crontab of the web server user:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo -u www-data crontab -e
|
sudo -u www-data crontab -e
|
||||||
@@ -75,13 +80,133 @@ First we need to fix our preview generation. By default, Nextcloud generates pho
|
|||||||
Add the following below line to the file. The below example runs the command every 10 minutes, but you can set the frequency to whatever you want.
|
Add the following below line to the file. The below example runs the command every 10 minutes, but you can set the frequency to whatever you want.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
* /10 * * * * /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate
|
*/10 * * * * /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE:** If you have a specific version of PHP installed beyond your distro's default, you'll want to specify that version of the binary above (e.g. `php7.4` instead of `php`).
|
**NOTE:** If you have a specific version of PHP installed beyond your distro's default, you'll want to specify that version of the binary above (e.g. `php7.4` instead of `php`).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Photo Sorting
|
# Photo Sorting
|
||||||
|
|
||||||
Sort order is a bit more difficult to tackle. Nextcloud is first and foremost a file sharing application, so it views files just as your file system would. This is great until you get to photo albums.
|
Nextcloud is first and foremost a file sharing application, so it views files just as your file system would. This is great until you get to photo albums, where the EXIF metadata of the photo is more relevant to sorting than the filename or modified date. To be sure that all photos in Nextcloud display in chronological order, we need to get creative.
|
||||||
|
|
||||||
|
That's where the wonderful exiftool comes in. This powerful command-line application allows you to read and manipulate the EXIF data of a photo. The feature that solves our problem is the ability to read the original capture date of a photo and apply it to both the *last modified* attribute and the *filename*. This way, no matter how you sort the images in Nextcloud, they'll display in **chronological** order.
|
||||||
|
|
||||||
|
To get started using exiftool, follow the instrutions below on one of your **Nextcloud clients.**
|
||||||
|
|
||||||
|
### Write the script
|
||||||
|
|
||||||
|
1. Install exiftool on your chosen Nextcloud client.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt install exiftool
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Create a new file with the below contents and save it as a script.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo nano photo-cleanup.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
albumdir=$1
|
||||||
|
|
||||||
|
echo "Changing modified date to shot date..."
|
||||||
|
exiftool "-filemodifydate<datetimeoriginal" -r "$albumdir"
|
||||||
|
|
||||||
|
echo "Renaming files to shot date..."
|
||||||
|
exiftool '-FileName<DateTimeOriginal' -r -d "%Y-%m-%d_%H.%M.%S%%-c.%%e" "$albumdir"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
```
|
||||||
|
|
||||||
|
I'll break down what's happening above:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
albumdir=$1
|
||||||
|
```
|
||||||
|
|
||||||
|
Sets your album directory as the first argument when you execute the script.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
exiftool "-filemodifydate<datetimeoriginal" -r "$albumdir"
|
||||||
|
```
|
||||||
|
|
||||||
|
Instructs exiftool to read `datetimeoriginal` (date and time the photo was shot) from each photo and apply it as the `filemodifydate`. The `-r` flag runs the command recursively so it will work its way through all folders in the photos directory.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
exiftool '-FileName<DateTimeOriginal' -r -d "%Y-%m-%d_%H.%M.%S%%-c.%%e" "$albumdir"
|
||||||
|
```
|
||||||
|
|
||||||
|
Similar to the previous command but applies `datetimeoriginal` to the filename. The `-d` flag specifies how the date and time data are laid out in the new filename.
|
||||||
|
|
||||||
|
### Test the script
|
||||||
|
|
||||||
|
Let's test this simple script on a directory of photos.
|
||||||
|
|
||||||
|
Give the script permission to execute.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
chmod +x photo-cleanup.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
You can see below a directory filled with photos. Note the modify dates and filenames on the right side.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
ls -al Photos
|
||||||
|
total 35340
|
||||||
|
drwxrwxr-x 2 raylyon raylyon 4096 Aug 6 18:49 .
|
||||||
|
drwxr-xr-x 6 raylyon raylyon 4096 Oct 25 21:51 ..
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 6280032 Oct 19 01:42 P1060462.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 4056662 Oct 19 02:02 P1060468.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 4915105 Oct 19 02:05 P1060481.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 6375408 Oct 19 02:06 P1060530.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 6635572 Oct 19 02:06 P1060546.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 7903375 Oct 19 02:08 P1060552.jpg
|
||||||
|
```
|
||||||
|
|
||||||
|
Now we'll run the script on this directory.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./photo-cleanup.sh "/home/raylyon/Nextcloud/Photos"
|
||||||
|
Changing modified date to shot date...
|
||||||
|
1 directories scanned
|
||||||
|
6 image files updated
|
||||||
|
Renaming files to shot date...
|
||||||
|
1 directories scanned
|
||||||
|
6 image files updated
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
ls -al Photos
|
||||||
|
total 35340
|
||||||
|
drwxrwxr-x 2 raylyon raylyon 4096 Oct 25 21:56 .
|
||||||
|
drwxr-xr-x 6 raylyon raylyon 4096 Oct 25 21:51 ..
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 6280032 Jul 31 11:27 2020-07-31_11.27.39.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 4056662 Jul 31 12:09 2020-07-31_12.09.05.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 4915105 Jul 31 12:35 2020-07-31_12.35.29.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 6375408 Aug 1 08:22 2020-08-01_08.22.03.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 6635572 Aug 1 19:46 2020-08-01_19.46.18.jpg
|
||||||
|
-rwxr-xr-x 1 raylyon raylyon 7903375 Aug 1 19:47 2020-08-01_19.47.24.jpg
|
||||||
|
```
|
||||||
|
|
||||||
|
Just like that, our filenames and metadata are updated.
|
||||||
|
|
||||||
|
### (Optional) Add a Cron job
|
||||||
|
|
||||||
|
You could run the script manually each time you add photos, but who has time for that? If you're frequently adding new photos and directories, you can automate it.
|
||||||
|
|
||||||
|
To do so, we'll add an entry to the crontab on the **client system.** Do this on a computer that has the photo albums synced with the Nextcloud client app.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
*/30 * * * * /path/to/your/script/photo-cleanup.sh "/path/to/Nextcloud/Photos"
|
||||||
|
```
|
||||||
|
|
||||||
|
The above entry runs the script every 30 minutes, checking the directory and any sub-directories for new photos and updating them accordingly. Adjust the timing to your needs.
|
||||||
|
|
||||||
|
Have any great Nextcloud photo tips that I missed? Shoot me an email or leave a comment below. Thanks for reading and happy hacking!
|
||||||
|
|||||||
BIN
assets/images/screenshots/nextcloud-photos-01.jpg
Normal file
BIN
assets/images/screenshots/nextcloud-photos-01.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Reference in New Issue
Block a user