From be6a7931143ba0eabe0317d670bbbfa48ad82449 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sat, 16 Oct 2021 13:35:44 +0200 Subject: [PATCH] nc picsort --- .../files/nextcloud-picsort} | 37 +++++++------------ bundles/nextcloud-picsort/items.py | 5 +++ bundles/nextcloud-picsort/metadata.py | 16 ++++++++ groups/applications/nextcloud.py | 1 + items/download.py | 12 +++--- nodes/home.server.py | 8 +++- 6 files changed, 49 insertions(+), 30 deletions(-) rename bundles/{picsort/files/picsort.sh => nextcloud-picsort/files/nextcloud-picsort} (55%) create mode 100644 bundles/nextcloud-picsort/items.py create mode 100644 bundles/nextcloud-picsort/metadata.py diff --git a/bundles/picsort/files/picsort.sh b/bundles/nextcloud-picsort/files/nextcloud-picsort similarity index 55% rename from bundles/picsort/files/picsort.sh rename to bundles/nextcloud-picsort/files/nextcloud-picsort index e1363f3..9aba5d7 100644 --- a/bundles/picsort/files/picsort.sh +++ b/bundles/nextcloud-picsort/files/nextcloud-picsort @@ -1,30 +1,19 @@ #!/bin/bash -#exit 0 -export LANGUAGE=en_US.UTF-8 -export LANG=en_US.UTF-8 -export LC_ALL=en_US.UTF-8 +USER="$1" +SOURCEPATH="/var/lib/nextcloud/$1/files/$2" +DESTINATIONPATH="/var/lib/nextcloud/$1/files/$3" -function log { - logger -st nc-picsort "${*:-$(/dev/null then - log "SKIP: no 'Create Date' in exif ($f)" + echo "SKIP: no 'Create Date' in exif ($f)" continue fi SCAN="TRUE" @@ -42,19 +31,19 @@ for f in `find "$SOURCEPATH" -iname *.PNG -o -iname *.JPG -o -iname *.CR2 -o -in else RAW="" fi - FILE="$DESTINATIONPATH$YEAR-$MONTH/$RAW$YEAR$MONTH$DAY"-"$HOUR$MINUTE$SECOND"_"$HASH"."$EXT" - log "DESTINATION: $FILE" + FILE="$DESTINATIONPATH/$YEAR-$MONTH/$RAW$YEAR$MONTH$DAY"-"$HOUR$MINUTE$SECOND"_"$HASH"."$EXT" + echo "DESTINATION: $FILE" mkdir -p "$(dirname "$FILE")" mv -v "$f" "$FILE" done if [ "$SCAN" == "TRUE" ]; then - log "SCANNING..." - # find "$SOURCEPATH/"* -type d -empty -delete >> /var/log/nc-picsort.log # nextcloud app bug when deleting folders + echo "SCANNING..." + # find "$SOURCEPATH/"* -type d -empty -delete >> /var/echo/nc-picsort.echo # nextcloud app bug when deleting folders chown -R www-data:www-data "$DESTINATIONPATH" chmod -R 777 "$DESTINATIONPATH" - sudo -u www-data php /var/www/nextcloud/occ files:scan $USER | log - sudo -u www-data php /var/www/nextcloud/occ preview:generate-all $USER | log + sudo -u www-data php /var/www/nextcloud/occ files:scan $USER + sudo -u www-data php /var/www/nextcloud/occ preview:generate-all $USER fi -log "FINISH." +echo "FINISH." diff --git a/bundles/nextcloud-picsort/items.py b/bundles/nextcloud-picsort/items.py new file mode 100644 index 0000000..26d204b --- /dev/null +++ b/bundles/nextcloud-picsort/items.py @@ -0,0 +1,5 @@ +files = { + '/opt/nextcloud-picsort': { + 'mode': '550', + }, +} diff --git a/bundles/nextcloud-picsort/metadata.py b/bundles/nextcloud-picsort/metadata.py new file mode 100644 index 0000000..513cdea --- /dev/null +++ b/bundles/nextcloud-picsort/metadata.py @@ -0,0 +1,16 @@ +from shlex import quote as q + + +@metadata_reactor.provides( + 'systemd-timers', +) +def systemd_timers(metadata): + return { + 'systemd-timers': { + f'nextcloud-picsort-{user}': { + 'command': f'/opt/nextcloud-picsort {q(user)} {q(paths["source"])} {q(paths["destination"])}', + 'when': '*:0/5', + } + for user, paths in metadata.get('nextcloud-picsort').items() + } + } diff --git a/groups/applications/nextcloud.py b/groups/applications/nextcloud.py index 626a331..705ada1 100644 --- a/groups/applications/nextcloud.py +++ b/groups/applications/nextcloud.py @@ -1,6 +1,7 @@ { 'bundles': [ 'nextcloud', + 'nextcloud-picsort', 'php', ], } diff --git a/items/download.py b/items/download.py index c710f01..799b1a1 100644 --- a/items/download.py +++ b/items/download.py @@ -75,6 +75,11 @@ class Download(Item): cdict['sha256'] = self.attributes['sha256'] elif self.attributes.get('gpg_signature_url'): cdict['verified'] = True + elif self.attributes.get('sha256_url'): + full_sha256_url = self.attributes['sha256_url'].format(url=self.attributes['url']) + cdict['sha256'] = force_text( + self.node.run(f"curl -sL -- {quote(full_sha256_url)}").stdout + ).strip().split()[0] else: raise @@ -90,12 +95,9 @@ class Download(Item): 'type': 'download', } if self.attributes.get('sha256'): - sdict['sha256'] = self.attributes['sha256'] + sdict['sha256'] = self.__hash_remote_file(self.name) elif self.attributes.get('sha256_url'): - full_sha256_url = self.attributes['sha256_url'].format(url=self.attributes['url']) - sdict['sha256'] = force_text( - self.node.run(f"curl -sL -- {quote(full_sha256_url)}").stdout - ).strip().split()[0] + sdict['sha256'] = self.__hash_remote_file(self.name) elif self.attributes.get('gpg_signature_url'): full_signature_url = self.attributes['gpg_signature_url'].format(url=self.attributes['url']) signature_path = f'{self.name}.signature' diff --git a/nodes/home.server.py b/nodes/home.server.py index 0b28065..a0be46d 100644 --- a/nodes/home.server.py +++ b/nodes/home.server.py @@ -46,7 +46,13 @@ }, 'nextcloud': { 'hostname': 'cloud.sublimity.de', - 'version': '21.0.3', + 'version': '21.0.5', + }, + 'nextcloud-picsort': { + 'ckn': { + 'source': 'SofortUpload/AutoSort', + 'destination': 'Bilder/Chronologie', + }, }, 'users': { 'root': {