Skip to content

Commit

Permalink
0.20171227
Browse files Browse the repository at this point in the history
Init version
  • Loading branch information
zvezdochiot authored and mykaralw committed Dec 27, 2017
1 parent e5cd124 commit f0253d7
Show file tree
Hide file tree
Showing 14 changed files with 463 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DEPENDS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
htmlz-bash
Version: 0.20171227
Description: HTMLZ (ZIP web archive) create and browse in bash
Depends: bash, 7z, sed, grep, findutils, coreutils, wget
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# htmlz-bash
Version 0.20171227

HTMLZ file (ZIP WEB archive) create and browse in bash.

Utils:

htmlz-browse
HTMLZ file (ZIP WEB archive) viewer in browser.

USAGE: htmlz-browse [options] file.htmlz
OPTIONS:
-b use browser (default = 'x-www-browser');
-h display help and exit

htmlz-create
HTMLZ file (ZIP WEB archive) creator.

USAGE: htmlz-create [options] /path/to/html/dir [file.htmlz]
OPTIONS:
-h display help and exit

htmlz-unpack
HTMLZ file (ZIP WEB archive) unpack.

USAGE: htmlz-unpack [options] file.htmz
OPTIONS:
-h display help and exit

htmlz-wget
HTMLZ file (ZIP WEB archive) wget page.

USAGE: htmlz-wget [options] name url/to/html/page
OPTIONS:
-c clean LIST (sample 'js,php,eot,wott,ttf', default = '')
-r reject LIST (sample 'js,php,eot,wott,ttf', default = '')
-h display help and exit

COPYRIGHT:
Copyright (c) 2017 zvezdochiot

CONTACTS:
Homepage: https://github.com/zvezdochiot/htmlz-bash
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.20171227
10 changes: 10 additions & 0 deletions etc/htmlz-bash.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# tmp dir
# WARNING! Do not use "%" in the path
#tmpdir="/tmp/htmlz"
tmpdir="/tmp/htmlz"
# browser
#browser="x-www-browser"
browser="x-www-browser"
# clean and reject options
#cleanlist='js,php,eot,wott,ttf'
#rejectlist='js,php,eot,wott,ttf'
51 changes: 51 additions & 0 deletions usr/bin/htmlz-browse
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

tmpdir="/tmp/htmlz"
browser="x-www-browser"
[ -f /etc/htmlz-bash.conf ] && source /etc/htmlz-bash.conf
[ -f ~/config/htmlz-bash.conf ] && source ~/config/htmlz-bash.conf
user="$(whoami)"
tmpdir="${tmpdir}_${user}"

function usage()
{
echo "HTMLZ file (ZIP WEB archive) viewer in browser."
echo
echo "USAGE: $0 [options] file.htmlz"
echo "options:"
echo " -b 'str' use browser (default = 'x-www-browser');"
echo " -h help."
echo
exit 1
}
if [ $# = 0 ]
then
usage
fi

while getopts ":b:h" opt
do
case $opt in
b) browser="$OPTARG"
;;
h) usage
;;
*) echo "Unknown option -$OPTARG"
exit 1
;;
esac
done
shift "$(($OPTIND - 1))"
htmlzfile="$1"
if [ -z "$htmlzfile" ]
then
usage
fi

rm -rf "$tmpdir"
mkdir -p "$tmpdir/$htmlzfile"
7z x "$htmlzfile" -o"$tmpdir/$htmlzfile"

$browser "$tmpdir/$htmlzfile/index.html"

rm -rf "$tmpdir"
88 changes: 88 additions & 0 deletions usr/bin/htmlz-create
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

tmpdir="/tmp/htmlz"
browser="x-www-browser"
[ -f /etc/htmlz-bash.conf ] && source /etc/htmlz-bash.conf
[ -f ~/config/htmlz-bash.conf ] && source ~/config/htmlz-bash.conf
user="$(whoami)"
tmpdir="${tmpdir}_${user}"

function usage()
{
echo "HTMLZ file (ZIP WEB archive) creator."
echo
echo "USAGE: $0 [options] /path/to/html/dir [file.htmlz]"
echo "options:"
echo " -h help."
echo
exit 1
}
if [ $# = 0 ]
then
usage
fi

while getopts ":h" opt
do
case $opt in
h) usage
;;
*) echo "Unknown option -$OPTARG"
exit 1
;;
esac
done
shift "$(($OPTIND - 1))"
htmldir="$1"
if [ ! -d "$htmldir" ]
then
usage
fi
htmlzfile="$2"
if [ -z "$htmlzfile" ]
then
htmlzfile="$(basename $htmldir).htmlz"
fi

rm -rf "$tmpdir"
mkdir -p "$tmpdir"
cp -frv "$htmldir" "$tmpdir"

function index_gen()
{
td="$1"
if [ -d "$td" ]
then
cd "$td"
cat > "index.html" <<EOF
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>$htmldir</title>
</head>
<body>
<h1>$htmldir</h1>
<ol>
EOF
find . -iname "*.html" -o -iname "*.htm" | sort | sed -e "s/.*/ <li><a href=\"&\">&<\/a><\/li>/;" >> "index.html"
cat >> "index.html" <<EOF
</ol>
</body>
</html>
EOF
sed -i -e '/<li><a href=".\/index.html">.\/index.html<\/a><\/li>/d' "index.html"
cd -
fi
}

