Advertisement
rs232

TTB v2.05

Oct 16th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.43 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # v1.00 Shibby 2013
  4. # v1.01 Fix memory leak + cosmetics - pedro 2019
  5. # v2.05 [Command line operation, custom URL, local storage] + GUI integration added - rs232 2019
  6.  
  7. PID=$$
  8. LOCK="/tmp/ttb.lock"
  9. DIR="/www/ext"
  10. LOGS="logger -s -t TTB[$PID]"
  11. SUBDIR="TomatoThemeBase"
  12. URL_ORIG="http://www.tomatothemebase.eu/wp-content/uploads"
  13.  
  14.  
  15. ttbexit() {
  16.         rm $LOCK >/dev/null 2>&1
  17.         exit $1
  18. }
  19.  
  20. ttbdownload() {
  21.         ls -l /www/ext/ | grep "\->" | cut -d" " -f 27 | while read file; do
  22.                 rm $DIR/$file  >/dev/null 2>&1
  23.         done
  24.         rm $DIR2/*  >/dev/null 2>&1
  25.         wget -T 10 -t 1 $URL/$TTB.zip -O $DIR2/$TTB.zip >/dev/null 2>&1
  26.         sleep 1
  27.         [ -f $DIR2/$TTB.zip ] && {
  28.                 cru d ttbDL
  29.         } || {
  30.                 cru a ttbDL "*/2 * * * * /usr/sbin/ttb"
  31.                 $LOGS "ERROR - Cannot download Online theme. Will try again soon..."
  32.                 ttbexit 1
  33.         }
  34. }
  35.  
  36. ttbextract() {
  37.         rm $DIR/*.css $DIR/*.zip $DIR/*.png $DIR/*.gif $DIR/*.jpg  >/dev/null 2>&1
  38.         unzip -o $DIR2/$TTB.zip -d $DIR2/ >/dev/null 2>&1
  39.         ls -1 $DIR2 | grep -v .zip | grep -v .list |
  40.         (
  41.         while read line; do
  42.                 ln -s $DIR2/$line $DIR/$line
  43.         done
  44.         )
  45.         $LOGS "INFO - The theme [ $TTB ] has been successfully applied"
  46. }
  47.  
  48. # check if another script in action
  49. [ -f $LOCK ] && {
  50.         $LOGS "WARNING - Another process in action - exiting"
  51.         exit 1
  52. }
  53.  
  54. # check if set to online
  55. [ ! "$(nvram get web_css)" == "online" ] && {
  56.         $LOGS "WARNING - The NVRAM variable [ web_css ] was not set to [ online ] - exiting"
  57.         exit 1
  58. }
  59.  
  60. [ -z "$(nvram get ttb_url)" ] && {
  61.         URL="$URL_ORIG"
  62.         nvram set ttb_url="$URL_ORIG"
  63.         nvram commit
  64. } || {
  65.         URL=$(echo $(nvram get ttb_url) | sed 's/\/$//')
  66. }
  67.  
  68. if [ -n "$2" ]; then
  69.         DIR2=$(echo $2 | sed 's/\/$//')
  70.         DIR2=$DIR2/$SUBDIR
  71.         nvram set ttb_loc="$2"
  72.         nvram commit
  73. elif [ ! -n "$(nvram get ttb_loc)" ]; then
  74.         $LOGS "INFO - The NVRAM variable ttb_loc not set. I don't know where to save the theme will keep it in RAM"
  75.         DIR2="/tmp/$SUBDIR"
  76. else
  77.         DIR2=$(echo $(nvram get ttb_loc) | sed 's/\/$//')
  78.         DIR2=$DIR2/$SUBDIR
  79. fi
  80.  
  81. [ -d $DIR2 ] || mkdir $DIR2
  82. touch $LOCK
  83.  
  84. [ -n "$1" ] && {
  85.         if [ $1 == "help" ]; then
  86.                 echo "
  87.  
  88. NOTE: This is to be used for troubleshooting, always prefer the tomato GUI whenever possible.
  89.  
  90.        TTB 2.05 - usage
  91.  
  92. ttb     <no parameter>          - execute TTB based on NVRAM settings
  93.        help                    - Shows this info
  94.        list                    - Display list of available themes, this uses a themes.txt from the defined URL.
  95.        <theme name>            - Download, sets the theme name and sets NVRAM variables
  96.        <theme name> <folder>   - Download, sets the theme name, stores locally and sets NVRAM variables
  97.  
  98. "
  99.                 ttbexit 0
  100.         elif [ $1 == "list" ]; then
  101.                 wget -q -O - $URL/themes.txt | more
  102.                 ttbexit 0
  103.         else
  104.                 TTB=$1
  105.                 nvram set ttb_css="$1"
  106.                 nvram commit
  107.         fi
  108. } || {
  109.         TTB=$(nvram get ttb_css)
  110.         [ -z $TTB ] && {
  111.                 $LOGS "ERROR - Using TTB but the ttb_css nvram variable meant to cointating the theme name is empty - exiting"
  112.                 ttbexit 1
  113.         }
  114. }
  115.  
  116. [ -f $DIR2/$TTB.css ] && {
  117.         $LOGS "INFO - Installing theme [ $TTB ] from the local storage [ $DIR2 ]"
  118.         ttbextract $DIR2
  119. } || {
  120.         [ $URL != $URL_ORIG ] && {
  121.                 SOURCE="custom url [ $URL ]"
  122.         } || {
  123.                 SOURCE="original TTB site"
  124.         }
  125.         $LOGS "INFO - Downloading theme [ $TTB ] from $SOURCE and storing it locally in [ $DIR2 ]"
  126.         ttbdownload $DIR2
  127.         ttbextract $DIR2
  128. }
  129.  
  130. ttbexit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement