# [question] how to copy individual files with updater-script lang



## PrimeDirective (Dec 31, 2011)

I'd like to make a script to copy my swype user keyboard to the SDcard before a ROM install. i can only find commands to copy files from a flashable zip though.

after this i'd like to make an init.d script that checks for the installed user keyboard on startup and if it's not present, checks for it on the SDcard and copies it, chown, and finish boot. if neither are present init.d does nothing.


----------



## blaineevans (Jul 11, 2011)

Not to stray off topic (help this guy first), but is it possible to delete individual apps from system via an updater script?

Sent from my Galaxy Nexus using Tapatalk 2


----------



## yarly (Jun 22, 2011)

blaineevans said:


> Not to stray off topic (help this guy first), but is it possible to delete individual apps from system via an updater script?
> 
> Sent from my Galaxy Nexus using Tapatalk 2


you can use package manager on the command line to do that in terminal emulator or adb shell.

type pm and it will show you usage.

Tutorial I wrote on how to do it a while ago

http://rootzwiki.com...ackage +manager

adb uninstall may also work, but haven't verified.

Also you can access the shell (and thus, shell scripts or bash if you have it in the ROM) if you really wanted to while in recovery so yes, it would be possible (and also access adb from recovery). That would let you do whatever you want like moving files, etc.

Also: http://www.londatiga...te-zip-package/

Offtopic, but that's a hideous avatar the OP has, lol.


----------



## PrimeDirective (Dec 31, 2011)

yarly said:


> you can use package manager on the command line to do that in terminal emulator or adb shell.
> 
> type pm and it will show you usage.
> 
> ...


haha i know. the years haven't been kind to ariel (sp?)


----------



## blaineevans (Jul 11, 2011)

yarly said:


> you can use package manager on the command line to do that in terminal emulator or adb shell.
> 
> type pm and it will show you usage.
> 
> ...


As soon as I get off I'll be doing some reading, thanks for the info yar.

Goal here - I always clean up a rom update.zip before flashing (removing apps and media I don't use), well with nightlies its become cumbersome to do that constantly when not near a PC (and being impatient).

I'd like to flash rom, flash gapps, flash kernel, flash script to clean up to my liking, reboot.

Sent from my Galaxy Nexus using Tapatalk 2


----------



## trparky (Sep 3, 2011)

There is the run_program() function that allows you to run binaries during the install script.

So you could potentially do this...
mount("ext4", "EMMC", "/dev/block/platform/omap/omap_hsmmc.0/by-name/system", "/system");
run_program("busybox", "cp", "/system/path/to/apk/file", "/path/to/sdcard");


----------



## sonicxml (Oct 1, 2011)

blaineevans said:


> Not to stray off topic (help this guy first), but is it possible to delete individual apps from system via an updater script?
> 
> Sent from my Galaxy Nexus using Tapatalk 2


are you just talking about the 
delete("/system/app/whatever.apk");
command?


----------



## blaineevans (Jul 11, 2011)

sonicxml said:


> are you just talking about the
> delete("/system/app/whatever.apk");
> command?


Yes, sir. Wasn't sure what the command was/how to implement it. Haven't had a chance to follow up with this yet, was in the garage all night with my car in the air unfortunately. But I'm pretty stoked to get some written, allowing me to flash things a lot faster.


----------



## sonicxml (Oct 1, 2011)

PrimeDirective said:


> Yes, sir. Wasn't sure what the command was/how to implement it. Haven't had a chance to follow up with this yet, was in the garage all night with my car in the air unfortunately. But I'm pretty stoked to get some written, allowing me to flash things a lot faster.


If you need any other help just ask


----------



## blaineevans (Jul 11, 2011)

Just to continue this a bit.. Is there a way of telling whether an app needs a lib or any other dependency ro funcion?

Example: With the help of Yarly and Sonicxml I've created an update-script to clean up a ROM after flashing, I'd like to pre-install RootExplorer before bootup after a fresh wipe. I know how to do this, but..

1) Will the market recognize my (paid) license?
2) Would I need just the .apk? (And how can I tell if that's all that's needed for any app?)


----------



## PrimeDirective (Dec 31, 2011)

blaineevans said:


> Just to continue this a bit.. Is there a way of telling whether an app needs a lib or any other dependency ro funcion?


I'd be interested in this as well for my own custom builds.

@blaineevans i found this to help you research
http://developer.android.com/reference/packages.html

also you can type adb shell pm list packages -f in command prompt.


----------



## blaineevans (Jul 11, 2011)

PrimeDirective said:


> I'd be interested in this as well for my own custom builds.
> 
> @blaineevans i found this to help you research
> http://developer.and...e/packages.html
> ...


So far I've lucked out and nothing seems to have needed a dependency.

I tried looking through the package manager before, but nothing relevant to dependencies is displayed as far as I can tell.


----------



## PrimeDirective (Dec 31, 2011)

