Hack of the day: Synology NAS: “semi-public” Photo Station albums

By | February 24, 2016

I have a Synology NAS running the beta release of DSM 6 (I don’t know if the following hack will work in DSM 5). I’m trying to migrate over to using Photo Station to manage my photos and videos, now that Picasa is being desupported by Google (*big sigh*). I have tens of thousands of photos and videos in thousands of hierarchical albums. I want all the people in my family to be able to access these albums, along with any new albums that I add, but I do not want our albums to be public. The only way Photo Station provides to accomplish this is to visit the thousands of albums one by one in the Photo Station web user interface, opening its properties and assigning the desired permissions to it. To say that this is prohibitively difficult is a massive understatement.

Here’s my solution. Edit the “users=” line near the top of this script, put it on your NAS, and run it, and it will grant access permission for the specified users to all Photo Station albums. You can rerun it whenever you add new albums and it will add permissions for the new albums as well. Each time you want it, it adds only the permissions needed to give all of the specified users access to all albums.

Note that this assumes that you user DSM user accounts for Photo Station access, rather than using separate Photo Station accounts. It would not be difficult to modify it to support the latter.


#!/bin/sh -e
# Give a set of users access to all of the albums in Photo Station.
# List the usernames of the users who should have access, with '|'
# symbols between them.
mkdir -p $td
chmod 777 $td
echo storing temporary files in $td
# Clean up on exit.
trap "rm -rf $td" EXIT
# Get a list of userids to which to assign permissions.
awk -F: '/^('"$users"'):/ {print $3}' /etc/passwd > $td/userids
# Get a list of permissions that are already assigned.
psql -U postgres -c "COPY photo_access_right_for_dsm_account (userid, shareid)
                     TO '$td/current_rights'" photo
sort -o $td/current_rights $td/current_rights
# Get a list of all albums.
psql -U postgres -c "COPY photo_share (shareid) TO '$td/shares'" photo
# Generate a list of desired permissions.
for userid in $(cat $td/userids); do
    for shareid in $(cat $td/shares); do
        echo "$userid	$shareid"
done | sort > $td/want_rights
# Generate a list of permissions that need to be added.
now="$(date '+%F %T')"
comm -13 $td/current_rights $td/want_rights |
    sed "s/$/	$now/" > $td/copy_rights
# Add the missing permissions.
psql -U postgres -c "COPY photo_access_right_for_dsm_account
                          (userid, shareid, create_time)
                     FROM '$td/copy_rights'" photo
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published.