Jump to content

Some bash scripting questions

WhitetailAni

I recently discovered the Coeus tweak for iOS and am attempting to make a vnodebypass button. I could do it by just launching the app, but that takes too long and Activator (what Coeus uses to tell the buttons in Control Center to do stuff) allows running scripts.

Problem is I don't know jack squat about bash scripting.

Here's the basic idea.

If button is set to OFF:
su root

type root password

vnodebypass -s

vnodebypass -h

If button is set to ON:
su root
type root password

vnodebypass -r

vnodebypass -R

 

I wasn't able to find a way to make Activator run two scripts alternating, so I have to make it so it runs the 2 command sets alternating - enable, disable, enable, disable, etc. I think it's possible with a variable setup (this is not actual code, just a thought), but I'm not sure if variable states persist if a script is killed and then restarted.

If variable states are preserved, then:

# 0 = off

# 1 = on

var STATE = 0  # this line needs to run once and never again, likely not possible. I'm fairly certain vnodebypass works by hiding files from view, so perhaps I can get the state of whether it's enabled or not by checking to see if a file exists?

if STATE = 0

vnodebypass -s

vnodebypass -h

var STATE 1

else

vnodebypass -r

vnodebypass -R

var STATE 0

 

The script does need to be run as root; is there a way for a bash script to elevate itself to root privileges whenever it is run?

If you need any more info I'm happy to provide!

 

Thanks!

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

Scripts can't elevate themselves to root because yikes the security issues that would create. You can either run the script in its entirety as root or, if you have access to sudo, change the sudoers file to allow sudo vnodebypass to be run without a password.

 

As for the variables, they'll reset if the script is restarted. You can save them by writing to a persistent file or, if the script is always run in the same terminal, you can save the state with an environment variable (kinda jank tbh, but doesn't involve creating a file)

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 Fractal Design Meshify C Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, BobVonBob said:

As for the variables, they'll reset if the script is restarted. You can save them by writing to a persistent file or, if the script is always run in the same terminal, you can save the state with an environment variable (kinda jank tbh, but doesn't involve creating a file)

Creating a separate file is fine by me.

1 minute ago, BobVonBob said:

Scripts can't elevate themselves to root because yikes the security issues that would create. You can either run the script in its entirety as root or, if you have access to sudo, change the sudoers file to allow sudo vnodebypass to be run without a password.

My phone is jailbroken, so I have full root access (complete with changing the root password from its default alpine). How would I go about using the sudoers command? Assume I know nothing about bash.

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, FakeKGB said:

How would I go about using the sudoers command? Assume I know nothing about bash.

sudoers is not a command, it's a file that says who can run what commands as root. Do note that I'm not great with this and I've never used either of those utilities, so this might be wrong, but the way you go about editing the file is by running this command. 

sudo visudo

This will launch it most likely in Vi, not an intuitive file editor, so the basic commands are:

  • "i" to insert text.
  • esc to get out of insert mode
  • ":q!" to quit without writing (done in normal mode)
  • ":wq" to quit with writing (done in normal mode)
  • hjkl as left, down, up, right respectively. 

You'll want to add a line to the end of the file that looks like this (assuming that Coeus has its own user named coeus) (this is where I am most likely to be wrong)

coeus	ALL=/sbin/vnodebypass

 

 

After that, it should be able to run the command as root by itself, thus not needing to have it run as sudo (hopefully)

 

 

As for how to do the rest of this, the super jank solution I'd probably do would be to create a file if it's on and delete that file if it's off. General structure for creating that would be this

FILE=/path/to/file
if [ -f "$FILE" ]; then
    echo "$FILE exists."
    rm "$FILE"
else 
    echo "$FILE does not exist."
    touch "$FILE"
fi

 

Basically change the echo command to everything you need to start/stop vnodebypass. Each time it runs, it will create or delete the file accordingly, and run the corresponding on or off commands. It's a little jank, but it's the solution Pop_OS! used to make apt Linus proof since it's so quick to implement. 

Link to comment
Share on other sites

Link to post
Share on other sites

18 hours ago, FakeKGB said:

The script does need to be run as root; is there a way for a bash script to elevate itself to root privileges whenever it is run?

If you need any more info I'm happy to provide!

Scripts cannot elevate themselves.

But you can however just run put sudo in front of the command to run the script like this:

sudo bash your_script.sh

then the script will be run as root.

 

But remember tp be careful when using sudo.

 

root can be dangerous to your system if used in the wrong way.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, WillLTT said:

Scripts cannot elevate themselves.

But you can however just run put sudo in front of the command to run the script like this:

sudo bash your_script.sh

then the script will be run as root.

 

But remember the standard sudo lecture:

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

 

