1
0
mirror of https://github.com/danog/gigaclone.git synced 2024-11-26 20:14:58 +01:00
gigaclone/mkurllist
2016-03-26 19:50:21 +00:00

108 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
conf() {
git config user.name "Daniil Gentili"
git config user.email "daniil.gentili.dg@gmail.com"
git config push.default simple
}
dir="$PWD"
tmp="$dir/tmp"
rm -r $tmp
mkdir -p $tmp
cd $tmp
{
extractlog() {
tar -xzf logs.tgz
cd log
for f in ./*;do {
echo "Working... for $f"
sed -i '/200\|206\|302\|301/!d;s/\sHTTP.*//g;s/.*\s/http:\/\/profile\.gigaset\.net/g;/http:\/\/profile\.gigaset\.net\"\"/d;s/?.*//g;s/\.net\/device/\.net\/chagall/g;s/^\.$//g' $f
echo "Remove duplicates for $f"
awk '!seen[$0]++' $f>>$tmp/tmp
};done
md5sum $tmp/logs.tgz >$dir/.md5sum
rm $tmp/logs.tgz
rdupes $tmp/tmp
}
rdupes() {
echo "Remove all duplicates for $*"
awk '!seen[$0]++' $* $dir/urllist >$dir/final
sed -i 's/\&hellip\///g' $dir/final
mv $dir/final $dir/urllist
rm $*
for dl in $(cat $dir/urllist); do {
curl -w "%{url_effective}\n" -L -f -s -I -S "$dl" -o /dev/null >> $dir/final
};done
sed -i '/HTTP/d;s/\&hellip\///g' $dir/final
mv $dir/final $dir/urllist
awk '!seen[$0]++' $dir/urllist >$dir/final
mv $dir/final $dir/urllist
}
extractbin() {
echo "Extracting urls..."
cd $tmp
for f in $(grep "\.bin" $dir/urllist);do {
[ $(wget -S --spider "$f" 2>&1 | sed '/Length/!d;s/Length\: //g;s/\s.*//g;s/\s//g;s/[^0-9]*//g' | tr -d "\n") -lt 52428800 ] && {
file=$(wget -qO- "$f" | strings)
echo "$file" | sed '/http:\/\//!d;/profile.gigaset.net\|update.gigaset.net/!d;s/.*http:\/\//http:\/\//g;s/update\.gigaset/profile\.gigaset/g'>>$tmp/tmp
baseurl="$(echo "$f" | sed 's/[^/]*$//')"
url=$(echo "$file" | sed '/http/d;/\.bin/!d')
for e in $url;do echo "$baseurl$e">>$tmp/tmp;done
}
}; done
rdupes $tmp/tmp
}
treegen() {
echo "Creating tree..."
rm -r tree
mkdir tree
cd tree
for f in $(sed 's/http:\/\/profile.gigaset.net\///g;s/^\/*//g' $dir/urllist);do {
mkdir $(dirname "$f")&>/dev/null
touch "$f"
};done
for f in $(find . -type d);do a=$(echo "$f" | sed 's/\.\///g'); cd $f; index="(tree -T "profile.gigaset.net" -C -H "http://profile.gigaset.net/"$a -L 1 | sed 's/net\/\.\//net\//g;s/class=\"DIR\" href=\"http\:\/\/profile\.gigaset\.net/class=\"DIR\" href=\"http\:\/\/daniil\.it\/gigaclone\/tree/g')"; echo "$index">index.html; cd $OLDPWD; done
find . -not -iname "index.html" -type f -a -not -name "." -exec rm {} \;
}
wget http://profile.gigaset.net/logs.tgz -qO logs.tgz
[ "$(md5sum $tmp/logs.tgz)" != "$(cat $dir/.md5sum)" ] && {
extractlog
extractbin
sort urllist > final
mv final urllist
}
checkurl
treegen
cd $dir
rm -rf $tmp/
mkdir $tmp
git clone https://$GH_TOKEN@github.com/danog/gigaclone.git $tmp/git
cd $tmp/git
config
cp $dir/* .
rm -rf tmp gigaclone.log
git add -A
git commit -m "Updated url list"
git push origin master &>/dev/null
git checkout gh-pages
cp $dir/tree.html .
git add -A
git commit -m "Updated dir tree"
git push origin gh-pages &>/dev/null
cd $dir
echo "Clean up."
rm -rf $tmp
} &> $dir/gigaclone.log