Image copyright AP Image caption Has Pakistan's military grown even more powerful under General Raheel Sharif's watch?

Days before he hangs up his spurs and retires on 29 November, Pakistan's army chief General Raheel Sharif stands at the height of his popularity.

His massive portraits adorn the backs of lorries, posters depict him as saviour of the nation and he continues to inspire devotional social media hashtags.

Indeed when it was announced on Monday that the general was kicking off "farewell visits", many media reports hailed him as "Pakistan's beloved army chief", while the reaction on Twitter was similarly effusive.

The announcement apparently put an end to fears of an 11th hour surprise, and many people praised the fact that he was sticking to the retirement plan, instead of finding a way to stay in power.

Why is Pakistan's army chief all over social media?

Viewpoint: How Peshawar massacre changed Pakistan

Pakistan's military has long played a prominent role in the country's politics, having staged three coups since independence in 1947. The army chief is widely seen as the most powerful person in the country - above the prime minister.

Gen Sharif stepped into the top job in the winter of 2013, just after a historic transfer of power between two civilian administrations. But the military has done anything but cede power and influence to the government during his reign. Instead, it has grown even more powerful.

Why is he so popular?

Gen Sharif has a distinguished pedigree. His father was an army major, and his late brother, Major Shabbir Sharif, was awarded Pakistan's highest gallantry award.

Media playback is unsupported on your device Media caption Pakistan's army chief has been very prominent on social media

Months after taking charge, the general took the bold step of launching a ground offensive to clear the Waziristan region of militant sanctuaries - a move Pakistan had been dragging its feet on despite repeated demands from its Western allies.

It led to a dramatic decline in militant attacks in northern Pakistan, instantly boosting his popularity ratings.

Image copyright @sajjad3370 Image caption The public responded well to Monday's announcement that General Sharif was beginning farewell visits

Image copyright @sarataseer Image caption Sara Taseer is the daughter of murdered Punjab governor Salman Taseer

In the south, the paramilitary Sindh Rangers under his watch took on the task of clearing Karachi, Pakistan's largest city, of a confusing array of armed militants, organised criminal groups and festering political corruption.

The results were equally impressive. The extortion rackets, targeted killings and kidnappings for ransom that had become a permanent feature of life in Karachi diminished visibly.

Moreover, Gen Sharif has been determined to make operational a $46bn Chinese funded economic corridor that links up the southern port of Gwadar to China's western Xinjiang province - a key part of China's bid to shore up its influence and strategic links in the region.

Why was he chosen?

Prime Minister Nawaz Sharif (no relation) won a landslide victory in 2013 and embarked on projects considered the exclusive domain of the military.

He instituted peace talks with the Pakistani Taliban, opened dialogue with separatists in Balochistan and made peace overtures to India.

He even tried to set a precedent by arraigning former army coup leader and later president, Pervez Musharraf, on charges of treason.

It was amid this civilian resurgence that he chose Gen Sharif as army chief, elevating him over two more senior officers.

But if he made the choice thinking Gen Sharif would behave like a professional soldier and accept civilian supremacy, it was not to be.

Image copyright AFP Image caption General Sharif took over from General Ashfaq Kayani (right) in 2013

How has Pakistan changed?

Room for criticism of the military has worsened since Gen Sharif took charge, says Ayesha Siddiqa, an analyst and expert on the Pakistani army.

The country's once vibrant electronic media has stopped reporting on "sensitive" and longstanding issues such as the military's alleged patronage of selected extremist groups and their political wings.

And it has desisted from asking questions about the links between these groups and those who continue to hit targets in Pakistan. Instead, it happily buys the military's line that these attacks are planned by Indian and Afghan intelligence services to harm the China-Pakistan Economic Corridor.

Image copyright Reuters Image caption The China-Pakistan Economic Corridor links Gwadar in Pakistan's south with Xinjiang in China's west

The media fell in line following a gun attack on a famous TV journalist, Hamid Mir, in March 2014. His family blamed the attack on the military intelligence service, the ISI. They said he was targeted for challenging the military's narrative about Baloch separatists.

The ISI denied the charge, but Geo TV, for which Mr Mir worked, remained off air for several weeks without any direct order from the government.

What underpins the army's power?

The army's huge financial clout means that it "is not answerable to anyone", Ms Siddiqa says. In 2007, the military's private economy was estimated at roughly $20bn, handled mostly through its welfare wings that run vast industrial, services, real estate and retail empires.

In addition, its position as a political force means it accrues the lion's share of foreign assistance that Pakistan receives. While the US post-9/11 aid pipelines are now drying up, China is providing tens of billions of dollars of assistance.

Over decades, Pakistan's civilian institutions have crumbled - arguably due to corruption and mismanagement - while those of the military have prospered.

This trajectory hasn't changed during Gen Sharif's reign.

"Under him, the military has operated outside the institutional plane, and as a result militarism in our policy has increased," Ms Siddiqa says.

In what ways has the military strengthened its role?

It is believed that the general decided to launch the military operation in Waziristan in June 2014 without a nod from political leaders in Islamabad.

The December 2014 militant attack on an army school in Peshawar further helped the military consolidate its hold on political decision making. The government formalised the military's role in law enforcement at the provincial level by giving it representation in "apex committees" created under a national action plan.

A constitutional amendment was then passed by parliament allowing terror suspects to be tried in military courts.

Image copyright Reuters Image caption The Army Public School massacre in Peshawar was the deadliest militant attack in Pakistan's history

At the same time, the military's media wing, the ISPR, launched an aggressive campaign to build up Gen Sharif's political image, charting each and every move he made and making sure that he received prime coverage on TV channels.

The ISPR has since invested in producing songs, anthems and films to promote the military's image.

Who will be the next army chief?

There are several four-star generals who could be chosen as chief of army staff, but only a handful of them have headed corps and are therefore seen as qualified for the job. All come from infantry.

In making his choice, Prime Minister Nawaz Sharif will be guided by personal and political considerations.

But regardless of who takes charge, the military is seen as wanting to control the political narrative going forward in order to protect and expand its financial empire. The narrative it prefers tends to be pro-religion, anti-India and at times anti-US.

So civilians in Pakistan are likely to continue for the foreseeable future to battle to regain their lost space as the military continues to find more subtle ways of controlling democracy.

The question as to who succeeds General Raheel Sharif and what style that person may bring to the job, therefore, is of little consequence.