How to Detect Apple Silicon and Rosetta from within a Shell Script

Compiled code can conclude the instruction set through conditional compilation. But what about processor-independent scripts? Finding out the current native processor architecture and emulation status thereof would be very useful in build systems that doesn’t support cross-compilations. Find out how a shell script can find out whether it is running under Apple’s processor, Intel, or emulated.