
StarlingX needs to download a variety of rpms and tarballs from various upstream sources. Unfortunately the upstream sources are not always dependable. Either servers go down, are unreachable, or drop older content that we still depend on. Our proposed solution is to run our own mirror to capture an independent copy of the content needed by StarlingX. For this purpose, a server has been set up at http://mirror.starlingx.cengn.ca/mirror/centos The mirror will use deterministic paths derived from the upstream urls. Scripts will be used to convert an upstream url to the mirror's equivalent url (see function url_to_stx_mirror_url in url_utils.sh) The mirror will be refreshed daily. New .lst entries will be processed at that time. Processing of changes under yum.repos.d is not automated by this update. Expect a follow-up update to address this issue soon. These scripts are found under the 'stx_mirror_scripts' subdirectory. Changes are made to the download_mirror.sh script, and it's supporting scripts. New arguments have been added to each script to select the download source. -s StarlingX mirror only -S StarlingX mirror, with upstream source as backup -u Upstream source only -U Upstream source, with StarlingX mirror as backup You do not need to provide any of these flags. Continue to us download_mirror.sh as you always have. The default behavior is currently set to '-S', i.e. first try the StarlingX mirror, with upstream source as backup. If this proves to place to heavy a load on the existing server, we might switch the default to '-U', i.e. first try the upstream source, with StarlingX mirror as backup. If poor download performance is seen, you might want to try explicitly adding -U as an argument. The remaining two options are not recommended for regular use. Upstream only, i.e. '-u', restores original behaviour, but you may once again encounter rpms that have aged out, and been removed from their original repos. StarlingX only, i.e. '-s', is vulnerable if a .lst file has been updated, but the mirror has not yet processed it. Change-Id: I7e0f3d9fb99253662f9f4bf12457d39250408c0b Story: 2003906 Task: 26785 Signed-off-by: Scott Little <scott.little@windriver.com>
206 lines
4.9 KiB
Bash
206 lines
4.9 KiB
Bash
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
UTILS_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
|
|
|
|
source $UTILS_DIR/url_utils.sh
|
|
|
|
get_yum_command() {
|
|
local _file=$1
|
|
local _level=$2
|
|
local rpm_name=""
|
|
local arr=( $(split_filename $_file) )
|
|
local arch=${arr[3]}
|
|
local yumdownloader_extra_opts=""
|
|
rpm_name="$(get_rpm_level_name $_file $_level)"
|
|
|
|
if [ "$arch" == "src" ]; then
|
|
yumdownloader_extra_opts="--source"
|
|
else
|
|
yumdownloader_extra_opts="--archlist=noarch,x86_64"
|
|
fi
|
|
|
|
echo "yumdownloader -q -C ${YUMCONFOPT} ${RELEASEVER} $yumdownloader_extra_opts $rpm_name"
|
|
}
|
|
|
|
get_wget_command() {
|
|
local _name="$1"
|
|
local _ret=""
|
|
if [[ "$_name" == http?(s)://* ]]; then
|
|
_ret="wget -q $_name"
|
|
else
|
|
_ret="wget -q $(koji_url $_name)"
|
|
fi
|
|
echo "$_ret"
|
|
}
|
|
|
|
get_rpm_level_name() {
|
|
local _rpm_name=$1
|
|
local _level=$2
|
|
if [ $_level == "L1" ]; then
|
|
SFILE=`echo $_rpm_name | rev | cut -d'.' -f3- | rev`
|
|
elif [ $_level == "L2" ];then
|
|
SFILE=`echo $_rpm_name | rev | cut -d'-' -f2- | rev`
|
|
elif [ $_level == "cengn" ];then
|
|
SFILE=`echo $_rpm_name | rev | cut -d'-' -f2- | rev`
|
|
else
|
|
SFILE=`echo $_rpm_name | rev | cut -d'-' -f3- | rev`
|
|
fi
|
|
echo "$SFILE"
|
|
}
|
|
|
|
get_url() {
|
|
local _name="$1"
|
|
local _level="$2"
|
|
local _ret=""
|
|
|
|
if [ "$_level" == "K1" ]; then
|
|
_ret="$(koji_url $_name)"
|
|
elif [[ "$_name" == *"#"* ]]; then
|
|
_ret="$(echo $_name | cut -d'#' -f2-2)"
|
|
if [ $_level == "stx_mirror" ]; then
|
|
_ret="$(url_to_stx_mirror_url $_ret $distro)"
|
|
fi
|
|
else
|
|
_url_cmd="$(get_yum_command $_name $_level)"
|
|
_ret="$($_url_cmd --url)"
|
|
fi
|
|
echo "$_ret"
|
|
}
|
|
|
|
# Function to split an rpm filename into parts.
|
|
#
|
|
# Returns a space seperated list containing:
|
|
# <NAME> <VERSION> <RELEASE> <ARCH> <EPOCH>
|
|
#
|
|
split_filename () {
|
|
local rpm_filename=$1
|
|
|
|
local RPM=""
|
|
local SFILE=""
|
|
local ARCH=""
|
|
local RELEASE=""
|
|
local VERSION=""
|
|
local NAME=""
|
|
local EPOCH=""
|
|
|
|
RPM=$(echo $rpm_filename | rev | cut -d'.' -f-1 | rev)
|
|
SFILE=$(echo $rpm_filename | rev | cut -d'.' -f2- | rev)
|
|
ARCH=$(echo $SFILE | rev | cut -d'.' -f-1 | rev)
|
|
SFILE=$(echo $SFILE | rev | cut -d'.' -f2- | rev)
|
|
RELEASE=$(echo $SFILE | rev | cut -d'-' -f-1 | rev)
|
|
SFILE=$(echo $SFILE | rev | cut -d'-' -f2- | rev)
|
|
VERSION=$(echo $SFILE | rev | cut -d'-' -f-1 | rev)
|
|
NAME=$(echo $SFILE | rev | cut -d'-' -f2- | rev)
|
|
|
|
if [[ $NAME = *":"* ]]; then
|
|
EPOCH=$(echo $NAME | cut -d':' -f-1)
|
|
NAME=$(echo $NAME | cut -d':' -f2-)
|
|
fi
|
|
|
|
echo "$NAME" "$VERSION" "$RELEASE" "$ARCH" "$EPOCH"
|
|
}
|
|
|
|
# Function to predict the URL where a rpm might be found.
|
|
# Assumes the rpm was compile for EPEL by fedora's koji.
|
|
koji_url () {
|
|
local rpm_filename=$1
|
|
|
|
local arr=( $(split_filename $rpm_filename) )
|
|
|
|
local n=${arr[0]}
|
|
local v=${arr[1]}
|
|
local r=${arr[2]}
|
|
local a=${arr[3]}
|
|
|
|
echo "https://kojipkgs.fedoraproject.org/packages/$n/$v/$r/$a/$n-$v-$r.$a.rpm"
|
|
}
|
|
|
|
get_dest_directory() {
|
|
local _type=$1
|
|
local _dest=""
|
|
if [ "$_type" == "src" ]; then
|
|
_dest="$MDIR_SRC"
|
|
else
|
|
_dest="$MDIR_BIN/$_type"
|
|
fi
|
|
echo "$_dest"
|
|
}
|
|
|
|
process_result() {
|
|
local _type="$1"
|
|
local dest_dir="$2"
|
|
local url="$3"
|
|
local sfile="$4"
|
|
|
|
if [ "$_type" != "src" ] && [ ! -d $dest_dir ]; then
|
|
mkdir -p $dest_dir
|
|
fi
|
|
|
|
echo "url_srpm:$url" >> $LOG
|
|
|
|
if ! mv -f $sfile* $dest_dir ; then
|
|
echo "FAILED to move $rpm_name"
|
|
echo "fail_move_srpm:$rpm_name" >> $LOG
|
|
fi
|
|
echo "found_srpm:$rpm_name" >> $LOG
|
|
echo $rpm_name >> $FOUND_SRPMS
|
|
}
|
|
|
|
|
|
get_download_cmd() {
|
|
local ff="$1"
|
|
local _level="$2"
|
|
|
|
# Decide if the list will be downloaded using yumdownloader or wget
|
|
if [[ $ff != *"#"* ]]; then
|
|
rpm_name=$ff
|
|
if [ $_level == "K1" ]; then
|
|
download_cmd="$(get_wget_command $rpm_name)"
|
|
else
|
|
# yumdownloader with the appropriate flag for src, noarch or x86_64
|
|
download_cmd="${SUDOCMD} $(get_yum_command $rpm_name $_level)"
|
|
fi
|
|
else
|
|
# Build wget command
|
|
rpm_url=$(get_url "$ff" "$_level")
|
|
download_cmd="$(get_wget_command $rpm_url)"
|
|
fi
|
|
|
|
echo "$download_cmd"
|
|
}
|
|
|
|
get_rpm_name() {
|
|
local ret=""
|
|
|
|
if [[ "$1" != *"#"* ]]; then
|
|
ret="$1"
|
|
else
|
|
ret="$(echo $1 | cut -d"#" -f1-1)"
|
|
fi
|
|
echo "$ret"
|
|
}
|
|
|
|
get_arch_from_rpm() {
|
|
local _file=$1
|
|
local _split=()
|
|
local _arch=""
|
|
if [[ "$1" == *"#"* ]]; then
|
|
_file=$(echo $_file | cut -d"#" -f1-1)
|
|
fi
|
|
|
|
_split=( $(split_filename $_file) )
|
|
_arch=${_split[3]}
|
|
|
|
echo "$_arch"
|
|
}
|
|
|
|
get_from() {
|
|
list=$1
|
|
base=$(basename $list .lst) # removing lst extension
|
|
base=$(basename $base .log) # removing log extension
|
|
from=$(echo $base | rev | cut -d'_' -f1-1 | rev)
|
|
echo $from
|
|
}
|