diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/debian/changelog goget-ubuntu-touch-0.3+14.10.20140709/debian/changelog --- goget-ubuntu-touch-0.2+14.10.20140429.1/debian/changelog 2014-07-27 17:29:20.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/debian/changelog 2014-07-27 17:29:20.000000000 +0000 @@ -1,8 +1,64 @@ -goget-ubuntu-touch (0.2+14.10.20140429.1-0ubuntu1~0trusty1) trusty; urgency=medium +goget-ubuntu-touch (0.3+14.10.20140709-0ubuntu1) utopic; urgency=low - * Trusty backport + [ Ubuntu daily release ] + * New rebuild forced - -- Zoltán Balogh Fri, 16 May 2014 16:07:46 +0300 + [ Sergio Schvezov ] + * ubuntu-emulator: add option to create a vfat formatted sdcard image. + * ubuntu-emulator: launch emulator from android source tree if the + build env is setup. + + [ Jani Monoses ] + * ubuntu-device-flash: Add --device-tarball flag to allow flashing a + tarball from the local disk. + + -- Ubuntu daily release Wed, 09 Jul 2014 08:53:17 +0000 + +goget-ubuntu-touch (0.3+14.10.20140619-0ubuntu1) utopic; urgency=low + + [ Ricardo Salveti de Araujo ] + * ubuntu-emulator: disable the remaining ethernet interfaces (don't + let them be managed by network manager) + + -- Ubuntu daily release Thu, 19 Jun 2014 14:36:56 +0000 + +goget-ubuntu-touch (0.3+14.10.20140618.1-0ubuntu1) utopic; urgency=medium + + [ Sergio Schvezov ] + * ubuntu-touch-do: new tool to interact with ubuntu devices. + * ubuntu-device-flash: option to flash with developer mode enabled. + * debian/control: add Built-Using for ubuntu-device-do + + [ Chris Wayne ] + * ubuntu-emulator: bash completion for running emulators + + [ Loïc Minier ] + * debian/control: add Built-Using field to binary packages to track + golang dependencies this was built against. + + [ Jani Monoses ] + * ubuntu-device-flash: Print error when parsing of cmdline args fails. + + -- Ubuntu daily release Wed, 18 Jun 2014 20:57:32 +0000 + +goget-ubuntu-touch (0.2+14.10.20140610-0ubuntu1) utopic; urgency=low + + [ Dimitri John Ledkov ] + * Unpack recovery & offer to launch it. + + -- Ubuntu daily release Tue, 10 Jun 2014 16:12:34 +0000 + +goget-ubuntu-touch (0.2+14.10.20140527-0ubuntu1) utopic; urgency=low + + [ Sergio Schvezov ] + * ubuntu-emulator: proper permissions on creation when using pkexec. + + [ Jani Monoses ] + * ubuntu-device-flash: make error message clearer. + * ubuntu-device-flash: Allow customizing the flashing by running a + user provided script + + -- Ubuntu daily release Tue, 27 May 2014 19:02:51 +0000 goget-ubuntu-touch (0.2+14.10.20140429.1-0ubuntu1) utopic; urgency=low diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/debian/control goget-ubuntu-touch-0.3+14.10.20140709/debian/control --- goget-ubuntu-touch-0.2+14.10.20140429.1/debian/control 2014-07-27 17:29:20.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/debian/control 2014-07-27 17:29:20.000000000 +0000 @@ -4,6 +4,7 @@ Maintainer: Ubuntu Developers Build-Depends: debhelper (>= 9), dh-golang, + bash-completion, golang-go, golang-go-flags-dev, golang-gocheck-dev, @@ -19,11 +20,21 @@ android-tools-fastboot, ${misc:Depends}, ${shlibs:Depends}, +Built-Using: ${misc:Built-Using} Description: Flash supported Nexus devices with Ubuntu Use this tool to flash a suported device with Ubuntu by either bootstrapping from fastboot or reflashing from an already supported device. +Package: ubuntu-device-do +Architecture: any +Depends: android-tools-adb, + ${misc:Depends}, + ${shlibs:Depends}, +Built-Using: ${misc:Built-Using} +Description: Tool to interact with Ubuntu Touch devices + Use this tool to interact with your Ubuntu Touch device + Package: ubuntu-emulator Architecture: i386 amd64 Depends: ubuntu-emulator-runtime, @@ -31,6 +42,7 @@ ${misc:Depends}, ${shlibs:Depends}, Recommends: android-tools-adb, +Built-Using: ${misc:Built-Using} Description: Create and run emulator images of Ubuntu Touch Create and destroy Ubuntu Touch instances and run them with the emulator diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/debian/rules goget-ubuntu-touch-0.3+14.10.20140709/debian/rules --- goget-ubuntu-touch-0.2+14.10.20140429.1/debian/rules 2014-07-27 17:29:20.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/debian/rules 2014-07-27 17:29:20.000000000 +0000 @@ -5,10 +5,11 @@ export DH_GOPKG := launchpad.net/goget-ubuntu-touch %: - dh $@ --buildsystem=golang --with=golang --fail-missing + dh $@ --buildsystem=golang --with=golang --fail-missing --with bash-completion override_dh_auto_install: dh_auto_install -O--buildsystem=golang rm -rf ${CURDIR}/debian/tmp/usr/bin/abootimg-extract rm -rf ${CURDIR}/debian/tmp/usr/share/gocode/src/launchpad.net/goget-ubuntu-touch/ubuntu-emulator rm -rf ${CURDIR}/debian/tmp/usr/share/gocode/src/launchpad.net/goget-ubuntu-touch/ubuntu-device-flash + rm -rf ${CURDIR}/debian/tmp/usr/share/gocode/src/launchpad.net/goget-ubuntu-touch/ubuntu-device-do diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/debian/ubuntu-device-do.install goget-ubuntu-touch-0.3+14.10.20140709/debian/ubuntu-device-do.install --- goget-ubuntu-touch-0.2+14.10.20140429.1/debian/ubuntu-device-do.install 1970-01-01 00:00:00.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/debian/ubuntu-device-do.install 2014-07-27 17:29:20.000000000 +0000 @@ -0,0 +1 @@ +usr/bin/ubuntu-device-do diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/debian/ubuntu-emulator.bash-completion goget-ubuntu-touch-0.3+14.10.20140709/debian/ubuntu-emulator.bash-completion --- goget-ubuntu-touch-0.2+14.10.20140429.1/debian/ubuntu-emulator.bash-completion 1970-01-01 00:00:00.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/debian/ubuntu-emulator.bash-completion 2014-07-27 17:29:20.000000000 +0000 @@ -0,0 +1,21 @@ +_foo() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="create list run destroy snapshot" + runopts="$(ubuntu-emulator list | cut -f1)" + + case $prev in + run) + COMPREPLY=( $(compgen -W "$runopts" -- $cur) ) + return 0 + ;; + esac + + COMPREPLY=( $(compgen -W "$opts" -- $cur) ) + return 0 +} +complete -F _foo ubuntu-emulator + diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-do/factory_reset.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-do/factory_reset.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-do/factory_reset.go 1970-01-01 00:00:00.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-do/factory_reset.go 2014-07-09 08:52:39.000000000 +0000 @@ -0,0 +1,69 @@ +// +// ubuntu-device-do - Tool to send commands to an Ubuntu device +// +// Copyright (c) 2013 Canonical Ltd. +// +// Written by Sergio Schvezov +// +package main + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License version 3, as published +// by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranties of +// MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program. If not, see . + +import ( + "fmt" + + "log" + + "launchpad.net/goget-ubuntu-touch/devices" + "launchpad.net/goget-ubuntu-touch/ubuntuimage" +) + +type FactoryResetCmd struct { + DeveloperMode bool `long:"developer-mode" description:"Enables developer mode after the factory reset"` + Serial string `long:"serial" description:"Serial of the device to operate"` +} + +var factoryResetCmd FactoryResetCmd + +func init() { + parser.AddCommand("factory-reset", + "Resets to stock install", + "Resets a device to its stock install with the possibility to enable developer mode by default", + &factoryResetCmd) +} + +func (factoryResetCmd *FactoryResetCmd) Execute(args []string) error { + var enableList []string + if factoryResetCmd.DeveloperMode { + enableList = append(enableList, "developer_mode") + } + //files: nil, files location: "", wipe: true, enable: enableList + ubuntuCommands, err := ubuntuimage.GetUbuntuCommands(nil, "", true, enableList) + if err != nil { + return fmt.Errorf("cannot create commands file: %s", err) + } + + adb, err := devices.NewUbuntuDebugBridge() + if err != nil { + log.Fatal(err) + } + if factoryResetCmd.Serial != "" { + adb.SetSerial(factoryResetCmd.Serial) + } + if err := adb.Push(ubuntuCommands, "/cache/recovery/ubuntu_command"); err != nil { + return err + } + fmt.Println("Rebooting to finish factory reset") + adb.RebootRecovery() + return nil +} diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-do/main.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-do/main.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-do/main.go 1970-01-01 00:00:00.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-do/main.go 2014-07-09 08:52:39.000000000 +0000 @@ -0,0 +1,38 @@ +// +// ubuntu-device-do - Tool to send commands to an Ubuntu device +// +// Copyright (c) 2013 Canonical Ltd. +// +// Written by Sergio Schvezov +// +package main + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License version 3, as published +// by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranties of +// MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program. If not, see . + +import ( + "os" + + flags "github.com/jessevdk/go-flags" +) + +var parser = flags.NewParser(nil, flags.Default) + +func init() { + +} + +func main() { + if _, err := parser.Parse(); err != nil { + os.Exit(1) + } +} diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-flash/args.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-flash/args.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-flash/args.go 2014-04-29 19:07:37.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-flash/args.go 2014-07-09 08:52:48.000000000 +0000 @@ -31,10 +31,13 @@ Wipe bool `long:"wipe" description:"Clear all data after flashing"` Channel string `long:"channel" description:"Specify an alternate channel"` Device string `long:"device" description:"Specify the device to flash"` + DeviceTarball string `long:"device-tarball" description:"Specify a local device tarball to override the one from the server (using official Ubuntu images with custom device tarballs)"` Serial string `long:"serial" description:"Serial of the device to operate"` Server string `long:"server" description:"Use a different image server"` CleanCache bool `long:"clean-cache" description:"Cleans up cache with all downloaded bits"` TLSSkipVerify bool `long:"tls-skip-verify" description:"Skip TLS certificate validation"` + DeveloperMode bool `long:"developer-mode" description:"Enables developer mode after the factory reset"` + RunScript string `long:"run-script" description:"Run a script given by path to finish the flashing process, instead of rebooting to recovery (mostly used during development to work around quirky or incomplete recovery images)"` } var args arguments diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-flash/main.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-flash/main.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-device-flash/main.go 2014-04-29 19:07:37.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-device-flash/main.go 2014-07-09 08:52:48.000000000 +0000 @@ -31,6 +31,7 @@ "os/exec" "path/filepath" "strings" + "syscall" "launchpad.net/goget-ubuntu-touch/devices" "launchpad.net/goget-ubuntu-touch/ubuntuimage" @@ -38,11 +39,43 @@ func main() { if _, err := parser.Parse(); err != nil { - os.Exit(1) + log.Fatal(err) } if args.TLSSkipVerify { ubuntuimage.TLSSkipVerify() } + script := args.RunScript + if script != "" { + if p, err := filepath.Abs(script); err != nil { + log.Fatal("Run script not found:", err) + } else { + script = p + } + + fi, err := os.Lstat(script) + if err != nil { + log.Fatal(err) + } + if fi.Mode()&0100 == 0 || !fi.Mode().IsRegular() { + log.Fatalf("The script %s passed via --run-script is not executable", script) + } + } + + tarballPath := args.DeviceTarball + if tarballPath != "" { + if p, err := filepath.Abs(tarballPath); err != nil { + log.Fatal("Device tarball not found", err) + } else { + tarballPath = p + } + fi, err := os.Lstat(tarballPath) + if err != nil { + log.Fatal(err) + } + if !fi.Mode().IsRegular() { + log.Fatalf("The file %s passed via --device-tarball is not a regular file\n", tarballPath) + } + } channels, err := ubuntuimage.NewChannels(args.Server) if err != nil { log.Fatal(err) @@ -114,8 +147,15 @@ totalFiles := len(image.Files) + len(signFiles) files := make(chan Files, totalFiles) done := make(chan bool, totalFiles) - for _, file := range image.Files { - go bitDownloader(file, files, args.Server, cacheDir) + for i, file := range image.Files { + if tarballPath != "" && strings.HasPrefix(file.Path, "/pool/device") { + //change the file paths so they are correctly picked up by bitPusher later on + image.Files[i].Path = tarballPath + image.Files[i].Signature = tarballPath + ".asc" + useLocalTarball(image.Files[i], files) + } else { + go bitDownloader(file, files, args.Server, cacheDir) + } } for _, file := range signFiles { go bitDownloader(file, files, args.Server, cacheDir) @@ -164,7 +204,12 @@ for i := 0; i < totalFiles; i++ { <-done } - ubuntuCommands, err := ubuntuimage.GetUbuntuCommands(image.Files, cacheDir, args.Wipe) + + var enableList []string + if args.DeveloperMode { + enableList = append(enableList, "developer_mode") + } + ubuntuCommands, err := ubuntuimage.GetUbuntuCommands(image.Files, cacheDir, args.Wipe, enableList) if err != nil { log.Fatal("Cannot create commands file") } @@ -179,16 +224,45 @@ } } }() - log.Print("Rebooting into recovery to flash") - adb.RebootRecovery() - err = adb.WaitForRecovery() + + // either customize the flashing process by running a user provided script + // or reboot into recovery to let the standard upgrade script to run + if script != "" { + log.Printf("Preparing to run %s to finish the flashing process\n", script) + cmd := exec.Command(script) + cmd.Stdout = os.Stdout + err = cmd.Run() + if err != nil { + log.Fatal(err) + } + + } else { + log.Print("Rebooting into recovery to flash") + adb.RebootRecovery() + err = adb.WaitForRecovery() + if err != nil { + log.Fatal(err) + } + } +} + +// ensureExists touches a file. It can be used to create a dummy .asc file if none exists +func ensureExists(path string) { + f, err := os.OpenFile(path, syscall.O_WRONLY|syscall.O_CREAT, 0666) if err != nil { - log.Fatal(err) + log.Fatal("Cannot touch %s : %s", path, err) } + f.Close() } type Files struct{ FilePath, SigPath string } +// useLocalTarball adds a local file to the ones to be pushed +func useLocalTarball(file ubuntuimage.File, files chan<- Files) { + ensureExists(file.Signature) + files <- Files{FilePath: file.Path, SigPath: file.Signature} +} + // bitDownloader downloads func bitDownloader(file ubuntuimage.File, files chan<- Files, server, downloadDir string) { err := file.MakeRelativeToServer(server) @@ -206,7 +280,7 @@ // bitPusher func bitPusher(adb devices.UbuntuDebugBridge, files <-chan Files, done chan<- bool) { if _, err := adb.Shell("rm -rf /cache/recovery/*.xz /cache/recovery/*.xz.asc"); err != nil { - log.Fatal("Cannot cleanup tree to ensure clean deployment", err) + log.Fatal("Cannot cleanup /cache/recovery/ to ensure clean deployment", err) } freeSpace := "unknown" dfCacheCmd := "df -h | grep /dev/disk/by-partlabel/cache" diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/common.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/common.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/common.go 2014-04-29 19:07:37.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/common.go 2014-07-09 08:52:39.000000000 +0000 @@ -38,8 +38,8 @@ return "", errors.New("Could not find device specific tar") } -func extractBoot(dataDir string) error { - bootPath := filepath.Join(dataDir, "boot.img") +func extractBoot(dataDir string, bootName string, ramdiskName string) error { + bootPath := filepath.Join(dataDir, bootName) imgBytes, err := ioutil.ReadFile(bootPath) if err != nil { return errors.New(fmt.Sprintf("Cannot read %s", bootPath)) @@ -48,13 +48,15 @@ if err != nil { return err } - ramdiskPath := filepath.Join(dataDir, "ramdisk.img") - kernelPath := filepath.Join(dataDir, kernelName) + ramdiskPath := filepath.Join(dataDir, ramdiskName) if err := boot.WriteRamdisk(ramdiskPath); err != nil { return err } - if boot.WriteKernel(kernelPath); err != nil { - return err + if (ramdiskName == bootRamdisk) { + kernelPath := filepath.Join(dataDir, kernelName) + if boot.WriteKernel(kernelPath); err != nil { + return err + } } return nil } diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/constants.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/constants.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/constants.go 2014-04-29 19:07:43.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/constants.go 2014-07-09 08:52:39.000000000 +0000 @@ -26,6 +26,10 @@ sdcardImage = "sdcard.img" systemImage = "system.img" cacheImage = "cache.img" + bootImage = "boot.img" + bootRamdisk = "ramdisk.img" + recoveryImage = "recovery.img" + recoveryRamdisk = "recovery-ramdisk.img" ) var devices map[string]map[string]string diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/create.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/create.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/create.go 2014-04-29 19:07:43.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/create.go 2014-07-09 08:52:56.000000000 +0000 @@ -37,6 +37,7 @@ Server string `long:"server" description:"Select image server"` Revision int `long:"revision" description:"Select revision"` RawDisk bool `long:"use-raw-disk" description:"Use raw disks instead of qcow2"` + SDCard bool `long:"with-sdcard" description:"Create an external vfat sdcard"` Arch string `long:"arch" description:"Device architecture to use (i386 or armhf)"` } @@ -73,7 +74,7 @@ } if syscall.Getuid() != 0 { - return errors.New("Creation requires sudo (root)") + return errors.New("Creation requires sudo/pkexec (root)") } // hack to circumvent https://code.google.com/p/go/issues/detail?id=1435 @@ -129,8 +130,13 @@ return err } - // boot.img must be in dataDir - if err = extractBoot(dataDir); err != nil { + // boot.img must be in dataDir (Normal Boot Ramdisk) + if err = extractBoot(dataDir, bootImage, bootRamdisk); err != nil { + return err + } + + // recovery.img must be in dataDir (Recovery Ramdisk) + if err = extractBoot(dataDir, recoveryImage, recoveryRamdisk); err != nil { return err } @@ -147,6 +153,14 @@ } } + if createCmd.SDCard { + fmt.Println("Creating vfat sdcard...") + sdcard := diskimage.New(filepath.Join(dataDir, "sdcardprime.img"), "SDCARD", 2) + if err := sdcard.CreateVFat(); err != nil { + return err + } + } + if err = sysutils.WriteStamp(dataDir, image); err != nil { return err } @@ -167,7 +181,7 @@ func createSystem(ubuntuImage, sdcardImage *diskimage.DiskImage, files []string) (err error) { for _, img := range []*diskimage.DiskImage{ubuntuImage, sdcardImage} { - if err := img.Create(); err != nil { + if err := img.CreateExt4(); err != nil { return err } } diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/diskimage/customization.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/diskimage/customization.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/diskimage/customization.go 2014-04-29 19:07:51.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/diskimage/customization.go 2014-07-09 08:52:39.000000000 +0000 @@ -36,6 +36,12 @@ netmask 255.255.255.0 gateway 10.0.2.2 dns-nameservers 10.0.2.3 + +iface eth1 inet manual +iface eth2 inet manual +iface eth3 inet manual +iface eth4 inet manual +iface eth5 inet manual ` type setupFile struct{ path, content string } diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/diskimage/image.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/diskimage/image.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/diskimage/image.go 2014-04-29 19:07:51.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/diskimage/image.go 2014-07-09 08:52:56.000000000 +0000 @@ -147,15 +147,19 @@ } //Create returns a ext4 partition for a given file -func (img DiskImage) Create() error { +func (img DiskImage) CreateExt4() error { if err := sysutils.CreateEmptyFile(img.path, img.size); err != nil { return err } - if err := exec.Command("mkfs.ext4", "-F", "-L", - img.label, img.path).Run(); err != nil { + return exec.Command("mkfs.ext4", "-F", "-L", img.label, img.path).Run() +} + +//Create returns a vfat partition for a given file +func (img DiskImage) CreateVFat() error { + if err := sysutils.CreateEmptyFile(img.path, img.size); err != nil { return err } - return nil + return exec.Command("mkfs.vfat", "-n", img.label, img.path).Run() } //unpackSystem moves the system partition up one level diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/run.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/run.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/run.go 2014-04-29 19:07:43.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/run.go 2014-07-09 08:53:06.000000000 +0000 @@ -22,10 +22,12 @@ import ( "errors" "fmt" - "launchpad.net/goget-ubuntu-touch/ubuntu-emulator/sysutils" "os" "os/exec" + "path" "path/filepath" + + "launchpad.net/goget-ubuntu-touch/ubuntu-emulator/sysutils" ) type RunCmd struct { @@ -33,15 +35,17 @@ KernelCmd string `long:"kernel-cmdline" description:"Replace kernel cmdline"` Memory string `long:"memory" description:"Set the device memory"` Scale string `long:"scale" description:"Scale the emulator size"` + Recovery bool `long:"recovery" description:"Boot into recovery"` } var runCmd RunCmd const ( - defaultMemory = "512" - defaultScale = "1.0" - defaultSkin = "EDGE" - emulatorCmd = "/usr/share/android/emulator/out/host/linux-x86/bin/emulator" + defaultMemory = "512" + defaultScale = "1.0" + defaultSkin = "EDGE" + installPath = "/usr/share/android/emulator" + subpathEmulatorCmd = "out/host/linux-x86/bin/emulator" ) var skinDirs = []string{ @@ -50,13 +54,19 @@ "/usr/share/android/emulator/development/tools/emulator/skins", } +var extendedRunHelp string = "Runs a new emulator instance name 'name' which " + + "was previously created. If the ANDROID_BUILD_TOP envionment variable is " + + "found, used during Android side development, the emulator runtime will " + + "be executed from there if possible. ANDROID_BUILT_TOP is set after an " + + "android 'lunch' target is selected." + func init() { runCmd.Skin = defaultSkin runCmd.Scale = defaultScale runCmd.Memory = defaultMemory parser.AddCommand("run", "Run emulator instance named 'name'", - "Runs a new emulator instance name 'name' which was previously created", + extendedRunHelp, &runCmd) } @@ -86,11 +96,16 @@ return errors.New("Cannot run specified emulator environment") } + ramdisk := bootRamdisk + if runCmd.Recovery { + ramdisk = recoveryRamdisk + } cmdOpts := []string{ "-memory", runCmd.Memory, "-skindir", skinDir, "-skin", runCmd.Skin, "-sysdir", dataDir, "-kernel", filepath.Join(dataDir, kernelName), + "-ramdisk", filepath.Join(dataDir, ramdisk), "-data", filepath.Join(dataDir, dataImage), "-system", filepath.Join(dataDir, systemImage), "-sdcard", filepath.Join(dataDir, sdcardImage), @@ -115,6 +130,8 @@ return err } + emulatorCmd := getEmulatorCmd() + cmd := exec.Command(emulatorCmd, cmdOpts...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -126,6 +143,16 @@ return nil } +func getEmulatorCmd() string { + androidTree := os.Getenv("ANDROID_BUILD_TOP") + cmd := path.Join(androidTree, subpathEmulatorCmd) + if fInfo, err := os.Stat(cmd); err == nil && fInfo.Mode()&0111 != 0 { + fmt.Println("Using", cmd, "for the emulator runtime") + return cmd + } + return path.Join(installPath, subpathEmulatorCmd) +} + func getSkinDir(skin string) (string, error) { for _, skinDir := range skinDirs { if dir, err := os.Stat(skinDir); err != nil || !dir.IsDir() { diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/run_test.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/run_test.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/run_test.go 1970-01-01 00:00:00.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/run_test.go 2014-07-09 08:53:06.000000000 +0000 @@ -0,0 +1,57 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * Authors: + * Sergio Schvezov: sergio.schvezov@canonical.com + * + * This file is part of ubuntu-emulator. + * + * ubuntu-emulator is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * ubuntu-emulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package main + +import ( + "os" + "path/filepath" + "testing" + . "launchpad.net/gocheck" +) + +var _ = Suite(&EmulatorRunTestSuite{}) + +type EmulatorRunTestSuite struct { + tmpDir string +} + +func (s *EmulatorRunTestSuite) SetUpTest(c *C) { + s.tmpDir = c.MkDir() +} + +func Test(t *testing.T) { TestingT(t) } + +func (s *EmulatorRunTestSuite) TestRunPathInstalled(c *C) { + c.Assert(getEmulatorCmd(), Equals, filepath.Join(installPath, subpathEmulatorCmd)) +} + +func (s *EmulatorRunTestSuite) TestRunPathAndroidTree(c *C) { + emuCmd := filepath.Join(s.tmpDir, subpathEmulatorCmd) + os.MkdirAll(filepath.Dir(emuCmd), 0777) + cmdFile, err := os.Create(emuCmd) + c.Assert(err, IsNil) + cmdFile.Chmod(0755) + cmdFile.Close() + c.Assert(os.Setenv("ANDROID_BUILD_TOP", s.tmpDir), IsNil) + c.Assert(getEmulatorCmd(), Equals, emuCmd) + c.Assert(os.Setenv("ANDROID_BUILD_TOP", ""), IsNil) +} diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/sysutils/utils.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/sysutils/utils.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntu-emulator/sysutils/utils.go 2014-04-29 19:07:37.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntu-emulator/sysutils/utils.go 2014-07-09 08:52:39.000000000 +0000 @@ -46,7 +46,7 @@ } func DropPrivs() error { - uid, gid := GetSudoEnvInt() + uid, gid := GetUserEnvInt() if err := syscall.Setregid(-1, gid); err != nil { return errors.New(fmt.Sprintf("Can't drop gid: %s", err)) } @@ -61,21 +61,28 @@ return err } -func GetSudoEnv() (uid, gid string) { - uid = os.Getenv("SUDO_UID") - gid = os.Getenv("SUDO_GID") - if uid == "" { +// GetUserEnv checks if the process can drop priviledges by checking if either +// SUDO_UID and SUDO_GID or PKEXEC_UID are set, it returns the corresponding +// uid and gid set in these or 0 otherwise. +func GetUserEnv() (uid, gid string) { + if v := os.Getenv("SUDO_UID"); v != "" { + uid = v + } else if v := os.Getenv("PKEXEC_UID"); v != "" { + uid = v + } else { uid = "0" } - if gid == "" { + if v := os.Getenv("SUDO_GID"); v != "" { + gid = v + } else { gid = "0" } return uid, gid } -func GetSudoEnvInt() (uid, gid int) { - uidString, gidString := GetSudoEnv() +func GetUserEnvInt() (uid, gid int) { + uidString, gidString := GetUserEnv() uid, _ = strconv.Atoi(uidString) gid, _ = strconv.Atoi(gidString) return uid, gid diff -Nru goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntuimage/images.go goget-ubuntu-touch-0.3+14.10.20140709/ubuntuimage/images.go --- goget-ubuntu-touch-0.2+14.10.20140429.1/ubuntuimage/images.go 2014-04-29 19:07:37.000000000 +0000 +++ goget-ubuntu-touch-0.3+14.10.20140709/ubuntuimage/images.go 2014-07-09 08:52:39.000000000 +0000 @@ -56,7 +56,7 @@ mount system ` -func GetUbuntuCommands(files []File, downloadDir string, wipe bool) (commandsFile string, err error) { +func GetUbuntuCommands(files []File, downloadDir string, wipe bool, enable []string) (commandsFile string, err error) { tmpFile, err := ioutil.TempFile(downloadDir, "ubuntu_commands") if err != nil { return commandsFile, err @@ -70,16 +70,23 @@ if wipe { writer.WriteString("format data\n") } - writer.WriteString(commandsStart) - order := func(f1, f2 *File) bool { - return f1.Order < f2.Order + if files != nil { + writer.WriteString(commandsStart) + order := func(f1, f2 *File) bool { + return f1.Order < f2.Order + } + By(order).Sort(files) + for _, file := range files { + writer.WriteString( + fmt.Sprintf("update %s %s\n", filepath.Base(file.Path), filepath.Base(file.Signature))) + } + writer.WriteString("unmount system\n") } - By(order).Sort(files) - for _, file := range files { - writer.WriteString( - fmt.Sprintf("update %s %s\n", filepath.Base(file.Path), filepath.Base(file.Signature))) + + //we cannot enable "things" outside of userdata + for i := range enable { + writer.WriteString(fmt.Sprintf("enable %s\n", enable[i])) } - writer.WriteString("unmount system\n") return tmpFile.Name(), err }