# TODO(mmoss) Support configuring multiple repositories (e.g. stable and # testing) REPOCONFIG="@@REPOCONFIG@@" APT_GET="`which apt-get 2> /dev/null`" APT_CONFIG="`which apt-config 2> /dev/null`" # 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 (see also: # http://www.google.com/linuxrepositories/aboutkey.html) install_key() { APT_KEY="`which apt-key 2> /dev/null`" if [ -x "$APT_KEY" ]; then "$APT_KEY" add - >/dev/null 2>&1 </dev/null | cut -d ':' -f 1) if [ -n "$SOURCELIST" ]; then return 0 fi printf "$REPOCONFIG\n" > "$APT_SOURCESDIR/@@PACKAGE@@.list" if [ $? -eq 0 ]; then return 1 fi fi # TODO(mmoss) What are the chances that any distro we support doesn't provide # APT_SOURCESDIR nowadays? Should we just bail if we get here? It makes # cleanup easier if we don't have to worry about undoing changes to # APT_SOURCES, which may conflict with other changes or manual edits. # Nothing to do if it's already there. SOURCELIST=$(grep -H "$REPOCONFIG" "$APT_SOURCES" 2>/dev/null \ | cut -d ':' -f 1) if [ -n "$SOURCELIST" ]; then return 0 fi if [ -w "$APT_SOURCES" ]; then printf "$REPOCONFIG #@@PACKAGE@@\n" >> "$APT_SOURCES" return 1 fi return 2 } # Remove a repository from the apt sources. # Returns: # 0 - successfully removed, or not configured # 1 - failed to remove clean_sources_lists() { find_apt_sources if [ -d "$APT_SOURCESDIR" ]; then # Check if our package.list has this repo configured. SOURCELIST=$(grep -H "$REPOCONFIG" "$APT_SOURCESDIR/@@PACKAGE@@.list" \ 2>/dev/null | cut -d ':' -f 1) if [ -n "$SOURCELIST" ]; then sed -i -e "\,$REPOCONFIG,d" "$SOURCELIST" if [ $? -ne 0 ]; then return 1 fi # Delete file if empty (all comments or whitespace) LINECOUNT=$(sed -e '/^[[:space:]]*\(#.*\|$\)/d' "$SOURCELIST" | wc -l) if [ "$LINECOUNT" = "0" ]; then rm -f "$SOURCELIST" fi fi fi # Also check if it was added to the global sources.list SOURCELIST=$(grep -H "$REPOCONFIG" "$APT_SOURCES" 2>/dev/null \ | cut -d ':' -f 1) if [ -n "$SOURCELIST" ]; then # Remove repo line(s) marked with our package comment sed -i -e "\,$REPOCONFIG #@@PACKAGE@@,d" "$SOURCELIST" if [ $? -ne 0 ]; then return 1 fi fi return 0 }