nettsiden/www/galleri/fetchPics.sh

24 lines
830 B
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
outfolder="bilder/pvv-photos"
2022-01-29 22:54:52 +01:00
echo "Fetching user list"
# Note: `~pvv/.ssh/authorized_keys` forces the command as such
folders="$(ssh pvv@microbel.pvv.ntnu.no -i /home/pvv/c/pvv/.ssh/photofetcher 'cat /etc/passwd' | while read line; do test `echo "$line" | cut -d: -f 3` -gt 1000 && echo "$(echo $line | cut -d: -f 6)/pvv-photos" ; done)"
unamefile="usernames.txt"
> $unamefile # Empty the file
for imgfolder in $folders; do
2022-01-29 22:54:52 +01:00
if ! test -d "$imgfolder"; then continue; fi
echo found $imgfolder
user="$(echo $imgfolder | cut -d "/" -f5)"
realname="$(getent passwd $user | cut -d ':' -f 5)"
2022-01-29 22:54:52 +01:00
echo "$user:$realname" >> "$unamefile"
destination="$outfolder/$user"
2022-01-29 22:54:52 +01:00
mkdir -p "$destination"
rsync -rtvz --delete "$imgfolder/" "$destination" # Copy and keep timestamps
2022-01-29 22:54:52 +01:00
echo
done