I'll double-check, but I don't think I can tell Activator to run scripts as root - they just run under the default user (not root), hence why I was hoping there was a way I could stick the root password for my device in the script. Using sudoers should work though.

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

20 hours ago, RONOTHAN## said:

sudoers is not a command, it's a file that says who can run what commands as root. Do note that I'm not great with this and I've never used either of those utilities, so this might be wrong, but the way you go about editing the file is by running this command. 

sudo visudo

This will launch it most likely in Vi, not an intuitive file editor, so the basic commands are:

  • "i" to insert text.
  • esc to get out of insert mode
  • ":q!" to quit without writing (done in normal mode)
  • ":wq" to quit with writing (done in normal mode)
  • hjkl as left, down, up, right respectively. 

You'll want to add a line to the end of the file that looks like this (assuming that Coeus has its own user named coeus) (this is where I am most likely to be wrong)

coeus	ALL=/sbin/vnodebypass

 

 

After that, it should be able to run the command as root by itself, thus not needing to have it run as sudo (hopefully)

Sadly this doesn't work as iOS doesn't have the visudo command installed, and (at least not that I found) no one has created a console package to add visudo. Fun fact: iOS doesn't come with nano or sudo commands installed either; I had to manually install both.

I tried opening it with nano but it spat a big warning "ONLY EDIT WITH VISUDO OR YOU MAY BREAK THIS FILE", can I edit it with nano?

 

EDIT:
I made a copy of it to my PC and when inside, everything in the file has one or two hashtags. Should I add zero, one, or two hashtags before my added line? It says "the '#' here does not indicate a comment" but I'm not sure if this means I need a #, or I need 2 #'s, or I need none.

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, FakeKGB said:

Sadly this doesn't work as iOS doesn't have the visudo command installed, and (at least not that I found) no one has created a console package to add visudo. Fun fact: iOS doesn't come with nano or sudo commands installed either; I had to manually install both.

I tried opening it with nano but it spat a big warning "ONLY EDIT WITH VISUDO OR YOU MAY BREAK THIS FILE", can I edit it with nano?

Yeah, visudo just has protections built in to make sure you don't accidentally write something wrong that breaks that sudo. If you can access the root user, just make a backup of the sudoers file before you edit it. If you don't have access to the root user, make sure you're really sure you edited it correctly before saving or try to enable the root user before you edit it. 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, RONOTHAN## said:

Yeah, visudo just has protections built in to make sure you don't accidentally write something wrong that breaks that sudo. If you can access the root user, just make a backup of the sudoers file before you edit it. If you don't have access to the root user, make sure you're really sure you edited it correctly before saving or try to enable the root user before you edit it. 

I have root user access yeah. What should I do with the hashtag thing?

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, FakeKGB said:

I have root user access yeah. What should I do with the hashtag thing?

The "#" designates a comment, some way "//" does in C/C++. You want whatever line you're adding to not have that in front. 

 

And again, make a backup of the file. Run this command to do that. 

sudo cp /etc/sudoers ~/sudoers.backup

To restore it run this command:

sudo cp ~/sudoers.backup /etc/sudoers

 

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, RONOTHAN## said:

The "#" designates a comment, some way "//" does in C/C++. You want whatever line you're adding to not have that in front. 

 

And again, make a backup of the file. Run this command to do that. 

sudo cp /etc/sudoers ~/sudoers.backup

To restore it run this command:

sudo cp ~/sudoers.backup /etc/sudoers

 

Aight, the sudoers part worked, but when I run the script iOS says:

bash-5.0# ./"vnodebypass.sh"
./vnodebypass.sh: line 6: syntax error near unexpected token `else'
./vnodebypass.sh: line 6: `else'
bash-5.0#

Here's my script, in case I botched something:

FILE=/Applications/vnodebypass.app/state.state
if [ -f "$FILE" ]; then
    vnodebypass -s
    vnodebypass -h
    rm "$FILE"
else 
    vnodebypass -r
    vnodebypass -R
    touch "$FILE"
fi

 

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, FakeKGB said:

Aight, the sudoers part worked, but when I run the script iOS says:

bash-5.0# ./"vnodebypass.sh"
./vnodebypass.sh: line 6: syntax error near unexpected token `else'
./vnodebypass.sh: line 6: `else'
bash-5.0#

Here's my script, in case I botched something:

FILE=/Applications/vnodebypass.app/state.state
if [ -f "$FILE" ]; then
    vnodebypass -s
    vnodebypass -h
    rm "$FILE"
else 
    vnodebypass -r
    vnodebypass -R
    touch "$FILE"
fi

 

That should work. Try adding this like to the top of the script and see if that fixes it.

