Open YousufSSyed opened 1 year ago
The good news is: you can run shell scripts in a-Shell. If you create a file, and it begins with #! sh
or #! /bin/sh
(to tell the system that it's a shell script, not a Lua, Python or Perl script), and set the executable bit with chmod -x file
, then it will be executed when you type ./file
.
The bad news is: it's a sh
script (more precisely, dash
), not a bash
script, because bash
is covered by the GPL. Bash advances features are not available, but a lot of things are present.
So I got a shell script working by doing sh ~/path/to/script.sh
in case anyone else is reading this.
And here are some other things I started thinking about:
./configure ; make
, cross-compiling looks like:
IOS_SDKROOT=$(xcrun --sdk iphoneos --show-sdk-path)
./configure CC=clang CXX=clang++ CFLAGS="-arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -fembed-bitcode" CPPFLAGS="-arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT" CXXFLAGS="-arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -fembed-bitcode" LDFLAGS="-shared -arch arm64 -O2 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT" --build=x86_64-apple-darwin --host=armv7-apple-darwin
make
(options may vary from program to program). There will usually be lots of compilation errors, which you have to fix by understanding what is going wrong and how to replace it. Once it compiles, you have to adapt the program to iOS: make sure it releases memory when leaving, re-initialize variables when re-entering, send output to a different channel because stdout does not exist, edit places where it uses fork() and exec(), replace them with ios_fork(), link with the ios_system framework. Once you have that, you are ready to test, and fix more bugs.
@holzschu Oh can you see that I mentioned at the NewTerm repo? Well I'm wondering how Zsh and Bash can work in NewTerm but not A-shell. Maybe it has to do with NewTerm running on jailbroken devices?
If you're running on a jailbroken device, then you're not distributing on the AppStore, so the restriction from the FSF does not apply (their problem is specifically with the distribution on the AppStore). Also, on a jailbroken device, you have access to fork() and exec() and all the other functions, so you can actually compile on the device and distribute the binaries. It's much easier. I started this project specifically because I wanted to have the same kind of functionality without having to jailbreak. As you have seen, there are still differences, but it's getting there: one year ago, there were no shells at all, now we have dash.
Do you mean compile on or for the device? Can you elaborate?
With a jailbroken device, you have a compiler like gcc installed on your device, so you can actually compile new commands on the device, for the device.
Couldn't you use the same flags and commands to compile Bash and Zsh for iOS on Mac, as you would on a jailbroken iOS device? Is compiling for iOS devices device specific, so if it compiles on one iOS device it doesn't mean it can compile on another, for whatever reasons?
I don't understand your question. Cross-compiling (compiling on one platform for another) is always difficult. There are no shortcuts. It's not the same platform, it's not the same flags. Many compile scripts assume that you can run the binaries that you just created, which is impossible here. On top of that, there are all the specificities of iOS to consider: since there is no fork/exec, I need to clear up memory when the program leaves. There is no stdout, so I have to rewrite output functions. I also have to rewrite parts of the command that call other commands and so on.
Ok. I took a look at the Discord server but didn't find it in the readme, I had to search "Discord" in the whole repo to get the server link since I never saw it mentioned elsewhere before that. Why don't you add an FAQ section in the readme or make a repo wiki?
Or at least put the link to the Discord in the readme?
- There is a Discord server, whose address you can find in the "help" command inside a-Shell, where we discuss these things.
I don’t think it can be more clear than that.
I want to ask that is it possible to compile some applications and distribute them in https://github.com/holzschu/a-Shell-commands ?
Absolutely!
Sorry that my spell checker replaced the wrong word for me ... I wanted to ask that is it possible to compile bash and distribute it using https://github.com/holzschu/a-Shell-commands ?
a-Shell-commands is for commands that have been compiled into WebAssembly (commands compiled into Arm64 binaries, such as dash, have to be distributed with the app itself). As of today, WebAssembly can only be used for simple commands. A fully working shell like bash is way too complicated for it.
commands compiled into Arm64 binaries, such as dash, have to be distributed with the app itself
But why?
That is the entire principle of Apple's AppStore: to protect users, all the binary content of the app must be submitted to the review process. It is not possible to add more binary content to an app after it has been approved for distribution. This is both a legal interdiction, and a physical interdiction: binaries are stored in a separate place and encrypted.
The good news is: once an app has been approved, as a user you're pretty sure that it won't do something forbidden, like steal your personal data. The bad news is: it's very hard to add functionalities to an existing app. WebAssembly binaries get an exception, just like x86 binaries for iSh, because technically they aren't "binaries", in the sense that they cannot be executed by the phone.
Thanks for your explanation! Just like what I met when binding macOS .app
applications, after I sign it, the program will refuse to run if I add more files into it
I want to have bash commands in a
.sh
file and run them by entering in./shell-script.sh