Android Community
Page 9 of 9 FirstFirst ... 7 8 9
Results 81 to 86 of 86

Thread: edit this script!!

  1. #81
    Join Date
    Nov 2008
    Posts
    944

    Default Re: edit this script!!


    Now, I don't know enough (or anything, for that matter) about Android-hacking, so my contribution will be limited.

    chmod changes the permissions on the file. The command to create /system/sd should have been a simple mkdir, though the ext2fs partition on the microSD gets mounted to this location later.

    @constellanation: this may be a useful guide for *nix hacking in general. Android is a pretty limited platform, but it still conforms to some well-established *nix conventions. But since you use a regular Linux distro, it might be good for you.

  2. #82
    Join Date
    Sep 2008
    Location
    The Boonies of Pinal County, Arizona
    Posts
    1,186

    Default Re: edit this script!!

    Quote Originally Posted by JuanGil View Post
    well I decided to give a try and did this one. :

    #!/bin/bash
    cd /system/sd
    mkdir cache
    cd /system/sd/cache
    mkdir files
    (snip nearly identical lines)

    dont know if is working yet
    You don't need to cd to a directory to make a symbolic link; you can say "ln -s /some/dir/somewhere /new/dir/elsewhere"

    Additionally you have a lot of repeated commands. A nicer idea would be to wrap those commands in a function:

    Code:
    function relocateCache()
    {
       OLD_CACHE_DIR=$1
       NEW_CACHE_DIR=$2
    
       mkdir $NEW_CACHE_DIR
       cp -R $OLD_CACHE_DIR $NEW_CACHE_DIR
       rm -rf $OLD_CACHE_DIR
       ln -s $NEW_CACHE_DIR $OLD_CACHE_DIR
    }
    You can then say something like:

    Code:
    #!/system/bin/sh
    ...
    relocateCache /data/data/com.myspace.android /system/sd/cache/files/myspace
    ...
    edit: An even nicer idea would be sanity checks in the relocateCache function to make sure the OLD_CACHE_DIR exists before operating on it and the path to the NEW_CACHE_DIR exists.
    Last edited by ickyfehmleh; 02-07-2009 at 02:09 PM. Reason: added link to sh tutorial

  3. #83
    Join Date
    Sep 2008
    Location
    The Boonies of Pinal County, Arizona
    Posts
    1,186

    Default Re: edit this script!!

    Quote Originally Posted by birdman81484 View Post
    I just need a guinea pig...

    our ways of writing this are totally different too....

    anyways what does the chmod 0777 do? and why does the script need to be in /data/local/bin/transfer.sh?
    also what program did you use to write you script?
    how is it is executed when you get into the terminal emulator?
    chmod changes the permissions of a file. "0777" is considered Very Bad as it leaves the file wide open for any user to modify. Generally scripts are 755 (rwxr-xr-x) or 700 (rwx------).

    1 = Execute bit
    2 = Write bit
    4 = Read bit

    So 0644 and 644 both mean "rw-r--r--". The shell will not allow you to execute this particular file since it lacks the execute bit, even though the file may be a binary or script. Shell scripts, since they are interpreted, need both the execute bit and the read bits set.

    The "0" prefix is mostly unnecessary for normal commands because shell scripts should never be set-uid or set-gid (eg run the command as whichever owner or group owns the file).

    People here tend to put their scripts in /data/local/bin because that directory is in the stock user's $PATH. Shells will attempt to find commands by consulting items in your path. For instance, if your $PATH is "/bin:/usr/local/bin:/system/bin" and you type in "foo", the shell will look for /bin/foo, then /usr/local/bin/foo, then /system/bin/foo before saying "foo: command not found". You don't need to put things in /data/local/bin because you can always say "./myscript" if you're in the same directory as the script or "/full/path/to/myscript" if you're not.

    edit: you can bypass all of the chmod and path issues by simply saying "sh /path/to/myscript" or "sh myscript" if it's in the same directory you're in (your current working directory, or 'cwd'). To find out which directory you're in, type "pwd" (print working directory).
    Last edited by ickyfehmleh; 02-07-2009 at 02:28 PM. Reason: added note about bypassing chmod restrictions

  4. #84
    Join Date
    Dec 2008
    Location
    Beautiful Arizona WHERE ANDROID COMMUNITY LIVES
    Posts
    641

    Default Re: edit this script!!

    Quote Originally Posted by ickyfehmleh View Post
    You don't need to cd to a directory to make a symbolic link; you can say "ln -s /some/dir/somewhere /new/dir/elsewhere"

    Additionally you have a lot of repeated commands. A nicer idea would be to wrap those commands in a function:

    Code:
    function relocateCache()
    {
       OLD_CACHE_DIR=$1
       NEW_CACHE_DIR=$2
    
       mkdir $NEW_CACHE_DIR
       cp -R $OLD_CACHE_DIR $NEW_CACHE_DIR
       rm -rf $OLD_CACHE_DIR
       ln -s $NEW_CACHE_DIR $OLD_CACHE_DIR
    }
    You can then say something like:

    Code:
    #!/system/bin/sh
    ...
    relocateCache /data/data/com.myspace.android /system/sd/cache/files/myspace
    ...
    edit: An even nicer idea would be sanity checks in the relocateCache function to make sure the OLD_CACHE_DIR exists before operating on it and the path to the NEW_CACHE_DIR exists.
    thank for the reply, I think I forgot to mention that I made it as script: "moveallcache.sh" is this still wrong?

    White G1 with a REALLY hard to see keyboard on low light due to backlight (not any more! I have "dark keys" installed)

    Haykuros 5.0.2H+engineering BL
    LavosHandy Font
    G1Tether & tetherWifi (just for backup)
    250 apps to EXT2 with 64Mb free
    Cache's & Dalvik to EXT2
    wallpaper from deviantart dot com
    Did I Just Become an
    ANDRODICTO?

  5. #85
    Join Date
    Sep 2008
    Location
    The Boonies of Pinal County, Arizona
    Posts
    1,186

    Default Re: edit this script!!

    Quote Originally Posted by JuanGil View Post
    thank for the reply, I think I forgot to mention that I made it as script: "moveallcache.sh" is this still wrong?
    You can call it whatever you'd like, UNIX doesn't care. It doesn't even need the '.sh' extension; that's somewhat of a convention.

    Is there a standard naming convention for caches -- are they all in somedir/cache or does it vary by application? If they're all in their own 'cache' directories you could simply loop through all the directories in /data/data and relocate them in one fell swoop:

    Code:
    for dir in /data/data/* 
    do
       if [ -d $dir/cache ]
       then
          relocateCache $dir/cache /sdcard/cache/$dir
       fi
    done
    This will loop through everything in /data/data ("for dir in /data/data/*"), check to see if the directory "/data/data/WHATEVER/cache" exists, and relocate it to the sdcard (as /sdcard/cache/WHATEVER) if it does. This method has the added benefit of not having application names in your script that the user may not have installed.

  6. #86
    Join Date
    Dec 2008
    Location
    Beautiful Arizona WHERE ANDROID COMMUNITY LIVES
    Posts
    641

    Default Re: edit this script!!


    thanks for the quick response, as for the name I didn't mean to say "I named like this or like that" just wanted to say that I didn't input the commands one by one on terminal. Also I don't think it would be a good idea to move all cache in data/data, just for certain apps. thanks
    excuse my poor english..

    White G1 with a REALLY hard to see keyboard on low light due to backlight (not any more! I have "dark keys" installed)

    Haykuros 5.0.2H+engineering BL
    LavosHandy Font
    G1Tether & tetherWifi (just for backup)
    250 apps to EXT2 with 64Mb free
    Cache's & Dalvik to EXT2
    wallpaper from deviantart dot com
    Did I Just Become an
    ANDRODICTO?

Page 9 of 9 FirstFirst ... 7 8 9

Similar Threads

  1. Replies: 11
    Last Post: 02-05-2009, 08:56 PM
  2. Google? Did you edit my review on an app?
    By K.Krstnsn in forum All About Andorid Software
    Replies: 15
    Last Post: 11-07-2008, 04:02 PM
  3. Edit existing code on the device?
    By flixxx in forum Developers Guild
    Replies: 1
    Last Post: 11-03-2008, 12:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •