4 if [[ $(id -u) != 0 ]]; then
5 echo "This migration needs to be run as root"
9 if [[ ! -f docker-compose.yml ]]; then
10 echo "No docker-compose.yml found in current directory. Is this the right folder?"
14 # Fixing pictrs permissions
15 mkdir -p volumes/pictrs
16 sudo chown -R 991:991 volumes/pictrs
18 echo "Restarting docker-compose, making sure that pictrs is started and pictshare is removed"
19 docker-compose up -d --remove-orphans
21 if [[ -z $(docker-compose ps | grep pictrs) ]]; then
22 echo "Pict-rs is not running, make sure you update Lemmy first"
26 # echo "Stopping Lemmy so that users dont upload new images during the migration"
27 # docker-compose stop lemmy
29 pushd volumes/pictshare/
30 echo "Importing pictshare images to pict-rs..."
32 for image in $IMAGE_NAMES; do
33 IMAGE_PATH="$(pwd)/$image/$image"
34 if [[ ! -f $IMAGE_PATH ]]; then
37 echo -e "\nImporting $IMAGE_PATH"
39 curl --silent --fail -F "images[]=@$IMAGE_PATH" http://127.0.0.1:8537/import || ret=$?
40 if [[ $ret != 0 ]]; then
41 echo "Error for $IMAGE_PATH : $ret"
45 echo "Fixing permissions on pictshare folder"
46 find . -type d -exec chmod 755 {} \;
47 find . -type f -exec chmod 644 {} \;
51 echo "Rewrite image links in Lemmy database"
52 docker-compose exec -u postgres postgres psql -U lemmy -c "UPDATE user_ SET avatar = REPLACE(avatar, 'pictshare', 'pictrs/image') WHERE avatar is not null;"
53 docker-compose exec -u postgres postgres psql -U lemmy -c "UPDATE post SET url = REPLACE(url, 'pictshare', 'pictrs/image') WHERE url is not null;"
55 echo "Moving pictshare data folder to pictshare_backup"
56 mv volumes/pictshare volumes/pictshare_backup
58 echo "Migration done, starting Lemmy again"
59 echo "If everything went well, you can delete ./volumes/pictshare_backup/"
60 docker-compose start lemmy