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
|
set -euo pipefail
|
||||||
|
|
||||||
# TODO: For Arch(-Linux) specific part please check if pacman exists first, if not it should be skipped.
|
# Note: The detect_repo_structure function below auto-detects the folder layout
|
||||||
|
|
||||||
# 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.
|
|
||||||
# Try to find the packages directory (different names in different versions)
|
# Try to find the packages directory (different names in different versions)
|
||||||
if which pacman &>/dev/null; then
|
if which pacman &>/dev/null; then
|
||||||
if [[ -d "${REPO_ROOT}/dist-arch" ]]; 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
|
# Track created directories to avoid redundant mkdir calls
|
||||||
declare -A CREATED_DIRS
|
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
|
# Auto-detect repository structure
|
||||||
detect_repo_structure() {
|
detect_repo_structure() {
|
||||||
local found_dirs=()
|
local found_dirs=()
|
||||||
@@ -644,23 +641,41 @@ build_packages() {
|
|||||||
log_info "Building package: $pkg_name"
|
log_info "Building package: $pkg_name"
|
||||||
|
|
||||||
if [[ "$DRY_RUN" == true ]]; then
|
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
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$pkg_dir" || {
|
# Create temp build directory to avoid polluting the repo
|
||||||
log_error "Failed to change to package directory: $pkg_dir"
|
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
|
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"
|
log_success "Successfully built and installed $pkg_name"
|
||||||
((rebuilt_packages++))
|
((rebuilt_packages++)) || true
|
||||||
else
|
else
|
||||||
log_error "Failed to build package $pkg_name"
|
log_error "Failed to build package $pkg_name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clean up temp build directory
|
||||||
cd "$REPO_ROOT" || log_die "Failed to return to repository 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
|
done
|
||||||
|
|
||||||
if [[ $rebuilt_packages -eq 0 ]]; then
|
if [[ $rebuilt_packages -eq 0 ]]; then
|
||||||
@@ -852,8 +867,12 @@ if git remote get-url origin &>/dev/null; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log_warning "Failed to pull changes from remote. Continuing with local repository..."
|
log_warning "Failed to pull changes from remote."
|
||||||
log_info "You may need to resolve conflicts manually later."
|
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
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -879,68 +898,70 @@ if [[ "$CHECK_PACKAGES" == true ]]; then
|
|||||||
|
|
||||||
if [[ "$PKG_TOOLS_AVAILABLE" == true ]]; then
|
if [[ "$PKG_TOOLS_AVAILABLE" == true ]]; then
|
||||||
if [[ ! -d "$ARCH_PACKAGES_DIR" ]]; 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
|
else
|
||||||
changed_pkgbuilds=()
|
# Scan for changed PKGBUILDs
|
||||||
for pkg_dir in "$ARCH_PACKAGES_DIR"/*/; do
|
changed_pkgbuilds=()
|
||||||
if [[ -f "${pkg_dir}/PKGBUILD" ]]; then
|
for pkg_dir in "$ARCH_PACKAGES_DIR"/*/; do
|
||||||
pkg_name=$(basename "$pkg_dir")
|
if [[ -f "${pkg_dir}/PKGBUILD" ]]; then
|
||||||
if check_pkgbuild_changed "$pkg_dir"; then
|
pkg_name=$(basename "$pkg_dir")
|
||||||
changed_pkgbuilds+=("$pkg_name")
|
if check_pkgbuild_changed "$pkg_dir"; then
|
||||||
fi
|
changed_pkgbuilds+=("$pkg_name")
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ${#changed_pkgbuilds[@]} -gt 0 ]]; then
|
|
||||||
log_info "Found ${#changed_pkgbuilds[@]} package(s) with changed PKGBUILDs: ${changed_pkgbuilds[*]}"
|
|
||||||
echo
|
|
||||||
echo "Package build options:"
|
|
||||||
echo "1) Build only packages with changed PKGBUILDs"
|
|
||||||
echo "2) List all packages and select which to build"
|
|
||||||
echo "3) Build all packages"
|
|
||||||
echo "4) Skip package building"
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [[ "$NON_INTERACTIVE" == true ]]; then
|
|
||||||
pkg_choice="1"
|
|
||||||
log_info "Non-interactive mode: Using default package option: $pkg_choice"
|
|
||||||
elif safe_read "Choose an option (1-4): " pkg_choice "1"; then
|
|
||||||
if [[ "$VERBOSE" == true ]]; then
|
|
||||||
log_info "User selected package option: $pkg_choice"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
log_warning "Failed to read input. Skipping package building."
|
|
||||||
pkg_choice=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$pkg_choice" ]]; then
|
|
||||||
case $pkg_choice in
|
|
||||||
1) build_packages "changed" ;;
|
|
||||||
2)
|
|
||||||
if list_packages; then
|
|
||||||
build_packages "select"
|
|
||||||
fi
|
fi
|
||||||
;;
|
fi
|
||||||
3) build_packages "all" ;;
|
done
|
||||||
4 | *) log_info "Skipping package building" ;;
|
|
||||||
esac
|
if [[ ${#changed_pkgbuilds[@]} -gt 0 ]]; then
|
||||||
fi
|
log_info "Found ${#changed_pkgbuilds[@]} package(s) with changed PKGBUILDs: ${changed_pkgbuilds[*]}"
|
||||||
else
|
echo
|
||||||
log_info "No PKGBUILDs have changed since last update."
|
echo "Package build options:"
|
||||||
echo
|
echo "1) Build only packages with changed PKGBUILDs"
|
||||||
if [[ "$NON_INTERACTIVE" == true ]]; then
|
echo "2) List all packages and select which to build"
|
||||||
check_anyway="N"
|
echo "3) Build all packages"
|
||||||
log_info "Non-interactive mode: Using default for check packages anyway: $check_anyway"
|
echo "4) Skip package building"
|
||||||
elif safe_read "Do you want to check and build packages anyway? (y/N): " check_anyway "N"; then
|
echo
|
||||||
if [[ "$VERBOSE" == true ]]; then
|
|
||||||
log_info "User chose to check packages anyway: $check_anyway"
|
if [[ "$NON_INTERACTIVE" == true ]]; then
|
||||||
|
pkg_choice="1"
|
||||||
|
log_info "Non-interactive mode: Using default package option: $pkg_choice"
|
||||||
|
elif safe_read "Choose an option (1-4): " pkg_choice "1"; then
|
||||||
|
if [[ "$VERBOSE" == true ]]; then
|
||||||
|
log_info "User selected package option: $pkg_choice"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_warning "Failed to read input. Skipping package building."
|
||||||
|
pkg_choice=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$pkg_choice" ]]; then
|
||||||
|
case $pkg_choice in
|
||||||
|
1) build_packages "changed" ;;
|
||||||
|
2)
|
||||||
|
if list_packages; then
|
||||||
|
build_packages "select"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
3) build_packages "all" ;;
|
||||||
|
4|*) log_info "Skipping package building" ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log_warning "Failed to read input. Skipping package management."
|
log_info "No PKGBUILDs have changed since last update."
|
||||||
check_anyway=""
|
echo
|
||||||
fi
|
if [[ "$NON_INTERACTIVE" == true ]]; then
|
||||||
|
check_anyway="N"
|
||||||
|
log_info "Non-interactive mode: Using default for check packages anyway: $check_anyway"
|
||||||
|
elif safe_read "Do you want to check and build packages anyway? (y/N): " check_anyway "N"; then
|
||||||
|
if [[ "$VERBOSE" == true ]]; then
|
||||||
|
log_info "User chose to check packages anyway: $check_anyway"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_warning "Failed to read input. Skipping package management."
|
||||||
|
check_anyway=""
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n "$check_anyway" && "$check_anyway" =~ ^[Yy]$ ]]; then
|
if [[ -n "$check_anyway" && "$check_anyway" =~ ^[Yy]$ ]]; then
|
||||||
if list_packages; then
|
if list_packages; then
|
||||||
echo
|
echo
|
||||||
echo "Package build options:"
|
echo "Package build options:"
|
||||||
@@ -950,9 +971,9 @@ if [[ "$CHECK_PACKAGES" == true ]]; then
|
|||||||
|
|
||||||
if safe_read "Choose an option (1-3): " build_choice "3"; then
|
if safe_read "Choose an option (1-3): " build_choice "3"; then
|
||||||
case $build_choice in
|
case $build_choice in
|
||||||
1) build_packages "select" ;;
|
1) build_packages "select" ;;
|
||||||
2) build_packages "all" ;;
|
2) build_packages "all" ;;
|
||||||
3 | *) log_info "Skipping package building" ;;
|
3|*) log_info "Skipping package building" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
log_info "Skipping package building"
|
log_info "Skipping package building"
|
||||||
@@ -963,10 +984,10 @@ if [[ "$CHECK_PACKAGES" == true ]]; then
|
|||||||
fi
|
fi
|
||||||
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
|
||||||
|
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
|
# Step 3: Update configuration files
|
||||||
|
|||||||
Reference in New Issue
Block a user