Ubuntu Pastebin

Paste from longsleep at Tue, 1 Dec 2015 11:13:02 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From 3b4d386d0333c6fe91a94ed986fa08bf431e4592 Mon Sep 17 00:00:00 2001
From: Simon Eisenmann <simon@struktur.de>
Date: Tue, 1 Dec 2015 12:11:33 +0100
Subject: [PATCH] Added hack to move generated snap services to writable
 partition.

---
 ubuntu-device-flash/core.go | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/ubuntu-device-flash/core.go b/ubuntu-device-flash/core.go
index dd0c58a..1d9222a 100644
--- a/ubuntu-device-flash/core.go
+++ b/ubuntu-device-flash/core.go
@@ -14,6 +14,7 @@ import (
 	"io"
 	"io/ioutil"
 	"os"
+	"os/exec"
 	"path/filepath"
 	"strings"
 	"time"
@@ -80,11 +81,41 @@ func (coreCmd *CoreCmd) Execute(args []string) error {
 	if !coreCmd.Deprecated.Cloud {
 		coreCmd.customizationFunc = append(coreCmd.customizationFunc, coreCmd.setupCloudInit)
 		coreCmd.customizationFunc = append(coreCmd.customizationFunc, coreCmd.setupOemConfigs)
+		coreCmd.customizationFunc = append(coreCmd.customizationFunc, coreCmd.moveSnapServicesWritable)
 	}
 
 	return coreCmd.create()
 }
 
+// hack to move snap services to writable
+func (coreCmd *CoreCmd) moveSnapServicesWritable() error {
+	fmt.Println("Moving snappy systemd services to writable ...")
+
+	systemPath := coreCmd.img.System()
+	writableSystemPath := filepath.Join(coreCmd.img.Writable(), "system-data")
+
+	paths := []string{
+		filepath.Join("etc", "systemd", "system"),
+		filepath.Join("etc", "systemd", "system", "multi-user.target.wants"),
+	}
+
+	for _, path := range paths {
+		sourceDir := filepath.Join(systemPath, path)
+		targetDir := filepath.Join(writableSystemPath, path)
+		if err := os.MkdirAll(targetDir, 0755); err != nil {
+			return err
+		}
+		mv := fmt.Sprintf("mv %s/*_*.service %s", sourceDir, targetDir)
+		cmd := exec.Command("/bin/sh", "-c", mv)
+		if out, err := cmd.CombinedOutput(); err != nil {
+			fmt.Printf("Failed to move systemd services to writable: %s\n", out)
+			break
+		}
+	}
+
+	return nil
+}
+
 // this is a hackish way to get the config in place
 func (coreCmd *CoreCmd) setupOemConfigs() error {
 	modprobeDContent := coreCmd.oem.Config.UbuntuCore.Modprobe
-- 
2.5.0
Download as text