I created a script for my rom. But..

kpbotbot

Senior Member
Dec 27, 2010
438
65
0
In an ark.
veryexistence.wordpress.com
Better, but:

- You don't need "fi" to end functions. It's for if statements.
- The exit function will not quit the script. Include the "exit" command or equivalent.
- This one:
Code:
tx(){
echo You need to run this only if you have Wi-Fi on!
iwconfig wlan0
fi
}
This will execute whether wifi is enabled or not. Place the warning on the main menu instead of the function where the command is executed :)

Also, do you have linux installed even on just a VM? You can try out the script with dummy outputs (just to test the script logic) in the terminal. Just replace the bash path with the proper one. (I use /system/bin/sh for phone testing and /bin/bash for PC)
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Better, but:

- The exit function will not quit the script. Include the "exit" command or equivalent.

Also, do you have linux installed even on just a VM? You can try out the script with dummy outputs (just to test the script logic) in the terminal. Just replace the bash path with the proper one. (I use /system/bin/sh for phone testing and /bin/bash for PC)
Man I just don't understand. How can I exit script?

And BTW thanks for the tip,I have linux installed on an External hard disk. My windows was running too slow,so I decided to put a windows vm on linux. I only have 512mb of ram but all works flawlessly :)

Sent from my LG Optimus One P500 using Tapatalk
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
When i run it from Linux,it says nothing. When i run it from Phone,it says:
Code:
sh .Tweaks.sh: /system/bin/sh: bad interpreter : Permission denied
What can i do? BTW I Corrected some errors,here's the script:
Code:
#! /system/bin/sh   

##########################################################################
# openOptimus tweaks v2 beta 2                                           #
# Script created by ciaox,only for openOptimus.                          #
# Copyright (c) ciaox 2011.                                              #
##########################################################################

exit(){
echo Goodbye! And hope you will enjoy openOptimus.
exit
}

hwon(){
setprop debug.sf.hw=1
  echo Hardware acceleration enabled.
}

hwoff(){
setprop debug.sf.hw=0
  echo Hardware acceleration disabled.
}

sfon(){
setprop media.stagefright.enable-player=true
setprop media.stagefright.enable-meta=true
setprop media.stagefright.enable-scan=true
setprop media.stagefright.enable-http=true
echo Stagefright player enabled.
}

sfoff(){
setprop media.stagefright.enable-player=false
setprop media.stagefright.enable-meta=false
setprop media.stagefright.enable-scan=false
setprop media.stagefright.enable-http=false
echo Stagefright player disabled.
}

megatron(){
cp /sdcard/openOptimus_resources/Megatron/bootanimation.zip /data/local
echo Boot animation copied.
}

particles(){
cp /sdcard/openOptimus_resources/Particles/bootanimation.zip /data/local
echo Boot animation copied.
}

cyan7(){
cp /sdcard/openOptimus_resources/CM7/bootanimation.zip /data/local
echo Boot animation copied.
}

coin(){
cp /sdcard/openOptimus_resources/Coin/bootanimation.zip /data/local
echo Boot animation copied.
}

boot(){
echo *********************************************************
echo *                              Boot animation changer   *
echo *********************************************************
echo Please choose one:
echo 1.Megatron boot animation
echo 2.Android particles
echo 3.CyanogenMod 7
echo 4.Coin
read megatron
read particles
read cyan7
read coin

if test "$megatron" == "1"
    then megatron
fi

if test "$particles" == "2"
    then particles
fi

if test "$cyan7" == "3"
    then cyan7
fi

if test "$coin" == "4"
    then coin
fi


}

tx(){
iwconfig wlan0
}

sf(){
echo *********************************************************
echo *stagefright player enabler/disabler                    *
echo *********************************************************                                                 


echo Please choose an option:
echo 1.Enable Stagefright player
echo 2.Disable stagefright player
read sfon
read sfoff

if test "$sfon" == "1"
    then sfon
fi

if test "$sfoff" == "2"
    then sfoff
fi
}

sf(){
echo  *********************************************************
echo  *               Hardware acceleration enabler/disabler  *   
echo  *********************************************************                                               
echo 
echo Please choose an option:
echo 1.Enable Hardware acceleration
echo 2.Disable Hardware acceleration
read hwon
read hwoff

if test "$hwon" == "1"
    then hwon
fi


if test "$hwoff" == "2"
    then hwoff
fi
}

main_menu(){
echo *********************************************************   
echo * Welcome to openOptimus modding script!                *
echo *********************************************************                  
     

echo Choose an option:
echo 1.Change boot animation
echo 2.Disable/enable Stagefright player
echo 3.Enable/disable Hardware acceleration
echo 4.Check Wi-Fi Tx-Power
echo 5.Exit

read  boot
read  sf
read  hw
read  tx
read  exit

if test "$boot" == "1"
then boot
fi

if test "$sf" == "2"
then sf
fi

if test "$hw" == "3"
then hw
 fi

if test "$tx" == "4"
then tx
fi

if test "$exit" == "5"
then exit
fi
}
I'm going crazy,what can i do?
 
