#!/bin/sh
# backset 1.0.0, by wynd.

WORKDIR=/var/mobile/Library/Wynd/BackBoard

if [ "$(id -u)" != "0" ]; then
	echo "Please run this as root"
	exit 1
fi

if [ "$1" = "" ]; then
	echo "Backset 1.0.0 by Wynd

To use:
-u <name>: Update a Springboard
-r <name>: Restore to a Springboard
-d <name>: Delete a Springboard
-k: clear cache respring"
	exit 0
fi

if [ ! -e /usr/bin/jback ]; then
	echo "Missing jback"
	exit 1
fi

if [ ! -d ${WORKDIR}/Profiles ]; then
	echo "Missing profiles"
	exit 1
fi

if [ "$1" == "-k" ]; then
	rm -rf /User/Library/Caches/com.apple.springboard-imagecache-icons
	rm -rf /User/Library/Caches/com.apple.springboard-imagecache-icons.plist
	rm -rf /User/Library/Caches/com.apple.springboard-imagecache-smallicons
	rm -rf /User/Library/Caches/com.apple.springboard-imagecache-smallicons.plist
    
	rm -rf /User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen
	rm -rf /User/Library/Caches/com.apple.SpringBoard.notificationCenterLinen

	rm -rf /User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.0
	rm -rf /User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.1
	rm -rf /User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.2
	rm -rf /User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.3
    
	rm -rf /User/Library/Caches/SpringBoardIconCache
	rm -rf /User/Library/Caches/SpringBoardIconCache-small
	rm -rf /User/Library/Caches/com.apple.IconsCache
	rm -rf /User/Library/Caches/com.apple.newsstand
	rm -rf /User/Library/Caches/com.apple.springboard.sharedimagecache
    
	killall lsd SpringBoard
	killall -9 lsd SpringBoard
	exit 0
fi

if [ "$2" == "" ]; then 
	echo "No Springboard specified"
	exit 1
fi

sb=$2
dir=${WORKDIR}/SpringBoards/${sb}

if [ ! -d "$dir" ]; then
    mkdir "$dir"
fi

if [ "$1" == "-u" ]; then
    jback -p ${WORKDIR}/Profiles/Complete -w "$dir" -i -b
fi

if [ "$1" == "-d" ]; then
	rm -rf $dir
fi

if [ "$1" == "-r" ]; then
	jback -p ${WORKDIR}/Profiles/Complete -w "$dir" -r
fi


