11#! /bin/bash
22
3+ tmpdir=" /tmp/war"
4+ browser=" x-www-browser"
5+ [ -f /etc/war-bash.conf ] && source /etc/war-bash.conf
6+ [ -f ~ /config/war-bash.conf ] && source ~ /config/war-bash.conf
37user=" $( whoami) "
4- tmpdir=" /tmp/war_$user "
5- tmpdirsed=" \/tmp\/war_$user \/"
8+ tmpdir=" ${tmpdir} _${user} "
69
710function usage()
811{
912 echo " WAR file (KDE WEB archive) creator."
1013 echo
11- echo " USAGE: $0 [options] /path/to/html file.war"
14+ echo " USAGE: $0 [options] /path/to/html/dir file.war"
1215 echo " options:"
13- echo " -i using exist index.html."
1416 echo " -h help."
1517 echo
1618 exit 1
2022 usage
2123fi
2224
23- indexuse=" false"
24-
25- while getopts " :ih" opt
25+ while getopts " :h" opt
2626do
2727 case $opt in
28- i) indexuse=" true"
29- ;;
3028 h) usage
3129 ;;
3230 * ) echo " Unknown option -$OPTARG "
4644 warfile=" $htmldir .war"
4745fi
4846
49- if [ $indexuse = " true" ]
47+ indexuse=" false"
48+ if [ -f " $htmldir /index.html" ]
5049then
51- if [ ! -f " $htmldir /index.html" ]
52- then
53- indexuse=" false"
54- fi
50+ indexuse=" true"
5551fi
5652
5753rm -rf " $tmpdir "
@@ -62,7 +58,8 @@ if [ $indexuse = "true" ]
6258then
6359 tar cz -C " $tmpdir /$htmldir " -f " $warfile " .
6460else
65- cat > " $tmpdir /index.html" << EOF
61+ tmpdirsed=" $( echo $tmpdir /$htmldir | sed ' s%\/%\\/%g' ) \/"
62+ cat > " $tmpdir /$htmldir /index.html" << EOF
6663<!DOCTYPE html>
6764<!-- Source is http://www.warmplace.ru/ -->
6865<html>
7471 <h1>$htmldir </h1>
7572 <ol>
7673EOF
77- find " $tmpdir " -iname " *.html" | sed -e " s/$tmpdirsed //;s/.*/ <li><a href=\" .\/&\" >&<\/a><\/li>/;" >> " $tmpdir /index.html"
78- find " $tmpdir " -iname " *.htm" | sed -e " s/$tmpdirsed //;s/.*/ <li><a href=\" .\/&\" >&<\/a><\/li>/;" >> " $tmpdir /index.html"
79- cat >> " $tmpdir /index.html" << EOF
74+ find " $tmpdir / $htmldir " -iname " *.html" | sed -e " s/$tmpdirsed //;s/.*/ <li><a href=\" .\/&\" >&<\/a><\/li>/;" >> " $tmpdir / $htmldir /index.html"
75+ find " $tmpdir / $htmldir " -iname " *.htm" | sed -e " s/$tmpdirsed //;s/.*/ <li><a href=\" .\/&\" >&<\/a><\/li>/;" >> " $tmpdir / $htmldir /index.html"
76+ cat >> " $tmpdir /$htmldir / index.html" << EOF
8077 </ol>
8178</body>
8279</html>
8380EOF
84- sed -i -e ' /<li><a href=".\/index.html">index.html<\/a><\/li>/d' " $tmpdir /index.html"
85- tar cz -C " $tmpdir " -f " $warfile " .
81+ sed -i -e ' /<li><a href=".\/index.html">index.html<\/a><\/li>/d' " $tmpdir /$htmldir / index.html"
82+ tar cz -C " $tmpdir / $htmldir " -f " $warfile " .
8683fi
8784rm -rf " $tmpdir "
0 commit comments