tazpanel view stripall.sh @ rev 525

Add "noheader" flag to get page without header/footer/panel "wrappers" (for pop-ups); strip, minify and gzip scripts and styles.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Aug 20 17:00:19 2015 +0300 (2015-08-20)
parents
children 4f619f973b88
line source
1 #!/bin/sh
2 # TazPanel - SliTaz Control Panel, hg.slitaz.org/tazpanel
3 # stripall.sh - strip and compact resources in build process
4 # Copyright (C) 2015 SliTaz GNU/Linux - BSD License
7 substitute_icons() {
8 grep -q 'data-icon="\|data-img"' $1 || return
10 echo -e "\
11 add  \n admin  \n back  \n battery 
12 brightness  \n cancel  \n cd  \n check 
13 clock  \n conf  \n daemons  \n delete 
14 detect  \n diff  \n download  \n edit 
15 eth  \n group  \n grub  \n hdd 
16 help  \n history  \n info  \n install 
17 link  \n list  \n locale  \n lock 
18 logs  \n loopback  \n modules  \n ok 
19 proc  \n refresh  \n removable  \n remove 
20 repack  \n report  \n restart  \n run 
21 save  \n scan  \n settings  \n start 
22 stop  \n sync  \n tag  \n tags 
23 tazx  \n temperature  \n terminal  \n text 
24 unlink  \n unlock  \n upgrade  \n user 
25 view  \n wifi  \n man  \n off 
26 on  \n opt  \n web  \n slitaz 
27 lvl0  \n lvl1  \n lvl2  \n lvl3 
28 lvl4  \n lvl5  \n online  \n offline 
29 sechi  \n secmi  \n seclo  \n pkg 
30 pkgi  \n pkgib  \n toggle  \n chlock 
31 calendar  \n modem  \n cpu  \n display 
32 msg  \n msgerr  \n msgwarn  \n msgup 
33 msgtip  \n vpn " | \
34 while read icon symbol; do
35 echo -n "."
36 sed -i "s|data-icon=\"$icon\"|data-icon=\"$symbol\"|g" $1
37 sed -i "s|data-img=\"$icon\"|data-img=\"$symbol\"|g" $1
38 done
39 }
42 cd build
44 echo -e "\nStrip shell scripts"
45 for CGI in *.cgi tazpanel libtazpanel bootloader *.html; do
46 echo -en "\nProcessing $CGI"
48 mv $CGI $CGI.old
49 # Copy initial comment (down to empty line)
50 sed '1,/^$/!d' $CGI.old > $CGI
51 # Remove initial tabs, other comments and empty lines
52 sed 's|^[\t ]*||;/^#/d;/^$/d' $CGI.old >> $CGI
53 rm $CGI.old
55 substitute_icons $CGI
57 sed -i 's|" *>|">|g' $CGI
58 sed -i "s|' *)|')|g" $CGI
59 sed -i 's| *;;|;;|g' $CGI
61 chmod a+x $CGI
63 done
66 echo -e "\n\nStrip CSS stylesheets"
67 for CSS in *.css; do
68 echo -en "\nProcessing $CSS"
70 mv $CSS $CSS.old
71 tr '\n' ' ' < $CSS.old > $CSS
72 rm $CSS.old
74 substitute_icons $CSS
76 sed -i 's|\t| |g; s| *| |g; s|/\*|‹|g; s|\*/|›|g; s|‹[^›][^›]*›||g; s| *| |g; s|^ ||; s| {|{|g; s|{ |{|g; s| *: *|:|g; s| *; *|;|g; s|;}|}|g; s|} |}|g; s| *> *|>|g; s| *, *|,|g; s|000000|000|g; s|CC0000|C00|g; s|00FFFF|0FF|g' $CSS
77 done
79 mkdir gz
80 cat *.css > gz/tazpanel.css
81 gzip -9 gz/tazpanel.css
84 echo -e "\n\nStrip JS scripts"
85 for JS in *.js; do
86 echo -en "\nProcessing $JS"
88 sed -i 's|^[\t ]*||; /^$/d; /^\/\//d; /console\./d' $JS
90 # Try "jsmin"
91 if [ -n "$(which jsmin)" ]; then
92 jsmin < $JS > $JS.new
93 mv -f $JS.new $JS
94 fi
95 done
97 cat *.js > gz/tazpanel.js
98 gzip -9 gz/tazpanel.js
100 echo