~baltix-members/baltix-default-settings/ubuntu

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/sh
#
# Copyright (c) 2011 Mantas Kriaučiūnas. All rights reserved.
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license.
#
# This script is part of the baltix-default-settings package.
#
# It copies software repositories from baltix-default-settings package's 
# /usr/share/app-install/channels/ folder to default APT repositories folder 
# (apt-config value 'Dir::Etc::sourceparts'
# TODO: monitor that config to see if it has been disabled by the overly aggressive
# distro upgrade process (e.g.  intrepid -> jaunty). When this situation is
# detected, the respository will be re-enabled. If the respository is disabled
# for any other reason, this won't re-enable it.
# This functionality can be controlled by creating the $DEFAULTS_FILE and
# setting "repo_add_once" and/or "repo_reenable_on_distupgrade" to "true" or
# "false" as desired. An empty $DEFAULTS_FILE is the same as setting both values
# to "false".
# System-wide package configuration.
#DEFAULTS_FILE="/etc/default/google-talkplugin"

# sources.list setting for google-talkplugin updates.
REPOCONFIG="deb http://dl.google.com/linux/talkplugin/deb/ stable main"

BALTIXREPOSLOCATION="/usr/share/app-install/channels/"

#APT_GET="`which apt-get 2> /dev/null`"
APT_CONFIG="`which apt-config 2> /dev/null`"

SOURCES_PREAMBLE="### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.\n"

# Parse apt configuration and return requested variable value.
apt_config_val() {
  APTVAR="$1"
  if [ -x "$APT_CONFIG" ]; then
    "$APT_CONFIG" dump | sed -e "/^$APTVAR /"'!d' -e "s/^$APTVAR \"\(.*\)\".*/\1/"
  fi
}

# Install the repository signing key
#install_key() {
#  APT_KEY="`which apt-key 2> /dev/null`"
#  if [ -x "$APT_KEY" ]; then
#    "$APT_KEY" add - >/dev/null 2>&1 << ...
#  fi
#}

# Set variables for the locations of the apt sources lists.
find_apt_sources() {
  APTDIR=$(apt_config_val Dir)
  APTETC=$(apt_config_val 'Dir::Etc')
  APT_SOURCES="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourcelist')"
  APT_SOURCESDIR="$APTDIR$APTETC$(apt_config_val 'Dir::Etc::sourceparts')"
}

# Note: this doesn't necessarily enable the repositories, it just makes sure the
# correct settings are available in the sources.list.d folder.
# Returns:
# 0 - no update necessary
# 2 - error
update_bad_sources() {
#  if [ ! "$REPOCONFIG" ]; then
#    return 0
#  fi

  find_apt_sources
  BALTIXSOURCES=$(dpkg -L baltix-default-settings |grep "$BALTIXREPOSLOCATION.*\.list$")
  BALTIXSOURCESNAMES=$(dpkg -L baltix-default-settings |grep "$BALTIXREPOSLOCATION.*\.list$"|sed -e "s/\/usr\/share\/app-install\/channels\///")
  USERSOURCES=$(find $APT_SOURCESDIR -name '*.list' -type f |grep -v -F "$BALTIXSOURCESNAMES")
#  SOURCELIST="$APT_SOURCESDIR/google-talkplugin.list"
  # Don't do anything if the file isn't there, since that probably means the
  # user disabled it.
#  if [ ! -r "$SOURCELIST" ]; then
#    return 0
#  fi

  # Basic check for active configurations (non-blank, non-comment lines).
  ACTIVECONFIGS=$(grep --no-filename -v "^[[:space:]]*\(#.*\)\?$" $BALTIXSOURCES|sed -e "s/[[:space:]]*#.*$//")

  TMPFOLDER=$(mktemp -t --directory baltix-software-repos.XXXX)

  # Removes duplicated repositories
  for repo in $USERSOURCES $APT_SOURCES
  do
    grep -v -F "$ACTIVECONFIGS" $repo > $TMPFOLDER/sources.list.d-repo
    mv -f $TMPFOLDER/sources.list.d-repo $repo
#   grep -l "^deb \+http://ppa\.launchpad\.net/baltix-members/ppa/ubuntu[/ ]\+natty" $APT_SOURCES $USERSOURCES
  done

  cp -b -f $BALTIXSOURCES $APT_SOURCESDIR

  return 0

#--code bellow is from google chrome or talkplugin, should remove unneeded parts--
  # Check if the correct repository configuration is in there.
  REPOMATCH=$(grep "^[[:space:]#]*\b$REPOCONFIG\b" "$SOURCELIST" \
    2>/dev/null)

  # Check if the correct repository is disabled.
  MATCH_DISABLED=$(echo "$REPOMATCH" | grep "^[[:space:]]*#" 2>/dev/null)

  # Now figure out if we need to fix things.
  BADCONFIG=1
  if [ "$REPOMATCH" ]; then
    # If it's there and active, that's ideal, so nothing to do.
    if [ ! "$MATCH_DISABLED" ]; then
      BADCONFIG=0
    else
      # If it's not active, but neither is anything else, that's fine too.
      if [ ! "$ACTIVECONFIGS" ]; then
        BADCONFIG=0
      fi
    fi
  fi

  if [ $BADCONFIG -eq 0 ]; then
    return 0
  fi

  # At this point, either the correct configuration is completely missing, or
  # the wrong configuration is active. In that case, just abandon the mess and
  # recreate the file with the correct configuration. If there were no active
  # configurations before, create the new configuration disabled.
  DISABLE=""
  if [ ! "$ACTIVECONFIGS" ]; then
    DISABLE="#"
  fi
  printf "$SOURCES_PREAMBLE" > "$SOURCELIST"
  printf "$DISABLE$REPOCONFIG\n" >> "$SOURCELIST"
  if [ $? -eq 0 ]; then
    return 0
  fi
  return 2
}

