Server synchronisation
This commit is contained in:
parent
4b101ef4b2
commit
bbec08ac4f
6 changed files with 218 additions and 18 deletions
83
gen_site.sh
83
gen_site.sh
|
|
@ -1,10 +1,91 @@
|
|||
#!/bin/sh
|
||||
|
||||
BASEURL="localhost"
|
||||
SALT_TEAM="connected"
|
||||
OUT_TEAM="./teams"
|
||||
|
||||
MAX_PARAL=9
|
||||
|
||||
DEBUG=0
|
||||
|
||||
|
||||
cd `dirname "$0"`
|
||||
|
||||
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
|
||||
|
||||
mkdir -p out
|
||||
cd out
|
||||
|
||||
wget -c -m https://$BASEURL/ https://$BASEURL/connected/
|
||||
# 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"
|
||||
|
|
|
|||
Reference in a new issue