File: 01-set-ubuntu-mirror

package info (click to toggle)
python-diskimage-builder 3.37.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,572 kB
  • sloc: sh: 7,380; python: 6,444; makefile: 37
file content (56 lines) | stat: -rwxr-xr-x 2,251 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

if [[ ${DIB_DEBUG_TRACE:-0} -gt 1 ]]; then
    set -x
fi
set -eu
set -o pipefail

DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-}
SIGNED_BY=${SIGNED_BY:-}
DEB822_SOURCES_FILE=/etc/apt/sources.list.d/ubuntu.sources

if [[ -z "$DIB_DISTRIBUTION_MIRROR" ]]; then
    echo "DIB_DISTRIBUTION_MIRROR is empty"
    exit 0
fi

# ubuntu versions > jammy use https://repolib.readthedocs.io/en/latest/deb822-format.html
# check if the sources file is in the sources.list.d directory.
if [[ -f "$DEB822_SOURCES_FILE" ]]; then
    # ubuntu > jammy
    while IFS= read line
    do
        if [[ -n "${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-}" && "$line" =~ ${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-} ]]; then
            # append line unmodified
            echo "$line" | tee --append /etc/apt/sources.list.d/ubuntu.sources.new
        else
            if [[ "$line" == URIs:* ]]; then
                line=$(echo "$line" | sed -e "s&http://\(archive\|security\).ubuntu.com/ubuntu&$DIB_DISTRIBUTION_MIRROR&")
            elif [[ -n "$SIGNED_BY" && "$line" == Signed-By:* ]]; then
                line="Signed-By: $SIGNED_BY"
            fi
            echo "$line" | tee --append /etc/apt/sources.list.d/ubuntu.sources.new
        fi
    done < /etc/apt/sources.list.d/ubuntu.sources
    mv /etc/apt/sources.list.d/ubuntu.sources.new /etc/apt/sources.list.d/ubuntu.sources
else
    # ubuntu <= jammy
    while IFS= read line
    do
        if [[ -n "${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-}" && "$line" =~ ${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-} ]]; then
            # append line unmodified
            echo "$line" | tee --append /etc/apt/sources.list.new
        else
            echo "$line" | \
                sed -e "s&http://\(archive\|security\).ubuntu.com/ubuntu&$DIB_DISTRIBUTION_MIRROR&" | \
                tee --append /etc/apt/sources.list.new
        fi
    done < /etc/apt/sources.list

    mv /etc/apt/sources.list.new /etc/apt/sources.list
fi
if [[ -n "${DIB_DISTRIBUTION_MIRROR_UBUNTU_INSECURE:-}" ]]; then
    echo "APT::Get::AllowUnauthenticated \"true\";" | tee /etc/apt/apt.conf.d/95allow-unauthenticated
    echo "Acquire::AllowInsecureRepositories \"true\";" | tee -a /etc/apt/apt.conf.d/95allow-unauthenticated
fi