initial commit
This commit is contained in:
40
publish_to_gitea.sh
Executable file
40
publish_to_gitea.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables
|
||||
GITEA_URL=$1 # Gitea server URL, e.g., https://gitea.example.com
|
||||
USERNAME=$2 # Your Gitea username
|
||||
OWNER=$3 # The owner of the package (user or organization)
|
||||
PROJECT_DIR=$4 # Path to the PHP project directory (not zipped)
|
||||
VERSION=$5 # Package version (optional)
|
||||
|
||||
# Prompt for password securely
|
||||
read -sp "Enter your Gitea password or token: " PASSWORD
|
||||
echo
|
||||
|
||||
PASSWORD_OR_TOKEN=$(printf '%q' "$PASSWORD")
|
||||
|
||||
# Create a ZIP file from the project directory
|
||||
ZIP_NAME="package-$(date +%Y%m%d%H%M%S).zip"
|
||||
zip -r $ZIP_NAME $PROJECT_DIR
|
||||
|
||||
# Check if version is provided
|
||||
if [ -z "$VERSION" ]; then
|
||||
URL="$GITEA_URL/api/packages/$OWNER/composer"
|
||||
else
|
||||
URL="$GITEA_URL/api/packages/$OWNER/composer?version=$VERSION"
|
||||
fi
|
||||
|
||||
# Publish the package
|
||||
curl --user $USERNAME:$PASSWORD_OR_TOKEN \
|
||||
--upload-file $ZIP_NAME \
|
||||
$URL
|
||||
|
||||
# Check for successful upload
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Package uploaded successfully."
|
||||
else
|
||||
echo "Failed to upload the package."
|
||||
fi
|
||||
|
||||
# Optionally, remove the ZIP file after upload
|
||||
rm $ZIP_NAME
|
||||
Reference in New Issue
Block a user