Last edited:

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Just moved to /system/bin and mounted it r/w with root explorer. I did su,then i did a chmod 755 for the script and ran it. Now it's a bit different:Script doesn't start even from phone.
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Ok,i rewrited again script but still nothing happens when i run it. Here's what i get:

Code:
export PATH=/data/local/bin:$PATH
sh-3.2$ su
sh-3.2# cd /system/bin
sh-3.2# chmod 755 TweaksV2.sh
sh-3.2# ./Tweaks.sh
sh-3.2#
You see? When i run it nothing happens.

So,here's the new script:
Code:
#! /system/bin/sh   

##########################################################################
# openOptimus tweaks v2 beta 3                                           #
# Script created by ciaox,only for openOptimus.                          #
##########################################################################


reboot(){
echo Phone is rebooting.. applying changes.
reboot
}

heap48(){
setprop dalvik.vm.heapsize=48m
echo Now Heapsize is 48m.
}

heap32(){
setprop dalvik.vm.heapsize=32m
echo Now Heapsize is 32m.
}

heap24(){
setprop dalvik.vm.heapsize=24m
echo Now Heapsize is 24m.
}

heapsize(){
echo *********************************************************
echo *                              Heap Size changer        *
echo *********************************************************
echo Please choose an option:
echo 1.Raise Heapsize to 48m
echo 2.Decrease Heapsize to 32m
echo 3.Decrease Heapsize to 24m
read heap48
read heap32
read heap24

if test "$heap48" == "1"
    then heap48
fi

if test "$heap32" == "2"
    then heap32
fi

if test "$heap24" == "3"
    then heap24
fi
}

exit(){
echo Goodbye! And hope you will enjoy openOptimus.
exit
}

hwon(){
setprop debug.sf.hw=1
  echo Hardware acceleration enabled.
}

hwoff(){
setprop debug.sf.hw=0
  echo Hardware acceleration disabled.
}

sfon(){
setprop media.stagefright.enable-player=true
setprop media.stagefright.enable-meta=true
setprop media.stagefright.enable-scan=true
setprop media.stagefright.enable-http=true
echo Stagefright player enabled.
}

sfoff(){
setprop media.stagefright.enable-player=false
setprop media.stagefright.enable-meta=false
setprop media.stagefright.enable-scan=false
setprop media.stagefright.enable-http=false
echo Stagefright player disabled.
}

megatron(){
cp /sdcard/openOptimus_resources/Megatron/bootanimation.zip /data/local
echo Boot animation copied.
}

particles(){
cp /sdcard/openOptimus_resources/Particles/bootanimation.zip /data/local
echo Boot animation copied.
}

cyan7(){
cp /sdcard/openOptimus_resources/CM7/bootanimation.zip /data/local
echo Boot animation copied.
}

coin(){
cp /sdcard/openOptimus_resources/Coin/bootanimation.zip /data/local
echo Boot animation copied.
}

boot(){
echo *********************************************************
echo *                              Boot animation changer   *
echo *********************************************************
echo Please choose one:
echo 1.Megatron boot animation
echo 2.Android particles
echo 3.CyanogenMod 7
echo 4.Coin
read megatron
read particles
read cyan7
read coin

if test "$megatron" == "1"
    then megatron
fi

if test "$particles" == "2"
    then particles
fi

if test "$cyan7" == "3"
    then cyan7
fi

if test "$coin" == "4"
    then coin
fi
}

tx(){
iwconfig wlan0
}

sf(){
echo *********************************************************
echo *stagefright player enabler/disabler                    *
echo *********************************************************                                                 


echo Please choose an option:
echo 1.Enable Stagefright player
echo 2.Disable stagefright player
read sfon
read sfoff

if test "$sfon" == "1"
    then sfon
fi

if test "$sfoff" == "2"
    then sfoff
fi
}

sf(){
echo  *********************************************************
echo  *               Hardware acceleration enabler/disabler  *   
echo  *********************************************************                                               
echo 
echo Please choose an option:
echo 1.Enable Hardware acceleration
echo 2.Disable Hardware acceleration
read hwon
read hwoff

if test "$hwon" == "1"
    then hwon
fi


if test "$hwoff" == "2"
    then hwoff
fi
}

