2022-11-08 18:09:53 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Generate the sources.list.<arch> in the config path
|
|
|
|
CONFIG_PATH=$1
|
|
|
|
export ARCHITECTURE=$2
|
|
|
|
export DISTRIBUTION=$3
|
|
|
|
|
2023-09-23 20:07:04 -05:00
|
|
|
# Handling default
|
|
|
|
[[ -z $APT_RETRIES_COUNT ]] && APT_RETRIES_COUNT=20
|
|
|
|
export APT_RETRIES_COUNT
|
|
|
|
|
2023-01-13 02:16:35 -06:00
|
|
|
DEFAULT_MIRROR_URL_PREFIX=http://packages.trafficmanager.net
|
2023-02-14 00:59:38 -06:00
|
|
|
MIRROR_VERSION_FILE=
|
|
|
|
[[ "$SONIC_VERSION_CONTROL_COMPONENTS" == *deb* || $SONIC_VERSION_CONTROL_COMPONENTS == *all* ]] && MIRROR_VERSION_FILE=files/build/versions/default/versions-mirror
|
2023-01-13 02:16:35 -06:00
|
|
|
[ -f target/versions/default/versions-mirror ] && MIRROR_VERSION_FILE=target/versions/default/versions-mirror
|
|
|
|
|
2022-11-08 18:09:53 -06:00
|
|
|
# The default mirror urls
|
|
|
|
DEFAULT_MIRROR_URLS=http://debian-archive.trafficmanager.net/debian/,http://packages.trafficmanager.net/debian/debian/
|
|
|
|
DEFAULT_MIRROR_SECURITY_URLS=http://debian-archive.trafficmanager.net/debian-security/,http://packages.trafficmanager.net/debian/debian-security/
|
|
|
|
|
2023-01-13 02:16:35 -06:00
|
|
|
|
2022-11-08 18:09:53 -06:00
|
|
|
# The debian-archive.trafficmanager.net does not support armhf, use debian.org instead
|
|
|
|
if [ "$ARCHITECTURE" == "armhf" ]; then
|
|
|
|
DEFAULT_MIRROR_URLS=http://deb.debian.org/debian/,http://packages.trafficmanager.net/debian/debian/
|
|
|
|
DEFAULT_MIRROR_SECURITY_URLS=http://deb.debian.org/debian-security/,http://packages.trafficmanager.net/debian/debian-security/
|
|
|
|
fi
|
|
|
|
|
2023-01-13 02:16:35 -06:00
|
|
|
if [ "$MIRROR_SNAPSHOT" == y ]; then
|
2023-02-14 00:59:38 -06:00
|
|
|
if [ -f "$MIRROR_VERSION_FILE" ]; then
|
2023-01-13 02:16:35 -06:00
|
|
|
DEBIAN_TIMESTAMP=$(grep "^debian==" $MIRROR_VERSION_FILE | tail -n 1 | sed 's/.*==//')
|
|
|
|
DEBIAN_SECURITY_TIMESTAMP=$(grep "^debian-security==" $MIRROR_VERSION_FILE | tail -n 1 | sed 's/.*==//')
|
|
|
|
elif [ -z "$DEBIAN_TIMESTAMP" ] || [ -z "$DEBIAN_SECURITY_TIMESTAMP" ]; then
|
|
|
|
DEBIAN_TIMESTAMP=$(curl $DEFAULT_MIRROR_URL_PREFIX/snapshot/debian/latest/timestamp)
|
|
|
|
DEBIAN_SECURITY_TIMESTAMP=$(curl $DEFAULT_MIRROR_URL_PREFIX/snapshot/debian-security/latest/timestamp)
|
|
|
|
fi
|
|
|
|
|
|
|
|
DEFAULT_MIRROR_URLS=http://deb.debian.org/debian/,http://packages.trafficmanager.net/snapshot/debian/$DEBIAN_TIMESTAMP/
|
|
|
|
DEFAULT_MIRROR_SECURITY_URLS=http://deb.debian.org/debian-security/,http://packages.trafficmanager.net/snapshot/debian-security/$DEBIAN_SECURITY_TIMESTAMP/
|
|
|
|
|
|
|
|
mkdir -p target/versions/default
|
|
|
|
if [ ! -f target/versions/default/versions-mirror ]; then
|
|
|
|
echo "debian==$DEBIAN_TIMESTAMP" > target/versions/default/versions-mirror
|
|
|
|
echo "debian-security==$DEBIAN_SECURITY_TIMESTAMP" >> target/versions/default/versions-mirror
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-09-23 20:07:04 -05:00
|
|
|
# Handle sources list
|
2022-11-08 18:09:53 -06:00
|
|
|
[ -z "$MIRROR_URLS" ] && MIRROR_URLS=$DEFAULT_MIRROR_URLS
|
|
|
|
[ -z "$MIRROR_SECURITY_URLS" ] && MIRROR_SECURITY_URLS=$DEFAULT_MIRROR_SECURITY_URLS
|
|
|
|
|
|
|
|
TEMPLATE=files/apt/sources.list.j2
|
|
|
|
[ -f files/apt/sources.list.$ARCHITECTURE.j2 ] && TEMPLATE=files/apt/sources.list.$ARCHITECTURE.j2
|
|
|
|
[ -f $CONFIG_PATH/sources.list.j2 ] && TEMPLATE=$CONFIG_PATH/sources.list.j2
|
|
|
|
[ -f $CONFIG_PATH/sources.list.$ARCHITECTURE.j2 ] && TEMPLATE=$CONFIG_PATH/sources.list.$ARCHITECTURE.j2
|
|
|
|
|
|
|
|
MIRROR_URLS=$MIRROR_URLS MIRROR_SECURITY_URLS=$MIRROR_SECURITY_URLS j2 $TEMPLATE | sed '/^$/N;/^\n$/D' > $CONFIG_PATH/sources.list.$ARCHITECTURE
|
2023-01-13 02:16:35 -06:00
|
|
|
if [ "$MIRROR_SNAPSHOT" == y ]; then
|
|
|
|
# Set the snapshot mirror, and add the SET_REPR_MIRRORS flag
|
|
|
|
sed -i -e "/^#*deb.*packages.trafficmanager.net/! s/^#*deb/#&/" -e "\$a#SET_REPR_MIRRORS" $CONFIG_PATH/sources.list.$ARCHITECTURE
|
|
|
|
fi
|
2023-09-23 20:07:04 -05:00
|
|
|
|
|
|
|
# Handle apt retry count config
|
|
|
|
APT_RETRIES_COUNT_FILENAME=apt-retries-count
|
|
|
|
TEMPLATE=files/apt/$APT_RETRIES_COUNT_FILENAME.j2
|
|
|
|
j2 $TEMPLATE > $CONFIG_PATH/$APT_RETRIES_COUNT_FILENAME
|