#!/bin/bash

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, RONOTHAN## said:

That should work. Try adding this like to the top of the script and see if that fixes it.

#!/bin/bash

 

That fixed that problem, now it's saying:

bash-5.0#  ./"vnodebypass.sh"
bash: ./vnodebypass.sh: No such file or directory
bash-5.0#

Unless I'm misreading this it's saying the file doesn't exist...?, despite it clearly existing.

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, FakeKGB said:

That fixed that problem, now it's saying:

bash-5.0#  ./"vnodebypass.sh"
bash: ./vnodebypass.sh: No such file or directory
bash-5.0#

Unless I'm misreading this it's saying the file doesn't exist...?, despite it clearly existing.

that's even weirder. Try entering the full file path and see if that works. i.e

./home/fakekgb/vnodebypass.sh

 

EDIT: You did make sure that file didn't delete itself somehow, running the "ls" command to make sure it's there?

Edited by RONOTHAN##
Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, RONOTHAN## said:

that's even weirder. Try entering the full file path and see if that works. i.e

./home/fakekgb/vnodebypass.sh

 

No luck. I even tried moving it from the app's directory:

/Applications/vnodebypass.app/vnodebypass.sh

To the regular phone user documents directory:

/var/mobile/Documents/vnodebypass.sh

And still the same "No such file or directory" thing. I'll try recreating the file from scratch, maybe my flash drive is going?

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, FakeKGB said:

No luck. I even tried moving it from the app's directory:

/Applications/vnodebypass.app/vnodebypass.sh

To the regular phone user documents directory:

/var/mobile/Documents/vnodebypass.sh

And still the same "No such file or directory" thing. I'll try recreating the file from scratch, maybe my flash drive is going?

Have you tried?:

bash <file name without ./>
On 4/5/2024 at 10:13 PM, LAwLz said:

I am getting pretty fucking sick and tired of the "watch something else" responses. It's such a cop out answer because you could say that about basically anything, and it doesn't address the actual complaints. People use it as some kind of card they pull when they can't actually respond to the criticism raised but they still feel like they need to defend some company/person. If you don't like this thread then stop reading it. See how stupid it is? It's basically like telling someone "shut the fuck up". It's not a clever responsive, it doesn't address anything said, and it is rude. 

 ^

 

bruh switch to dark mode its at the bottom of this page

VPN Server Guide

Link to comment
Share on other sites

Link to post
Share on other sites

26 minutes ago, RockSolid1106 said:

Maybe try

bash <file name without ./>
-sh: vnodebypass.sh: command not found

I am in the correct directory, the script is in said directory, etc.

When I use "ls" there, I get:
vnodebypass.shvnodebypass2electricboogaloo.sh*
Complete with colors

I tried ./vnodebypass.sh again, same "no such file or directory"

 

EDIT: I’m an idiot dumbface and forgot the bash part of

@RockSolid1106’s suggestion. Progress! It gives me a different error now:

 

vnodebypass.sh: line 7:  syntax error newr unexpected token `else'
'nodebypass.sh: line 7: `else'

 

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

56 minutes ago, FakeKGB said:
-sh: vnodebypass.sh: command not found

I am in the correct directory, the script is in said directory, etc.

When I use "ls" there, I get:
vnodebypass.shvnodebypass2electricboogaloo.sh*
Complete with colors

I tried ./vnodebypass.sh again, same "no such file or directory"

 

EDIT: I’m an idiot dumbface and forgot the bash part of

@RockSolid1106’s suggestion. Progress! It gives me a different error now:

 

vnodebypass.sh: line 7:  syntax error newr unexpected token `else'
'nodebypass.sh: line 7: `else'

 

Try changing it to one of these and see if they make it work. 

#!/bin/bash
FILE=/Applications/vnodebypass.app/state.state
if [ -f "$FILE" ]
then
    vnodebypass -s
    vnodebypass -h
    rm "$FILE"
else 
    vnodebypass -r
    vnodebypass -R
    touch "$FILE"
fi

or 

#!/bin/bash
FILE=/Applications/vnodebypass.app/state.state
if [[ -f "$FILE" ]]
then
    vnodebypass -s
    vnodebypass -h
    rm "$FILE"
else 
    vnodebypass -r
    vnodebypass -R
    touch "$FILE"
fi

 

EDIT: also try entering in the script to the terminal line by line, it should let you do that. See if it still gives you the error like that

Edited by RONOTHAN##
Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, RONOTHAN## said:
#!/bin/bash
FILE=/Applications/vnodebypass.app/state.state
if [[ -f "$FILE" ]]
then
    vnodebypass -s
    vnodebypass -h
    rm "$FILE"
