Files
ignition-pi4/home/root/move-downloads-nextcloud.sh
2025-11-06 20:28:41 +01:00

29 lines
1.0 KiB
Bash

#!/bin/bash
set -o errexit -o pipefail -o noclobber -o nounset
echo "Running $(date)"
torrents=/var/mnt/nas/containers/qbittorrent/storage/torrents
jdownloader=/var/mnt/nas/containers/jdownloader/storage/output/completed
target=/var/mnt/nas/containers/nextcloud/storage/data/__groupfolders/1/downloads
num_torrents="$(find "${torrents}" -maxdepth 1 -type f | wc -l)" || echo 0
if [[ "${num_torrents}" -gt 0 ]]; then
find "${torrents}" -maxdepth 1 -type f -exec mv {} "${target}/" \;
fi
echo "Found ${num_torrents} torrent files"
num_jdownloader="$(ls "${jdownloader}" | wc -l)" || echo 0
if [[ "${num_jdownloader}" -gt 0 ]]; then
mv "${jdownloader}/"* "${target}/"
fi
echo "Found ${num_jdownloader} jdownloader files"
total_files=$(("${num_torrents}" + "${num_jdownloader}"))
if [[ "${total_files}" -gt 0 ]]; then
ugid="$(stat -c "%U:%G" "${target}")"
chown -R "${ugid}" "${target}/"*
chmod 755 "${target}/"*
echo "Running podman"
cd /var/home/nextcloud
sudo -u nextcloud podman exec -it nextcloud bash -c "/var/www/html/occ groupfolders:scan 1"
cd -
fi