2015-11-23 22:29:53 +01:00
#!/bin/bash
2015-11-24 21:51:59 +01:00
2016-03-22 20:47:45 +01:00
dir="$PWD"
2015-11-23 22:29:53 +01:00
tmp="$dir/tmp"
2016-03-22 20:47:45 +01:00
rm -r $tmp
2015-12-26 15:33:08 +01:00
mkdir -p $tmp
2015-11-23 22:29:53 +01:00
cd $tmp
2015-12-08 14:57:48 +01:00
{
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
2016-03-26 15:32:10 +01:00
rm $tmp/logs.tgz
2015-12-08 14:57:48 +01:00
rdupes $tmp/tmp
}
rdupes() {
2016-03-26 21:15:10 +01:00
[ "$1" != "" ] && {
echo "Remove all duplicates for $*"
2016-03-31 20:37:55 +02:00
sed -i 's/\/\//\//g;s/\/$//g' $dir/urllist
2016-03-26 21:15:10 +01:00
awk '!seen[$0]++' $* $dir/urllist >$dir/final
2016-03-26 17:44:57 +01:00
2016-03-26 21:15:10 +01:00
mv $dir/final $dir/urllist
rm $*
}
2016-03-22 20:47:45 +01:00
for dl in $(cat $dir/urllist); do {
2016-03-31 04:05:38 +02:00
a=$(curl -w "%{url_effective}\n" -L -f -s -I -S "$dl" -o /dev/null)
[ $? = "0" ] && echo "$a" >> $dir/final
2016-03-22 20:47:45 +01:00
};done
mv $dir/final $dir/urllist
awk '!seen[$0]++' $dir/urllist >$dir/final
mv $dir/final $dir/urllist
2015-12-08 14:57:48 +01:00
}
extractbin() {
2016-03-22 20:47:45 +01:00
echo "Extracting urls..."
2015-12-08 14:57:48 +01:00
cd $tmp
for f in $(grep "\.bin" $dir/urllist);do {
2016-03-26 14:59:32 +01:00
[ $(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 ] && {
2016-03-22 20:47:45 +01:00
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
2016-03-31 17:06:02 +02:00
baseurl="$(dirname "$f")"/
2016-03-22 20:47:45 +01:00
url=$(echo "$file" | sed '/http/d;/\.bin/!d')
for e in $url;do echo "$baseurl$e">>$tmp/tmp;done
}
2015-12-08 14:57:48 +01:00
}; done
rdupes $tmp/tmp
}
2016-03-26 14:59:32 +01:00
treegen() {
2016-03-22 20:47:45 +01:00
echo "Creating tree..."
2016-03-30 20:02:59 +02:00
cd $dir
2016-03-26 20:50:21 +01:00
rm -r tree
mkdir tree
cd tree
2015-12-08 14:57:48 +01:00
for f in $(sed 's/http:\/\/profile.gigaset.net\///g;s/^\/*//g' $dir/urllist);do {
2016-03-31 04:05:38 +02:00
mkdir -p $(dirname "$f")&>/dev/null
2016-03-26 17:44:57 +01:00
touch "$f"
2015-12-08 14:57:48 +01:00
};done
2016-03-31 22:10:50 +02:00
for f in $(find . -type d);do a=$(echo "$f" | sed 's/\.\///g'); cd $f; index="$(tree -a -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' | sed 's/<\/a> /<\/a><br>\
2016-03-31 20:37:55 +02:00
/g')"; echo "$index">index.html; cd $OLDPWD; done
2016-03-26 20:50:21 +01:00
find . -not -iname "index.html" -type f -a -not -name "." -exec rm {} \;
2015-12-08 14:57:48 +01:00
}
2016-03-22 20:47:45 +01:00
wget http://profile.gigaset.net/logs.tgz -qO logs.tgz
2015-12-08 14:57:48 +01:00
[ "$(md5sum $tmp/logs.tgz)" != "$(cat $dir/.md5sum)" ] && {
extractlog
extractbin
}
2016-03-31 04:05:38 +02:00
[ "$1" = 'check' ] && { extractbin; }
2016-03-30 20:02:59 +02:00
cd $dir
sort urllist > final
mv final urllist
2016-03-26 14:59:32 +01:00
treegen
2015-12-08 14:57:48 +01:00
cd $dir
rm -rf $tmp/
mkdir $tmp
git clone https://$GH_TOKEN@github.com/danog/gigaclone.git $tmp/git
cd $tmp/git
2016-03-30 21:41:32 +02:00
rm -r tree
2016-03-26 21:07:01 +01:00
cp -a $dir/* .
2016-03-26 14:59:32 +01:00
rm -rf tmp gigaclone.log
2015-12-08 14:57:48 +01:00
git add -A
git commit -m "Updated url list"
git push origin master &>/dev/null
git checkout gh-pages
2016-03-26 21:07:01 +01:00
rm -r tree
cp -a $dir/tree .
2015-12-08 14:57:48 +01:00
git add -A
git commit -m "Updated dir tree"
git push origin gh-pages &>/dev/null
cd $dir
echo "Clean up."
2016-03-22 20:47:45 +01:00
rm -rf $tmp
2016-03-26 14:59:32 +01:00
} &> $dir/gigaclone.log