Fix to optimize package repo pulling and scoping

This commit is contained in:
Ilia Ross
2024-12-31 03:03:02 +02:00
parent 7ed1497f8d
commit 871152f723
5 changed files with 95 additions and 132 deletions

View File

@@ -65,7 +65,7 @@ build_module() {
rel=1
fi
if [ -z "$ver" ]; then
ver=$(get_module_version)
ver=$(get_module_version "$root_module")
fi
if [[ "'$*'" == *"--testing"* ]]; then
devel=1

View File

@@ -44,8 +44,8 @@ build_prod() {
# Define root
local prod=$1
ROOT_PROD="$ROOT_DIR/$prod"
local root_apt="$ROOT_PROD/deb"
local root_prod="$ROOT_DIR/$prod"
local root_apt="$root_prod/deb"
local ver=""
local devel=0
@@ -57,47 +57,25 @@ build_prod() {
echo " build start date: $date "
echo " package format: DEB "
echo " product: $prod "
(make_prod_repos "$ROOT_PROD" "$prod") &
spinner " package output version:"
# Pull main project first to get the latest tag
cd "$ROOT_PROD" || exit 1
cmd="git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs1=$?
# Clean and try again
if [ "$rs1" != "0" ]; then
cmd="git checkout \"*\" $VERBOSITY_LEVEL && \
git clean -f -d $VERBOSITY_LEVEL && \
git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs1=$?
fi
# Descend to theme dir
cd "authentic-theme" || exit 1
cmd="git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs2=$?
# Clean and try again
if [ "$rs2" != "0" ]; then
cmd="git checkout \"*\" $VERBOSITY_LEVEL && \
git clean -f -d $VERBOSITY_LEVEL && \
git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs2=$?
fi
if [ "$rs1" != "0" ] || [ "$rs2" != "0" ]; then
rs=1
echo -n " downloading packages: "
# Download products from repos
make_packages_repos "$root_prod" "$prod"
local rs=$? # Store to print success or failure nicely later
if [ $rs -eq 0 ]; then
echo -e "✔"
else
rs=0
echo -e "✘"
fi
# Build number
date_version=$(get_latest_commit_date_version)
# Print package version
echo -n " package version: "
# Get latest product version (theme vs product); expects to start in theme
# repo and switch to product repo internally
date_version=$(get_latest_commit_date_version "$root_prod")
# Handle other params
cd "$ROOT_PROD" || exit 1
if [[ "'$2'" != *"--"* ]]; then
ver=$2
fi
@@ -109,7 +87,7 @@ build_prod() {
relval=""
fi
if [ -z "$ver" ]; then
ver=$(get_current_repo_tag)
ver=$(get_current_repo_tag "$root_prod")
fi
if [[ "'$*'" == *"--testing"* ]]; then
devel=1
@@ -130,20 +108,20 @@ build_prod() {
# Make sure directories exist
make_dir "$ROOT_REPOS/"
make_dir "$root_apt/"
make_dir "$ROOT_PROD/newkey/deb/"
make_dir "$ROOT_PROD/umodules/"
make_dir "$ROOT_PROD/minimal/"
make_dir "$ROOT_PROD/tarballs/"
make_dir "$root_prod/newkey/deb/"
make_dir "$root_prod/umodules/"
make_dir "$root_prod/minimal/"
make_dir "$root_prod/tarballs/"
# Re-create legacy link
remove_dir "$ROOT_DIR/webadmin"
ln -s "$ROOT_DIR/webmin" "$ROOT_DIR/webadmin"
# Purge old files
purge_dir "$ROOT_PROD/newkey/deb"
purge_dir "$ROOT_PROD/umodules"
purge_dir "$ROOT_PROD/minimal"
purge_dir "$ROOT_PROD/tarballs"
purge_dir "$root_prod/newkey/deb"
purge_dir "$root_prod/umodules"
purge_dir "$root_prod/minimal"
purge_dir "$root_prod/tarballs"
if [ "$prod" != "" ]; then
rm -f "$ROOT_REPOS/$prod-"*
rm -f "$ROOT_REPOS/${prod}_"*
@@ -152,7 +130,7 @@ build_prod() {
echo
# Descend to project dir
cd "$ROOT_PROD" || exit 1
cd "$root_prod" || exit 1
if [ "$english_only" = "1" ]; then
echo "Cleaning languages .."
@@ -191,7 +169,7 @@ build_prod() {
cd "$ROOT_DIR" || exit 1
echo "Preparing built files for upload .."
cmd="cp -f $ROOT_PROD/tarballs/${prod}-${ver}*\.tar.gz \
cmd="cp -f $root_prod/tarballs/${prod}-${ver}*\.tar.gz \
$ROOT_REPOS/${prod}-$ver.tar.gz $VERBOSITY_LEVEL"
eval "$cmd"
cmd="find $root_apt -name ${prod}_${ver}${relval}*\.deb -exec mv '{}' \

View File

@@ -69,7 +69,7 @@ build_module() {
epoch="--epoch $4"
fi
if [ -z "$ver" ]; then
ver=$(get_module_version)
ver=$(get_module_version "$root_module")
fi
if [[ "'$*'" == *"--testing"* ]]; then
devel=1

View File

@@ -46,7 +46,7 @@ build_prod() {
local ver=""
local prod=$1
local devel=0
ROOT_PROD="$ROOT_DIR/$prod"
local root_prod="$ROOT_DIR/$prod"
# Print build actual date
date=$(get_current_date)
@@ -56,45 +56,25 @@ build_prod() {
echo " build start date: $date "
echo " package format: RPM "
echo " product: $prod "
(make_prod_repos "$ROOT_PROD" "$prod") &
spinner " package output version:"
# Pull main project first to get the latest tag
cd "$ROOT_PROD" || exit 1
cmd="git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs1=$?
# Clean and try again
if [ "$rs1" != "0" ]; then
cmd="git checkout \"*\" $VERBOSITY_LEVEL && git clean -f -d \
$VERBOSITY_LEVEL && git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs1=$?
fi
# Pull theme to theme dir
cd "authentic-theme" || exit 1
cmd="git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs2=$?
# Clean and try again
if [ "$rs2" != "0" ]; then
cmd="git checkout \"*\" $VERBOSITY_LEVEL && git clean -f -d \
$VERBOSITY_LEVEL && git pull $VERBOSITY_LEVEL"
eval "$cmd"
rs2=$?
fi
if [ "$rs1" != "0" ] || [ "$rs2" != "0" ]; then
rs=1
echo -n " downloading packages: "
# Download products from repos
make_packages_repos "$root_prod" "$prod"
local rs=$? # Store to print success or failure nicely later
if [ $rs -eq 0 ]; then
echo -e "✔"
else
rs=0
echo -e "✘"
fi
# Build number
date_version=$(get_latest_commit_date_version)
# Print package version
echo -n " package version: "
# Get latest product version (theme vs product); expects to start in theme
# repo and switch to product repo internally
date_version=$(get_latest_commit_date_version "$root_prod")
# Handle other params
cd "$ROOT_PROD" || exit 1
if [[ "'$2'" != *"--"* ]]; then
ver=$2
fi
@@ -104,7 +84,7 @@ build_prod() {
rel=1
fi
if [ -z "$ver" ]; then
ver=$(get_current_repo_tag)
ver=$(get_current_repo_tag "$root_prod")
fi
if [[ "'$*'" == *"--testing"* ]]; then
devel=1
@@ -124,10 +104,10 @@ build_prod() {
echo "Pre-clean up .."
# Make sure directories exist
make_dir "$ROOT_PROD/newkey/rpm/"
make_dir "$ROOT_PROD/umodules/"
make_dir "$ROOT_PROD/minimal/"
make_dir "$ROOT_PROD/tarballs/"
make_dir "$root_prod/newkey/rpm/"
make_dir "$root_prod/umodules/"
make_dir "$root_prod/minimal/"
make_dir "$root_prod/tarballs/"
make_dir "$ROOT_BUILD/BUILD/"
make_dir "$ROOT_BUILD/BUILDROOT/"
make_dir "$ROOT_BUILD/RPMS/"
@@ -141,10 +121,10 @@ build_prod() {
ln -s "$ROOT_DIR/webmin" "$ROOT_DIR/webadmin"
# Purge old files
purge_dir "$ROOT_PROD/newkey/rpm"
purge_dir "$ROOT_PROD/umodules"
purge_dir "$ROOT_PROD/minimal"
purge_dir "$ROOT_PROD/tarballs"
purge_dir "$root_prod/newkey/rpm"
purge_dir "$root_prod/umodules"
purge_dir "$root_prod/minimal"
purge_dir "$root_prod/tarballs"
purge_dir "$ROOT_BUILD/BUILD"
purge_dir "$ROOT_BUILD/BUILDROOT"
purge_dir "$ROOT_BUILD/RPMS"
@@ -161,7 +141,7 @@ build_prod() {
echo
# Descend to project dir
cd "$ROOT_PROD" || exit 1
cd "$root_prod" || exit 1
if [ "$english_only" = "1" ]; then
echo "Cleaning languages .."
@@ -202,7 +182,7 @@ build_prod() {
cd "$ROOT_DIR" || exit 1
echo "Preparing built files for upload .."
cmd="cp -f $ROOT_PROD/tarballs/$prod-$ver*\.tar.gz \
cmd="cp -f $root_prod/tarballs/$prod-$ver*\.tar.gz \
$ROOT_REPOS/${prod}-$ver.tar.gz $VERBOSITY_LEVEL"
eval "$cmd"
cmd="find $ROOT_RPMS -name $prod-$ver-$rel*\.rpm -exec mv '{}' \

View File

@@ -159,14 +159,18 @@ remove_dir() {
# Get latest tag version
get_current_repo_tag() {
# shellcheck disable=SC2153
cd "$ROOT_PROD" || exit 1
tg=$(git rev-list --tags --max-count=1)
ds=$(git describe --tags "$tg")
ds="${ds/v/}"
echo "$ds"
local root_prod="$1"
(
cd "$root_prod" || exit 1
ds=$(git ls-remote --tags --refs --sort="v:refname" origin | tail -n1 | \
awk '{print $2}' | sed 's|refs/tags/||')
ds="${ds/v/}"
echo "$ds"
)
}
get_module_version() {
local module_root="$1"
local version=""
# Check if module.info exists and extract version
@@ -178,7 +182,7 @@ get_module_version() {
# Fallback to get_current_repo_tag if no version found
if [ -z "$version" ]; then
version=$(get_current_repo_tag)
version=$(get_current_repo_tag "$module_root")
fi
# Return version (assumes version is always found)
@@ -196,9 +200,10 @@ get_latest_commit_date_version() {
local prod_version
local max_prod
local highest_version
local root_prod="$1"
theme_version=$(git log -n1 --pretty='format:%cd' --date=format:'%Y%m%d%H%M')
cd "$ROOT_PROD" || exit 1
cd "$root_prod" || exit 1
prod_version=$(git log -n1 --pretty='format:%cd' --date=format:'%Y%m%d%H%M')
max_prod=("$theme_version" "$prod_version")
highest_version=$(max "${max_prod[@]}")
@@ -206,29 +211,39 @@ get_latest_commit_date_version() {
}
# Pull project repo and theme
make_prod_repos() {
make_packages_repos() {
local root_prod="$1"
local prod="$2"
local cmd;
# Webmin or Usermin
if [ ! -d "$root_prod" ]; then
local repo="webmin/$prod.git"
cmd="git clone --depth 1 $GIT_BASE_URL/$repo $VERBOSITY_LEVEL"
local cmd
local reqrepo="webmin"
local repo="$reqrepo/$prod.git"
local theme="authentic-theme"
# Clone repo
cmd="git clone --depth 1 $GIT_BASE_URL/$repo $VERBOSITY_LEVEL"
eval "$cmd"
if [ "$?" != "0" ]; then
return 1
fi
# Clone required repo
if [ ! -d "$reqrepo" ]; then
cmd="git clone --depth 1 $WEBMIN_REPO $VERBOSITY_LEVEL"
eval "$cmd"
if [ ! -d "webmin" ]; then
cmd="git clone --depth 1 $WEBMIN_REPO \
$VERBOSITY_LEVEL"
eval "$cmd"
if [ "$?" != "0" ]; then
return 1
fi
fi
# Theme
local theme="authentic-theme"
if [ ! -d "$root_prod/$theme" ]; then
cd "$root_prod" || exit 1
local repo="webmin/$theme.git"
cmd="git clone --depth 1 $GIT_BASE_URL/$repo $VERBOSITY_LEVEL"
eval "$cmd"
# Clone theme
cd "$root_prod" || exit 1
repo="$reqrepo/$theme.git"
cmd="git clone --depth 1 $GIT_BASE_URL/$repo $VERBOSITY_LEVEL"
eval "$cmd"
if [ "$?" != "0" ]; then
return 1
fi
return 0
}
# Make module repo
@@ -348,13 +363,3 @@ adjust_module_filename() {
return $failed
}
spinner() {
local msg=$1
local pid=$!
printf "%s " "$msg"
while kill -0 $pid 2>/dev/null; do
printf "."
sleep 2
done
printf "\n"
}