#!/bin/bash
# extrainst_
# postrm

## Acceptable parameters for finish
# return - normal behaviour (return to cydia)
# reopen - exit cydia
# restart - reload springboard
# reload - reload springboard
# reboot - reboot device
##
# Historically, 'restart' restarted springboard but did not reload the launchdaemon.
# (reload was used for this purpose.) Now, restart and reload are equivalent.
function finish() {
    f="${1}"

    # No control fd: bail out
    [[ -z "${f}" || -z "${CYDIA}" ]] && return

    cydia=(${CYDIA})

    # Cydia control fd version != 1: bail out
    [[ ${cydia[1]} -eq 1 ]] || return

    echo "finish:${f}" >&${cydia[0]}
}

## Choose one of the below sections (not both.) :P
# If this is extrainst_
finish restart

# If this script is postrm, you need to do something a bit more complex:
# postrm is called with remove, purge, upgrade, failed-upgrade, abort-install and abort-upgrade
# You probably only want to act on remove and (as this is the actual removal phase.)
if [[ "$1" == "remove" ]]; then
    finish restart
fi
