2013-12-09 10:54:06 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
BASEURL="localhost"
|
2013-12-13 17:45:25 +00:00
|
|
|
SALT_TEAM="connected"
|
|
|
|
OUT_TEAM="./teams"
|
|
|
|
|
|
|
|
MAX_PARAL=9
|
|
|
|
|
|
|
|
DEBUG=0
|
|
|
|
|
2013-12-09 10:54:06 +00:00
|
|
|
|
|
|
|
cd `dirname "$0"`
|
|
|
|
|
2013-12-13 17:45:25 +00:00
|
|
|
if [ "$UID" = "0" ]
|
|
|
|
then
|
|
|
|
SCRIPT=`pwd`/`basename "$0"`
|
|
|
|
su -c "sh -c '$SCRIPT $@'" synchro
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "/tmp/generate_site" ]
|
|
|
|
then
|
|
|
|
echo "This script is already running" 1>&2
|
|
|
|
echo "Remove the file /tmp/generate_site if you are sure this is not true" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
touch /tmp/generate_site
|
|
|
|
|
|
|
|
WGET_OPT="--no-check-certificate -c"
|
|
|
|
|
|
|
|
if [ $DEBUG -ne 1 ]
|
|
|
|
then
|
|
|
|
WGET_OPT="-q"
|
|
|
|
fi
|
|
|
|
|
2013-12-09 10:54:06 +00:00
|
|
|
mkdir -p out
|
|
|
|
cd out
|
|
|
|
|
2013-12-13 17:45:25 +00:00
|
|
|
# First, remove existing version if any
|
|
|
|
rm -rf "$BASEURL" "$OUT_TEAM"
|
|
|
|
|
|
|
|
wget $WGET_OPT -m -b "http://$BASEURL/" -o /dev/null
|
|
|
|
|
|
|
|
mkdir -p "$BASEURL"
|
|
|
|
ln -sf "`pwd`/../files/" "$BASEURL/files"
|
|
|
|
|
|
|
|
NB=0
|
|
|
|
PIDLIST=
|
|
|
|
# Get list of teams and fetch them in parallel
|
|
|
|
for l in $(curl -k "http://$BASEURL/$SALT_TEAM/" 2> /dev/null | grep -oE "/[^/]+/[0-9]+/")
|
|
|
|
do
|
|
|
|
(
|
|
|
|
wget $WGET_OPT -m "http://$BASEURL/$l"
|
|
|
|
|
|
|
|
for m in $(grep -R "<form " "$BASEURL/$l" | grep -oE "/[^/]+/([^/]+)/([0-9]+)-[^/]+/([a-zA-Z0-9_]+)/submission")
|
|
|
|
do
|
|
|
|
OUT=`echo "$m" | sed -E 's#/([^/]+)/([^/]+)/([0-9]+)-[^/]+/([a-zA-Z0-9_]+)/submission#\1/\2/submission-\3-\4#'`
|
|
|
|
wget $WGET_OPT "http://$BASEURL/$m" -O "$BASEURL/$OUT.html"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Remove /connected/XY
|
|
|
|
sed -Ei "s#/[^/]+/([0-9]+)/#/#" "$BASEURL/$l/"*
|
|
|
|
sed -Ei "s#/([0-9]+)-[^/]*/([a-zA-Z0-9_]+)/submission#/submission-\1-\2.html#" "$BASEURL/$l/"*
|
|
|
|
) &
|
|
|
|
|
|
|
|
PIDLIST="$PIDLIST $!"
|
|
|
|
NB=$(($NB + 1))
|
|
|
|
|
|
|
|
if [ $NB -ge $MAX_PARAL ]
|
|
|
|
then
|
|
|
|
echo "Generating teams ...$PIDLIST"
|
|
|
|
wait $PIDLIST
|
|
|
|
PIDLIST=
|
|
|
|
NB=0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Generating teams ...$PIDLIST"
|
|
|
|
wait $PIDLIST
|
|
|
|
|
|
|
|
rm /tmp/generate_site
|
|
|
|
|
|
|
|
# Move connected/ at root
|
|
|
|
mv "$BASEURL/$SALT_TEAM/" "$OUT_TEAM"
|
|
|
|
|
|
|
|
# Remove all robots.txt
|
|
|
|
find . -name robots.txt -exec rm {} \;
|
|
|
|
|
|
|
|
# Remove useless symlink
|
|
|
|
rm "$BASEURL/files"
|