else 
    vnodebypass -r
    vnodebypass -R
    touc

 

8 hours ago, RONOTHAN## said:

Try changing it to one of these and see if they make it work. 

#!/bin/bash
FILE=/Applications/vnodebypass.app/state.state
if [ -f "$FILE" ]
then
    vnodebypass -s
    vnodebypass -h
    rm "$FILE"
else 
    vnodebypass -r
    vnodebypass -R
    touch "$FILE"
fi

or 

#!/bin/bash
FILE=/Applications/vnodebypass.app/state.state
if [[ -f "$FILE" ]]
then
    vnodebypass -s
    vnodebypass -h
    rm "$FILE"
else 
    vnodebypass -r
    vnodebypass -R
    touch "$FILE"
fi

 

EDIT: also try entering in the script to the terminal line by line, it should let you do that. See if it still gives you the error like that

The third  script works halfway - if I run it the first time it enables vnodebypass, but when I run it the second time it only says “./vnodebypass3.sh”.

I checked and it is creating and deleting state.state in the correct directory though.

Thanks for your help with this by the way!

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, FakeKGB said:

 

The third  script works halfway - if I run it the first time it enables vnodebypass, but when I run it the second time it only says “./vnodebypass3.sh”.

I checked and it is creating and deleting state.state in the correct directory though.

Thanks for your help with this by the way!

OK, so it sounds like iOS uses some odd version of the BASH shell. The first versions were the universally compatible ones, and the last one was the "only works with the really new stuff" ones. You can try installing the sh shell (the shell BASH is based on), editing the first line to "#!/bin/sh", and running it by typing this command:

sh ./vnodebypass.sh

 

Do note that I've been just guessing since that original script didn't work, since everything I've done with BASH scripting, including running that script myself on my own system (just by changing the vnodebypass commands to something else), says that script should work. 

 

That said, the fact that the file is deleting and creating itself makes this even weirder. It means the if statement is working, and thus it's running the commands to enable and disable the script. If they were misspelled, you would probably get a "command not found" type of error. Maybe try running it with the echo commands that were in my first message, just to eliminate vnodebypass as the issue? I'm kinda grasping at straws here, it should've been working for a while now. 

Link to comment
Share on other sites

Link to post
Share on other sites

25 minutes ago, RONOTHAN## said:

That said, the fact that the file is deleting and creating itself makes this even weirder. It means the if statement is working, and thus it's running the commands to enable and disable the script. If they were misspelled, you would probably get a "command not found" type of error. Maybe try running it with the echo commands that were in my first message, just to eliminate vnodebypass as the issue? I'm kinda grasping at straws here, it should've been working for a while now. 

I made a copy and changed it to the echo lines, and it does work properly that way, but as soon as I add the vnodebypass lines in it gives me the same "./vnodebypass3.sh" error.

I've made a post on r/jailbreak about using vnodebypass this way because maybe I'm missing something, will update ya.

 

EDIT:
I am a HUGE idiot dumbface. I forgot something about vnodebypass.

When vnodebypass is enabled, all of my jailbreak-installed things (except vnodebypass) no longer work, including the shell process (as it appears to be added functionality when jailbreaking, why would iOS need it)

What I've done in the past after the script fails to disable vnodebypass is use the app to disable it as it detects the state, and just for the heck of it ran the script again - and it ran the disable commands.

So the script is working, just my shell is blocked after vnodebypass is enabled.

This means I have to:

A. Find a way to exclude blocking the shell from vnodebypass

B. Install a separate shell elsewhere...? Not sure

 

EDIT #2:
I installed zsh and if I run the script with zsh it works fine in NewTerm 2.

I'm not sure how to flag Activator to use zsh though, perhaps I can tell the script to run with zsh? How would I do that? I tried changing #!/bin/bash to #!/bin/zsh at the top of the script but that didn't appear to change anything.

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

29 minutes ago, FakeKGB said:

I tried changing #!/bin/bash to #!/bin/zsh at the top of the script but that didn't appear to change anything.

That would've been my first recommendation.

 

After a quick google search to see how you run a script with activator, if this is how you run the script

https://coderedirect.com/questions/684783/ios-execute-shell-script-from-activator

then it's actually pretty easy to do. Change the "./bin/myscript" to "zsh vnodeactivator.sh"

 

If that's not how you do it, then how do you do it?

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, RONOTHAN## said:

If that's not how you do it, then how do you do it?

In my version of Activator at least, there's an option to "Build Action" and from there I have the option to do a "Custom command".

I typed in "zsh /var/mobile/Documents/vnodebypass/vnodebypass3echo.sh" and it just does nothing. I'll look into the "make a dummy app to run a script" option, thanks!

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×