add debug
[kps.git] / kps_web / back_home.sh
blobc1f63d643a80e6d24dc0d587e65e4ca3766f0a29
1 #!/bin/bash
3 case $1 in
4 "-t")
5 MODE="TEXT";
6 ;;
7 "-h")
8 MODE="WEB";
9 ;;
11 echo -e "Error arguments!\n\t./add_back.sh -t/-h filename backaddress";
12 echo -e "\t\t-t means text\n\t\t-h means html";
13 exit 1;
15 esac
17 if [ ! -f "$2" ]; then
18 echo "File missing: $2!" >>/tmp/kps
19 exit 1
22 if [ -z "$3" ]; then
23 echo "Please input Home address."
24 exit 1
27 if [ $MODE = "TEXT" ]; then
28 sed -i 's/</\&lt;/g' $2
29 sed -i 's/>/\&gt;/g' $2
30 sed -i '1i<html><A href="'$3'">Back to home</A>\n<pre>' $2
31 echo "</pre></html>" >> $2
32 cp ./google_adsense /tmp/google_adsense
33 cat $2 >> /tmp/google_adsense
34 mv /tmp/google_adsense $2
35 exit 0
38 if [ $MODE = "WEB" ]; then
39 addr=`echo $3 | sed 's/\//\\\\\//g'`
40 grep '<body>' $2 >/dev/null && sed -i 's/<body>/<body>\n<A href="'$addr'">Back to home<\/A>/g' $2
41 grep '<BODY>' $2 >/dev/null && sed -i 's/<BODY>/<BODY>\n<A href="'$addr'">Back to home<\/A>/g' $2
42 cp ./google_adsense /tmp/google_adsense
43 cat $2 >> /tmp/google_adsense
44 mv /tmp/google_adsense $2
45 exit 0