Tuesday, May 14, 2024
27
rated 0 times [  27] [ 0]  / answers: 1 / hits: 67618  / 1 Year ago, tue, february 21, 2023, 2:11:38

I am looking for the best method to restore /etc/apt/sources.list to default from the command line.



Is there no way to reference the source code of the package which generates this file or something like that? I want a trusted and version-independent way of restoring this file.



Solutions Ruled Out



Before you mark this as a duplicate, note that I have reviewed this question already. It is only applicable if you have the Ubuntu GUI available. This question is specific to the command line.



I have also reviewed this question where the accepted solution is someone pasted the contents of their sources.list file. This is not an appropriate way to restore the file as the intentions of the person providing the file contents cannot be verified and the file is subject to change with new releases.



I checked out the generator at simplelinux.ch, but this is also not from Ubuntu so I do not plan to use it.


More From » command-line

 Answers
2

I'm not sure what you want, but:



  • The parent repository is always http://archive.ubuntu.com/ubuntu - everything else is a mirror of this. The other primary mirrors all have a domain of the form <cctld>.archive.ubuntu.com, where the two character short code is the Country Code Top Level Domain. You can find additional mirrors with their status at Launchpad.

    • If you're on an architecture other than amd64 (e.e.g, arm64, armhf, ppc64el, etc.), then the parent repository is http://ports.ubuntu.com/ubuntu-ports. Use ports.ubuntu.com/ubuntu-ports instead of archive.ubuntu.com/ubuntu in everything that follows.



  • The distribution codename is part of the channel (the third term). You can use lsb_release -sc to find that out, and it's the first word of the release pretty name in lowercase (trusty for Trusty Tahr, for example).

  • There are five channels: <codename>, <codename>-security, <codename>-updates, <codename>-backports and <codename>-proposed. The first is necessary as it is the base, the second is highly recommended as it contains security fixes, the fourth only if you need some package backported from a newer release and the fifth only if a developer asks you to enable it for testing a possible fix.

  • There are four repository sections: main, multiverse, universe and restricted (What's the difference between multiverse, universe, restricted and main?)


So you can always create a safe sources.list which contains just:


deb http://archive.ubuntu.com/ubuntu <codename> main multiverse universe restricted
deb http://archive.ubuntu.com/ubuntu <codename>-security main multiverse universe restricted

If you want a command to do this:


printf 'deb http://archive.ubuntu.com/ubuntu %s main multiverse universe restricted
' "$(lsb_release -sc)"{,-security} > /etc/apt/sources.list

Or, lsb_release isn't available, use /etc/os-release from the base-files package:


printf 'deb http://archive.ubuntu.com/ubuntu %s main multiverse universe restricted
' "$(. /etc/os-release; printf "%s" "$UBUNTU_CODENAME")"{,-security} > /etc/apt/sources.list



In addition to the Launchpad list, the list provided by the Software Sources program is
from /usr/share/python-apt/templates/Ubuntu.mirrors, which is from the python-apt-common package. This package is only an indirect Suggests dependency of apt, so it may not be installed by default on a server.


[#21282] Wednesday, February 22, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lotceptin

Total Points: 374
Total Questions: 106
Total Answers: 118

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
;