Re: Ultimately though
Yes, Apple spent much of this period on death's doorstep.
If I were a government minister in 1997, weighing up the income-tax receipts for 1,000 well-paid jobs versus the corporation tax receipts from a company that was losing money hand over fist (and I mean losing money in the old-fashioned way of spending more than it got from sales; no financial trickery needed), I'd have made the same decision.
Back in those days, one of those jobs would have been mine, so this isn't entirely dispassionate, but the fact was that this deal was a calculated risk taken on by the Irish government with the intention of maximising tax revenue at the expense of some future corporation-tax receipts. Of all the manufacturing exporters operating in Ireland at that time, nobody would have predicted that it would be Apple that would become the world's highest-valued corporation - even as late as 2005, the company was merely "doing okay", and at that point I'd suspect the balance was still in favour of the Irish government.
Apple was not the only company offered this arrangement, but the company's stratospheric profit growth right at the end of the period it was in effect does make it look worse than it was. I've no love for the company that Apple has become, but I think this ruling is stepping over the line of allowing member states to organise their own tax affairs.
Maybe, with twenty years of hindsight, Ireland's government shouldn't have assisted Apple to remain in Ireland in this way, but that's like saying that maybe, in hindsight, Decca should have signed the Beatles when they auditioned for them in 1962.