ALGIERS He has survived a revolt, Western air strikes and the defection of some of his closest aides, and now Libyan leader Muammar Gaddafi is hunkering down for a long siege.
In the past few days Gaddafi's administration has emerged from a period of paralysis and started drawing up a blueprint for how to run the country -- at least the parts he still controls -- while isolated by the outside world.
It is not clear how long Gaddafi can last, but the fact he seems to be digging in for a prolonged stay will be disheartening to Western governments under pressure from war-weary publics to deliver a swift conclusion in Libya.
"The conflict is going to be long and drawn out," said Geoff Porter of North Africa Risk Consulting.
"Over the long term, Libya clearly won't be united again under ... (Gaddafi's) leadership, but it's also increasingly unlikely that the rebels will get anywhere close to Tripoli and without Tripoli there is no rebel victory."
The long-established pattern in Libya is that when Gaddafi's inner circle is in crisis, decision-making grinds to a halt and officials disappear from view.
This is what appears to have happened when Foreign Minister Moussa Koussa landed at a military airfield in southern England on March 30 and resigned from the Libyan government.
For days afterwards, there were almost no public pronouncements from Libyan officials, Gaddafi and his sons dropped out of sight and even minders watching over foreign journalists in a Tripoli hotel did not show up for work.
There are signs now the internal crisis has passed. Gaddafi's son Saif al-Islam has given interviews to the media, officials are back at work and the state media has reported a flurry of instructions from government ministries.
In the first such session since the crisis began, Libya's ministry for industry, economy and trade convened a meeting this week to work out how to ensure supplies of food and medicine in the face of disruption caused by sanctions and air strikes.
"The secretariat stressed the importance of operating stalled factories and providing them with raw materials, and facilitating the procedures for bringing in (foreign) labor and granting incentives to the Libyans working there," the state news agency reported.
At the same time, Gaddafi has consolidated his control -- at least for now -- on two important fronts.
Predictions that Koussa's departure would unleash a wave of defections have not come to pass, though it is not clear if that is because officials do not want to defect, or because they and their families are being physically prevented from leaving.
At the same time, Gaddafi's military has halted the rebel advance in the east of the country.
They have done that, in part, by adopting the same low-key, guerrilla-style tactics used by the rebels, making it harder for pilots of Western warplanes to target them.
Gaddafi's stronghold now is the capital and Libya's western province, known historically as Tripolitania. There, the biggest threat to his hold on power has been not rebels but public anger at a shortage of food and fuel.
His administration has been getting to grips with that problem. According to one Tripoli resident, every neighborhood now has a state-run shop, known as "Government Consumer Societies," which sell subsidized goods.
These shops used to exist when Libya was run along socialist lines and were abolished soon after the reformist Shokri Ghanem, now Libya's top oil official, was made prime minister in 2003. They have made a comeback.
"In normal shops one bottle of (cooking) oil is 4-5 Libyan dinars and in these kind of shops we buy one bottle for 60 cents," the Tripoli resident said.
Fuel shortages, which had led to huge queues at petrol stations, are easing.
A source close to the NOC state oil company said Zawiyah oil refinery, about 50 km (30 miles) west of Tripoli, is supplying 40 percent of fuel needs and the rest was being imported.
The source, who did not want to be identified, said the fuel distribution and retail system ground to a halt because it relied on low-paid foreign workers who had fled the country, and Libyans did not want to do their jobs.
"The authorities are working to increase the wages of the Libyans who are working in the petrol stations" he said.
As a result, queues at petrol stations have shrunk. "Last night I refueled my car. I waited in the car for about 45 minutes. I had to spend five or six hours (queuing before)," the Tripoli resident said.
The rebellion in the east of the country, coupled with the halting of deliveries by ship, disrupted the supply of imported foodstuffs. The World Food program says Libya needs 110,000 tons of food a month, 75 percent of which is imported.
But in the past few days, overland supply routes via the Ras Jdir border crossing with neighboring Tunisia have started functioning again.
"Tens of trucks are transporting tons of food products, like sugar and pasta," a Tunisian trade union activist from Ben Guerdane, the nearest big town to the border, said. "These ... (products) cross the border at Ras Jdir."
He said, though, that fuel retailers in Tunisia -- a country which ousted its president in a revolt earlier this year -- were refusing to sell petrol to Libyans out of solidarity with the anti-Gaddafi rebels.
DWINDLING CASH PILE
Unless Tripoli is overrun by the rebels, Gaddafi flees or is toppled in a palace coup, the biggest question mark over his grip on power in Tripolitania is how long his cash reserves will last.
Libya is still having problems with cash shortages. The central bank has limited people to withdrawing 500 dinars ($400) per month from their accounts. Sometimes bank tellers tell them even that amount is not available, residents say.
"What I am going to do with this 500 dinars?" a man called Noureddine said as he came out of a bank in Tripoli.
"I have to repair my car ... This money is only going to cover basic living costs. They should take care of our needs."
The bigger problem is not Libyan currency but foreign exchange, which the government needs to pay for imported goods.
An International Monetary Fund report put Libya's net foreign assets held by the central bank and the sovereign wealth fund at $150 billion at the end of last year.
Some of these assets were abroad and have been seized as part of sanctions against Libya. The U.S. Treasury said it had frozen $34 billion in Libyan assets, while European governments have also frozen assets.
That will still leave Gaddafi with a large pile of currency, but with no new foreign exchange coming in from the sale of oil -- which is also blocked by sanctions -- those reserves will dwindle.
(Additional reporting by Tarek Amara in Tunis, Hamid Ould Ahmed in Algiers and Maria Golovnina in Tripoli; Writing by Christian Lowe; Editing by Richard Lough and Michael Roddy)