LIEUTENANT Mehmet Ali Celebi has not sat in a gunship cockpit for years, but will jump back in at a moment’s notice if the Turkish army comes calling. A promising helicopter pilot, Mr Celebi was sentenced to 16 years in jail in 2013, framed by policemen who uploaded numbers belonging to Islamist radicals onto his phone. He was released a year later, along with hundreds of other secularist officers who had been locked away on trumped-up charges by prosecutors close to the Gulen community, a secretive Islamic movement.

Since July’s thwarted coup, staged by an army faction believed to be led by Gulenists, the tables have turned. Today, it is Gulen followers in the bureaucracy who are being indiscriminately purged by their one-time patrons, the ruling Justice and Development (AK) party. Some 70,000 civil servants, including judges, prosecutors and teachers, have been sacked or suspended, sometimes on the thinnest of evidence. At least 32,000 people, including more than 100 journalists, are in prison.

The crackdown has left the second-biggest army in NATO in turmoil—this at a time when it is supposed to be fighting in Syria, alongside Syrian rebels, to push back both Islamic State (IS) and Kurdish militias.

About 5,000 soldiers, including almost half of all admirals and generals, have been sacked or detained. The air force has lost at least 265 pilots, leaving it with fewer pilots than fighter jets. Experts say replacing them may take ten years; the defence ministry says it can do so in three.

Thanks to President Recep Tayyip Erdogan’s insistence that the coup was the work of a small cabal, the army’s reputation has only been lightly tarnished, despite a night of chaotic violence that left some 270 dead. A survey in August found that 66% of Turks still trust the armed forces, down from 78% at the start of the year. Indeed, soldiers who saw the Gulenists rise through the ranks, often replacing secularist officers arrested like Mr Celebi, hope the purges will make the army more transparent, says Hasan Selim Ozertem, an Ankara-based analyst. “But there’s also fear,” he adds.

Many of the sacked generals have already been replaced. The air force, unless confronted with a full-scale war, should be able to cope. A handful of pilots imprisoned with Mr Celebi in the early 2010s have been reinstated. The successful operation in Syria has restored confidence in the army, and Mr Erdogan suggests it may push farther south to take the fight to IS.

A bigger challenge is an emergency decree authorising the president and prime minister to issue orders to commanders. Military schools have been closed to make way for a government-run national defence university. Two ministries, defence and interior, now control separate branches of the armed forces. Cabinet ministers will outnumber generals in the council responsible for military appointments. These may be the most profound changes to the army’s structure since Turkey’s foundation, says Doruk Ergun of EDAM, an Istanbul think-tank.

They may also be long overdue. For decades, the military enjoyed what Mr Ergun calls an “extrajudicial right” to overthrow governments, and did so on four occasions. Civilian control, which AK has sought since coming to power in 2002, should stop it from doing so again. “The military is finally shedding the Prussian school from its make-up,” says Soli Ozel, a professor at Kadir Has University.

What worries former soldiers is that the new measures could let the government bypass the chain of command, confusing decision-making. “This will erode fighting capacity,” says Oktay Bingol, a retired brigadier general. Browbeaten generals may refer key matters to Mr Erdogan and his ministers, says Mr Ergun. Yet for many Turks, a timid army beats a disloyal one.