~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to data/apt-cdrom-check

  • Committer: Michael Vogt
  • Date: 2012-03-22 20:17:55 UTC
  • Revision ID: michael.vogt@ubuntu.com-20120322201755-v7kc7wlrtuax2p82
add empty test in preparation for more to come :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# helper to check if we actually have an ubuntu CD
 
4
#
 
5
# Returncode:
 
6
# 0 - no ubuntu CD
 
7
# 1 - CD with packages 
 
8
# 2 - dist-upgrader CD
 
9
# 3 - addon CD
 
10
# 4 - aptoncd media
 
11
# (if the returncodes change, make sure to update src/gdu.c)
 
12
 
13
 
 
14
mount_point="$1"
 
15
addon_dir="$mount_point/app-install/"
 
16
aptoncd_file="$mount_point/aptoncd.info"
 
17
 
 
18
# sanity checks
 
19
if [ -z "$mount_point" ]; then
 
20
    exit 0
 
21
fi
 
22
 
 
23
if [ -f "$aptoncd_file" ]; then
 
24
    exit 4
 
25
fi
 
26
 
 
27
if [ ! -d "$mount_point/ubuntu" ] && [ ! -f "$mount_point/cdromupgrade" ]; then
 
28
    exit 0
 
29
fi
 
30
 
 
31
# check if there are "Packages" files on the cd (and ignore the 
 
32
# debian-installer dir)
 
33
find "$mount_point/dists/"  -name "Packages.gz" | grep -q -v debian-installer
 
34
 
 
35
# 1 means "no lines were selected" in grep (no Packages file but the 
 
36
# debian-installer ones)
 
37
if [ $? -eq 1 ]; then
 
38
    exit 0
 
39
fi
 
40
 
 
41
# get some apt-config vars
 
42
label_start=0
 
43
cdrom_id=""
 
44
 
 
45
apt_dir="/"
 
46
apt_state_dir="var/lib/apt/"
 
47
apt_cdrom_list="cdrom.list"
 
48
eval $(apt-config shell apt_dir Dir \
 
49
                        apt_state_dir Dir::State \
 
50
                        apt_cdrom_list Dir::State::cdroms)
 
51
 
 
52
 
 
53
 
 
54
# identifying ... [afkdsjaf] line
 
55
line=$(apt-cdrom -d="$1" -m ident|grep "\[.*\]")
 
56
 
 
57
# remove the stuff before "Identifying... [dasjflkd]" -> "dasjflkd"
 
58
line=${line%]*}
 
59
cdrom_id=${line#*\[}
 
60
 
 
61
if [ -z "$cdrom_id" ]; then
 
62
    # something bad happened here, we return "not yet scanned" as 
 
63
    # fallback (because we are cheap)
 
64
    return 1
 
65
fi
 
66
 
 
67
# we always return ADDON cd regardless if we know it already or not
 
68
# the rationale is that it easier for people this way and less 
 
69
# confusing
 
70
if [ -d "$addon_dir" ] && [ -x /usr/bin/gnome-app-install ]; then
 
71
    exit 3
 
72
fi
 
73
 
 
74
# [cdrom-id] -> cdrom-id  
 
75
if grep -s -q "$cdrom_id"  $apt_dir$apt_state_dir$apt_cdrom_list; then
 
76
    # already in sources.list, ignore
 
77
    exit 0
 
78
fi
 
79
 
 
80
# so this is a CD we don't know yet and it has packages. good!
 
81
 
 
82
# now check if it contains a signed dist-upgrader
 
83
for d in "$mount_point"/dists/*/main/dist-upgrader/binary-all/; do
 
84
    if [ -d "$d" ]; then
 
85
        # ok, we have one, now check the authentication 
 
86
        GPG="gpgv --ignore-time-conflict --keyring /etc/apt/trusted.gpg"
 
87
        if $GPG "$d/"*.tar.gz.gpg "$d"/*.tar.gz; then
 
88
        # verified ok, we have a valid upgrader, if it was not ok, the
 
89
        # fallback to the end is ok because we still have packages on it
 
90
            exit 2
 
91
        fi
 
92
    fi
 
93
done
 
94
 
 
95
# we got an ubuntu CD with packages
 
96
exit 1