#!/bin/bash # # Written for BUGGER-1 # # Download a copy of the publicly available BUGGER subdirectory and create a static archive wget -k -p -m http://projects.bentasker.co.uk/archived_content/ cd projects.bentasker.co.uk/archived_content for fname in projsummary.php* do projnum=$(echo "$fname" | grep -o -P "[0-9]+") mv "$fname" Project_${projnum}.html # Update all references sed -i -e "s/projsummary\.php?Project=${projnum}\"/Project_${projnum}.html\"/g" *.php* *.html sed -i -e "s/projsummary\.php?Project=${projnum}'/Project_${projnum}.html'/g" *.php* *.html # Grab the Task and Changelog views wget http://projects.bentasker.co.uk/archived_content/changelogview.php?Project=${projnum} -O changelog_project_${projnum}.html sed -i -e "s/changelogview\.php?Project=${projnum}'/changelog_project_${projnum}.html'/g" *.php* *.html wget http://projects.bentasker.co.uk/archived_content/tasks.php?Project=${projnum} -O tasks_project_${projnum}.html sed -i -e "s/tasks\.php?Project=${projnum}'/tasks_project_${projnum}.html'/g" *.php* *.html done for fname in buglist.php* do projnum=$(echo "$fname" | grep -o -P "[0-9]+") mv "$fname" buglist_Project_${projnum}.html # Update all references sed -i -e "s/buglist\.php?Project=${projnum}\"/buglist_Project_${projnum}.html\"/g" *.php* *.html sed -i -e "s/buglist\.php?Project=${projnum}'/buglist_Project_${projnum}.html'/g" *.php* *.html done for fname in docview.php* do projnum=$(echo "$fname" | grep -o -P "[0-9]+") mv "$fname" docview_Project_${projnum}.html # Update all references sed -i -e "s/docview\.php?Project=${projnum}\"/docview_Project_${projnum}.html\"/g" *.php* *.html sed -i -e "s/docview\.php?Project=${projnum}'/docview_Project_${projnum}.html'/g" *.php* *.html done for fname in relview.php* do projnum=$(echo "$fname" | grep -o -P "[0-9]+") mv "$fname" relview_Project_${projnum}.html # Update all references sed -i -e "s/relview\.php?Project=${projnum}\"/relview_Project_${projnum}.html\"/g" *.php* *.html sed -i -e "s/relview\.php?Project=${projnum}'/relview_Project_${projnum}.html'/g" *.php* *.html done for fname in License.php* do projnum=$(echo "$fname" | grep -o -P "[0-9]+") mv "$fname" License_${projnum}.html # Update all references sed -i -e "s/License\.php?ref=${projnum}\"/License_${projnum}.html\"/g" *.php* *.html sed -i -e "s/License\.php?ref=${projnum}'/License_${projnum}.html'/g" *.php* *.html done for i in 112 114 116 137 139 148 157 186 187 188 243; do rm viewbug.php\?BUGID\=${i}; done mv viewbug.php\?BUGID\=230 viewbug.php\?BUGID\=230\&Project=4 sed -i -e "s/viewbug\.php?BUGID=230\"/viewbug\.php?BUGID=230\&Project=4\"/g" *.php* *.html for fname in viewbug.php* do projnum=$(echo "$fname" | grep -o -P "BUGID=[0-9]+" | sed 's/=/_/g') mv "$fname" viewbug_${projnum}.html exactnum=$(echo $projnum | grep -o -P "[0-9]+" ) # Update all references sed -i -e "s/viewbug\.php?BUGID=${exactnum}\&/viewbug_${projnum}.html?/g" *.php* *.html sed -i -e "s/viewbug\.php?BUGID=${exactnum}\"/viewbug_${projnum}.html\"/g" *.php* *.html sed -i -e "s/viewbug\.php?BUGID=${exactnum}'/viewbug_${projnum}.html'/g" *.php* *.html done #Replace references to the old index sed -i -e 's/index.php/index.html/g' *.php* *.html # Start work on the downloads mkdir downloads > downloads/index.html # Downloads for fname in Download.php* do echo "Updating $fname" realfname=$(curl -JLO "http://projects.bentasker.co.uk/archived_content/$fname" 2>&1 | grep Saved | grep -o -P "'[^\']+'" | sed "s/'//g") doc_id=$(echo "$fname" | grep -o -P "id=[0-9]+" | sed 's/id=//g' ) doc_type=$(echo "$fname" | grep -o -P "type=[a-z]+" | sed 's/type=//g' ) mv "$realfname" downloads/${doc_id}_${realfname} sed -i -e "s/$fname\"/downloads\/${doc_id}_$realfname\"/g" *.php* *.html sed -i -e "s/$fname'/downloads\/${doc_id}_$realfname'/g" *.php* *.html htmld=$(echo "$fname" | sed 's/\&/\&/g') sed -i -e "s/$htmld\"/downloads\/${doc_id}_$realfname\"/g" *.php* *.html sed -i -e "s/$htmld'/downloads\/${doc_id}_$realfname'/g" *.php* *.html #echo "redirect 301 /archived_content/$fname /archived_content/downloads/${doc_id}_${realfname}" >> redirects.txt cat << EOM >> redirects.txt RewriteCond %{REQUEST_URI} ^/archived_content/Download\.php\$ RewriteCond %{QUERY_STRING} ^id=$doc_id\&type=${doc_type} RewriteRule ^(.*)$ /archived_content_static/downloads/${doc_id}_${realfname}? [R=301,L] EOM done rm Download.php* # Tidy up the two file-extension less files sed -i 's/31_Protocol_Documentation/31_Protocol_Documentation.txt/g' *.html *.txt sed -i 's/57_INSTALL/57_INSTALL.txt/g' *.html *.txt mv downloads/57_INSTALL downloads/57_INSTALL.txt mv downloads/31_Protocol_Documentation downloads/31_Protocol_Documentation.txt sed -i "s/BUGGER is still under Heavy Development, Please Bear with me/At the time of it's abandonment, BUGGERs template was still under development. Apologies for any feelings of nausea/g" *html