apt.include revision 868fa2fe829687343ffae624259930155e16dbd8
1@@include@@variables.include
2
3APT_GET="`which apt-get 2> /dev/null`"
4APT_CONFIG="`which apt-config 2> /dev/null`"
5
6SOURCES_PREAMBLE="### THIS FILE IS AUTOMATICALLY CONFIGURED ###
7# You may comment out this entry, but any other modifications may be lost.\n"
8
9# Parse apt configuration and return requested variable value.
10apt_config_val() {
11  APTVAR="$1"
12  if [ -x "$APT_CONFIG" ]; then
13    "$APT_CONFIG" dump | sed -e "/^$APTVAR /"'!d' -e "s/^$APTVAR \"\(.*\)\".*/\1/"
14  fi
15}
16
17# Install the repository signing key (see also:
18# http://www.google.com/linuxrepositories/aboutkey.html)
19install_key() {
20  APT_KEY="`which apt-key 2> /dev/null`"
21  if [ -x "$APT_KEY" ]; then
22    "$APT_KEY" add - >/dev/null 2>&1 <<KEYDATA
23-----BEGIN PGP PUBLIC KEY BLOCK-----
24Version: GnuPG v1.4.2.2 (GNU/Linux)
25
26mQGiBEXwb0YRBADQva2NLpYXxgjNkbuP0LnPoEXruGmvi3XMIxjEUFuGNCP4Rj/a
27kv2E5VixBP1vcQFDRJ+p1puh8NU0XERlhpyZrVMzzS/RdWdyXf7E5S8oqNXsoD1z
28fvmI+i9b2EhHAA19Kgw7ifV8vMa4tkwslEmcTiwiw8lyUl28Wh4Et8SxzwCggDcA
29feGqtn3PP5YAdD0km4S4XeMEAJjlrqPoPv2Gf//tfznY2UyS9PUqFCPLHgFLe80u
30QhI2U5jt6jUKN4fHauvR6z3seSAsh1YyzyZCKxJFEKXCCqnrFSoh4WSJsbFNc4PN
31b0V0SqiTCkWADZyLT5wll8sWuQ5ylTf3z1ENoHf+G3um3/wk/+xmEHvj9HCTBEXP
3278X0A/0Tqlhc2RBnEf+AqxWvM8sk8LzJI/XGjwBvKfXe+l3rnSR2kEAvGzj5Sg0X
334XmfTg4Jl8BNjWyvm2Wmjfet41LPmYJKsux3g0b8yzQxeOA4pQKKAU3Z4+rgzGmf
34HdwCG5MNT2A5XxD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jpvHtwAnA1R3IHqFLQ2X3xJ40XPuAyY
51/FJG
52=Quqp
53-----END PGP PUBLIC KEY BLOCK-----
54KEYDATA
55  fi
56}
57
58# Set variables for the locations of the apt sources lists.
59find_apt_sources() {
60  APTDIR=$(apt_config_val Dir)
61  APTETC=$(apt_config_val 'Dir::Etc')
62  APT_SOURCES="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourcelist')"
63  APT_SOURCESDIR="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourceparts')"
64}
65
66# Update the Google repository if it's not set correctly.
67# Note: this doesn't necessarily enable the repository, it just makes sure the
68# correct settings are available in the sources list.
69# Returns:
70# 0 - no update necessary
71# 2 - error
72update_bad_sources() {
73  if [ ! "$REPOCONFIG" ]; then
74    return 0
75  fi
76
77  find_apt_sources
78
79  SOURCELIST="$APT_SOURCESDIR/@@PACKAGE@@.list"
80  # Don't do anything if the file isn't there, since that probably means the
81  # user disabled it.
82  if [ ! -r "$SOURCELIST" ]; then
83    return 0
84  fi
85
86  # Basic check for active configurations (non-blank, non-comment lines).
87  ACTIVECONFIGS=$(grep -v "^[[:space:]]*\(#.*\)\?$" "$SOURCELIST" 2>/dev/null)
88
89  # Check if the correct repository configuration is in there.
90  REPOMATCH=$(grep "^[[:space:]#]*\b$REPOCONFIG\b" "$SOURCELIST" \
91    2>/dev/null)
92
93  # Check if the correct repository is disabled.
94  MATCH_DISABLED=$(echo "$REPOMATCH" | grep "^[[:space:]]*#" 2>/dev/null)
95
96  # Now figure out if we need to fix things.
97  BADCONFIG=1
98  if [ "$REPOMATCH" ]; then
99    # If it's there and active, that's ideal, so nothing to do.
100    if [ ! "$MATCH_DISABLED" ]; then
101      BADCONFIG=0
102    else
103      # If it's not active, but neither is anything else, that's fine too.
104      if [ ! "$ACTIVECONFIGS" ]; then
105        BADCONFIG=0
106      fi
107    fi
108  fi
109
110  if [ $BADCONFIG -eq 0 ]; then
111    return 0
112  fi
113
114  # At this point, either the correct configuration is completely missing, or
115  # the wrong configuration is active. In that case, just abandon the mess and
116  # recreate the file with the correct configuration. If there were no active
117  # configurations before, create the new configuration disabled.
118  DISABLE=""
119  if [ ! "$ACTIVECONFIGS" ]; then
120    DISABLE="#"
121  fi
122  printf "$SOURCES_PREAMBLE" > "$SOURCELIST"
123  printf "$DISABLE$REPOCONFIG\n" >> "$SOURCELIST"
124  if [ $? -eq 0 ]; then
125    return 0
126  fi
127  return 2
128}
129
130# Add the Google repository to the apt sources.
131# Returns:
132# 0 - sources list was created
133# 2 - error
134create_sources_lists() {
135  if [ ! "$REPOCONFIG" ]; then
136    return 0
137  fi
138
139  find_apt_sources
140
141  SOURCELIST="$APT_SOURCESDIR/@@PACKAGE@@.list"
142  if [ -d "$APT_SOURCESDIR" ]; then
143    printf "$SOURCES_PREAMBLE" > "$SOURCELIST"
144    printf "$REPOCONFIG\n" >> "$SOURCELIST"
145    if [ $? -eq 0 ]; then
146      return 0
147    fi
148  fi
149  return 2
150}
151
152# Remove our custom sources list file.
153# Returns:
154# 0 - successfully removed, or not configured
155# !0 - failed to remove
156clean_sources_lists() {
157  if [ ! "$REPOCONFIG" ]; then
158    return 0
159  fi
160
161  find_apt_sources
162
163  rm -f "$APT_SOURCESDIR/@@PACKAGE@@.list" \
164        "$APT_SOURCESDIR/@@PACKAGE@@-@@CHANNEL@@.list"
165}
166
167# Detect if the repo config was disabled by distro upgrade and enable if
168# necessary.
169handle_distro_upgrade() {
170  if [ ! "$REPOCONFIG" ]; then
171    return 0
172  fi
173
174  find_apt_sources
175  SOURCELIST="$APT_SOURCESDIR/@@PACKAGE@@.list"
176  if [ -r "$SOURCELIST" ]; then
177    REPOLINE=$(grep -E "^[[:space:]]*#[[:space:]]*$REPOCONFIG[[:space:]]*# disabled on upgrade to .*" "$SOURCELIST")
178    if [ $? -eq 0 ]; then
179      sed -i -e "s,^[[:space:]]*#[[:space:]]*\($REPOCONFIG\)[[:space:]]*# disabled on upgrade to .*,\1," \
180        "$SOURCELIST"
181      LOGGER=$(which logger 2> /dev/null)
182      if [ "$LOGGER" ]; then
183        "$LOGGER" -t "$0" "Reverted repository modification: $REPOLINE."
184      fi
185    fi
186  fi
187}
188
189DEFAULT_ARCH="@@ARCHITECTURE@@"
190
191get_lib_dir() {
192  if [ "$DEFAULT_ARCH" = "i386" ]; then
193    LIBDIR=lib/i386-linux-gnu
194  elif [ "$DEFAULT_ARCH" = "amd64" ]; then
195    LIBDIR=lib/x86_64-linux-gnu
196  else
197    echo Unknown CPU Architecture: "$DEFAULT_ARCH"
198    exit 1
199  fi
200}
201