# Add the Google repository to the apt sources.
# Returns:
# 0 - sources list was created
# 2 - error
create_sources_lists() {
  if [ ! "$REPOCONFIG" ]; then
    return 0
  fi

  find_apt_sources

  SOURCELIST="$APT_SOURCESDIR/google-talkplugin.list"
  if [ -d "$APT_SOURCESDIR" ]; then
    printf "$SOURCES_PREAMBLE" > "$SOURCELIST"
    printf "$REPOCONFIG\n" >> "$SOURCELIST"
    if [ $? -eq 0 ]; then
      return 0
    fi
  fi
  return 2
}

# Remove our custom sources list file.
# Returns:
# 0 - successfully removed, or not configured
# !0 - failed to remove
clean_sources_lists() {
  if [ ! "$REPOCONFIG" ]; then
    return 0
  fi

  find_apt_sources

  rm -f "$APT_SOURCESDIR/google-talkplugin.list" \
        "$APT_SOURCESDIR/google-talkplugin-.list"
}

# Detect if the repo config was disabled by distro upgrade and enable if
# necessary.
handle_distro_upgrade() {
  if [ ! "$REPOCONFIG" ]; then
    return 0
  fi

  find_apt_sources
  SOURCELIST="$APT_SOURCESDIR/google-talkplugin.list"
  if [ -r "$SOURCELIST" ]; then
    REPOLINE=$(grep -E "^[[:space:]]*#[[:space:]]*$REPOCONFIG[[:space:]]*# disabled on upgrade to .*" "$SOURCELIST")
    if [ $? -eq 0 ]; then
      sed -i -e "s,^[[:space:]]*#[[:space:]]*\($REPOCONFIG\)[[:space:]]*# disabled on upgrade to .*,\1," \
        "$SOURCELIST"
      LOGGER=$(which logger 2> /dev/null)
      if [ "$LOGGER" ]; then
        "$LOGGER" -t "$0" "Reverted repository modification: $REPOLINE."
      fi
    fi
  fi
}


## MAIN ##
#DEFAULTS_FILE="/etc/default/google-talkplugin"
#if [ -r "$DEFAULTS_FILE" ]; then
#  . "$DEFAULTS_FILE"
#fi

#if [ "$repo_add_once" = "true" ]; then
#  install_key
#  create_sources_lists
#  RES=$?
#  # Sources creation succeeded, so stop trying.
#  if [ $RES -ne 2 ]; then
#    sed -i -e 's/[[:space:]]*repo_add_once=.*/repo_add_once="false"/' "$DEFAULTS_FILE"
#  fi
#else
update_bad_sources
#fi

#if [ "$repo_reenable_on_distupgrade" = "true" ]; then
#  handle_distro_upgrade
#fi