#!/bin/bash


fqdn=$1

#UA list

useragent[1]="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
useragent[2]="Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3694.0 Mobile Safari/537.36 Chrome-Lighthouse"
useragent[3]="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Mobile Safari/537.36"
useragent[4]="Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36"
useragent[5]="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3694.0 Safari/537.36 Chrome-Lighthouse"
useragent[6]="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/61.0.3163.100 Chrome/61.0.3163.100 Safari/537.36 PingdomPageSpeed/1.0 (pingbot/2.0; +http://www.pingdom.com/)"
useragent[7]="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
useragent[8]="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"
useragent[9]="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0"

#This wget to extract urls from sitemap

wget  -q https://$fqdn/sitemap_index.xml --no-cache --output-document - | grep -E -o '<loc>.*</loc>'|sed -e 's/<loc>//g' -e 's/<\/loc>//g' | while read line; do
        wget -q $line --no-cache --output-document - | grep -E -o '<loc>.*</loc>' | sed -e 's/<loc>//g' -e 's/<\/loc>//g'| while read line2; do

#2 Random UA for the 2 most used screen sizes

number=$( shuf -i 4-9 -n 1) > /dev/null 2>&1
number1=$( shuf -i 1-4 -n 1)  > /dev/null 2>&1

/usr/lib64/chromium-browser/headless_shell --disable-translate --disable-background-networking --safebrowsing-disable-auto-update --disable-sync  --disable-default-apps --disable-software-rasterizer --single_process --disable-features --disable-extensions --disable-setuid-sandbox --no-sandbox --disable-gpu --lang=es_ES --tls1.3  --window-size=360,640 --user-agent="${useragent[$number1]}" --disable-features=NetworkService --enable-tcp-fast-open --disable-zygote --enable-ipv6 $line2 > /dev/null 2>&1
#echo $line2

/usr/lib64/chromium-browser/headless_shell --disable-translate --disable-background-networking --safebrowsing-disable-auto-update --disable-sync  --disable-default-apps --disable-software-rasterizer --single_process --disable-features --disable-extensions --no-sandbox --disable-gpu --lang=es_ES --tls1.3 --window-size=1920,1080 --user-agent="${useragent[$number]}" --disable-features=NetworkService --enable-tcp-fast-open --disable-zygote --enable-ipv6 $line2 > /dev/null 2>&1 
#echo $line2


        done
done
