Ubuntu Pastebin

Paste from morphis at Tue, 14 Jul 2015 11:18:15 +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
67
68
diff --git a/bootable/recovery/system-image-upgrader b/bootable/recovery/system-image-upgrader
index f665d49..c273634 100755
--- a/bootable/recovery/system-image-upgrader
+++ b/bootable/recovery/system-image-upgrader
@@ -13,6 +13,9 @@ REMOVE_LIST="$COMMAND_FILE"
 # Used as a security check to see if we would change the password
 DATA_FORMAT=0
 
+# Used as indication if we have applied an update or not
+UPDATE_APPLIED=0
+
 # System Mountpoint
 SYSTEM_MOUNTPOINT=/cache/system
 
@@ -320,6 +323,15 @@ do
                 ;;
 
                 data)
+                    WHITELIST=".last_update .last_ubuntu-build system-data/var/lib/dbus/machine-id system-data/var/lib/whoopsie/whoopsie-id"
+                    BACKUP_DIR=`mktemp -d /tmp/backup.XXXXXX`
+
+                    # Backup all whitelisted files here so we can restore them later
+                    for file in $WHITELIST ; do
+                        mkdir -p $BACKUP_DIR/`dirname $file`
+                        cp -av $file $BACKUP_DIR/data/$file
+                    done
+
                     # If Android bits are used from the real system partition and we don't
                     # have any image in /data we need to loop mount we can simply reformat
                     # the userdata partition instead of erasing just files. In the other
@@ -342,6 +354,12 @@ do
                         done
                     fi
 
+                    # Now restore all files we created a backup for
+                    for file in $WHITELIST ; do
+                        mkdir -p /data/`dirname $file`
+                        cp -av $BACKUP_DIR/$file /data/$file
+                    done
+
                     # mtp is always enabled by default
                     usb_enable mtp
                     DATA_FORMAT=1
@@ -511,6 +529,8 @@ do
                     rm partitions/${part}.img
                 fi
             done
+
+            UPDATE_APPLIED=1
         ;;
 
         *)
@@ -561,7 +581,14 @@ fi
 chmod 600 /data/SWAP.img
 chown 0:0 /data/SWAP.img
 
-touch /data/.last_update || true
+# Only touch .last_update file when
+# * it doesn't exist
+# * or an update was applied
+# In all other caes we leave it as is to avoid changing it's access time
+if [ ! -e /data/.last_update ] || [ "$UPDATE_APPLIED" -eq 0 ] ; then
+    touch /data/.last_update
+fi
+
 sync
 
 echo "Done upgrading: $(date)"
Download as text