Merge lp:~robru/phablet-tools/use-ticket-number into lp:phablet-tools

Proposed by Robert Bruce Park on 2016-09-12
Status: Merged
Approved by: Robert Bruce Park on 2016-09-13
Approved revision: 376
Merged at revision: 368
Proposed branch: lp:~robru/phablet-tools/use-ticket-number
Merge into: lp:phablet-tools
Diff against target: 116 lines (+49/-10)
1 file modified
bileto (+49/-10)
To merge this branch: bzr merge lp:~robru/phablet-tools/use-ticket-number
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team 2016-09-12 Pending
Review via email: mp+305426@code.launchpad.net

Commit message

Only reboot device if something actually updated.

To post a comment you must log in.
369. By Robert Bruce Park on 2016-09-12

Only reboot device if something was actually updated.

370. By Robert Bruce Park on 2016-09-12

Only reboot device if something from the right PPA was actually updated.

371. By Robert Bruce Park on 2016-09-12

Only reboot when new packages installed from PPAs.

372. By Robert Bruce Park on 2016-09-12

Check only the one PPA we are trying to install

373. By Robert Bruce Park on 2016-09-12

Make it actually work.

374. By Robert Bruce Park on 2016-09-12

Make before/after files one line per package.

375. By Robert Bruce Park on 2016-09-12

Cleanup

376. By Robert Bruce Park on 2016-09-13

Make big noisy error when installation fails.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bileto'
2--- bileto 2016-09-02 17:06:03 +0000
3+++ bileto 2016-09-13 18:21:00 +0000
4@@ -16,7 +16,7 @@
5
6 usage () {
7 cat <<EOF
8-usage: $0 COMMAND SILO-NUMBER [DEVICE-PASSWORD]
9+usage: $0 COMMAND TICKET-NUMBER [DEVICE-PASSWORD]
10 $1
11
12 COMMANDS:
13@@ -35,6 +35,25 @@
14 adb shell "$@"
15 }
16
17+# List all packages available in PPA $NAME, and all packages installed locally
18+_apt_ppa_manifest() {
19+ adb shell 'sed --quiet --expression "s/^Package: //p" /var/lib/apt/lists/*ppa-service*'$NAME'*Packages' | tr -d '\r'
20+ adb shell dpkg --get-selections | grep --invert-match deinstall | tr -d '\r' | tr : '\t' | cut --field 1
21+}
22+
23+# Lists binary packages installed from PPA $NAME.
24+apt_ppa_manifest() {
25+ _apt_ppa_manifest | sort | uniq --repeated
26+}
27+
28+# List packages names & versions which were installed from PPA $NAME.
29+apt_ppa_versions() {
30+ for binary in $(apt_ppa_manifest); do
31+ # shellcheck disable=SC2046
32+ echo $(adb shell "apt-cache policy $binary" | head -2)
33+ done
34+}
35+
36 [ -x /usr/bin/sudo ] || { echo "Please install 'sudo'"; exit 1; }
37 [ -x /usr/bin/add-apt-repository ] || { echo "Please install 'software-properties-common'"; exit 1; }
38
39@@ -57,16 +76,18 @@
40 [ $# -gt 0 ] && shift || usage "Missing COMMAND"
41
42 # Check that silo number is really a number.
43-echo "$1" | egrep -q "^[0-9]+$" || usage "SILO-NUMBER not a number."
44+echo "$1" | egrep -q "^[0-9]+$" || usage "TICKET-NUMBER not a number."
45
46 # Read the second positional argument.
47-SILO="landing-$1"
48-[ $# -gt 0 ] && shift || usage "Missing SILO-NUMBER."
49+TICKET="$1"
50+[ $# -gt 0 ] && shift || usage "Missing TICKET-NUMBER."
51+
52+NAME="$(curl https://requests.ci-train.ubuntu.com/v1/ticket/$TICKET | grep --perl-regexp --only-matching '"siloname":\s?"\K[^"]+' | sed --quiet --expression '1s#\w\+/##p')"
53
54 case "$COMMAND" in
55 host-upgrade)
56- set -x
57- sudo add-apt-repository "$PPA/$SILO"
58+ set -eux
59+ sudo add-apt-repository "$PPA/$NAME"
60 sudo apt-get update -qq
61 sudo apt-get dist-upgrade --yes
62 ;;
63@@ -88,12 +109,12 @@
64
65 # Stable images have stable-snapshot PPA but sometimes we need to pull deps from overlay:
66 loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A add-apt-repository -y "$PPA/$DISTRO/stable-phone-overlay"
67- loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A add-apt-repository -y "$PPA/$DISTRO/$SILO"
68+ loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A add-apt-repository -y "$PPA/$DISTRO/$NAME"
69
70 loudly "test -e /usr/sbin/policy-rc.d && cp /usr/sbin/policy-rc.d /tmp/policy-rc.d"
71 loudly "echo 'exit 101' | SUDO_ASKPASS=/tmp/askpass.sh sudo -A tee /usr/sbin/policy-rc.d"
72 loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A chmod +x /usr/sbin/policy-rc.d
73- loudly "echo -e 'Package: *\nPin: release o=*$SILO*\nPin-Priority: 1100\n\nPackage: *\nPin: release a=$SERIES*\nPin-Priority: 50' | SUDO_ASKPASS=/tmp/askpass.sh sudo -A tee /etc/apt/preferences.d/extra-ppas.pref"
74+ loudly "echo -e 'Package: *\nPin: release o=*$NAME*\nPin-Priority: 1100\n\nPackage: *\nPin: release a=$SERIES*\nPin-Priority: 50' | SUDO_ASKPASS=/tmp/askpass.sh sudo -A tee /etc/apt/preferences.d/extra-ppas.pref"
75 loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-get update
76
77 # We need to put lxc-android-config on hold here as it's the only
78@@ -101,18 +122,36 @@
79 # https://wiki.ubuntu.com/Touch/Testing/lxc-android-config for details.
80 loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-mark hold lxc-android-config
81
82+ before="$(mktemp /tmp/bileto-before-XXX.txt)"
83+ apt_ppa_versions > "$before"
84+
85 loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-get dist-upgrade --yes --force-yes
86 loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-get autoremove --yes --force-yes
87
88+ after="$(mktemp /tmp/bileto-after-XXX.txt)"
89+ apt_ppa_versions > "$after"
90+
91 loudly "test ! -e /tmp/policy-rc.d && SUDO_ASKPASS=/tmp/askpass.sh sudo -A rm /usr/sbin/policy-rc.d"
92 loudly "test -e /tmp/policy-rc.d && SUDO_ASKPASS=/tmp/askpass.sh sudo -A mv /tmp/policy-rc.d /usr/sbin/policy-rc.d"
93 loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A apt-mark unhold lxc-android-config
94- loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A reboot
95+
96+ if diff "$before" "$after"; then
97+ echo "ERROR: No new packages installed! Skipping reboot, please investigate why installation failed."
98+ echo
99+ echo "PPA manifest before installation:"
100+ cat "$before"
101+ echo
102+ echo "PPA manifest after installation:"
103+ cat "$after"
104+ else
105+ loudly SUDO_ASKPASS=/tmp/askpass.sh sudo -A reboot
106+ fi
107+ rm --force "$before" "$after"
108 ;;
109
110 host-purge)
111 set -x
112- sudo ppa-purge "$PPA/$SILO"
113+ sudo ppa-purge "$PPA/$NAME"
114 ;;
115
116 device-purge)

Subscribers

People subscribed via source and target branches