trparky said:


> There is the run_program() function that allows you to run binaries during the install script.
> 
> So you could potentially do this...
> mount("ext4", "EMMC", "/dev/block/platform/omap/omap_hsmmc.0/by-name/system", "/system");
> run_program("busybox", "cp", "/system/path/to/apk/file", "/path/to/sdcard");


wouldn't you need to mount the SDcard too? and i could just reverse the paths at the end of the script to copy back right?


----------



## yarly (Jun 22, 2011)

blaineevans said:


> Just to continue this a bit.. Is there a way of telling whether an app needs a lib or any other dependency ro funcion?
> 
> Example: With the help of Yarly and Sonicxml I've created an update-script to clean up a ROM after flashing, I'd like to pre-install RootExplorer before bootup after a fresh wipe. I know how to do this, but..
> 
> ...


1) Most likely, yes
2) Yes. If you wanted data (/data/data/) you would have to back that up separately).

Really the best way to do most of this is put it all in a shell script and run it, after making sure you installed busybox first. Then you can directly mount stuff as you normally would and use shell commands directly instead of dealing with the updater commands unless needed.

If you're not experienced at creating shell scripts, intellij idea ide has a free third party plugin that helps you to write them by doing syntax checking, code completion, refactoring, etc. Community edition of intellij is free.

Good tutorial series on learning the basics of how to use the command line: http://cli.learncode...rdway.org/book/


----------



## blaineevans (Jul 11, 2011)

yarly said:


> 1) Most likely, yes
> 2) Yes. If you wanted data (/data/data/) you would have to back that up separately).
> 
> Really the best way to do most of this is put it all in a shell script and run it, after making sure you installed busybox first. Then you can directly mount stuff as you normally would and use shell commands directly instead of dealing with the updater commands unless needed.
> ...


One thing at a time here yarly, haha. No, I'll look into here later today. I was just stoked to get my updater-script working (sonic basically walked me through it, lol), haven't looked at code for about 10 years.. and even then it was just CSS/XHTML and some PHP.

Unfortunately any time I add an app to the updater zip and try and set permissions in the script I break it. Haven't had more than a couple minutes to look into it though so the learning process is slow. (With a 2 year old I'm lucky to grab even an hour to work on other shit, lol.)

Thanks for the info though.

Sent from my Galaxy Nexus using Tapatalk 2


----------



## yarly (Jun 22, 2011)

blaineevans said:


> One thing at a time here yarly, haha. No, I'll look into here later today. I was just stoked to get my updater-script working (sonic basically walked me through it, lol), haven't looked at code for about 10 years.. and even then it was just CSS/XHTML and some PHP.
> 
> Unfortunately any time I add an app to the updater zip and try and set permissions in the script I break it. Haven't had more than a couple minutes to look into it though so the learning process is slow. (With a 2 year old I'm lucky to grab even an hour to work on other shit, lol.)
> 
> ...


Could you paste exactly what you were doing that caused the error? Also I'm generally on IRC freenode somewhere using "yareally" like probably #android-dev. Usually I'm not paying attention to it though and it's set to be on even when I'm not here, but eventually I will see it.


----------



## blaineevans (Jul 11, 2011)

yarly said:


> Could you paste exactly what you were doing that caused the error? Also I'm generally on IRC freenode somewhere using "yareally" like probably #android-dev. Usually I'm not paying attention to it though and it's set to be on even when I'm not here, but eventually I will see it.


I'm not at home and for some reason the .zip isn't on my SD. But basically, I'm deleting several (in the range of 50) apps after a fresh flash, wiping and adding media. This all works just fine. But when I pull the RootExplorer.apk out of /data/app and add it to /system/app in the update.zip, then run..

```
set_perm_recursive(0, 0, 0755, 0644, "/system/app");
```
 ..something breaks and the .zip fails.

The only things changed are the structure of /system in the .zip (adding an app folder), and that single line in the script.

Sent from my Galaxy Nexus using Tapatalk 2


----------



## yarly (Jun 22, 2011)

set_perm_recursive 0 0 0755 0644 SYSTEM:app

should be the command you are looking for (typed just like that ↑)

see random pastebin example I found http://pastebin.com/VjdTstmG


----------



## PrimeDirective (Dec 31, 2011)

i'm still not getting any files to copy when i run the install script. here is what i have. any thoughts? suggestions to try?

[background=rgb(245, 245, 245)]ui_print("backing up dictionaries");[/background]
[background=rgb(245, 245, 245)]mount("ext4", "EMMC", "/dev/block/platform/omap/omap_hsmmc.0/by-name/system", "/data");[/background]
[background=rgb(245, 245, 245)]run_program("busybox", "cp", "/data/data/com.swype.android.inputmethod/swypedata/udb/UserData.udb", "/sdcard/UserData.udb"); [/background]
[background=rgb(245, 245, 245)]unmount("/data");[/background]

