syncStore.sh

#!/bin/bash

SERVER=YOUR_STORE.COM
MAIL=YOU@YOUR_DOMAIN.COM

function create_item_description() {
# set java classpath
export CLASSPATH=/media/programme/java/classpath/RitterDefault_lin.jar:/media/programme/java/classpath/ojdbc14.jar

# export descriptions from db
for i in 2 3 7; do
java LagerlisteCreator -q "Webshop" "${SERVER}_${i}" > /tmp/${SERVER}_${i}.out

if [ ! $? -eq 0 ]; then
mail "${MAIL}" -s "ERROR in ${SERVER}_${i} export" < /tmp/sync_ma.out
fi
done
}

function sync_item_descritpion() {
echo "Sync item descriptions..."

# upload item import files
for i in $(ls /media/lagerliste/Webshop/texte/${SERVER}_import_*.csv); do
FILE=${i##*/}
FILE=${FILE//${SERVER}_/}

echo "upload import file: ${FILE}"
cp ${i} /tmp/${SERVER}/import/${FILE}
mv ${i} ${i}.$(date +%Y-%m-%d_%H-%M)
done
}

function sync_item_images() {
echo "Sync item images..."

# get image list from ftp
ls /tmp/${SERVER}/images/product_images/original_images/ | grep .jpg | sort > /tmp/${SERVER}_img.list

# get image list from db
/media/scripte/service/sql.sh "select * from \"WEBSHOP\".\"IMAGES_${SERVER}\"" | sort > /tmp/webshop_img.list

# upload new images
for i in $(comm -3 -1 /tmp/${SERVER}_img.list /tmp/webshop_img.list); do
echo "upload image: $i"
cp /media/bilder/webshop/gross/$i /tmp/${SERVER}/images/product_images/original_images/;
done

# delete unused images
for i in $(comm -3 -2 /tmp/${SERVER}_img.list /tmp/webshop_img.list); do
echo "delete image: $i"
rm /tmp/${SERVER}/images/product_images/original_images/$i
done

# clean up
rm /tmp/${SERVER}_img.list
rm /tmp/webshop_img.list
}

# check mount directory
[ ! -d /tmp/${SERVER} ] && mkdir /tmp/${SERVER}

# mount ftp
curlftpfs ${SERVER} /tmp/${SERVER}

# create item descriptions
create_item_description

# sync item description
sync_item_descritpion

# sync images
sync_item_images

# umound ftp
umount /tmp/${SERVER}