diff --git a/DEPENDS b/DEPENDS new file mode 100644 index 0000000..4ddf0f6 --- /dev/null +++ b/DEPENDS @@ -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 diff --git a/README.md b/README.md index aa12c0a..b2969f2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..2cf58d9 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.20171227 diff --git a/etc/htmlz-bash.conf b/etc/htmlz-bash.conf new file mode 100644 index 0000000..4be5aa3 --- /dev/null +++ b/etc/htmlz-bash.conf @@ -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' diff --git a/usr/bin/htmlz-browse b/usr/bin/htmlz-browse new file mode 100644 index 0000000..10f4d3a --- /dev/null +++ b/usr/bin/htmlz-browse @@ -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" diff --git a/usr/bin/htmlz-create b/usr/bin/htmlz-create new file mode 100644 index 0000000..44c747b --- /dev/null +++ b/usr/bin/htmlz-create @@ -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" < + + + + $htmldir + + +

$htmldir

+
    +EOF + find . -iname "*.html" -o -iname "*.htm" | sort | sed -e "s/.*/
  1. &<\/a><\/li>/;" >> "index.html" + cat >> "index.html" < + + +EOF + sed -i -e '/
  2. .\/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" diff --git a/usr/bin/htmlz-unpack b/usr/bin/htmlz-unpack new file mode 100644 index 0000000..82e4505 --- /dev/null +++ b/usr/bin/htmlz-unpack @@ -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" diff --git a/usr/bin/htmlz-wget b/usr/bin/htmlz-wget new file mode 100644 index 0000000..2fac10e --- /dev/null +++ b/usr/bin/htmlz-wget @@ -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" < + + + + + $htmldir + + +

    $htmldir

    +
      +EOF + find . -iname "*.html" -o -iname "*.htm" | sort | sed -e "s/.*/
    1. &<\/a><\/li>/;" >> "index.html" + cat >> "index.html" < + + +EOF + sed -i -e '/
    2. .\/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" diff --git a/usr/share/doc/htmlz-bash/AUTORS b/usr/share/doc/htmlz-bash/AUTORS new file mode 100644 index 0000000..7d2a914 --- /dev/null +++ b/usr/share/doc/htmlz-bash/AUTORS @@ -0,0 +1,2 @@ +zvezdochiot +https://github.com/zvezdochiot/htmlz-bash diff --git a/usr/share/doc/htmlz-bash/DEPENDS b/usr/share/doc/htmlz-bash/DEPENDS new file mode 100644 index 0000000..4ddf0f6 --- /dev/null +++ b/usr/share/doc/htmlz-bash/DEPENDS @@ -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 diff --git a/usr/share/doc/htmlz-bash/README.md b/usr/share/doc/htmlz-bash/README.md new file mode 100644 index 0000000..b2969f2 --- /dev/null +++ b/usr/share/doc/htmlz-bash/README.md @@ -0,0 +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 diff --git a/usr/share/doc/htmlz-bash/VERSION b/usr/share/doc/htmlz-bash/VERSION new file mode 100644 index 0000000..2cf58d9 --- /dev/null +++ b/usr/share/doc/htmlz-bash/VERSION @@ -0,0 +1 @@ +0.20171227 diff --git a/usr/share/doc/htmlz-bash/sample/sys-bash.htmlz b/usr/share/doc/htmlz-bash/sample/sys-bash.htmlz new file mode 100644 index 0000000..464e49e Binary files /dev/null and b/usr/share/doc/htmlz-bash/sample/sys-bash.htmlz differ diff --git a/usr/share/man/man1/htmlz-bash.1 b/usr/share/man/man1/htmlz-bash.1 new file mode 100644 index 0000000..b85b642 --- /dev/null +++ b/usr/share/man/man1/htmlz-bash.1 @@ -0,0 +1,59 @@ +.TH htmlz-bash 1 "27 Dec 2017" "0.20171223" "User Manual" +.SH NAME +\fBhtmlz-browse\fP +.SH DESCRIPTION +HTMLZ file (ZIP WEB archive) viewer in browser. +.SH USAGE +htmlz-browse [options] file.htmlz +.SH OPTIONS +.TP +\fB-b\fP 'str' +use browser (default = 'x-www-browser'); +.TP +\fB-h\fP +display help and exit +.SH NAME +\fBhtmlz-create\fP +.SH DESCRIPTION +HTMLZ file (ZIP WEB archive) creator. +.SH USAGE +htmlz-create [options] /path/to/html/dir [file.htmlz] +.SH OPTIONS +.TP +\fB-h\fP +display help and exit +.SH NAME +\fBhtmlz-unpack\fP +.SH DESCRIPTION +HTMLZ file (ZIP WEB archive) unpack. +.SH USAGE +htmlz-unpack [options] file.htmlz +.SH OPTIONS +.TP +\fB-h\fP +display help and exit +.SH NAME +\fBhtmlz-wget\fP +.SH DESCRIPTION +HTMLZ file (ZIP WEB archive) wget page. +.SH USAGE +htmlz-wget [options] name url/to/html/page +.SH OPTIONS +.TP +\fB-c\fP +clean LIST (sample 'js,php,eot,wott,ttf', default = '') +.TP +\fB-r\fP +reject LIST (sample 'js,php,eot,wott,ttf', default = '') +.TP +\fB-h\fP +display help and exit +.SH CONFIG FILE + /etc/htmlz-bash.conf + ~/config/htmlz-bash.conf +.SH COPYRIGHT + Copyright (c) 2017 zvezdochiot +.SH SEE ALSO + war-create(1). +.SH CONTACTS + Homepage: https://github.com/zvezdochiot/htmlz-bash