Issue
There is a development and production environment. In each one there is a Debian repository. For example http://dev
and http://prod
.
When the machine is transfered (physically) to the production environment, how to avoid changing /etc/apt/sources.list
?
One solution is to write both:
deb http://dev/debian main
deb http://prod/debian main
It's ok to have a warning about inaccessible http://prod/
in the dev environment. But how to get rid of the warning in the production network?
Solution
There is a neat mirror feature. In /etc/apt/sources.list
:
deb mirror://localhost/mirrors.txt jessie main
And in mirrors.txt
hosted on the same machine:
http://dev/debian
http://prod/debian
So, it'll find some repository in every config.
But it complains anyways. I'll go with a script:
#!/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"
Answered By - Velkan Answer Checked By - Marie Seifert (WPSolving Admin)