~phablet-team/phablet-tools/trunk

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh -e
# This program is free software: you can redistribute it and/or modify it
# under the terms of the 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 applicable version of 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 <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2014 Canonical, Ltd.

usage () {
cat <<EOF
usage: $0 COMMAND SILO-NUMBER

COMMANDS:
    host-install        Deprecated. Please use host-upgrade instead.
    device-install      Deprecated. Please use device-upgrade instead.
    host-upgrade        Upgrades your host machine with packages from the silo.
    device-upgrade      Upgrades your connected device with packages from the silo.
    host-purge          Uses ppa-purge to uninstall the silo contents from the host machine.
    device-purge        Not implemented.

SILO-NUMBER:
    1..20
EOF
exit 1
}

[ -x /usr/bin/sudo               ] || { echo "Please install 'sudo'"; exit 1; }
[ -x /usr/bin/add-apt-repository ] || { echo "Please install 'software-properties-common'"; exit 1; }

if [ -f "$(dirname $0)/shell-adb-common.sh" ]; then
    . "$(dirname $0)/shell-adb-common.sh"
else
    . "/usr/share/phabletutils/shell-adb-common.sh"
fi

# Defaults
PPA="ppa:ci-train-ppa-service"
HTTP="http://ppa.launchpad.net/ci-train-ppa-service"
SOURCES="ubuntu/dists/devel/main/source/Sources"

# Read the first positional argument.
COMMAND="$1"
[ $# -gt 0 ] && shift || usage

# Check that silo number is really a number.
echo "$1" | egrep -q "^[0-9]{1,3}$" || usage

# Read the second positional argument.
SILO=landing-$(printf "%03d" "$1")
[ $# -gt 0 ] && shift || usage

case "$COMMAND" in
    host-install)
        usage
        ;;

    device-install)
        usage
        ;;

    host-upgrade)
        set -x
        sudo add-apt-repository $PPA/$SILO
        sudo apt-get update -qq
        sudo apt-get dist-upgrade --yes
        ;;

    device-upgrade)
        check_devices
        echo "These PPAs are enabled on the device:"
        set -x
        adb shell egrep ^deb /etc/apt/sources.list.d/\*.list
        phablet-config writable-image --ppa $PPA/$SILO
        adb shell sudo apt-get -o Dir::Etc::SourceList=/dev/null update
        adb shell sudo apt-get dist-upgrade --yes
        adb reboot
        ;;

    host-purge)
        set -x
        sudo ppa-purge $PPA/$SILO
        ;;

    device-purge)
        echo "Unfortunately purging from the device is unsupported because"
        echo "ppa-purge is not installed by default in the images."
        echo "However, the silo packages go away next time you flash the device."
        ;;

    *)
        usage
        ;;
esac