init
This commit is contained in:
196
init.sh
Executable file
196
init.sh
Executable file
@@ -0,0 +1,196 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Firefox Development Environment Initialization Script
|
||||
# This script downloads Firefox source code, sets up the build environment,
|
||||
# and prepares everything for building with mach
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
# Configuration
|
||||
FIREFOX_VERSION="140.0.2"
|
||||
SOURCE_URL="https://ftp.mozilla.org/pub/firefox/releases/${FIREFOX_VERSION}/source/firefox-${FIREFOX_VERSION}.source.tar.xz"
|
||||
SOURCE_FILE="firefox-${FIREFOX_VERSION}.source.tar.xz"
|
||||
SOURCE_DIR="firefox-${FIREFOX_VERSION}"
|
||||
CODE_DIR="code"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Helper functions
|
||||
print_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if required tools are installed
|
||||
check_dependencies() {
|
||||
print_info "Checking dependencies..."
|
||||
|
||||
local missing_deps=()
|
||||
|
||||
# Required tools for Firefox build
|
||||
local required_tools=("curl" "tar" "xz" "python3" "gcc" "g++" "make" "pkg-config" "autoconf")
|
||||
|
||||
for tool in "${required_tools[@]}"; do
|
||||
if ! command -v "$tool" &> /dev/null; then
|
||||
missing_deps+=("$tool")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing_deps[@]} -ne 0 ]; then
|
||||
print_error "Missing required dependencies: ${missing_deps[*]}"
|
||||
print_info "Please install these dependencies first:"
|
||||
print_info "Ubuntu/Debian: sudo apt-get install ${missing_deps[*]} build-essential"
|
||||
print_info "CentOS/RHEL: sudo yum install ${missing_deps[*]}"
|
||||
print_info "Arch Linux: sudo pacman -S ${missing_deps[*]} base-devel"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "All dependencies are installed"
|
||||
}
|
||||
|
||||
# Create code directory
|
||||
setup_code_directory() {
|
||||
print_info "Setting up code directory..."
|
||||
|
||||
if [ ! -d "$CODE_DIR" ]; then
|
||||
mkdir -p "$CODE_DIR"
|
||||
print_success "Created directory: $CODE_DIR"
|
||||
else
|
||||
print_warning "Directory $CODE_DIR already exists"
|
||||
fi
|
||||
|
||||
cd "$CODE_DIR"
|
||||
}
|
||||
|
||||
# Download Firefox source
|
||||
download_source() {
|
||||
print_info "Downloading Firefox source ($FIREFOX_VERSION)..."
|
||||
|
||||
if [ -f "$SOURCE_FILE" ]; then
|
||||
print_warning "Source file already exists: $SOURCE_FILE"
|
||||
read -p "Do you want to re-download? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_info "Skipping download"
|
||||
return
|
||||
fi
|
||||
rm -f "$SOURCE_FILE"
|
||||
fi
|
||||
|
||||
curl -L -o "$SOURCE_FILE" "$SOURCE_URL"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Downloaded: $SOURCE_FILE"
|
||||
else
|
||||
print_error "Failed to download Firefox source"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Extract Firefox source
|
||||
extract_source() {
|
||||
print_info "Extracting Firefox source..."
|
||||
|
||||
if [ -d "$SOURCE_DIR" ]; then
|
||||
print_warning "Source directory already exists: $SOURCE_DIR"
|
||||
read -p "Do you want to re-extract? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_info "Skipping extraction"
|
||||
return
|
||||
fi
|
||||
rm -rf "$SOURCE_DIR"
|
||||
fi
|
||||
|
||||
tar -xf "$SOURCE_FILE"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Extracted to: $SOURCE_DIR"
|
||||
else
|
||||
print_error "Failed to extract Firefox source"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Copy mozconfig
|
||||
copy_mozconfig() {
|
||||
print_info "Copying RBT source file..."
|
||||
|
||||
if [ -d "../src/" ]; then
|
||||
rsync -av "../src/" "$SOURCE_DIR/"
|
||||
print_success "Copied RBT source to $SOURCE_DIR/"
|
||||
else
|
||||
print_error "RBT source file not found in parent directory"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Setup build environment
|
||||
setup_build_environment() {
|
||||
print_info "Setting up build environment..."
|
||||
|
||||
cd "$SOURCE_DIR"
|
||||
|
||||
# Ensure mozconfig exists in src directory
|
||||
if [ ! -f "src/.mozconfig" ]; then
|
||||
print_error ".mozconfig file is missing in src/ directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create objdir if it doesn't exist
|
||||
if [ ! -d "obj-release" ]; then
|
||||
mkdir -p obj-release
|
||||
fi
|
||||
|
||||
print_success "Build environment ready"
|
||||
}
|
||||
|
||||
# Display next steps
|
||||
show_next_steps() {
|
||||
print_info "Firefox development environment is ready!"
|
||||
echo
|
||||
echo -e "${YELLOW}Next steps:${NC}"
|
||||
echo "1. cd $CODE_DIR/$SOURCE_DIR"
|
||||
echo "2. ./mach bootstrap # Install required dependencies"
|
||||
echo "3. ./mach build # Build Firefox"
|
||||
echo "4. ./mach run # Run Firefox"
|
||||
echo "5. ./mach package # Create installable package"
|
||||
echo
|
||||
print_info "For more information, visit:"
|
||||
print_info "https://firefox-source-docs.mozilla.org/setup/index.html"
|
||||
print_info "https://firefox-source-docs.mozilla.org/contributing/index.html"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
print_info "Starting Firefox development environment setup..."
|
||||
|
||||
check_dependencies
|
||||
setup_code_directory
|
||||
download_source
|
||||
extract_source
|
||||
copy_mozconfig
|
||||
setup_build_environment
|
||||
show_next_steps
|
||||
|
||||
print_success "Setup completed successfully!"
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main
|
||||
Reference in New Issue
Block a user