#!/bin/dash # Change that shell to /bin/sh , /bin/ash , /bin/dash or /bin/bash , if needed. # mirrorpoetry.sh # Just a little shell script hack for mirroring and # repackaging my poetry. # Copyright (c) 2003, 2006, 2007 and 2008 Juhapekka Tolvanen # http://iki.fi/juhtolv/ # juhtolv (at) iki (dot) fi # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ################################################################ #URL_BASE="http://iki.fi/juhtolv/runot/" #WGET_COMMAND="wget -q -r -N -l inf -nr --no-host-directories --cut-dirs=2 --no-parent" set -o errexit #if gfind --help 2>&1 | grep -i "gnu.org" > /dev/null 2>&1 #then # alias find='gfind' #elif find --help 2>&1 | grep -i "gnu.org" > /dev/null 2>&1 #then # : #else # echo "You do not have GNU find." # echo 'I refuse to play with you!' # echo "Exiting ..." # exit 1 #fi #if gxargs --help 2>&1 | grep -i "gnu.org" > /dev/null 2>&1 #then # alias xargs='gxargs' #elif xargs --help 2>&1 | grep -i "gnu.org" > /dev/null 2>&1 #then # : #else # echo "You do not have GNU xargs" # echo 'I refuse to play with you!' # echo "Exiting ..." # exit 1 #fi #if type wget > /dev/null 2>&1 #then # : #else # echo "wget not found" # echo "Exiting ..." # exit 1 #fi if type gzip > /dev/null 2>&1 then : else echo "gzip not found" echo "Exiting ..." exit 1 fi if type bzip2 > /dev/null 2>&1 then : else echo "bzip2 not found" echo "Exiting ..." exit 1 fi # AFAIK star is faster and better than GNU tar if star --version 2>&1 | grep -i "Schilling" > /dev/null 2>&1 then alias tar='star' echo "Cool... You have star, not just GNU tar or plain tar" elif gtar --help 2>&1 | grep -i "gnu.org" > /dev/null 2>&1 then alias tar="gtar" echo "Cool... You have GNU tar, not just plain tar" elif tar --help 2>&1 | grep -i "gnu.org" > /dev/null 2>&1 then echo "Cool... You have GNU tar, not just plain tar" fi recursiveunpack () { for f in * do if test -d "$f" then echo cd "$f" cd "$f" echo recursiveunpack recursiveunpack echo 'cd ..' cd .. elif test -f "$f" then case "$f" in *.bz2) echo "bunzip2 "$f"" bunzip2 "$f" ;; *.gz) echo "gunzip "$f"" gunzip "$f" ;; *.zip|*.ZIP) echo "unzip -o "$f"" unzip -o "$f" ;; *.lha|*.lzh) echo "lha e "$f"" lha e "$f" ;; *) : esac fi done } recursivegzip () { for f in * do if test -d "$f" then echo cd "$f" cd "$f" echo recursivegzip recursivegzip echo 'cd ..' cd .. elif test -f "$f" then case "$f" in *.gz) echo ""$f" is packed with gzip already" ;; *.bz2) echo ""$f" is packed with bzip2 already" BASENAME="`basename $f .bz2`" bzip2 -dc "${BASENAME}.bz2" | gzip -9 > "${BASENAME}.gz" rm -f "${BASENAME}.bz2" ;; *) echo gzip -9 "$f" gzip -9 "$f" esac fi done } #recursivezip () #{ # for f in * # do # if test -d "$f" # then # echo cd "$f" # cd "$f" # echo recursivezip # recursivezip # echo 'cd ..' # cd .. # elif test -f "$f" # then # case "$f" in # *.gz) # echo ""$f" is packed with gzip already" # BASENAME="`basename $f .gz`" # gunzip "${BASENAME}.gz" # zip "${BASENAME}.zip" "${BASENAME}" # rm -f "${BASENAME}.gz" "${BASENAME}" # ;; # *.bz2) # echo ""$f" is packed with bzip2 already" # BASENAME="`basename $f .bz2`" # bunzip2 "${BASENAME}.bz2" # zip "${BASENAME}.zip" "${BASENAME}" # rm -f "${BASENAME}.bz2" "${BASENAME}" # ;; # *) # echo zip "${f}.zip" "$f" # zip "${f}.zip" "$f" # rm -f "${f}" # esac # fi # done #} # #recursivelha () #{ # for f in * # do # if test -d "$f" # then # echo cd "$f" # cd "$f" # echo recursivelha # recursivelha # echo 'cd ..' # cd .. # elif test -f "$f" # then # case "$f" in # *.gz) # echo ""$f" is packed with gzip already" # BASENAME="`basename $f .gz`" # gunzip "${BASENAME}.gz" # lha c "${BASENAME}.lzh" "${BASENAME}" # rm -f "${BASENAME}.gz" "${BASENAME}" # ;; # *.bz2) # echo ""$f" is packed with bzip2 already" # BASENAME="`basename $f .bz2`" # bunzip2 "${BASENAME}.bz2" # lha c "${BASENAME}.lzh" "${BASENAME}" # rm -f "${BASENAME}.bz2" "${BASENAME}" # ;; # *) # echo lha c "${f}.lha" "$f" # lha c "${f}.lzh" "$f" # rm -f "${f}" # esac # fi # done #} # This function is not used at all in this script #recursivebzip2 () #{ # for f in * # do # if test -d "$f" # then # echo cd "$f" # cd "$f" # echo recursivebzip2 # recursivebzip2 # echo 'cd ..' # cd .. # elif test -f "$f" # then # case "$f" in # *.gz) # echo ""$f" is packed with gzip already" # BASENAME="`basename $f .gz`" # gzip -dc "${BASENAME}.gz" | bzip2 -9 > "${BASENAME}.bz2" # rm -f "${BASENAME}.gz" # ;; # *.bz2) # echo ""$f" is packed with bzip2 already" # ;; # *) # echo bzip2 -9 "$f" # bzip2 -9 "$f" # esac # fi # done #} ########################################################### # ACTION !!! # cd ~/www/runot/othercompress || exit 1 rm -rf ./* #mkdir runot #cd runot ############## # Plain text #echo ${WGET_COMMAND} ${URL_BASE}txt-bz2/ #${WGET_COMMAND} ${URL_BASE}txt-bz2/ #cp -a ../txt-bz2 ./ #find ./txt-bz2 -type f -iname '*html*' -print0 | xargs -0r rm -f mkdir txt cp ../txt-bz2/* ./txt/ cp ~/www/licenses/dsl.txt ./txt/ #rmdir txt-bz2 cd txt recursiveunpack cd .. # .gz mkdir txt-gz cp -r txt/* txt-gz/ cd txt-gz recursivegzip cd .. # .zip #mkdir txt-zip #cp -r txt/* txt-zip/ #cd txt-zip #recursivezip #cd .. # .lha #mkdir txt-lzh #cp -r txt/* txt-lzh/ #cd txt-lzh #recursivelha #cd .. # tar.gz tar -c -f - txt | gzip -9vv > txt.tar.gz # tar.bz2 tar -c -f - txt | bzip2 -9v > txt.tar.bz2 # zip #zip -r txt.zip txt # lha #lha c txt.lzh txt ############## LaTeX #echo ${WGET_COMMAND} ${URL_BASE}latex-bz2/ #${WGET_COMMAND} ${URL_BASE}latex-bz2/ #find ./latex-bz2 -type f -iname '*html*' -print0 | xargs -0r rm -f mkdir latex cp -r ../latex-bz2/* ./latex/ rm -f ./latex/dsl.txt echo foo cp ~/www/licenses/dsl.txt ./latex/ echo bar cd latex recursiveunpack cd .. mkdir latex-gz cp -r latex/* latex-gz/ cd latex-gz recursivegzip cd .. ## .zip #mkdir latex-zip #cp -r latex/* latex-zip/ #cd latex-zip #recursivezip #cd .. ## .lzh #mkdir latex-lzh #cp -r latex/* latex-lzh/ #cd latex-lzh #recursivelha #cd .. # tar.gz tar -c -f - latex | gzip -9vv > latex.tar.gz # tar.bz2 tar -c -f - latex | bzip2 -9v > latex.tar.bz2 # zip #zip -r latex.zip latex # lzh #lha c latex.lzh latex ############### # PDF-files # mkdir latex-pdf cp latex/*/*.pdf latex-pdf cp latex/*/*/*.pdf latex-pdf cp ~/www/licenses/dsl.txt ./latex-pdf/ # tar.gz tar -c -f - latex-pdf | gzip -9vv > latex-pdf.tar.gz # tar.bz2 tar -c -f - latex-pdf | bzip2 -9v > latex-pdf.tar.bz2 # zip #zip -r latex-pdf.zip latex-pdf # lzh #lha c latex-pdf.lzh latex-pdf rm -rf latex-pdf ############### # PS-files # mkdir latex-ps cp latex/*/*.ps latex-ps cp latex/*/*/*.ps latex-ps cp ~/www/licenses/dsl.txt ./latex-ps/ # tar.gz tar -c -f - latex-ps | gzip -9vv > latex-ps.tar.gz # tar.bz2 tar -c -f - latex-ps | bzip2 -9v > latex-ps.tar.bz2 # zip #zip -r latex-ps.zip latex-ps # lzh #lha c latex-ps.lzh latex-ps rm -rf latex-ps # We don't need unpacked LaTeX-files rm -rf latex ##################### # Best as Plain text # mkdir best-txt cd best-txt #echo wget ${URL_BASE}best-txt-bz2/best.names.txt #wget ${URL_BASE}best-txt-bz2/best.names.txt cp ../../best-txt-bz2/best.names.txt ./ for f in `awk '{print $1}' best.names.txt` do ln -s ../txt/${f} ./ done cp ~/www/licenses/dsl.txt ./ cd .. #mkdir best-txt-bz2 #cp best-txt/best.names.txt best-txt-bz2/ #cd best-txt-bz2 #for f in `awk '{print $1}' best.names.txt` #do # ln -s ../txt-bz2/${f}.bz2 ./ #done #bzip2 -9 best.names.txt #ln -s ../txt-bz2/dsl.txt.bz2 ./ #cd .. mkdir best-txt-gz cp best-txt/best.names.txt best-txt-gz/ cd best-txt-gz for f in `awk '{print $1}' best.names.txt` do ln -s ../txt-gz/${f}.gz ./ done gzip -9 best.names.txt ln -s ../txt-gz/dsl.txt.gz ./ cd .. #mkdir best-txt-zip #cp best-txt/best.names.txt best-txt-zip/ #cd best-txt-zip #for f in `awk '{print $1}' best.names.txt` #do # ln -s ../txt-zip/${f}.zip ./ #done #zip best.names.txt.zip best.names.txt #rm -f best.names.txt #ln -s ../txt-zip/dsl.txt.zip ./ #cd .. #mkdir best-txt-lzh #cp best-txt/best.names.txt best-txt-lzh/ #cd best-txt-lzh #for f in `awk '{print $1}' best.names.txt` #do # ln -s ../txt-lzh/${f}.lzh ./ #done #lha c best.names.txt.lzh best.names.txt #rm -f best.names.txt #ln -s ../txt-lzh/dsl.txt.lzh ./ #cd .. mv best-txt best-txt.BAK mkdir best-txt cp best-txt.BAK/best.names.txt best-txt/ cp ../best-txt-bz2/best.names.txt best-txt/ cd best-txt for f in `awk '{print $1}' best.names.txt` do cp ../txt/${f} ./ done cp ~/www/licenses/dsl.txt ./ cd .. # tar.gz tar -c -f - best-txt | gzip -9vv > best-txt.tar.gz # tar.bz2 tar -c -f - best-txt | bzip2 -9v > best-txt.tar.bz2 # zip #zip -r best-txt.zip best-txt # lzh #lha c best-txt.lzh best-txt rm -rf best-txt #mv best-txt.BAK best-txt #ln -s txt/dsl.txt ./dsl.txt cp ${0} ./mirrorpoetry.sh.txt rm -rf txt best-txt.BAK #echo wget ${URL_BASE}dsl.boilerplates.txt #wget ${URL_BASE}dsl.boilerplates.txt chmod -R go-w,ugo+rX .