New: XDA launches forum for app developers. Discuss coding, tools, marketing, and more.
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
Bytecode
Old
#1  
Bytecode's Avatar
Recognized Developer - OP
Thanks Meter 4369
Posts: 2,496
Join Date: Dec 2010
Location: /dev/null
Default I created a script for my rom. But..

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.
Bytecode - fourteen years-old experienced developer.

My devices:
  • LG-P500 (qcom msm7x27t, mdpi, codename: thunderg)
  • Xperia T (msm8x60a, xhdpi, codename: mint)



Quote:
I respect GPL and other people - you can find all my sources at github.com/BytecodeX
Quote:
I am a androidarmv6 contributor - helping old legacy devices get a better Android experience. https://github.com/androidarmv6
 
kpbotbot
Old
#2  
kpbotbot's Avatar
Senior Member
Thanks Meter 62
Posts: 419
Join Date: Dec 2010
Location: In an ark.
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 (:
‎( ) iPhone
( ) iPad
( ) iPad 2
( ) iPod Touch
(✔) iDon't have money
The Following User Says Thank You to kpbotbot For This Useful Post: [ Click to Expand ]
 
Bytecode
Old
#3  
Bytecode's Avatar
Recognized Developer - OP
Thanks Meter 4369
Posts: 2,496
Join Date: Dec 2010
Location: /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?
Bytecode - fourteen years-old experienced developer.

My devices:
  • LG-P500 (qcom msm7x27t, mdpi, codename: thunderg)
  • Xperia T (msm8x60a, xhdpi, codename: mint)



Quote:
I respect GPL and other people - you can find all my sources at github.com/BytecodeX
Quote:
I am a androidarmv6 contributor - helping old legacy devices get a better Android experience. https://github.com/androidarmv6
 
sarfaraz1989
Old
#4  
Senior Member
Thanks Meter 42
Posts: 566
Join Date: Jan 2011
Location: New Delhi
@kpbotbot ..i wanted to look at sed and your example just made it very easy
 
kpbotbot
Old
#5  
kpbotbot's Avatar
Senior Member
Thanks Meter 62
Posts: 419
Join Date: Dec 2010
Location: In an ark.
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
‎( ) iPhone
( ) iPad
( ) iPad 2
( ) iPod Touch
(✔) iDon't have money
 
Bytecode
Old
#6  
Bytecode's Avatar
Recognized Developer - OP
Thanks Meter 4369
Posts: 2,496
Join Date: Dec 2010
Location: /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.
Bytecode - fourteen years-old experienced developer.

My devices:
  • LG-P500 (qcom msm7x27t, mdpi, codename: thunderg)
  • Xperia T (msm8x60a, xhdpi, codename: mint)



Quote:
I respect GPL and other people - you can find all my sources at github.com/BytecodeX
Quote:
I am a androidarmv6 contributor - helping old legacy devices get a better Android experience. https://github.com/androidarmv6
 
kpbotbot
Old
#7  
kpbotbot's Avatar
Senior Member
Thanks Meter 62
Posts: 419
Join Date: Dec 2010
Location: In an ark.
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
‎( ) iPhone
( ) iPad
( ) iPad 2
( ) iPod Touch
(✔) iDon't have money
 
franciscofranco
Old
#8  
franciscofranco's Avatar
Recognized Developer
Thanks Meter 48963
Posts: 10,784
Join Date: Dec 2010
Location: Mountain View, CA

 
DONATE TO ME
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
Old
#9  
kpbotbot's Avatar
Senior Member
Thanks Meter 62
Posts: 419
Join Date: Dec 2010
Location: In an ark.
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
‎( ) iPhone
( ) iPad
( ) iPad 2
( ) iPod Touch
(✔) iDon't have money
 
franciscofranco
Old
#10  
franciscofranco's Avatar
Recognized Developer
Thanks Meter 48963
Posts: 10,784
Join Date: Dec 2010
Location: Mountain View, CA

 
DONATE TO ME
Quote:
Originally Posted by kpbotbot View Post
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.