#!/bin/bash

echo "######### STARTUP: Running cydia startup script" 

export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin

if [[ ! -e /var/lib/cydia/firmware.ver ]]; then
    cache=
fi

echo "STARTUP: Running firmware.sh"

/usr/libexec/cydia/firmware.sh

debs=(/var/root/Media/Cydia/AutoInstall/*.deb)
if [[ ${#debs[@]} -ne 0 && -f ${debs[0]} ]]; then
    echo "Installing deb"
    dpkg -i "${debs[@]}" 1>/tmp/startup.log 2>/tmp/startup.log
    rm -f "${debs[@]}"
    cache=

   echo "STARTUP: XXX NITOTV SHIT"
    # XXX: nitoTV
    launchctl unload /System/Library/LaunchDaemons/com.apple.frontrow.plist
    launchctl load /System/Library/LaunchDaemons/com.apple.frontrow.plist
fi

if [[ ${cache+@} ]]; then
    su -c uicache mobile
fi