main_menu(){
echo *********************************************************   
echo * Welcome to openOptimus modding script!                *
echo *********************************************************                  
     

echo Choose an option:
echo 1.Change boot animation
echo 2.Disable/enable Stagefright player
echo 3.Enable/disable Hardware acceleration
echo 4.Check Wi-Fi Tx-Power,run only with Wifi On.
echo 5.Exit
echo 6.Reboot

read  boot
read  sf
read  hw
read  tx
read  exit
read  reboot

if test "$boot" == "1"
then boot
fi

if test "$sf" == "2"
then sf
fi

if test "$hw" == "3"
then hw
 fi

if test "$tx" == "4"
then tx
fi

if test "$exit" == "5"
then exit
fi

if test "$reboot" == "6"
then reboot
fi
}
I can't understand. If anyone want to try it i attached a zip with my script inside.
 

Attachments

Last edited:

ungaze

Senior Member
Jul 27, 2010
401
158
0
manila
I hope your still up, I think you didn't call your "main menu" function at all.

So just add a line at the bottom to call your main menu

Just add the
Code:
main_menu
at the bottom-most part of your script.
-------

Another thing, if its in bin try removing the "./" part and just type "tweaks"
 
Last edited:

ungaze

Senior Member
Jul 27, 2010
401
158
0
manila
http://www.youtube.com/watch?v=ByH3-t2kX54 i added "main_menu" at the bottom of the script.
I really don't get why you need the multiple "read" command on your main menu. As I've mentioned before, I think its better to use the "case" loop, but if you really want to use the "If fi" loop, I think just one read command and the use of elif is enough.

Code:
One common case of nested conditionals is used to check for more than two possible alternatives. For example, you might have

     #if X == 1
     ...
     #else /* X != 1 */
     #if X == 2
     ...
     #else /* X != 2 */
     ...
     #endif /* X != 2 */
     #endif /* X != 1 */
Another conditional directive, `#elif', allows this to be abbreviated as follows:

     #if X == 1
     ...
     #elif X == 2
     ...
     #else /* X != 2 and X != 1*/
     ...
     #endif /* X != 2 and X != 1*/
`#elif' stands for “else if”. Like `#else', it goes in the middle of a conditional group and subdivides it; it does not require a matching `#endif' of its own. Like `#if', the `#elif' directive includes an expression to be tested. The text following the `#elif' is processed only if the original `#if'-condition failed and the `#elif' condition succeeds.

More than one `#elif' can go in the same conditional group. Then the text after each `#elif' is processed only if the `#elif' condition succeeds after the original `#if' and all previous `#elif' directives within it have failed.

`#else' is allowed after any number of `#elif' directives, but `#elif' may not follow `#else'.

BTW, what happens if you choose option 1?
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Just rewrited script,now uses case. Here it is:
Code:
#! /system/bin/sh 

##########################################################################
# openOptimus tweaks v2 beta 4,now uses case                             #
# Script created by ciaox,only for openOptimus.                          #
##########################################################################


reboot(){
echo Phone is rebooting.. applying changes.
reboot
}

heap48(){
setprop dalvik.vm.heapsize=48m
echo Now Heapsize is 48m.
}

heap32(){
setprop dalvik.vm.heapsize=32m
echo Now Heapsize is 32m.
}

heap24(){
setprop dalvik.vm.heapsize=32m
echo Now Heapsize is 32m.
}

heapsize(){
echo *********************************************************
echo *                              Heap Size changer        *
echo *********************************************************
echo Please choose an option:
echo 1.Raise Heapsize to 48m
echo 2.Decrease Heapsize to 32m
echo 3.Decrease Heapsize to 24m
    read $heap48
        case $heap48 in
        1)
            heap48
        ;;
        2)
            heap32
        ;;
        3)
            heap24
        ;;
        esac 

exit(){
echo Goodbye! And hope you will enjoy openOptimus.
exit
}

hwon(){
setprop debug.sf.hw=1
  echo Hardware acceleration enabled.
}

hwoff(){
setprop debug.sf.hw=0
  echo Hardware acceleration disabled.
}

sfon(){
setprop media.stagefright.enable-player=true
setprop media.stagefright.enable-meta=true
setprop media.stagefright.enable-scan=true
setprop media.stagefright.enable-http=true
echo Stagefright player enabled.
}

sfoff(){
setprop media.stagefright.enable-player=false
setprop media.stagefright.enable-meta=false
setprop media.stagefright.enable-scan=false
setprop media.stagefright.enable-http=false
echo Stagefright player disabled.
}

megatron(){
cp /sdcard/openOptimus_resources/Megatron/bootanimation.zip /data/local
echo Boot animation copied.
}

particles(){
cp /sdcard/openOptimus_resources/Particles/bootanimation.zip /data/local
echo Boot animation copied.
}

cyan7(){
cp /sdcard/openOptimus_resources/CM7/bootanimation.zip /data/local
echo Boot animation copied.
}

