11#! /bin/bash
22# clean-html-js.sh
33
4- VER=" 1.3"
5- GREEN=" \033[1;32m"
6- RED=" \033[0;31m"
7- YELLOW=" \033[1;33m"
8- ENDCOLOR=" \033[0m"
4+ VER=" 1.4"
95
106tproc=` basename $0 `
11- echo -e $GREEN " $tproc version $VER " $ENDCOLOR
7+ echo -e " $tproc version $VER "
128echo " "
139
1410usage ()
1511{
1612 tproc=` basename $0 `
17- echo -e $YELLOW " usage:" $ENDCOLOR
18- echo -e $GREEN " bash $tproc input.html" $ENDCOLOR
13+ echo -e " usage:"
14+ echo -e " bash $tproc input.html"
1915 echo " options:"
20- echo " -c not clean comment (default = false);"
16+ echo " -c clean comment (default = false);"
17+ echo " -i iconvert (default = false);"
2118 echo " -n not verify type file (default = false);"
2219 echo " -o str output path (default = input.utf8.html);"
2320 echo " -r rewrite file (default = false);"
@@ -29,45 +26,30 @@ usage()
2926testcomponent ()
3027{
3128 tnocomp=" "
32- tcomp=" /usr/bin/iconv"
33- tdeb=" libc-bin_*.deb"
34- if [ ! -f " $tcomp " ]
29+ tcomp=" iconv"
30+ [ ! " $( command -v $tcomp ) " ] && tnocomp=" $tnocomp $tcomp "
31+ tcomp=" enca"
32+ [ ! " $( command -v $tcomp ) " ] && tnocomp=" $tnocomp $tcomp "
33+ tcomp=" sed"
34+ [ ! " $( command -v $tcomp ) " ] && tnocomp=" $tnocomp $tcomp "
35+ tcomp=" grep"
36+ [ ! " $( command -v $tcomp ) " ] && tnocomp=" $tnocomp $tcomp "
37+ if [ " x$tnocomp " != " x" ]
3538 then
36- tnocomp=" $tnocomp $tcomp ($tdeb )"
37- fi
38- tcomp=" /usr/bin/enca"
39- tdeb=" enca_*.deb"
40- if [ ! -f " $tcomp " ]
41- then
42- tnocomp=" $tnocomp $tcomp ($tdeb )"
43- fi
44- tcomp=" /bin/sed"
45- tdeb=" sed_*.deb"
46- if [ ! -f " $tcomp " ]
47- then
48- tnocomp=" $tnocomp $tcomp ($tdeb )"
49- fi
50- tcomp=" /bin/grep"
51- tdeb=" grep_*.deb"
52- if [ ! -f " $tcomp " ]
53- then
54- tnocomp=" $tnocomp $tcomp ($tdeb )"
55- fi
56- if [ " +$tnocomp " != " +" ]
57- then
58- echo -e $RED " Not found $tnocomp !" $ENDCOLOR
59- echo " "
60- exit 0
39+ echo " Not found:${tnocomp} !"
40+ exit 1
6141 fi
6242}
6343
6444main ()
6545{
66- while getopts " :cno :rh" opt
46+ while getopts " :cino :rh" opt
6747do
6848 case $opt in
6949 c) tcomment=" 1"
7050 ;;
51+ i) ticonv=" 1"
52+ ;;
7153 n) tnoverify=" 1"
7254 ;;
7355 o) tdest=" $OPTARG "
@@ -87,8 +69,6 @@ if [ -z "$SRCNAME" ]
8769then
8870 usage
8971fi
90- echo " $src "
91- echo " "
9272if [ -z " $tnoverify " ]
9373then
9474 thtml=` file " $SRCNAME " | grep " HTML document" `
@@ -101,15 +81,20 @@ then
10181 NEWNAME=" $NEWNAME .utf8.html"
10282 echo " $SRCNAME -> $NEWNAME "
10383
104- CODENAME=$( /usr/bin/enca -i " $SRCNAME " )
105- if [ " +$CODENAME " = " +" -o " +$CODENAME " = " +???" ]
106- then
107- CODENAME=" UTF-8"
108- elif [ " +$CODENAME " != " +UTF-8" ]
84+ if [ -z " $ticonv " ]
10985 then
110- echo " Convert: $CODENAME -> UTF8"
86+ cat " $SRCNAME " > " $NEWNAME "
87+ else
88+ CODENAME=$( enca -i " $SRCNAME " )
89+ if [ " +$CODENAME " = " +" -o " +$CODENAME " = " +???" ]
90+ then
91+ CODENAME=" UTF-8"
92+ elif [ " +$CODENAME " != " +UTF-8" ]
93+ then
94+ echo " Convert: $CODENAME -> UTF8"
95+ fi
96+ cat " $SRCNAME " | iconv -c -f ${CODENAME} -t UTF8 > " $NEWNAME "
11197 fi
112- cat " $SRCNAME " | iconv -c -f ${CODENAME} -t UTF8 > " $NEWNAME "
11398
11499echo -e -n " [4]: 0.."
115100
@@ -154,7 +139,7 @@ echo -e -n "2.."
154139
155140echo -e -n " 3.."
156141
157- if [ -z " $tcomment " ]
142+ if [ ! -z " $tcomment " ]
158143 then
159144 sed -i -e '
160145 /^<\!--/,/^-->/d
@@ -163,11 +148,14 @@ echo -e -n "3.."
163148
164149echo -e -n " 4.."
165150
166- sed -i -e '
167- s/content="text\/html; charset=.*">/content="text\/html; charset=utf-8">/ig
168- s/[ \t]*$//
169- /^$/d
170- ' " $NEWNAME "
151+ if [ ! -z " $ticonv " ]
152+ then
153+ sed -i -e '
154+ s/content="text\/html; charset=.*">/content="text\/html; charset=utf-8">/ig
155+ s/[ \t]*$//
156+ /^$/d
157+ ' " $NEWNAME "
158+ fi
171159
172160flgpre=` grep -i " <pre" " $NEWNAME " `
173161if [ " +$flgpre " = " +" ]
0 commit comments