if [ ! -f "$tmpdir/$htmldir/index.html" ]
then
index_gen "$tmpdir/$htmldir"
fi

cd "$tmpdir/$htmldir"
7z a "$htmlzfile" -tzip .
cd -
mv "$tmpdir/$htmldir/$htmlzfile" "$htmlzfile"
rm -rf "$tmpdir"
48 changes: 48 additions & 0 deletions usr/bin/htmlz-unpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

tmpdir="/tmp/htmlz"
browser="x-www-browser"
[ -f /etc/htmlz-bash.conf ] && source /etc/htmlz-bash.conf
[ -f ~/config/htmlz-bash.conf ] && source ~/config/htmlz-bash.conf
user="$(whoami)"
tmpdir="${tmpdir}_${user}"

function usage()
{
echo "HTMLZ file (ZIP WEB archive) unpack."
echo
echo "USAGE: $0 [options] file.htmlz"
echo "options:"
echo " -h help."
echo
exit 1
}
if [ $# = 0 ]
then
usage
fi

while getopts ":h" opt
do
case $opt in
h) usage
;;
*) echo "Unknown option -$OPTARG"
exit 1
;;
esac
done
shift "$(($OPTIND - 1))"
htmlzfile="$1"
if [ -z "$htmlzfile" ]
then
usage
fi

upkdir="${htmlzfile%.*}"
if [ "$upkdir" = "$htmlzfile" ]
then
upkdir="${htmlzfile}$$"
fi
mkdir -p "$upkdir"
7z x "$htmlzfile" -o"$upkdir"
111 changes: 111 additions & 0 deletions usr/bin/htmlz-wget
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash

tmpdir="/tmp/htmlz"
browser="x-www-browser"
[ -f /etc/htmlz-bash.conf ] && source /etc/htmlz-bash.conf
[ -f ~/config/htmlz-bash.conf ] && source ~/config/htmlz-bash.conf
user="$(whoami)"
tmpdir="${tmpdir}_${user}"

function usage()
{
echo "HTMLZ file (ZIP WEB archive) wget page."
echo
echo "USAGE: $0 [options] name url/to/html/page"
echo "options:"
echo " -c clean LIST (sample 'js,php,eot,wott,ttf', default = '')"
echo " -r reject LIST (sample 'js,php,eot,wott,ttf', default = '')"
echo " -h help."
echo
exit 1
}
if [ $# = 0 ]
then
usage
fi

while getopts ":c:r:h" opt
do
case $opt in
c) cleanlist="$OPTARG"
;;
r) rejectlist="$OPTARG"
;;
h) usage
;;
*) echo "Unknown option -$OPTARG"
exit 1
;;
esac
done
shift "$(($OPTIND - 1))"
htmldir="$1"
if [ -z "$htmldir" ]
then
usage
fi
htmlurl="$2"
if [ -z "$htmlurl" ]
then
usage
fi
if [ -z "$htmlzfile" ]
then
htmlzfile="$htmldir.htmlz"
fi

rm -rf "$tmpdir"
mkdir -p "$tmpdir/$htmldir"

if [ -z "$rejectlist" ]
then
wget -c -t0 -p -k -E -P "$tmpdir/$htmldir" "$htmlurl"
else
wget -c -t0 -p -k -E -R "$rejectlist" -P "$tmpdir/$htmldir" "$htmlurl"
fi

function index_gen()
{
td="$1"
if [ -d "$td" ]
then
cd "$td"
cat > "index.html" <<EOF
<!DOCTYPE html>
<!-- Source is http://www.warmplace.ru/ -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>$htmldir</title>
</head>
<body>
<h1>$htmldir</h1>
<ol>
EOF
find . -iname "*.html" -o -iname "*.htm" | sort | sed -e "s/.*/ <li><a href=\"&\">&<\/a><\/li>/;" >> "index.html"
cat >> "index.html" <<EOF
</ol>
</body>
</html>
EOF
sed -i -e '/<li><a href=".\/index.html">.\/index.html<\/a><\/li>/d' "index.html"
cd -
fi
}

if [ ! -f "$tmpdir/$htmldir/index.html" ]
then
index_gen "$tmpdir/$htmldir"
fi

cleanopt=$(echo "$cleanlist" | sed "s/\,/|/g")
if [ ! -z "$cleanopt" ]
then
find "$tmpdir" -type f -regextype posix-egrep -regex '.*\.('$cleanopt')$' | xargs rm -v
find "$tmpdir" -type f -regextype posix-egrep -regex '.*\.('$cleanopt')\?.*$' | xargs rm -v
fi
cd "$tmpdir/$htmldir"
7z a "$htmlzfile" -tzip
cd -
mv "$tmpdir/$htmldir/$htmlzfile" "$htmlzfile"
rm -rf "$tmpdir"
2 changes: 2 additions & 0 deletions usr/share/doc/htmlz-bash/AUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zvezdochiot <zvezdochiot@github.com>
https://github.com/zvezdochiot/htmlz-bash
4 changes: 4 additions & 0 deletions usr/share/doc/htmlz-bash/DEPENDS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
htmlz-bash
Version: 0.20171227
Description: HTMLZ (ZIP web archive) create and browse in bash
Depends: bash, 7z, sed, grep, findutils, coreutils, wget
Loading

0 comments on commit f0253d7

Please sign in to comment.