#!/bin/sh

PERL=$(which perl)

FOLD_DIR=/opt/fah/folding
MEMORY="memory"

USE_TIME=$1

if [ ! -z "$USE_TIME" ]; then
  PERL="time $PERL"
fi

FAH_DB="fah.db"

# Dossier folding
cd $FOLD_DIR

# Creation du RAMDisk
mkdir -p /tmp/$MEMORY
sudo mount -t tmpfs -o size=1024M tmpfs /tmp/$MEMORY
sleep 1

# Copie BDD dans RAMDisk
\cp -f saved_$FAH_DB /tmp/$MEMORY/$FAH_DB

# Creation pages
$PERL Alliance_Light.pl
$PERL message.pl

cd $FOLD_DIR
# Copie de la BDD depuis RAMDisk
\cp -f /tmp/$MEMORY/$FAH_DB ./saved_$FAH_DB
sleep 1

# Destruction du RAMDisk
sudo umount /tmp/$MEMORY
sleep 1
rmdir /tmp/$MEMORY

echo "Fin du traitement pour aujourd'hui !"

