Browse Source

add option to only install for specific user

pull/68/head
Linus789 3 years ago
parent
commit
4555f85e3c
  1. 13
      adb/device.go
  2. 11
      install.go

13
adb/device.go

@ -149,6 +149,19 @@ func (d *Device) Install(path string) error {
return parseError(getFailureCode(installFailureRegex, line))
}
func (d *Device) InstallUser(path, user string) error {
cmd := d.AdbCmd(append([]string{"install", "-r", "--user"}, user, path)...)
output, err := cmd.CombinedOutput()
if err != nil {
return err
}
line := getResultLine(output)
if line == "Success" {
return nil
}
return parseError(getFailureCode(installFailureRegex, line))
}
func getResultLine(output []byte) string {
scanner := bufio.NewScanner(bytes.NewReader(output))
for scanner.Scan() {

11
install.go

@ -28,6 +28,7 @@ list of apps to install from standard input, like:
var (
installUpdates = cmdInstall.Fset.Bool("u", false, "Upgrade all installed apps")
installDryRun = cmdInstall.Fset.Bool("n", false, "Only print the operations that would be done")
installUser = cmdInstall.Fset.String("user", "", "Only install for specified user")
)
func init() {
@ -143,8 +144,14 @@ func downloadAndDo(apps []fdroid.App, device *adb.Device) error {
func installApk(device *adb.Device, apk *fdroid.Apk, path string) error {
fmt.Printf("Installing %s\n", apk.AppID)
if err := device.Install(path); err != nil {
return fmt.Errorf("could not install %s: %v", apk.AppID, err)
if *installUser != "" {
if err := device.InstallUser(path, *installUser); err != nil {
return fmt.Errorf("could not install %s: %v", apk.AppID, err)
}
} else {
if err := device.Install(path); err != nil {
return fmt.Errorf("could not install %s: %v", apk.AppID, err)
}
}
return nil
}

Loading…
Cancel
Save