nc picsort

This commit is contained in:
mwiegand 2021-10-16 13:35:44 +02:00
parent 1010537699
commit be6a793114
6 changed files with 49 additions and 30 deletions

View file

@ -1,30 +1,19 @@
#!/bin/bash #!/bin/bash
#exit 0 USER="$1"
export LANGUAGE=en_US.UTF-8 SOURCEPATH="/var/lib/nextcloud/$1/files/$2"
export LANG=en_US.UTF-8 DESTINATIONPATH="/var/lib/nextcloud/$1/files/$3"
export LC_ALL=en_US.UTF-8
function log { echo "STARTING..."
logger -st nc-picsort "${*:-$(</dev/stdin)}"
}
SOURCEPATH="/var/lib/nextcloud/ckn/files/SofortUpload/AutoSort/"
DESTINATIONPATH="/var/lib/nextcloud/ckn/files/Bilder/Chronologie/"
USER="ckn"
log "STARTING..."
if ps aux | grep cron | grep nc-picsort | grep -v $$; then log "EXIT: still running"; exit 0; fi
SCAN="FALSE" SCAN="FALSE"
IFS=$'\n' IFS=$'\n'
for f in `find "$SOURCEPATH" -iname *.PNG -o -iname *.JPG -o -iname *.CR2 -o -iname *.CR3 -o -iname *.MP4 -o -iname *.MOV`; do for f in `find "$SOURCEPATH" -iname *.PNG -o -iname *.JPG -o -iname *.CR2 -o -iname *.CR3 -o -iname *.MP4 -o -iname *.MOV`; do
log "PROCESSING: $f" echo "PROCESSING: $f"
DATE=`exiftool "$f" | grep -m 1 "Create Date"` DATE=`exiftool "$f" | grep -m 1 "Create Date"`
if ! echo "$DATE" | grep "Create Date" >/dev/null if ! echo "$DATE" | grep "Create Date" >/dev/null
then then
log "SKIP: no 'Create Date' in exif ($f)" echo "SKIP: no 'Create Date' in exif ($f)"
continue continue
fi fi
SCAN="TRUE" SCAN="TRUE"
@ -42,19 +31,19 @@ for f in `find "$SOURCEPATH" -iname *.PNG -o -iname *.JPG -o -iname *.CR2 -o -in
else else
RAW="" RAW=""
fi fi
FILE="$DESTINATIONPATH$YEAR-$MONTH/$RAW$YEAR$MONTH$DAY"-"$HOUR$MINUTE$SECOND"_"$HASH"."$EXT" FILE="$DESTINATIONPATH/$YEAR-$MONTH/$RAW$YEAR$MONTH$DAY"-"$HOUR$MINUTE$SECOND"_"$HASH"."$EXT"
log "DESTINATION: $FILE" echo "DESTINATION: $FILE"
mkdir -p "$(dirname "$FILE")" mkdir -p "$(dirname "$FILE")"
mv -v "$f" "$FILE" mv -v "$f" "$FILE"
done done
if [ "$SCAN" == "TRUE" ]; then if [ "$SCAN" == "TRUE" ]; then
log "SCANNING..." echo "SCANNING..."
# find "$SOURCEPATH/"* -type d -empty -delete >> /var/log/nc-picsort.log # nextcloud app bug when deleting folders # find "$SOURCEPATH/"* -type d -empty -delete >> /var/echo/nc-picsort.echo # nextcloud app bug when deleting folders
chown -R www-data:www-data "$DESTINATIONPATH" chown -R www-data:www-data "$DESTINATIONPATH"
chmod -R 777 "$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 files:scan $USER
sudo -u www-data php /var/www/nextcloud/occ preview:generate-all $USER | log sudo -u www-data php /var/www/nextcloud/occ preview:generate-all $USER
fi fi
log "FINISH." echo "FINISH."

View file

@ -0,0 +1,5 @@
files = {
'/opt/nextcloud-picsort': {
'mode': '550',
},
}

View file

@ -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()
}
}

View file

@ -1,6 +1,7 @@
{ {
'bundles': [ 'bundles': [
'nextcloud', 'nextcloud',
'nextcloud-picsort',
'php', 'php',
], ],
} }

View file

@ -75,6 +75,11 @@ class Download(Item):
cdict['sha256'] = self.attributes['sha256'] cdict['sha256'] = self.attributes['sha256']
elif self.attributes.get('gpg_signature_url'): elif self.attributes.get('gpg_signature_url'):
cdict['verified'] = True 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: else:
raise raise
@ -90,12 +95,9 @@ class Download(Item):
'type': 'download', 'type': 'download',
} }
if self.attributes.get('sha256'): if self.attributes.get('sha256'):
sdict['sha256'] = self.attributes['sha256'] sdict['sha256'] = self.__hash_remote_file(self.name)
elif self.attributes.get('sha256_url'): elif self.attributes.get('sha256_url'):
full_sha256_url = self.attributes['sha256_url'].format(url=self.attributes['url']) sdict['sha256'] = self.__hash_remote_file(self.name)
sdict['sha256'] = force_text(
self.node.run(f"curl -sL -- {quote(full_sha256_url)}").stdout
).strip().split()[0]
elif self.attributes.get('gpg_signature_url'): elif self.attributes.get('gpg_signature_url'):
full_signature_url = self.attributes['gpg_signature_url'].format(url=self.attributes['url']) full_signature_url = self.attributes['gpg_signature_url'].format(url=self.attributes['url'])
signature_path = f'{self.name}.signature' signature_path = f'{self.name}.signature'

View file

@ -46,7 +46,13 @@
}, },
'nextcloud': { 'nextcloud': {
'hostname': 'cloud.sublimity.de', 'hostname': 'cloud.sublimity.de',
'version': '21.0.3', 'version': '21.0.5',
},
'nextcloud-picsort': {
'ckn': {
'source': 'SofortUpload/AutoSort',
'destination': 'Bilder/Chronologie',
},
}, },
'users': { 'users': {
'root': { 'root': {