Merge lp:~sergiusens/goget-ubuntu-touch/static_ited into lp:goget-ubuntu-touch

Proposed by Sergio Schvezov
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 97
Merged at revision: 97
Proposed branch: lp:~sergiusens/goget-ubuntu-touch/static_ited
Merge into: lp:goget-ubuntu-touch
Prerequisite: lp:~sergiusens/goget-ubuntu-touch/emupass
Diff against target: 138 lines (+44/-14)
3 files modified
debian/control (+1/-0)
diskimage/customization.go (+0/-13)
ubuntu-emulator/create.go (+43/-1)
To merge this branch: bzr merge lp:~sergiusens/goget-ubuntu-touch/static_ited
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+242776@code.launchpad.net

This proposal supersedes a proposal from 2014-11-25.

Commit message

ubuntu-emulator: fixing password setup for phablet user when setting up an armhf instance

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Good, works as expected.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-11-18 16:31:22 +0000
3+++ debian/control 2014-11-25 13:09:00 +0000
4@@ -43,6 +43,7 @@
5 ${misc:Depends},
6 ${shlibs:Depends},
7 Recommends: android-tools-adb,
8+ qemu-user-static,
9 Built-Using: ${misc:Built-Using}
10 Description: Create and run emulator images of Ubuntu Touch
11 Create and destroy Ubuntu Touch instances and run them with the emulator
12
13=== modified file 'diskimage/customization.go'
14--- diskimage/customization.go 2014-11-03 14:30:04 +0000
15+++ diskimage/customization.go 2014-11-25 13:09:00 +0000
16@@ -20,11 +20,9 @@
17 // with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 import (
20- "errors"
21 "fmt"
22 "io/ioutil"
23 "os"
24- "os/exec"
25 "path/filepath"
26 )
27
28@@ -85,14 +83,3 @@
29 writeFlag := filepath.Join(img.Mountpoint, ".adb_onlock")
30 return ioutil.WriteFile(writeFlag, []byte(""), 0644)
31 }
32-
33-//SetPassword is an ugly hack to set the password
34-func (img DiskImage) SetPassword(user, password string) error {
35- // Run something that would look like this
36- // PATH=$path chroot "$SYSTEM_MOUNTPOINT" /bin/sh -c "echo -n "$user:$password" | chpasswd"
37- chrootCmd := fmt.Sprintf("echo -n '%s:%s' | chpasswd", user, password)
38- if out, err := exec.Command("chroot", img.Mountpoint, "/bin/sh", "-c", chrootCmd).CombinedOutput(); err != nil {
39- return errors.New(string(out))
40- }
41- return nil
42-}
43
44=== modified file 'ubuntu-emulator/create.go'
45--- ubuntu-emulator/create.go 2014-11-25 13:09:00 +0000
46+++ ubuntu-emulator/create.go 2014-11-25 13:09:00 +0000
47@@ -23,6 +23,7 @@
48 "errors"
49 "fmt"
50 "os"
51+ "os/exec"
52 "path/filepath"
53 "runtime"
54 "syscall"
55@@ -50,6 +51,11 @@
56 defaultArch = "i386"
57 )
58
59+const (
60+ binQemuArmStatic = "/usr/bin/qemu-arm-static"
61+ pkgQemuUserStatic = "qemu-user-static"
62+)
63+
64 func init() {
65 createCmd.Arch = defaultArch
66 createCmd.Channel = defaultChannel
67@@ -67,6 +73,10 @@
68 }
69 instanceName := args[0]
70
71+ if err := createCmd.verifyDependencies(); err != nil {
72+ return err
73+ }
74+
75 var device string
76 if d, ok := devices[createCmd.Arch]; ok {
77 device = d["name"]
78@@ -180,6 +190,17 @@
79 return systemImage.ExtractFile("build.prop", filepath.Join(dataDir, "system"))
80 }
81
82+func (createCmd *CreateCmd) verifyDependencies() error {
83+ switch createCmd.Arch {
84+ case "armhf":
85+ if _, err := os.Stat(binQemuArmStatic); err != nil {
86+ return fmt.Errorf("missing dependency %s (apt install %s)", binQemuArmStatic, pkgQemuUserStatic)
87+ }
88+ }
89+
90+ return nil
91+}
92+
93 func (createCmd *CreateCmd) createSystem(ubuntuImage, sdcardImage *diskimage.DiskImage, files []string) (err error) {
94 for _, img := range []*diskimage.DiskImage{ubuntuImage, sdcardImage} {
95 if err := img.CreateExt4(); err != nil {
96@@ -206,13 +227,15 @@
97 }
98 return err
99 }
100+
101 fmt.Printf("Setting up a default password for phablet to: '%s'\n", createCmd.Password)
102- if err := ubuntuImage.SetPassword("phablet", createCmd.Password); err != nil {
103+ if err := createCmd.setPassword(ubuntuImage.Mountpoint); err != nil {
104 if err := ubuntuImage.Unmount(); err != nil {
105 fmt.Println("Unmount error :", err)
106 }
107 return err
108 }
109+
110 if err := ubuntuImage.Unmount(); err != nil {
111 return err
112 }
113@@ -232,6 +255,25 @@
114 return nil
115 }
116
117+// setPassword is an ugly hack to set the password
118+func (createCmd *CreateCmd) setPassword(chroot string) error {
119+ if createCmd.Arch == "armhf" {
120+ dst := filepath.Join(chroot, binQemuArmStatic)
121+ if out, err := exec.Command("cp", binQemuArmStatic, dst).CombinedOutput(); err != nil {
122+ return fmt.Errorf("issues while setting up password: %s", out)
123+ }
124+ defer os.Remove(dst)
125+ }
126+
127+ // Run something that would look like this
128+ // PATH=$path chroot "$SYSTEM_MOUNTPOINT" /bin/sh -c "echo -n "$user:$password" | chpasswd"
129+ chrootCmd := fmt.Sprintf("echo -n '%s:%s' | chpasswd", "phablet", createCmd.Password)
130+ if out, err := exec.Command("chroot", chroot, "/bin/sh", "-c", chrootCmd).CombinedOutput(); err != nil {
131+ return errors.New(string(out))
132+ }
133+ return nil
134+}
135+
136 func download(image ubuntuimage.Image) (files []string, err error) {
137 cacheDir := ubuntuimage.GetCacheDir()
138 totalFiles := len(image.Files)

Subscribers

People subscribed via source and target branches