Skip to content

Commit 9cc6826

Browse files
zvezdochiotmykaralw
authored andcommitted
0.20171221
Init version
1 parent 7e0cfa0 commit 9cc6826

File tree

6 files changed

+201
-0
lines changed

6 files changed

+201
-0
lines changed

DEPENDS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
war-bash
2+
Version: 0.20171221
3+
Description: WAR (KDE web archive) create and browse in bash
4+
Depends: bash, tar, gzip, sed, grep, findutils, coreutils

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
# war-bash
2+
Version 0.20171221
3+
24
WAR file (KDE WEB archive) create and browse in bash.
5+
6+
Utils:
7+
8+
war-browse
9+
WAR file (KDE WEB archive) viewer in browser.
10+
11+
USAGE: war-browse [options] file.war
12+
OPTIONS:
13+
-b use browser (default = 'x-www-browser');
14+
-h display help and exit
15+
16+
war-create
17+
WAR file (KDE WEB archive) creator.
18+
19+
USAGE: war-create [options] /path/to/html file.war
20+
OPTIONS:
21+
-i using exist index.html
22+
-h display help and exit
23+
24+
25+
COPYRIGHT:
26+
Copyright (c) 2017 zvezdochiot
27+
28+
CONTACTS:
29+
Homepage: https://github.com/zvezdochiot/war-bash

sample/sys-bash.war

398 KB
Binary file not shown.

war-bash.1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.TH war-bash 1 "21 Dec 2017" "0.20171221" "User Manual"
2+
.SH NAME
3+
war-browse
4+
.SH DESCRIPTION
5+
WAR file (KDE WEB archive) viewer in browser.
6+
.SH USAGE
7+
war-browse [options] file.war
8+
.SH OPTIONS
9+
.TP
10+
\fB-b\fP 'str'
11+
use browser (default = 'x-www-browser');
12+
.TP
13+
\fB-h\fP
14+
display help and exit
15+
.SH NAME
16+
war-create
17+
.SH DESCRIPTION
18+
WAR file (KDE WEB archive) creator.
19+
.SH USAGE
20+
war-create [options] /path/to/html file.war
21+
.SH OPTIONS
22+
.TP
23+
\fB-i\fP
24+
using exist index.html.
25+
.TP
26+
\fB-h\fP
27+
display help and exit
28+
.SH COPYRIGHT
29+
Copyright (c) 2017 zvezdochiot
30+
.SH SEE ALSO
31+
war-create(1).
32+
.SH CONTACTS
33+
Homepage: https://github.com/zvezdochiot/war-bash

war-browse

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
user="$(whoami)"
4+
tmpdir="/tmp/war_$user"
5+
browser="x-www-browser"
6+
7+
function usage()
8+
{
9+
echo "WAR file (KDE WEB archive) viewer in browser."
10+
echo
11+
echo "USAGE: $0 [options] file.war"
12+
echo "options:"
13+
echo " -b 'str' use browser (default = 'x-www-browser');"
14+
echo " -h help."
15+
echo
16+
exit 1
17+
}
18+
if [ $# = 0 ]
19+
then
20+
usage
21+
fi
22+
23+
browser="x-www-browser"
24+
25+
while getopts ":b:h" opt
26+
do
27+
case $opt in
28+
b) browser="$OPTARG"
29+
;;
30+
h) usage
31+
;;
32+
*) echo "Unknown option -$OPTARG"
33+
exit 1
34+
;;
35+
esac
36+
done
37+
shift "$(($OPTIND - 1))"
38+
warfile="$1"
39+
if [ -z "$warfile" ]
40+
then
41+
usage
42+
fi
43+
44+
rm -rf "$tmpdir"
45+
mkdir -p "$tmpdir"
46+
tar xz -C "$tmpdir" -f "$warfile"
47+
48+
$browser "$tmpdir/index.html"
49+
50+
rm -rf "$tmpdir"

war-create

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
user="$(whoami)"
4+
tmpdir="/tmp/war_$user"
5+
tmpdirsed="\/tmp\/war_$user\/"
6+
7+
function usage()
8+
{
9+
echo "WAR file (KDE WEB archive) creator."
10+
echo
11+
echo "USAGE: $0 [options] /path/to/html file.war"
12+
echo "options:"
13+
echo " -i using exist index.html."
14+
echo " -h help."
15+
echo
16+
exit 1
17+
}
18+
if [ $# = 0 ]
19+
then
20+
usage
21+
fi
22+
23+
indexuse="false"
24+
25+
while getopts ":ih" opt
26+
do
27+
case $opt in
28+
i) indexuse="true"
29+
;;
30+
h) usage
31+
;;
32+
*) echo "Unknown option -$OPTARG"
33+
exit 1
34+
;;
35+
esac
36+
done
37+
shift "$(($OPTIND - 1))"
38+
htmldir="$1"
39+
if [ ! -d "$htmldir" ]
40+
then
41+
usage
42+
fi
43+
warfile="$2"
44+
if [ -z "$warfile" ]
45+
then
46+
warfile="$htmldir.war"
47+
fi
48+
49+
if [ $indexuse = "true" ]
50+
then
51+
if [ ! -f "$htmldir/index.html" ]
52+
then
53+
indexuse="false"
54+
fi
55+
fi
56+
57+
rm -rf "$tmpdir"
58+
mkdir -p "$tmpdir"
59+
cp -frv "$htmldir" "$tmpdir"
60+
61+
if [ $indexuse = "true" ]
62+
then
63+
tar cz -C "$tmpdir/$htmldir" -f "$warfile" .
64+
else
65+
cat > "$tmpdir/index.html" <<EOF
66+
<!DOCTYPE html>
67+
<!-- Source is http://www.warmplace.ru/ -->
68+
<html>
69+
<head>
70+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
71+
<title>$htmldir</title>
72+
</head>
73+
<body>
74+
<h1>$htmldir</h1>
75+
<ol>
76+
EOF
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
80+
</ol>
81+
</body>
82+
</html>
83+
EOF
84+
sed -i -e '/<li><a href=".\/index.html">index.html<\/a><\/li>/d' "$tmpdir/index.html"
85+
tar cz -C "$tmpdir" -f "$warfile" .
86+
fi
87+
rm -rf "$tmpdir"

0 commit comments

Comments
 (0)