14

I'd like to SSH into my phone, download an APK, and install it remotely. Is there a command available on the phone that would allow me to do this?

EG:

wget localhost/file.apk 
android_install file.apk

Need to automate an install, as I just accidentally wiped my SD card and everything on it. :(

Naftuli Kay
  • 2,652
  • 7
  • 29
  • 38

3 Answers3

12

In adb shell or terminal emulator (and most likely over SSH) you can use the pm utility to install apps. The command is:

pm install /sdcard/app1.apk

The following are the switches of pm:

usage: pm [list|path|install|uninstall]
       pm list packages [-f] [-d] [-e] [-u] [FILTER]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE]
       pm list features
       pm list libraries
       pm path PACKAGE
       pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
       pm uninstall [-k] PACKAGE
       pm clear PACKAGE
       pm enable PACKAGE_OR_COMPONENT
       pm disable PACKAGE_OR_COMPONENT
       pm setInstallLocation [0/auto] [1/internal] [2/external]

The list packages command prints all packages, optionally only
those whose package name contains the text in FILTER.  Options:
  -f: see their associated file.
  -d: filter to include disbled packages.
  -e: filter to include enabled packages.
  -u: also include uninstalled packages.

The list permission-groups command prints all known
permission groups.

The list permissions command prints all known
permissions, optionally only those in GROUP.  Options:
  -g: organize by group.
  -f: print all information.
  -s: short summary.
  -d: only list dangerous permissions.
  -u: list only the permissions users will see.

The list instrumentation command prints all instrumentations,
or only those that target a specified package.  Options:
  -f: see their associated file.

The list features command prints all features of the system.

The path command prints the path to the .apk of a package.

The install command installs a package to the system.  Options:
  -l: install the package with FORWARD_LOCK.
  -r: reinstall an exisiting app, keeping its data.
  -t: allow test .apks to be installed.
  -i: specify the installer package name.
  -s: install package on sdcard.
  -f: install package on internal flash.

The uninstall command removes a package from the system. Options:
  -k: keep the data and cache directories around.
after the package removal.

The clear command deletes all data associated with a package.

The enable and disable commands change the enabled state of
a given package or component (written as "package/class").

The getInstallLocation command gets the current install location
  0 [auto]: Let system decide the best location
  1 [internal]: Install on internal device storage
  2 [external]: Install on external media

The setInstallLocation command changes the default install location
  0 [auto]: Let system decide the best location
  1 [internal]: Install on internal device storage
  2 [external]: Install on external media

For example, you can force the app to install directly to the external storage (Froyo/Gingerbread style.)

P.S. The wget utility should be available via BusyBox on CM7. If not, you can always install it via Android Market.

Chahk
  • 19,555
  • 3
  • 57
  • 80
6

I'd suggest you plug your phone into a pc with the sdk (or at least adb) installed and in debugging mode. After this, write a script that goes through your apps and installs them via adb, e.g. adb install x:\path\to\app1.apk.

aleksikallio
  • 16,330
  • 6
  • 49
  • 73
2

I am using the same method and yes SSH is great! But it seems when you SSH to Android it gets a different shell than sh so if you put sh in front of the command it should work.

Here's an example: sh /system/bin/pm install app1.apk

Peanut
  • 3,396
  • 5
  • 30
  • 43
mehellra
  • 21
  • 1