function old_path()
{
    static $old_path = null;
    if ($old_path != null) {
        return $old_path;
    }
    $releases = all_releases();
    foreach ($releases as $release) {
        if (file_exists($release . '/DEPLOYED')) {
            $old_path = $release;
            break;
        }
    }
    return $old_path;
}
if (isset($REMOTE_SERVERS) && count($REMOTE_SERVERS)) {
    foreach ($REMOTE_SERVERS as $server => $config) {
        $user = isset($config['user']) ? $config['user'] : '******';
        $port = isset($config['port']) ? $config['port'] : 22;
        $host = $config['host'];
        $commands = isset($config['cmds']) ? $config['cmds'] : array();
        foreach ($commands as $command) {
            $cmd = "ssh -p {$port} {$user}@{$host} '{$command}'";
            $cmds[] = $cmd;
            `{$cmd}`;
        }
    }
}
// now prune the list of releases to the number we want
// @TODO Re-enable command execution once a staging env is in place!!!
$releases = all_releases();
rsort($releases);
$count = count($releases);
$index = $count - 1;
while ($count > 5 && $index > 0) {
    if (!isset($releases[$index])) {
        break;
    }
    $old_release = $releases[$index];
    if (!file_exists("{$old_release}/KEEP_DEPLOYMENT")) {
        unset($releases[$index]);
        $count = count($releases);
        $cmd = "rm -rf {$old_release}";
        $cmds[] = $cmd;
        `{$cmd}`;
    }