1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
#!/bin/bash
set -e
if [ $# -ne 1 ]; then
echo "Usage: $0 <version>"
echo "Example: $0 0.7.0"
exit 1
fi
VERSION="$1"
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
TARGET="$(dirname "$(dirname "$(dirname "$SCRIPT_DIR")")")"
echo "Repacking coreutils version $VERSION"
echo "Target directory: $TARGET"
# Check if running interactively
if [ -t 0 ]; then
echo "Please update the version in src/coreutils/debian/changelog"
read -p "Press enter when done..."
else
echo "Running non-interactively - assuming changelog is up to date"
fi
# Run update.sh (will fail as expected)
echo "Running update.sh (expected to fail)..."
cd "$TARGET"
rm -rf build/coreutils
./update.sh coreutils || true
# Clone tagged source first
echo "Cloning coreutils source at version $VERSION..."
cd "$TARGET"
rm -rf coreutils
if ! git clone git@github.com:uutils/coreutils.git -b "$VERSION" coreutils; then
echo "Error: Failed to clone coreutils at version $VERSION"
exit 1
fi
# Clone l10n repo
echo "Cloning coreutils-l10n at version $VERSION..."
rm -rf /tmp/coreutils-l10n
if ! git clone https://github.com/uutils/coreutils-l10n.git -b "$VERSION" /tmp/coreutils-l10n; then
echo "Warning: Failed to clone coreutils-l10n at version $VERSION, trying main branch..."
if ! git clone https://github.com/uutils/coreutils-l10n.git /tmp/coreutils-l10n; then
echo "Error: Failed to clone coreutils-l10n repo"
exit 1
fi
fi
# Clean up old build
rm -rf "$TARGET/build/coreutils"
# Use the cloned source as base for build directory
echo "Setting up build directory..."
cp -R "$TARGET/coreutils" "$TARGET/build/coreutils"
cd "$TARGET/build/coreutils"
# Add localized versions (only locale files, not overwriting structure)
echo "Adding localized files..."
if [ -d "/tmp/coreutils-l10n/src/uu" ]; then
for util_dir in /tmp/coreutils-l10n/src/uu/*/; do
util_name=$(basename "$util_dir")
if [ -d "./src/uu/$util_name" ]; then
cp -R "$util_dir"* "./src/uu/$util_name/" 2>/dev/null || true
fi
done
fi
if [ -d "/tmp/coreutils-l10n/src/uucore" ]; then
cp -R /tmp/coreutils-l10n/src/uucore/* ./src/uucore/ 2>/dev/null || true
fi
# Download tldr pages
echo "Downloading tldr pages..."
mkdir -p docs
if ! curl -L https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip -o docs/tldr.zip; then
echo "Warning: Failed to download tldr.zip, continuing without it"
rm -f docs/tldr.zip
fi
# Vendor dependencies
echo "Vendoring Cargo dependencies..."
if ! cargo vendor; then
echo "Error: Failed to vendor cargo dependencies"
exit 1
fi
cd "$TARGET"
# Copy debian directory to build directory
echo "Copying debian directory to build directory..."
if ! cp -R "$TARGET/src/coreutils/debian" "$TARGET/build/coreutils/"; then
echo "Error: Failed to copy debian directory"
exit 1
fi
# Create source package
cd "$TARGET/build"
rm -rf coreutils.orig coreutils/.pc/
# Force clean before creating tarball
echo "Running debian/rules clean..."
cd coreutils
debian/rules clean || true
cd ..
# Remove problematic symlinks that point outside the source tree
echo "Removing problematic symlinks..."
find coreutils/debian/cargo_registry -type l -delete 2>/dev/null || true
echo "Creating source tarball..."
if ! tar Jcvf "rust-coreutils_${VERSION}.orig.tar.xz" coreutils/; then
echo "Error: Failed to create source tarball"
exit 1
fi
echo "Building source package..."
if ! dpkg-source -b -i coreutils; then
echo "dpkg-source failed - attempting to rebase patches automatically..."
cd "$TARGET/build/coreutils"
# Remove any partially applied patches
QUILT_PATCHES=debian/patches quilt pop -a 2>/dev/null || true
# Get list of all patches
total_patches=$(QUILT_PATCHES=debian/patches quilt series | wc -l)
echo "Found $total_patches patches to rebase"
# Apply and refresh each patch individually
patch_count=0
failed_patches=0
# Try to apply as many patches as possible
while QUILT_PATCHES=debian/patches quilt push -f 2>/dev/null; do
patch_count=$((patch_count + 1))
current_patch=$(QUILT_PATCHES=debian/patches quilt top)
echo "Applied patch: $current_patch"
# Try to refresh it
if QUILT_PATCHES=debian/patches quilt refresh; then
echo "✓ Successfully refreshed $current_patch"
else
echo "⚠ Warning: Failed to refresh $current_patch, but continuing..."
failed_patches=$((failed_patches + 1))
fi
done
echo "Patch rebase complete: $patch_count applied, $failed_patches failed"
cd "$TARGET/build"
echo "Retrying dpkg-source after patch rebase..."
if ! dpkg-source -b -i coreutils; then
echo "Warning: dpkg-source still has issues but continuing..."
echo "Some patches may need manual adjustment later."
echo "Check patches in: $TARGET/build/coreutils/debian/patches/"
# Try to create a minimal source package by temporarily removing problematic patches
cd "$TARGET/build/coreutils"
# Pop all patches and just apply the ones that worked
QUILT_PATCHES=debian/patches quilt pop -a 2>/dev/null || true
# Apply only the patches we know work
for i in $(seq 1 $patch_count); do
if ! QUILT_PATCHES=debian/patches quilt push 2>/dev/null; then
break
fi
done
cd "$TARGET/build"
echo "Creating source package with partial patches applied..."
if ! dpkg-source -b -i coreutils; then
echo "Error: Unable to create source package even with partial patches"
echo "Manual intervention definitely required."
exit 1
fi
fi
fi
echo ""
echo "✅ Repack complete!"
echo "Created: rust-coreutils_${VERSION}.orig.tar.xz"
echo "Created: rust-coreutils_${VERSION}-1.dsc"
echo "Created: rust-coreutils_${VERSION}-1.debian.tar.xz"
# Cleanup
cd "$TARGET"
rm -rf coreutils
|