[background=rgb(245, 245, 245)]*automated wiping script here*[/background]
[background=rgb(245, 245, 245)]*ROM install script here*[/background]

[background=rgb(245, 245, 245)]ui_print("installing user dictionary");[/background]
[background=rgb(245, 245, 245)]mount("ext4", "EMMC", "/dev/block/platform/omap/omap_hsmmc.0/by-name/system", "/data");[/background]
[background=rgb(245, 245, 245)]run_program("busybox", "cp", "/sdcard/UserData.udb", "/data/data/com.swype.android.inputmethod/swypedata/udb/UserData.udb");[/background]
[background=rgb(245, 245, 245)]unmount("/data");[/background]

[background=rgb(245, 245, 245)]also, i noticed in the pastebin example that O RLY put... he called to remove journalism during the install script??? what is the purpose of this? i thought it was an init.d tweak to improve I/O[/background]


----------



## yarly (Jun 22, 2011)

I would just ignore my paste. It's just going to confuse more than I thought.

You should really just do most of the stuff as a shell script as possible

you can replace your backup with http://pastie.org/pr...kj9l4p0yun2kp7q

and then tweak it a bit to do the restore

Then just do


```
run_program("PACKAGE:backup-swype.sh");
```
instead before and after you do the commands to do your reformat and rom install

shell scripts are much easier to work with imho.

*obviously make sure the scripts back up your data before you actually do the whole process. Not responsible for the implications of losing your data if you don't test first


----------



## PrimeDirective (Dec 31, 2011)

thanks a million man. that makes this whole thing a lot easier for me to try out. I have an 00oninstall init.d file i can put it in that reindexes and defrags sqlite before deleting itself.. that would be the perfect place for this.

EDIT: the /data and /sdcard locations are switched... this would be the part to restore the user dictionary file to the SD card. the first part is copying it from the install script (updater-script) using edify. i'll just switch them around and see what happens


----------



## Gunthermic (Nov 3, 2011)

I am very interested. Did it work? if so please post your new script?


----------



## PrimeDirective (Dec 31, 2011)

Gunthermic said:


> I am very interested. Did it work? if so please post your new script?


#beginning before autowipe portion of install script. runs script, doesn't seem to copy any files though (none present after reboot)
mount("ext4", "EMMC", "/dev/block/platform/omap/omap_hsmmc.0/by-name/system", "/data");
run_program("/sbin/busybox", "mount", "/sdcard");
run_program("busybox", "cp", "/data/data/com.swype.android.inputmethod/swypedata/udb/UserData.udb", "/sdcard/UserData.udb");

# init.d portion to copy dictionarys back. placed in an init.d script that deletes itself on first boot.
# "restoring Swype dictionary"

# mount data
#mount -o remount rw /data
# not sure if sdcard is mounted
#mount -o remount rw /sdcard

#cp /sdcard/UserData.udb /data/data/com.swype.android.inputmethod/swypedata/udb/UserData.udb

#mount -o remount ro /data
#mount -o remount ro /sdcard

the # was placed there because the script must have had an error in it or something. it wont boot past the google splash logo when it's active.


----------



## yarly (Jun 22, 2011)

PrimeDirective said:


> #beginning before autowipe portion of install script. runs script, doesn't seem to copy any files though (none present after reboot)
> mount("ext4", "EMMC", "/dev/block/platform/omap/omap_hsmmc.0/by-name/system", "/data");
> run_program("/sbin/busybox", "mount", "/sdcard");
> run_program("busybox", "cp", "/data/data/com.swype.android.inputmethod/swypedata/udb/UserData.udb", "/sdcard/UserData.udb");
> ...


You weren't mixing those 2 scripts together were you? The recovery commands have to be done in recovery and the others (shell ones) have to be either executed with that command I mentioned in recovery and placed in their own file within the zip.

If not, it was probably the sdcard mounting. That or you have to mount them from the block first as they weren't mounted to begin with at all.


----------



## PrimeDirective (Dec 31, 2011)

yarly said:


> You weren't mixing those 2 scripts together were you? The recovery commands have to be done in recovery and the others (shell ones) have to be either executed with that command I mentioned in recovery and placed in their own file within the zip.
> 
> If not, it was probably the sdcard mounting. That or you have to mount them from the block first as they weren't mounted to begin with at all.


the first portion was in the installer script, the second portion was in an init.d file. I'm guessing it's mount related.. unfortunately i dont know what the proper mounting method would be. The init.d portion (backup restore) wont let it go past the google splash screen. i'm pretty sure init.d uses bash? maybe the syntax is wrong?


----------



## yarly (Jun 22, 2011)

Do /proc/mounts or /proc/emmc or /proc/mtd in the terminal and it will show you the proper mount point locations.

sdcard might be mounted by the time the init.d script is loaded though. I really dont know offhand.


----------

