I created a script for my rom. But..

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Hi to all guys i'm developing a new rom and i'd like to put an executable script in it. I'm not very goot at bash,but you can help me. Here it is:

Code:
    Welcome to openOptimus modding script!                    
     

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

read -p "Change boot animation" choice
read -p "Disable/enable Stagefright player" choice
read -p "Enable/disable Hardware acceleration" choice
read -p "Enable/disable Hardware acceleration" choice
read -p "Check Wi-Fi Tx-Power" choice

if test "$choice" == "1"
then
     goto bootanim
fi

if test "$choice" == "2"
then
     goto stagefright
fi

if test "$choice" == "3"
 then
      goto hwacc
 fi

if test "$choice" == "4"
 then
      echo You need to run this only if you have Wi-Fi on!
iwconfig wlan0
 fi

:bootanim
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 -p "Megatron boot animation" bootchoice
read -p "Android particles" bootchoice
read -p "CyanogenMod 7" bootchoice
read -p "Coin" bootchoice

if test "$bootchoice" == "1"
  then
       busybox cp /sdcard/openOptimus_resources/Megatron/bootanimation.zip /data/local
echo Boot animation copied.

if test "$bootchoice" == "2"
   then
        busybox cp /sdcard/openOptimus_resources/Particles/bootanimation.zip /data/local
echo Boot animation copied.

if test "$bootchoice" == "3"
   then
        busybox cp /sdcard/openOptimus_resources/CM7/bootanimation.zip /data/local
echo Boot animation copied.
  fi

if test "$bootchoice" == "4"
   then
        busybox cp /sdcard/openOptimus_resources/Coin/bootanimation.zip /data/local
echo Boot animation copied.
fi

:stagefright
        
Stagefright player enabler/disabler                                                    


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


read -p "Enable Stagefright player" stagefright
 read -p "Disable stagefright player" stagefright
  

if test "$stagefright" == "1"
    then
          busybox cp /sdcard/openOptimus_resources/Stagefright2/build.prop /system
 echo Stagefright player enabled.
fi

if test "$stagefright" == "2"
     then
          busybox cp /sdcard/openOptimus_resources/Stagefright2/build.prop /system
  echo Stagefright player disabled.
 fi

:hwacc
echo 
 echo               Hardware acceleration enabler/disabler    
                                            
 echo  WARNING:This disables/enables Hwacc,but enables stagefright   
 echo 
echo Please choose an option:
echo 1.Enable Hardware acceleration
echo 2.Disable Hardware acceleration

read -p "Enable Hardware acceleration" hwacc
  read -p "Disable Hardware acceleration" hwacc
  
if test "$hwacc" == "1"
     then
          busybox cp /sdcard/openOptimus_resources/Hwacc1/build.prop /system
  echo Hardware acceleration enabled.
 fi

if test "$hwacc" == "2"
      then
           busybox cp /sdcard/openOptimus_resources/Hwacc2/build.prop /system
   echo Hardware acceleration disabled.
  fi
It's all ok? Please answer me,in my last three topics nobody answered me.
 

kpbotbot

Senior Member
Dec 27, 2010
438
65
0
In an ark.
veryexistence.wordpress.com
Uhh, what exactly is the problem?

The only problem I see in this is that you use multiple build.prop files for enabling/disable stagefright and hardware acceleration.

My suggestion is you use sed, a stream editor. This way, you won't need copying files from the folder and may actually make the code easier to read.

This is how I use sed. It creates a backup of the file, searches for the string to be replaced, and then replaces it.

Code:
sed -i.bak 's/ro.media.enc.jpeg.quality=90/ro.media.enc.jpeg.quality=100/g' /system/build.prop
If you plan on doing this, read more about sed. I've kinda forgotten the syntax since I made this 15 days ago and never really used it again. And yes, that's how fast I forget stuff :)
 
  • Like
Reactions: sarfaraz1989

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Thanks kpbotbot ur da man of xda. So,there are no syntax problems in the script except the build.prop? Maybe i can use setprop to disable/enable hwacc/stagefright. I read about setprop in franciscofranco's tweaks topic. Can i use it?
 

kpbotbot

Senior Member
Dec 27, 2010
438
65
0
In an ark.
veryexistence.wordpress.com
Lol no I'm not.

I'm not entirely sure how bash handles input. I haven't given scripting much time yet despite the fact that I've been on linux for quite some time xD The logic is in the script though. Have you tested it?

