forked from Shinonome/dots-hyprland
fix(exp-update): build packages in /tmp with auto-cleanup (#2768)
This commit is contained in:
@@ -31,9 +31,7 @@
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
# TODO: For Arch(-Linux) specific part please check if pacman exists first, if not it should be skipped.
|
||||
|
||||
# TODO: Is this really needed? `git pull` should do a full upgrade, not partially, which means this script will be updated along with the folder structure together.
|
||||
# Note: The detect_repo_structure function below auto-detects the folder layout
|
||||
# Try to find the packages directory (different names in different versions)
|
||||
if which pacman &>/dev/null; then
|
||||
if [[ -d "${REPO_ROOT}/dist-arch" ]]; then
|
||||
@@ -56,7 +54,6 @@ declare -a IGNORE_SUBSTRING_PATTERNS=()
|
||||
# Track created directories to avoid redundant mkdir calls
|
||||
declare -A CREATED_DIRS
|
||||
|
||||
# TODO: Is this really needed? `git pull` should do a full upgrade, not partially, which means this script will be updated along with the folder structure together.
|
||||
# Auto-detect repository structure
|
||||
detect_repo_structure() {
|
||||
local found_dirs=()
|
||||
@@ -644,23 +641,41 @@ build_packages() {
|
||||
log_info "Building package: $pkg_name"
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
log_info "[DRY-RUN] Would build package in directory: $pkg_dir"
|
||||
log_info "[DRY-RUN] Would build package in temp directory and clean up after"
|
||||
continue
|
||||
fi
|
||||
|
||||
cd "$pkg_dir" || {
|
||||
log_error "Failed to change to package directory: $pkg_dir"
|
||||
# Create temp build directory to avoid polluting the repo
|
||||
local build_tmp_dir
|
||||
build_tmp_dir=$(mktemp -d "/tmp/pkgbuild-${pkg_name}-XXXXXX")
|
||||
|
||||
# Copy package files to temp directory (using /. to include hidden files)
|
||||
cp -r "$pkg_dir"/. "$build_tmp_dir/" || {
|
||||
log_error "Failed to copy package files to temp directory"
|
||||
rm -rf "$build_tmp_dir"
|
||||
continue
|
||||
}
|
||||
|
||||
if makepkg -si --noconfirm; then
|
||||
cd "$build_tmp_dir" || {
|
||||
log_error "Failed to change to temp build directory: $build_tmp_dir"
|
||||
rm -rf "$build_tmp_dir"
|
||||
continue
|
||||
}
|
||||
|
||||
if makepkg -sCi --noconfirm; then
|
||||
log_success "Successfully built and installed $pkg_name"
|
||||
((rebuilt_packages++))
|
||||
((rebuilt_packages++)) || true
|
||||
else
|
||||
log_error "Failed to build package $pkg_name"
|
||||
fi
|
||||
|
||||
# Clean up temp build directory
|
||||
cd "$REPO_ROOT" || log_die "Failed to return to repository directory"
|
||||
rm -rf "$build_tmp_dir"
|
||||
log_info "Cleaned up temp build directory"
|
||||
|
||||
# Also clean any old build artifacts in the original package directory
|
||||
rm -rf "${pkg_dir}/src" "${pkg_dir}/pkg" "${pkg_dir}"/*.pkg.tar.* 2>/dev/null || true
|
||||
done
|
||||
|
||||
if [[ $rebuilt_packages -eq 0 ]]; then
|
||||
@@ -852,8 +867,12 @@ if git remote get-url origin &>/dev/null; then
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_warning "Failed to pull changes from remote. Continuing with local repository..."
|
||||
log_info "You may need to resolve conflicts manually later."
|
||||
log_warning "Failed to pull changes from remote."
|
||||
log_warning "This could be due to:"
|
||||
log_warning " - Network issues"
|
||||
log_warning " - Uncommitted local changes (use 'git stash' first)"
|
||||
log_warning " - Diverged history (may need 'git pull --rebase')"
|
||||
log_info "Continuing with local repository state..."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
@@ -879,8 +898,10 @@ if [[ "$CHECK_PACKAGES" == true ]]; then
|
||||
|
||||
if [[ "$PKG_TOOLS_AVAILABLE" == true ]]; then
|
||||
if [[ ! -d "$ARCH_PACKAGES_DIR" ]]; then
|
||||
log_warning "No packages directory found (tried: dist-arch, arch-packages, sdata/dist-arch). Skipping package management."
|
||||
log_warning "No packages directory found (tried: dist-arch, arch-packages, sdata/dist-arch)."
|
||||
log_warning "Skipping package management."
|
||||
else
|
||||
# Scan for changed PKGBUILDs
|
||||
changed_pkgbuilds=()
|
||||
for pkg_dir in "$ARCH_PACKAGES_DIR"/*/; do
|
||||
if [[ -f "${pkg_dir}/PKGBUILD" ]]; then
|
||||
@@ -963,11 +984,11 @@ if [[ "$CHECK_PACKAGES" == true ]]; then
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_header "Package Management"
|
||||
log_info "Package checking disabled. Use -p or --packages flag to enable package management."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 3: Update configuration files
|
||||
log_header "Updating Configuration Files"
|
||||
|
||||
Reference in New Issue
Block a user