Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # v1.00 Shibby 2013
- # v1.01 Fix memory leak + cosmetics - pedro 2019
- # v2.05 [Command line operation, custom URL, local storage] + GUI integration added - rs232 2019
- PID=$$
- LOCK="/tmp/ttb.lock"
- DIR="/www/ext"
- LOGS="logger -s -t TTB[$PID]"
- SUBDIR="TomatoThemeBase"
- URL_ORIG="http://www.tomatothemebase.eu/wp-content/uploads"
- ttbexit() {
- rm $LOCK >/dev/null 2>&1
- exit $1
- }
- ttbdownload() {
- ls -l /www/ext/ | grep "\->" | cut -d" " -f 27 | while read file; do
- rm $DIR/$file >/dev/null 2>&1
- done
- rm $DIR2/* >/dev/null 2>&1
- wget -T 10 -t 1 $URL/$TTB.zip -O $DIR2/$TTB.zip >/dev/null 2>&1
- sleep 1
- [ -f $DIR2/$TTB.zip ] && {
- cru d ttbDL
- } || {
- cru a ttbDL "*/2 * * * * /usr/sbin/ttb"
- $LOGS "ERROR - Cannot download Online theme. Will try again soon..."
- ttbexit 1
- }
- }
- ttbextract() {
- rm $DIR/*.css $DIR/*.zip $DIR/*.png $DIR/*.gif $DIR/*.jpg >/dev/null 2>&1
- unzip -o $DIR2/$TTB.zip -d $DIR2/ >/dev/null 2>&1
- ls -1 $DIR2 | grep -v .zip | grep -v .list |
- (
- while read line; do
- ln -s $DIR2/$line $DIR/$line
- done
- )
- $LOGS "INFO - The theme [ $TTB ] has been successfully applied"
- }
- # check if another script in action
- [ -f $LOCK ] && {
- $LOGS "WARNING - Another process in action - exiting"
- exit 1
- }
- # check if set to online
- [ ! "$(nvram get web_css)" == "online" ] && {
- $LOGS "WARNING - The NVRAM variable [ web_css ] was not set to [ online ] - exiting"
- exit 1
- }
- [ -z "$(nvram get ttb_url)" ] && {
- URL="$URL_ORIG"
- nvram set ttb_url="$URL_ORIG"
- nvram commit
- } || {
- URL=$(echo $(nvram get ttb_url) | sed 's/\/$//')
- }
- if [ -n "$2" ]; then
- DIR2=$(echo $2 | sed 's/\/$//')
- DIR2=$DIR2/$SUBDIR
- nvram set ttb_loc="$2"
- nvram commit
- elif [ ! -n "$(nvram get ttb_loc)" ]; then
- $LOGS "INFO - The NVRAM variable ttb_loc not set. I don't know where to save the theme will keep it in RAM"
- DIR2="/tmp/$SUBDIR"
- else
- DIR2=$(echo $(nvram get ttb_loc) | sed 's/\/$//')
- DIR2=$DIR2/$SUBDIR
- fi
- [ -d $DIR2 ] || mkdir $DIR2
- touch $LOCK
- [ -n "$1" ] && {
- if [ $1 == "help" ]; then
- echo "
- NOTE: This is to be used for troubleshooting, always prefer the tomato GUI whenever possible.
- TTB 2.05 - usage
- ttb <no parameter> - execute TTB based on NVRAM settings
- help - Shows this info
- list - Display list of available themes, this uses a themes.txt from the defined URL.
- <theme name> - Download, sets the theme name and sets NVRAM variables
- <theme name> <folder> - Download, sets the theme name, stores locally and sets NVRAM variables
- "
- ttbexit 0
- elif [ $1 == "list" ]; then
- wget -q -O - $URL/themes.txt | more
- ttbexit 0
- else
- TTB=$1
- nvram set ttb_css="$1"
- nvram commit
- fi
- } || {
- TTB=$(nvram get ttb_css)
- [ -z $TTB ] && {
- $LOGS "ERROR - Using TTB but the ttb_css nvram variable meant to cointating the theme name is empty - exiting"
- ttbexit 1
- }
- }
- [ -f $DIR2/$TTB.css ] && {
- $LOGS "INFO - Installing theme [ $TTB ] from the local storage [ $DIR2 ]"
- ttbextract $DIR2
- } || {
- [ $URL != $URL_ORIG ] && {
- SOURCE="custom url [ $URL ]"
- } || {
- SOURCE="original TTB site"
- }
- $LOGS "INFO - Downloading theme [ $TTB ] from $SOURCE and storing it locally in [ $DIR2 ]"
- ttbdownload $DIR2
- ttbextract $DIR2
- }
- ttbexit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement