#!/bin/bash -e
# © Friedhelm Mehnert <friedhelm@friedhelms.net>

# if the "old" directory does not exist, we're done!
found=$(find /home -type d -name 'Simple Sokoban')
[ -z "$found" ] && exit 0

# put the users found into an array
users=$(echo "$found" | cut -d / -f 3 -)

#iterate over the users
for user in ${users}; do
   # we need to make sure that the target directories exist
   mkdir -p "/home/$user/.local/share/simplesok/solved"
   chown -R $user:$user "/home/$user/.local/share/simplesok"
   # now copy the files
   cp -n "/home/$user/.local/share/Mateusz Viste/Simple Sokoban/"*"" \
   "/home/$user/.local/share/simplesok/solved/" 2>/dev/null || :
   # remove the "old" directory
   rm -rf "/home/$user/.local/share/Mateusz Viste/Simple Sokoban"

done

#DEBHELPER#

exit 0

