0

I have been attempting to write a script to harden android. I have had no success!

I am running a AVD via emulator and have tried this with both the android shell and bash shell which i loaded. The script is simple as you will see below and each command runs fine independently but in a script it just runs through too fast or something.

I know there's no shebang at the top but that's because of errors when i inserted one.

my script is:

echo             ANDROID
echo      HARDENING STARTED
device=/dev/block/mtdblock0
mount -o rw,remount $device /system
#removing files in the /system/xbin directory
rm  /system/xbin/tcpdump
rm  /system/xbin/su
#removing files in the /system/bin directory
rm  /system/bin/bootanimation
rm  /system/bin/dumpstate
rm  /system/bin/ping
rm  /system/bin/ping6
echo                    ANDROID
echo              HARDENING COMPLETE

I have taken all indenting out as i thought this may be causing the error and the directories and files definitely exist. I have been on this for three days now and its wearing thin.

I had an if statement at the beginning to select devices on other handsets but i took this out in attempt to reduce errors (that's why i declare device instead of mounting).

here is the error:

             ANDROID
      HARDENING STARTED
mount: no such file or directory exist
, no such file or directorytcpdump   
, no such file or directorysu
, no such file or directoryootanimation
, no such file or directoryumpstate
, no such file or directorying
, no such file or directorying6

     ANDROID
 HARDENING COMPLETED

NOTICE THE MERGING AFTER DIRECTORY THIS IS NOT A TYPO.

thanks Ryan

choco_linux
  • 143
  • 1
  • 1
  • 8
  • It seems that the $device variable is empty; could you try to `echo $device` just before the mount command? – Alepac Jan 16 '13 at 13:46

2 Answers2

3

You edited this file on a Windows system and it has DOS-style end-of-lines (<cr><lf>). Convert it to use Unix-style end-of-line markers (<lf>) and it should work fine. Any decent programmer's editor will have the ability to do this for you, or you can do it using standard command line tools.

Incidentally, the shell doesn't care about indenting at all. This:

echo Hello
echo world.

Is the same as:

echo Hello
              echo world.
Community
  • 1
  • 1
larsks
  • 277,717
  • 41
  • 399
  • 399
  • The mangled error messages clearly indicate that this is the case. The file name gets printed, it ends with `\r`, so cursor moves back to the first column and the error message gets printed over beginning of the filename. It explains even the error from mount as the device name also gets `\r` at the end. – Jan Hudec Jan 16 '13 at 14:01
1

Change the line ending to Unix style, will solve all your problem.

jingyu
  • 21
  • 1