apt-get抑制有关缺少回购的警告

时间:2015-09-21 14:48:29

标签: linux apt

有一个开发和生产环境。每个都有一个Debian存储库。例如http://devhttp://prod

当机器(物理上)转移到生产环境时,如何避免更改/etc/apt/sources.list

一种解决方案是同时写两个:

deb http://dev/debian main
deb http://prod/debian main

可以在开发环境中发出关于无法访问http://prod/的警告。但是如何摆脱生产网络中的警告呢?

1 个答案:

答案 0 :(得分:0)

有一个整洁的镜子功能。在/etc/apt/sources.list

deb mirror://localhost/mirrors.txt jessie main

在同一台机器上托管的mirrors.txt中:

http://dev/debian
http://prod/debian

因此,它会在每个配置中找到一些存储库。

但无论如何它都会抱怨。我会选择一个剧本:

#!/bin/bash

# Generates a list of available repositories.

set -e

release_codename="$(lsb_release -cs)"

all_mirrors_list=/etc/locate-my-repositories/all-my-mirrors.list
active_list=/var/lib/locate-my-repositories/my.list

mirrors="$(cat "$all_mirrors_list")"

active=$(for r in $mirrors; do
    if curl -s "$r"/dists/"$release_codename"/main/binary-"$(dpkg --print-architecture)"/Release | grep -q '^Component:'; then
        printf '%s\n' "$r"
    fi
done)

# Formats a valid /etc/apr/sources.list: makes "deb http://url jessie main"
# entry from "http://url".
function to_sources_list() {
    sed "s/\(.*\)/deb \\1 $release_codename main/"
}

if [ -z "$active" ]; then
    # Nothing is found. Give everything to apt-get, maybe it will be more lucky.
    cat "$all_mirrors_list"
else
    printf '%s\n' "$active"
fi | to_sources_list > "$active_list"