Regarding the franciscofranco's scripts, of course you can use them :p
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
I'm trying it with setprop. BTW,i don't wanna piss you off guys but take a look in Optimus One General. Take a look at "APKManager not working" It's very important.
 

kpbotbot

Senior Member
Dec 27, 2010
438
65
0
In an ark.
veryexistence.wordpress.com
I don't have any idea what in the world is wrong with APKManager since I don't use or plan on using it. What do you need it for anyway? :)

By the way, had a look at bash scripting. Why does this have 4 read lines?
Code:
read -p "Change boot animation" choice
read -p "Disable/enable Stagefright player" choice
read -p "Enable/disable Hardware acceleration" choice
read -p "Enable/disable Hardware acceleration" choice
read -p "Check Wi-Fi Tx-Power" choice
 

franciscofranco

Recognized Developer
Dec 9, 2010
24,725
136,397
0
Carcavelos
I've had a quick look on your script. First of all DON'T USE GOTO's!!!

You have two "read -p "Enable/disable Hardware acceleration" choice".

Code:
echo You need to run this only if you have Wi-Fi on!
iwconfig wlan0
Why do you have iwconfig wlan0 lying there? If you don't have Wi-Fi on it will just simply output an error saying it's not on...
 

kpbotbot

Senior Member
Dec 27, 2010
438
65
0
In an ark.
veryexistence.wordpress.com
Use functions instead.

Try a little tutorial here (http://tldp.org/LDP/abs/html/functions.html) about functions. I didn't recommend using this a few minutes ago for some reason. Anyway, you may need to make a major rewrite to your script, but better readability and flow make it easier to maintain and trace errors.

I'm not sure if there are any other (or better) ways of doing this. Have a look at ruigui's script :)
 

franciscofranco

Recognized Developer
Dec 9, 2010
24,725
136,397
0
Carcavelos
Use functions instead.

Try a little tutorial here (http://tldp.org/LDP/abs/html/functions.html) about functions. I didn't recommend using this a few minutes ago for some reason. Anyway, you may need to make a major rewrite to your script, but better readability and flow make it easier to maintain and trace errors.

I'm not sure if there are any other (or better) ways of doing this. Have a look at ruigui's script :)
I agree, functions would be better than the way you're doing atm.
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Yea now i'm gonna take a look at ruigui's script.

Dudes i wanna ask you some:


  • When i cook my rom and change framework i get bootloop. This doesn't happen if i cook rom w/ original framework,or if i flash a zip that contains that particular framework.

    And,i downloaded black mms apk from void and ringnofade. When i put 'em in my rom they force close! Why? Do i need to change classes.dex?
.

EDIT:I taked a look at ruigui's script,but this didn't help me. Please fix my script.

Thanks guys.
 
Last edited:

kpbotbot

Senior Member
Dec 27, 2010
438
65
0
In an ark.
veryexistence.wordpress.com
I don't know most of bash's syntax, so you do it :p

Here's how you should do it:

  • Create the functions. 1 for bootanim changer, 1 for enabling of hardware acceleration, 1 for SF, and 1 for the other one I forgot
  • Make the choosing part (the one with the reads)
  • Call appropriate function depending on choice

If you come to think of it this is actually easier than gotos.

ciaox said:
Dudes i wanna ask you some:

* When i cook my rom and change framework i get bootloop. This doesn't happen if i cook rom w/ original framework,or if i flash a zip that contains that particular framework.
Because you're not supposed to replace framework-res.apk because on the first boot, android checks signatures. It will get into a bootloop when it fails on that. (Experts please follow this up. I'm not sure).

Just replace the stuff inside the framework-res.apk with the stuff in the themed framework so as not to break signing. Just open framework-res.apk with an archiving tool and drag stuff onto it replacing the previous stuff. DO NOT EXTRACT :D

At least that's how I avoid bootloops. Try asking paolo how he did some of the stuff :)

EDIT: Also, do not resign framework-res.apk. You shouldn't sign it with a testkey xD
 
  • Like
Reactions: Bytecode

franciscofranco

Recognized Developer
Dec 9, 2010
24,725
136,397
0
Carcavelos
EDIT:I taked a look at ruigui's script,but this didn't help me. Please fix my script.
We ain't gonna fix your script. If you come here with valuable questions after you did your research, then we can help and answer, if you come here asking for us to fix "your" work, sorry dude, ain't going to happen.