coin(){
cp /sdcard/openOptimus_resources/Coin/bootanimation.zip /data/local
echo Boot animation copied.
}

boot(){
echo *********************************************************
echo *                              Boot animation changer   *
echo *********************************************************
echo Please choose one:
echo 1.Megatron boot animation
echo 2.Android particles
echo 3.CyanogenMod 7
echo 4.Coin
    read $megatron
        case $megatron in
        1)
            megatron
        ;;
        2)
            particles
        ;;
        3)
            cyan7
        ;; 
        4)
            coin
        esac 

tx(){
iwconfig wlan0
}

sf(){
echo *********************************************************
echo *Stagefright player enabler/disabler                    *
echo *********************************************************                                                 


echo Please choose an option:
echo 1.Enable Stagefright player
echo 2.Disable stagefright player
    read $sfon
        case $sfon in
        1)
            sfon
        ;;
        2)
            sfoff
        esac 


hw(){
echo  *********************************************************
echo  *               Hardware acceleration enabler/disabler  *   
echo  *********************************************************                                               
echo 
echo Please choose an option:
echo 1.Enable Hardware acceleration
echo 2.Disable Hardware acceleration

    read $hwon
        case $sfon in
        1)
            hwon
        ;;
        2)
            hwoff
        esac 

main_menu(){
echo *********************************************************   
echo * Welcome to openOptimus modding script!                *
echo *********************************************************                  
     

echo Choose an option:
echo 1.Change boot animation
echo 2.Disable/enable Stagefright player
echo 3.Enable/disable Hardware acceleration
echo 4.Check Wi-Fi Tx-Power,run only with Wifi On.
echo 5.Exit
echo 6.Reboot

    read $boot
        case $boot in
        1)
            boot
        ;;
        2)
            sf
        ;;
        3)
            hw
        ;; 
        4)
            tx
        ;; 
        5)
            exit
        ;; 
        6)
            reboot
        esac 
main_menu
But it gives me syntax error on 206th line. It sez:
Code:
Line 206:syntax error:unexpected end of file
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Ok i did not close some functions. Now that is fixed,it still gives me errors(i tried it only from pc). It lists all my files in the folder where TweaksV2 is executed,and if i choose an option script quits.
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Ok,problem solved. Now i'm trying it on my phone,but when i choose an option it quits. I think it's a problem of case loop. Can anyone help me with this case?
 

ungaze

Senior Member
Jul 27, 2010
401
158
0
manila
could you update us on what your script looks like now? Lot of unclosed blocks on your script up there which you have probably corrected by now.

and this:
Code:
read $boot
should be like this:
Code:
read boot
and when asking for an input with only 2 possible answers, if-fi loop should fit the job perfectly rather than the case loop, as such on you on and off functions.
 
Last edited:
  • Like
Reactions: Bytecode

ruigui

Senior Member
Oct 11, 2010
54
23
0
Man what a mess you are making.
Start with something simple. When it works, continue with your work. It's much easier to learn and correct mistakes....

Take a look at this script. It doesn't do nothing, but just try to understand it and then make your own. I didn't try it but it should be ok. It's based on my script for tweaks.

Code:
#! /system/bin/sh

key ()
{
echo "=========================="
echo "Press Enter to continue..."
read opt
}

error ()
{
echo "wrong option"
key
}

#############
### menus ###
#############

menu_main ()
{
clear
echo "1 - testing option 1"
echo "2 - testing option 2"
echo
echo "q - quit"
echo "=================="
echo -n "enter your option: "
read opt
clear
}

test_opt_1 ()
{
while :
do
	clear
	echo "testing 1"
	echo "1- opt 1.1"
	echo "2- opt 1.2"
	echo
	echo "b - back..."
	echo "=================="
	echo -n "enter your option: "
	read opt
	clear

	case $opt in
	1)
		echo "you have chosen 1.1"
		key
	;;
	2)
		echo "you have chosen 1.2"
		key
	;;
	b)
		break
	;;
	*)
		error
	;;
	esac
done
}

test_opt_2 ()
{
while :
do
	clear
	echo "testing 2"
	echo "1- opt 2.1"
	echo "2- opt 2.2"
	echo
	echo "b - back..."
	echo "=================="
	echo -n "enter your option: "
	read opt
	clear

	case $opt in
	1)
		echo "you have chosen 2.1"
		key
	;;
	2)
		echo "you have chosen 2.2"
		key
	;;
	b)
		break
	;;
	*)
		error
	;;
	esac
done
}

####################
### main program ###
####################

while :
do
	menu_main

	case $opt in
	1)
		test_opt_1
	;;
	2)
		test_opt_2
	;;
	q)
		clear
		exit
	;;
	*)
		error
	;;
	esac
done