#!/bin/bash


shopt -s extglob # "Shell option set extglob" https://www.linuxjournal.com/content/bash-extended-globbing

set -f # "Disable file name generation (globbing)."

SELECTBACKUP=$1

set +f
FLASHBACKDIR="/var/mobile/Library/FlashBack"
SELECTLOCATION=$FLASHBACKDIR/Backups/$SELECTBACKUP

# COPY BACKUP TO SYSTEM

cp -r $SELECTLOCATION/Preferences/* /var/mobile/Library/Preferences/ || STATUS="cp failed"
cp -r $SELECTLOCATION/HomePlusPreferences/* /var/mobile/Documents/HomePlus/ || STATUS="cp failed"
cp -r $SELECTLOCATION/SBFolder/* /var/mobile/Library/SpringBoard/ || STATUS="cp failed"

if [[ -d $SELECTLOCATION/HomePlusPreferences/ ]]
then
cp -r $SELECTLOCATION/HomePlusPreferences/* /var/mobile/Documents/HomePlus/ || STATUS="cp failed"
fi

if [[ -d $SELECTLOCATION/AutoWall/ ]]
then
rm -rf "/var/mobile/Media/AutoWall/"*
cp -rf "$SELECTLOCATION/AutoWall/"* "/var/mobile/Media/AutoWall/" &>/dev/null
fi

# clear caches and respring
uicache
recache --no respring &>/dev/null
fbmobileldrestart

exit 0
