]> Git — Sourcephile - julm/camera.git/blob - julm/pull.sh
sevy/pull: update to use julm/pull's logic
[julm/camera.git] / julm / pull.sh
1 #!/usr/bin/env bash
2 host=Xiaomi_SDM439-QRD__SN%3AB0796589_c7565cf60006
3 cd "${0%/*}"
4 set -eux
5
6 uid=$(id -u)
7 year=${year:-$(date +%Y)}
8 # FIXME: handle previous year on new year
9
10 if gio mount -l | grep file:///run/media/"$USER"/disk ||
11 gio mount file:///run/media/"$USER"/disk
12 then
13 find /run/media/julm/disk/DCIM/ -type f -not -name "IMG_*" -not -name "VID_*" |
14 while read -r file; do
15 #--remove-source-files
16 ext=${file##*.}
17 case $(file --mime-type "$file") in
18 *:\ video/*) prefix=VID;;
19 *:\ image/*) prefix=IMG;;
20 esac
21 # rsync -ai --no-inc-recursive --info=progress2 --inplace --partial
22 out=$(date -r "$file" +"$(dirname "$file")/${prefix}_%Y%m%d_%H%M%S")
23 test "$file" = "$out.$ext" ||
24 mv -n "$file" "$out.$ext" ||
25 { i=1; while ! mv -n "$file" "${out}_$i.$ext"; do i=$((i+1)); done; }
26 done
27 fi
28
29 if gio mount -l | grep mtp://"$host" ||
30 gio mount mtp://"$host"/"Carte SD SanDisk"/
31 then
32 mkdir -p "$year"/audio/src
33 test ! -d /run/user/"$uid"/gvfs/mtp:host="$host"/"Espace de stockage interne partagé"/MIUI/sound_recorder ||
34 rsync -ai --no-inc-recursive --info=progress2 --inplace --partial \
35 --remove-source-files \
36 /run/user/"$uid"/gvfs/mtp:host="$host"/"Espace de stockage interne partagé"/MIUI/sound_recorder \
37 "$year"/audio/src/
38
39 fi
40
41 gio mount -l | grep file:///run/media/"$USER"/6365-3561 ||
42 gio mount file:///run/media/"$USER"/6365-3561 || true
43
44 mkdir -p "$year"/src
45 for month in {01..12}; do
46 for src in \
47 /run/media/"$USER"/disk/DCIM/ \
48 /run/media/"$USER"/6365-3561/DCIM/ \
49 /run/user/"$uid"/gvfs/mtp:host="$host"/"Espace de stockage interne partagé"/DCIM/Camera/ \
50 /run/user/"$uid"/gvfs/mtp:host="$host"/"Carte SD SanDisk"/DCIM/Camera/
51 do
52 test ! -e "$src" ||
53 find "$src" -type f -name "???_$year$month*" -print0 |
54 rsync -ai0 --no-inc-recursive --info=progress2 --inplace --partial \
55 --remove-source-files \
56 --files-from - --no-relative \
57 / "$year"/src/"$month"
58 done
59 done