upload script

This commit is contained in:
partisan 2024-08-03 20:11:24 +02:00
parent 8d3571dd99
commit 3a3c48ca49
4 changed files with 231 additions and 3 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
/mozilla-central /mozilla-central
/patches /patches
/packages.json

View file

@ -19,7 +19,87 @@ Run the script `builder.sh` with the following options:
- `-r, --run` : Run the project after build using mach run in the browser directory - `-r, --run` : Run the project after build using mach run in the browser directory
- `-h, --help` : Display usage instructions. - `-h, --help` : Display usage instructions.
For example: ## For example:
```bash ```bash
./builder.sh --all ./builder.sh --all
```
# Repositary
Optinally script also contains code to upload builds to sourceforge, but this can be acessed only with auth key.
```bash
./upload.sh
```
## Structure
```
spitfire-browser/
├── browser/
│ ├── x86_64/
│ │ ├── stable/
│ │ │ ├── latest/example.tar.gz
│ │ │ ├── x.x.x/example.tar.gz
│ │ ├── nightly/
│ │ ├── latest/example.tar.gz
│ │ ├── yyyy-mm-dd/example.tar.gz
│ ├── arm/
│ │ ├── stable/
│ │ │ ├── latest/
│ │ │ ├── x.x.x/
│ │ ├── nightly/
│ │ ├── latest/
│ │ ├── yyyy-mm-dd/
│ ├── README.md
├── cli-package-manager/
│ ├── stable/
│ │ ├── latest/
│ │ ├── x.x.x/
│ ├── nightly/
│ ├── latest/
│ ├── yyyy-mm-dd/
│ ├── README.md
├── gui-installer/
│ ├── stable/
│ │ ├── latest/
│ │ ├── x.x.x/
│ ├── nightly/
│ ├── latest/
│ ├── yyyy-mm-dd/
│ ├── README.md
├── gui-package-manager/
│ ├── stable/
│ │ ├── latest/
│ │ ├── x.x.x/
│ ├── nightly/
│ ├── latest/
│ ├── yyyy-mm-dd/
│ ├── README.md
├── addons/
│ ├── themes/
│ │ ├── stable/
│ │ │ ├── latest/
│ │ │ ├── x.x.x/
│ │ ├── nightly/
│ │ ├── latest/
│ │ ├── yyyy-mm-dd/
│ ├── custom-configs/
│ │ ├── stable/
│ │ │ ├── latest/
│ │ │ ├── x.x.x/
│ │ ├── nightly/
│ │ ├── latest/
│ │ ├── yyyy-mm-dd/
│ ├── search-engines/
│ ├── stable/
│ │ ├── latest/
│ │ ├── x.x.x/
│ ├── nightly/
│ ├── latest/
│ ├── yyyy-mm-dd/
│ ├── README.md
├── packages.json
├── README.md
```

5
sourceforge_config.sh Executable file
View file

@ -0,0 +1,5 @@
# sourceforge_config.sh
SF_USER="internet-addict"
SF_PROJECT="spitfire-browser"
SF_HOST="frs.sourceforge.net"
SF_KEY_PATH="$HOME/.ssh/id_rsa" # Path to your SSH private key for SourceForge

142
upload.sh Executable file
View file

@ -0,0 +1,142 @@
#!/bin/bash
# Load SourceForge configuration
source sourceforge_config.sh
# Function to print usage instructions
print_help() {
echo "Usage: ./upload.sh -p=<path-to-build> -t=<target> [-c|--compress] [-v|--version=<version>]"
echo ""
echo "Options:"
echo " -p, --path : Path to the build directory"
echo " -t, --target : Target location format: component-arch-release-platform"
echo " -c, --compress : Compress the build directory into a tar.gz file before uploading"
echo " -v, --version : Specify version for the package. For nightly, use current date if not specified. For stable, increment version if not specified."
echo " -h, --help : Display this help message"
echo ""
echo "Example use:"
echo " # Without compression"
echo " ./upload.sh -p=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -t=browser-x86_64-stable-linux -v=1.0"
echo ""
echo " # With compression"
echo " ./upload.sh -p=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -t=browser-x86_64-stable-linux -c -v=1.0"
echo ""
echo " # Nightly build without specifying version"
echo " ./upload.sh -p=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -t=browser-x86_64-nightly-linux -c"
exit 0
}
COMPRESS=false
VERSION=""
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-p=*|--path=*)
BUILD_PATH="${1#*=}"
shift
;;
-t=*|--target=*)
TARGET="${1#*=}"
shift
;;
-c|--compress)
COMPRESS=true
shift
;;
-v=*|--version=*)
VERSION="${1#*=}"
shift
;;
-h|--help)
print_help
;;
*)
echo "Invalid option: $1"
print_help
;;
esac
done
# Check if both required arguments are provided
if [ -z "$BUILD_PATH" ] || [ -z "$TARGET" ]; then
echo "Error: Both path and target must be specified."
print_help
fi
# Split the target into its components
IFS='-' read -r COMPONENT ARCH RELEASE PLATFORM <<< "$TARGET"
# Determine the upload directory based on the target
UPLOAD_DIR="$COMPONENT/$ARCH/$RELEASE/$PLATFORM"
# Construct the remote directory path
REMOTE_DIR="/home/frs/project/$SF_PROJECT/$UPLOAD_DIR"
# Handle versioning
if [ -z "$VERSION" ]; then
if [[ "$RELEASE" == "nightly" ]]; then
VERSION=$(date +"%Y%m%d")
elif [[ "$RELEASE" == "stable" ]]; then
CURRENT_VERSION=$(grep -oP '(?<="'"$COMPONENT"'": ")([^"]*)' packages.json)
if [ -n "$CURRENT_VERSION" ]; then
MAJOR_VERSION=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR_VERSION=$(echo $CURRENT_VERSION | cut -d. -f2)
MINOR_VERSION=$((MINOR_VERSION + 1))
VERSION="${MAJOR_VERSION}.${MINOR_VERSION}"
else
VERSION="1.0"
fi
fi
fi
# Update packages.json
if [ ! -f packages.json ]; then
echo "{}" > packages.json
fi
jq --arg comp "$COMPONENT" --arg ver "$VERSION" '.[$comp] = $ver' packages.json > packages_temp.json && mv packages_temp.json packages.json
# Handle compression if specified
if [ "$COMPRESS" = true ]; then
COMPRESSED_FILE="/tmp/${TARGET}.tar.gz"
echo "Compressing $BUILD_PATH into $COMPRESSED_FILE..."
tar -czf "$COMPRESSED_FILE" -C "$BUILD_PATH" .
BUILD_PATH="$COMPRESSED_FILE"
fi
# Upload the files to SourceForge
echo "Uploading files from $BUILD_PATH to $REMOTE_DIR on SourceForge..."
scp -i "$SF_KEY_PATH" "$BUILD_PATH" "$SF_USER@$SF_HOST:$REMOTE_DIR/" 2>/dev/null
UPLOAD_STATUS=$?
if [ $UPLOAD_STATUS -ne 0 ]; then
echo "Failed to upload files directly. Creating local directory structure and uploading..."
# Create the local directory structure
TEMP_DIR=$(mktemp -d)
mkdir -p "$TEMP_DIR/$UPLOAD_DIR"
# Upload the directory structure
rsync -av --omit-dir-times --no-perms -e "ssh -i $SF_KEY_PATH" "$TEMP_DIR/" "$SF_USER@$SF_HOST:/home/frs/project/$SF_PROJECT/" || { echo "Failed to upload directory structure. Exiting."; rm -rf "$TEMP_DIR"; exit 1; }
# Clean up the temporary directory
rm -rf "$TEMP_DIR"
# Retry uploading the files
scp -i "$SF_KEY_PATH" "$BUILD_PATH" "$SF_USER@$SF_HOST:$REMOTE_DIR/" || { echo "Failed to upload files after creating directory structure. Exiting."; exit 1; }
fi
# Upload the updated packages.json to the root directory
echo "Uploading packages.json to the root directory on SourceForge..."
scp -i "$SF_KEY_PATH" packages.json "$SF_USER@$SF_HOST:/home/frs/project/$SF_PROJECT/" || { echo "Failed to upload packages.json. Exiting."; exit 1; }
echo "Upload completed successfully."
# Clean up compressed file if it was created
if [ "$COMPRESS" = true ]; then
rm "$COMPRESSED_FILE"
fi
exit 0