And about gotos, anyone that programmed anything in his/her life will know that gotos = problems and possible security holes.
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
We ain't gonna fix your script. If you come here with valuable questions after you did your research, then we can help and answer, if you come here asking for us to fix "your" work, sorry dude, ain't going to happen.

And about gotos, anyone that programmed anything in his/her life will know that gotos = problems and possible security holes.
Man i'm sorry about dis,i will take a look at kpbotbot's script. Many thanks to everyone. Please keep thread open cuz i'm gonna need you guys..
oh man i get this. I can now call functions,i will let u know
Many thanks :)

[OT] I wanna integrate dspmanager in my rom but it doesn't work,and if i put libaudioflinger.so from cm7 by mik i can't hear anything. [/OT]
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Yeah guys just rewrited my script! Now it must be ok! Check it out,i think it's OK.

Code:
#!/system/bin/sh   

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


hwon(){
  cp /sdcard/openOptimus_resources/Hwacc1/build.prop /system
  echo Hardware acceleration enabled.
 fi
}

hwoff(){
  cp /sdcard/openOptimus_resources/Hwacc2/build.prop /system
  echo Hardware acceleration disabled.
 fi
}

sfon(){
cp /sdcard/openOptimus_resources/Stagefright1/build.prop /system
echo Stagefright player enabled.
fi
}

sfoff(){
cp /sdcard/openOptimus_resources/Stagefright2/build.prop /system
echo Stagefright player disabled.
fi
}

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(){
echo You need to run this only if you have Wi-Fi on!
iwconfig wlan0
fi
}

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  WARNING:This disables/enables Hwacc,but enables stagefright   
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
}

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

read  boot
read  sf
read  hw
read  tx

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
 

ungaze

Senior Member
Jul 27, 2010
401
158
0
manila
you called you hardware acceleration disabler/enabler as "sf" instead of "hw".

I think you should call a case loop instead of this:
Code:
read  boot
read  sf
read  hw
read  tx

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

if test "$sf" == "2"
then sf
fi. . . . . . .
which should be something like this:
Code:
read $option

case $option in
1)
	boot
;;
2)
	sf
;;
3)
	hw
;;
4)
	tx
;;
esac
or something like that. btw, what happens after you're finished with one tweak, let's say disabling/enabling stagefright? I think you should call you main menu as another function and just call it at the bottom of you script. not an expert, just giving some inputs.
 
Last edited:

kpbotbot

Senior Member
Dec 27, 2010
438
65
0
In an ark.
veryexistence.wordpress.com
Code:
hwon(){
  cp /sdcard/openOptimus_resources/Hwacc1/build.prop /system
  echo Hardware acceleration enabled.
 fi
}

hwoff(){
  cp /sdcard/openOptimus_resources/Hwacc2/build.prop /system
  echo Hardware acceleration disabled.
 fi
}

sfon(){
cp /sdcard/openOptimus_resources/Stagefright1/build.prop /system
echo Stagefright player enabled.
fi
}

sfoff(){
cp /sdcard/openOptimus_resources/Stagefright2/build.prop /system
echo Stagefright player disabled.
fi
}
What happened to setprop? :p Using multiple build.prop files will make it even more complicated. And if someone made modifications to their build.prop files then used this, they would lose their changes.
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Code:
hwon(){
  cp /sdcard/openOptimus_resources/Hwacc1/build.prop /system
  echo Hardware acceleration enabled.
 fi
}

hwoff(){
  cp /sdcard/openOptimus_resources/Hwacc2/build.prop /system
  echo Hardware acceleration disabled.
 fi
}

sfon(){
cp /sdcard/openOptimus_resources/Stagefright1/build.prop /system
echo Stagefright player enabled.
fi
}

sfoff(){
cp /sdcard/openOptimus_resources/Stagefright2/build.prop /system
echo Stagefright player disabled.
fi
}
What happened to setprop? :p Using multiple build.prop files will make it even more complicated. And if someone made modifications to their build.prop files then used this, they would lose their changes.
Oh yeah forgot this..will update script. Thx to ungaze for the tip i'm gonna add a main_menu function. And i will use case.
 

Bytecode

Inactive Recognized Developer
Dec 30, 2010
2,684
4,487
0
22
/dev/null
Ok i rewrited script again:
Code:
#!/system/bin/bash   

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

exit(){
echo Goodbye! And hope u will enjoy openOptimus (:
 fi
}

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

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

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.
fi
}

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.
fi
}

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(){
echo You need to run this only if you have Wi-Fi on!
iwconfig wlan0
fi
}

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
}
 
Last edited: