package script added

This commit is contained in:
partisan 2024-09-04 19:11:37 +02:00
parent 5fd9a5f45f
commit f904f731f3
5 changed files with 179 additions and 38 deletions

View file

@ -9,11 +9,14 @@ PATCHES_REPO="https://weforgecode.xyz/Spitfire/Browser.git"
SOURCE_PATH=$(realpath "$SOURCE_PATH") || { echo "Failed to resolve SOURCE_PATH. Exiting."; exit 1; }
PATCHES_DIR=$(realpath "$PATCHES_DIR") || { echo "Failed to resolve PATCHES_DIR. Exiting."; exit 1; }
# Array to store errors
errors=()
# Function to download Mozilla source if not present
download_source() {
if [ ! -d "$SOURCE_PATH" ]; then
echo "Mozilla source not found. Cloning from repository..."
hg clone "$SOURCE_REPO" "$SOURCE_PATH" || { echo "Failed to clone Mozilla repository. Exiting."; exit 1; }
hg clone "$SOURCE_REPO" "$SOURCE_PATH" || errors+=("Failed to clone Mozilla repository.")
else
echo "Mozilla source already exists."
fi
@ -22,22 +25,22 @@ download_source() {
# Function to discard uncommitted changes
discard_changes() {
echo "Discarding uncommitted changes..."
hg revert --all --no-backup -R "$SOURCE_PATH" || { echo "Failed to revert changes in Mozilla repository. Exiting."; exit 1; }
hg revert --all --no-backup -R "$SOURCE_PATH" || errors+=("Failed to revert changes in Mozilla repository.")
}
# Function to clean build
clean_build() {
echo "Cleaning build..."
cd "$SOURCE_PATH" || { echo "Failed to navigate to source directory. Exiting."; exit 1; }
hg revert --all --no-backup || { echo "Failed to revert changes in Mozilla repository. Exiting."; exit 1; }
./mach clobber || { echo "Failed to clean build. Exiting."; exit 1; }
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
hg revert --all --no-backup || errors+=("Failed to revert changes in Mozilla repository.")
./mach clobber || errors+=("Failed to clean build.")
}
# Function to update Mozilla repository
update_repo() {
echo "Updating Mozilla repository..."
cd "$SOURCE_PATH" || { echo "Failed to navigate to source directory. Exiting."; exit 1; }
hg pull -u || { echo "Failed to update Mozilla repository. Exiting."; exit 1; }
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
hg pull -u || errors+=("Failed to update Mozilla repository.")
}
# Function to update patches
@ -45,56 +48,56 @@ update_patches() {
echo "Updating patches..."
if [ -d "$PATCHES_DIR" ]; then
echo "Patches directory already exists. Cleaning and pulling updates..."
cd "$PATCHES_DIR" || { echo "Failed to navigate to patches directory. Exiting."; exit 1; }
git clean -xdf || { echo "Failed to clean patches directory. Exiting."; exit 1; }
cd "$PATCHES_DIR" || { errors+=("Failed to navigate to patches directory."); return; }
git clean -xdf || errors+=("Failed to clean patches directory.")
# Stash any local changes to ensure a clean rebase
git stash push --include-untracked || { echo "Failed to stash local changes. Exiting."; exit 1; }
git stash push --include-untracked || echo "No local changes to save."
# Fetching all branches
git fetch || { echo "Failed to fetch updates from patches repository. Exiting."; exit 1; }
git fetch || errors+=("Failed to fetch updates from patches repository.")
# Trying to rebase onto 'main' branch
if git show-ref --verify --quiet refs/heads/main; then
git rebase origin/main || { echo "Failed to rebase updates from main branch. Exiting."; exit 1; }
git rebase origin/main || errors+=("Failed to rebase updates from main branch.")
elif git show-ref --verify --quiet refs/heads/master; then
# Fallback to 'master' branch if 'main' does not exist
git rebase origin/master || { echo "Failed to rebase updates from master branch. Exiting."; exit 1; }
git rebase origin/master || errors+=("Failed to rebase updates from master branch.")
else
echo "No valid branch (main or master) found in patches repository. Exiting."
exit 1
errors+=("No valid branch (main or master) found in patches repository.")
return
fi
# Drop stashed changes to discard local modifications
git stash drop || { echo "Failed to drop stashed changes. Exiting."; exit 1; }
# Check if there are any stashes before popping
if git stash list | grep -q 'stash@{0}'; then
git stash pop || errors+=("Failed to apply and drop stashed changes.")
else
echo "No stash entries found, skipping pop."
fi
else
echo "Patches directory does not exist. Cloning repository..."
git clone "$PATCHES_REPO" "$PATCHES_DIR" || { echo "Failed to clone patches repository. Exiting."; exit 1; }
git clone "$PATCHES_REPO" "$PATCHES_DIR" || errors+=("Failed to clone patches repository.")
fi
echo "Copying files from patches directory to Firefox source directory..."
rsync -av --exclude='.git' "$PATCHES_DIR/" "$SOURCE_PATH/" || { echo "Failed to copy files. Exiting."; exit 1; }
rsync -av --exclude='.git' "$PATCHES_DIR/" "$SOURCE_PATH/" || errors+=("Failed to copy files.")
}
# Function to configure Spitfire
configure() {
echo "Configuring Spitfire..."
cd "$SOURCE_PATH" || { echo "Failed to navigate to source directory. Exiting."; exit 1; }
./mach configure || { echo "Configuration failed. Exiting."; exit 1; }
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
./mach configure || errors+=("Configuration failed.")
}
# Function to build Spitfire
build() {
echo "Building Spitfire..."
cd "$SOURCE_PATH" || { echo "Failed to navigate to source directory. Exiting."; exit 1; }
./mach build || { echo "Build failed. Exiting."; exit 1; }
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to source directory."); return; }
./mach build || errors+=("Build failed.")
}
# Function to run the project after build
run_project() {
echo "Running the project..."
cd "$SOURCE_PATH" || { echo "Failed to navigate to browser directory. Exiting."; exit 1; }
./mach run || { echo "Failed to run the project. Exiting."; exit 1; }
cd "$SOURCE_PATH" || { errors+=("Failed to navigate to browser directory."); return; }
./mach run || errors+=("Failed to run the project.")
}
# Function to print usage instructions
@ -181,4 +184,12 @@ else
print_help
fi
# Print all collected errors at the end
if [ ${#errors[@]} -ne 0 ]; then
echo "The following errors occurred during execution:"
for error in "${errors[@]}"; do
echo "- $error"
done
fi
exit 0