tazpanel annotate stripall.sh @ rev 538
Speed-up interface: cache xhtml header; need to use 'tazpanel cc' to clean cache when TazPanel menu changes (in post-install and post-remove functions for TazPanel modules)
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sun Aug 30 23:46:37 2015 +0300 (2015-08-30) |
parents | 5323427d34b9 |
children | 694b20d6963c |
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@526 | 10 # Customize sed script |
al@526 | 11 cp "$sed_script" "$sed_script.do" |
al@526 | 12 sed -i "s|@@@|$1|" "$sed_script.do" |
al@526 | 13 # Run sed script |
al@526 | 14 sh "$sed_script.do" |
al@526 | 15 rm "$sed_script.do" |
al@526 | 16 } |
al@526 | 17 |
al@526 | 18 |
al@526 | 19 # Make script for substitution |
al@526 | 20 sed_script="$(mktemp)" |
al@526 | 21 echo -n "sed -i '" > "$sed_script" |
al@525 | 22 echo -e "\ |
al@525 | 23 add \n admin \n back \n battery |
al@525 | 24 brightness \n cancel \n cd \n check |
al@525 | 25 clock \n conf \n daemons \n delete |
al@525 | 26 detect \n diff \n download \n edit |
al@525 | 27 eth \n group \n grub \n hdd |
al@525 | 28 help \n history \n info \n install |
al@525 | 29 link \n list \n locale \n lock |
al@525 | 30 logs \n loopback \n modules \n ok |
al@525 | 31 proc \n refresh \n removable \n remove |
al@525 | 32 repack \n report \n restart \n run |
al@525 | 33 save \n scan \n settings \n start |
al@525 | 34 stop \n sync \n tag \n tags |
al@525 | 35 tazx \n temperature \n terminal \n text |
al@525 | 36 unlink \n unlock \n upgrade \n user |
al@525 | 37 view \n wifi \n man \n off |
al@525 | 38 on \n opt \n web \n slitaz |
al@525 | 39 lvl0 \n lvl1 \n lvl2 \n lvl3 |
al@525 | 40 lvl4 \n lvl5 \n online \n offline |
al@525 | 41 sechi \n secmi \n seclo \n pkg |
al@525 | 42 pkgi \n pkgib \n toggle \n chlock |
al@525 | 43 calendar \n modem \n cpu \n display |
al@525 | 44 msg \n msgerr \n msgwarn \n msgup |
al@525 | 45 msgtip \n vpn " | \ |
al@525 | 46 while read icon symbol; do |
al@526 | 47 echo -n "s|data-icon=\"$icon\"|data-icon=\"$symbol\"|g; " >> "$sed_script" |
al@526 | 48 echo -n "s|data-img=\"$icon\"|data-img=\"$symbol\"|g; " >> "$sed_script" |
al@525 | 49 done |
al@526 | 50 echo "' @@@" >> "$sed_script" |
al@525 | 51 |
al@525 | 52 |
al@525 | 53 cd build |
al@525 | 54 |
al@525 | 55 echo -e "\nStrip shell scripts" |
al@525 | 56 for CGI in *.cgi tazpanel libtazpanel bootloader *.html; do |
al@526 | 57 echo "Processing $CGI" |
al@525 | 58 |
al@525 | 59 mv $CGI $CGI.old |
al@525 | 60 # Copy initial comment (down to empty line) |
al@525 | 61 sed '1,/^$/!d' $CGI.old > $CGI |
al@525 | 62 # Remove initial tabs, other comments and empty lines |
al@525 | 63 sed 's|^[\t ]*||;/^#/d;/^$/d' $CGI.old >> $CGI |
al@525 | 64 rm $CGI.old |
al@525 | 65 |
al@525 | 66 substitute_icons $CGI |
al@525 | 67 |
al@525 | 68 sed -i 's|" *>|">|g' $CGI |
al@525 | 69 sed -i "s|' *)|')|g" $CGI |
al@525 | 70 sed -i 's| *;;|;;|g' $CGI |
al@525 | 71 |
al@525 | 72 chmod a+x $CGI |
al@525 | 73 |
al@525 | 74 done |
al@525 | 75 |
al@525 | 76 |
al@525 | 77 echo -e "\n\nStrip CSS stylesheets" |
al@525 | 78 for CSS in *.css; do |
al@526 | 79 echo "Processing $CSS" |
al@525 | 80 |
al@525 | 81 mv $CSS $CSS.old |
al@525 | 82 tr '\n' ' ' < $CSS.old > $CSS |
al@525 | 83 rm $CSS.old |
al@525 | 84 |
al@525 | 85 substitute_icons $CSS |
al@525 | 86 |
al@525 | 87 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 | 88 done |
al@525 | 89 |
al@525 | 90 mkdir gz |
al@525 | 91 cat *.css > gz/tazpanel.css |
al@525 | 92 gzip -9 gz/tazpanel.css |
al@525 | 93 |
al@525 | 94 |
al@525 | 95 echo -e "\n\nStrip JS scripts" |
al@525 | 96 for JS in *.js; do |
al@525 | 97 echo -en "\nProcessing $JS" |
al@525 | 98 |
al@525 | 99 sed -i 's|^[\t ]*||; /^$/d; /^\/\//d; /console\./d' $JS |
al@525 | 100 |
al@525 | 101 # Try "jsmin" |
al@525 | 102 if [ -n "$(which jsmin)" ]; then |
al@525 | 103 jsmin < $JS > $JS.new |
al@525 | 104 mv -f $JS.new $JS |
al@525 | 105 fi |
al@525 | 106 done |
al@525 | 107 |
al@525 | 108 cat *.js > gz/tazpanel.js |
al@525 | 109 gzip -9 gz/tazpanel.js |
al@525 | 110 |
al@526 | 111 rm "$sed_script" |
al@525 | 112 echo |