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

« back to all changes in this revision

Viewing changes to data/apt-cdrom-check

  • Committer: Balint Reczey
  • Date: 2020-06-11 18:46:02 UTC
  • Revision ID: balint.reczey@canonical.com-20200611184602-2rv1zan3xu723x2u
Moved to git at https://git.launchpad.net/update-notifier

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