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