Batch/Bash scripting for Jailbroken iOS devices - ios

So I have a jailbroken iPhone and would like to automate some tasks on my phone but I would rather do this myself, rather than download tweaks or apps that can achieve this same functionality.
I do not have a Mac computer, so developing apps and/or tweaks will be a pain in the butt, from what I have read, so then I got thinking about Batch files. And .js and .vbs files that you can use to automate things in Windows.
Does iOS have any similar or equivelant's to Batch file scripting? Can I write a script that can perform a simple task on my iPhone once I have launched that script file on my phone?
Is this possible?

Yes, jailbroken phones have access to bash, and as such you can create bash script files.
See here on how to start writing bash scripts. You write it to a file (typically ending in .sh), make it executable (via chmod +x scriptFile.sh), then run it (./scriptFile.sh). There is also access to Ruby and Python, so you could write scripts in those languages too if you prefer.
You also don't need to write the scripts on the device, you can write them on your PC, and transfer the files over via SCP. This gets a little more complex, as you'll need to install SSH (and make sure you change the default passwords, there is a guide on how via Cydia), and other tools in order to copy them over.

Related

Can I run a shell script on OpenWrt from a remote host using OpenWISP2?

I am working on a hardware device running OpenWrt. I was wondering if I can manage my hardware and run shell scripts etc. remotely using OpenWisp2. Is it possible? If yes, then how to do that?
Not at the moment I'm writing.
You can only send configuration files, which can include scripts that can be also added to the crontab.
Sending commands will be possible once this branch is merged: https://github.com/openwisp/openwisp-controller/pull/31

Bash on iOS issue

When any application that uses bash to launch their executables as root, iOS registers the bash script as the main executable instead of the intended executable.
The problem is that I cannot turn off cellular access to these applications because iOS calls the script rather than the applications executable and nothing happens.
I found a partial method that works, but it's not practical because the application looses root capabilities, but it will allow the setting's app to disable cellular data for the application;
Remove the bash script,
Rename the apps main executable to the bash scrips name,
Reboot.
Can I do anything to solve this?
Thanks, Jason.

Install non-UI app on jailbroken device via AFC2

I am trying to install an app to a jailbroken iPhone from PC via USB (using AFC2), for personal research. The app is actually an installer, so it has no UI.
My biggest 2 problems are: I don't know any API to run a command via an USB services, to run the binary after copying.
Then, I installed a LaunchDaemon plist to start my installer, but it seems that the binary is copied with no execution rights (maybe a limitation in AFC2), so the launch daemon fails.
So now I am stucked. Do you have any ideeas?
UPDATE
Thanks to creker I made some steps into achieving my goal. He provided me with several solutions, but I chosen the automatically install DEB via Cydia, since it looks the most simple and elegant method of all.
Nevertheless, I hit some bumps with this method also:
now I am able to succesfully install the .deb file via Cydia; I load the app and a launch daemon in the deb, but the launch daemon is unable to start the app, since installd fails to validate the app, which was fake-signed with ldid (I thought ldid signing is sufficient for running in jailbroken environment); so I guess either I sign it for real or I use a tweak like AppSync, to bypass validation
I also tried the following formula: a launch daemon to launch a bash script, which then starts the app, since I saw that cydia and OpenSSH registers some launch daemons like that, but my script / launch daemon is ignored, so I presume there should be a trick somewhere. Am I missing something here?
Do you have a WiFi? If not, you can use USB tunneling. Then you can SCP your app on a device and install it with SSH (give it persmissions you need and then launch). That's enough for testing. Or you can pack it into debian package with postinst script that will do all the installation. Debian packages can be installed manually through ssh and deb -i command. Or you can copy it into /var/root/Media/Cydia/AutoInstall and it will be installed automatically on device boot.
As for root:wheel, you can do this in your postinst script. The script by default is executed with root permissions. Just set all necessary permissions in it for all your files. If it's a daemon, you can even manually add it to launchd and launch immediatelly.

Run a local script on an SSH machine

I would like to run a script on a device that I have established an SSH session into. However, the script is on my local Windows machine.
For my experiment, I have:
A python script on my local machine (Windows)
A jailbroken iOS device that I can SSH into using putty
I want to run the python script, that's located on my windows machine, on my jailbroken device.
Is this possible?
I know on a Mac, you can actually use the terminal to do just that and it would look something like this.
python [pythonfile].py [parameters] [target device]
The reason why I can't just run the python script on my device is because I can't install python on that device (at least it isn't on Cydia). Plus, I don't want to pay for an app that executes it.
Let me know if you have any suggestions, thanks.
Have you tried this libssh2-for-iOS. Its an open source library which does exactly the same thing you are looking for.

BlackBerry Code Signing for Multiple OS'es

I wanted to do a couple of things and am wondering if they're possible, and if so, how to do them.
I was going to make a Virtual Machine to run code-signing in. That way if my computer dies I can hopefully minimize downtime by simply running the VM in a new system. I know the code keys are tied to the machine they're run on. If anyone has done code signing in a VM and switched the VM to another physical machine please let me know if the keys continued to work or not.
I also wanted to run more than one JDE in the VM to sign code for different OSes. From what I understand the code signing uses a code signing app located in each JDE's directory. Is it possible to run multiple JDE's on the same system and be able to sign code for a specific OS (I'm planning on having JDE 4.2.1, 4.5, 4.6.1, 4.7, and eventually 5.0 on the code-signing VM). If so, do I need multiple keys - one for each JDE version - or is there some way to use the same keys for the different versions?
Thanks for any help in answering this.
It's certainly possible to migrate the keys between machines - We have a set of keys that have been used on Windows XP, Mac OS X and Linux machines.
If you look in one of your BlackBerry JDE Component Package X.Y.Z\bin directories after you've used the signing tool manually you'll see these files:
sigtool.csk
sigtool.db
These are the files you need. Simply copy them to the equivalent location in the alternate JDE trees and you will be able to use them for 'multiple targets'. I've not done this with 4.7.0, but have with 4.6.0, 4.5.0, 4.3.0, and 4.2.1. We're run the signer using
java -jar bin/SignatureTool.jar
I'm not sure whether other methods would work.
Migrating to UNIX-like build machines introduces a twist, and this is why I think RIM say the keys are not portable - the SignatureTool application seems to not detect the operating system-specific directory path separator character. The upshot is that it looks for the key files in these locations, even on a UNIX machine (note the backslashes):
bin\sigtool.csk
bin\sigtool.db
when you'd think it would look for bin/sigtool.csk for example. A solution for this is simply to create soft links with these names that point to the actual files. In the component package top-level directory we do this:
ln -s bin/sigtool.db bin\\sigtool.db
ln -s bin/sigtool.csk bin\\sigtool.csk
I've only signed in one VM - a Windows XP image. It worked fine.
Another solution is to just fix the problem with SignatureTool (FYI, RAPC has similar issues), as this blog describes:
http://www.slashdev.ca/2008/03/16/using-sigtool-in-linux/

Resources