2015-03-17 02:31:32 +00:00
|
|
|
#!/bin/bash -xe
|
|
|
|
|
|
|
|
# Working variables
|
|
|
|
MIRROR_ROOT=$1
|
2016-02-03 18:19:29 -08:00
|
|
|
|
|
|
|
# A temporary file to which to write the new index
|
2016-03-23 15:37:58 -04:00
|
|
|
TMP_INDEX_FILE=$(mktemp)
|
2016-02-03 18:19:29 -08:00
|
|
|
trap "rm -f -- '$TMP_INDEX_FILE'" EXIT
|
|
|
|
|
|
|
|
# And the final location
|
2015-03-17 02:31:32 +00:00
|
|
|
INDEX_FILE=${MIRROR_ROOT}/index.html
|
|
|
|
|
|
|
|
# Start building our file
|
2016-02-03 18:19:29 -08:00
|
|
|
echo -e "<html>\n <head>\n <title>Wheel Index</title>\n </head>" > $TMP_INDEX_FILE
|
|
|
|
echo -e " <body>\n <ul>" >> $TMP_INDEX_FILE
|
2015-03-17 02:31:32 +00:00
|
|
|
|
|
|
|
# Get a list of files
|
|
|
|
FILES=`find $MIRROR_ROOT -maxdepth 2 -type d`
|
2016-02-04 17:31:39 -08:00
|
|
|
REGEX="([^/])\/(\1[^/]+)$"
|
2015-03-17 02:31:32 +00:00
|
|
|
for f in $FILES; do
|
|
|
|
if [[ $f =~ $REGEX ]]; then
|
2016-02-03 18:19:29 -08:00
|
|
|
echo " <li><a href=\"./${BASH_REMATCH[2]}/\">${BASH_REMATCH[2]}</a></li>" >> $TMP_INDEX_FILE
|
2015-03-17 02:31:32 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-02-03 18:19:29 -08:00
|
|
|
echo -e " </ul>\n </body>\n</html>" >> $TMP_INDEX_FILE
|
|
|
|
|
2016-02-04 08:59:55 -08:00
|
|
|
if ! cmp $TMP_INDEX_FILE $INDEX_FILE >/dev/null 2>&1; then
|
|
|
|
# Atomically replace the index file
|
|
|
|
mv $TMP_INDEX_FILE $INDEX_FILE
|
|
|
|
else
|
|
|
|
rm $TMP_INDEX_FILE
|
|
|
|
fi
|
2016-02-03 18:19:29 -08:00
|
|
|
|
|
|
|
# The tempfile is gone so we don't need the trap
|
|
|
|
trap - EXIT
|