add: auto deployment scripts

This commit is contained in:
iceBear67 committed 2024-09-02 00:55:52 +08:00
1 parent a8719412c3
commit f2a8e26893
3 files changed
+89 -1

No files matched your search

+1 -1
View File
@@ -43,6 +43,6 @@ jobs:
TOKEN: ${{ secrets.TOKEN }} TOKEN: ${{ secrets.TOKEN }}
UPLOAD: "/home/runner/sfcraft/build/libs" UPLOAD: "/home/runner/sfcraft/build/libs"
run: | run: |
cd /bin cd scripts
chmod +x ./special_curl.sh chmod +x ./special_curl.sh
sh ./update.sh sh ./update.sh
+60
View File
@@ -0,0 +1,60 @@
#!/bin/bash
# Function to get IP address of a domain
get_ip() {
local domain=$1
# Get IP address (first one found) for the domain
dig +short "$domain" | head -n 1
}
# Check if a URL is provided
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <url> [curl options...]"
exit 1
fi
# Extract the URL
url="$1"
shift
# Define the fixed domain for --resolve
fixed_domain="gov.cn"
# Parse the URL
protocol=$(echo "$url" | awk -F:// '{print $1}')
original_domain_port=$(echo "$url" | awk -F:// '{print $2}' | awk -F/ '{print $1}')
path=$(echo "$url" | sed 's|^[^/]*/||')
# Extract port from the original URL
original_domain=$(echo "$original_domain_port" | awk -F: '{print $1}')
port=$(echo "$original_domain_port" | awk -F: '{print $2}')
# If port is not specified, default to 80 for HTTP or 443 for HTTPS
if [ -z "$port" ]; then
if [ "$protocol" == "http" ]; then
port=80
elif [ "$protocol" == "https" ]; then
port=443
else
echo "Unknown protocol. Please specify port in URL."
exit 1
fi
fi
ip=$(get_ip "$original_domain")
if [ -z "$ip" ]; then
echo "Could not resolve IP address for domain $fixed_domain"
exit 1
fi
# Construct the --resolve argument
resolve_arg="-k --resolve $fixed_domain:$port:$ip"
# Replace the original domain with the fixed domain in the URL
modified_url=$(echo "$url" | sed "s/$original_domain/$fixed_domain/")
# Run curl with the resolve argument and any additional curl options
#echo "Running: curl $resolve_arg $@ $modified_url"
curl $resolve_arg "$@" "$modified_url"
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
UPLOAD=$(ls $UPLOAD | tr ' ' '\n' | grep -v "all")
if ! test -f "$UPLOAD"; then
echo "File does not exist. $UPLOAD"
exit
fi
MOD=$(special_curl $API_ENDPOINT/api/client/servers/$SERVER_ID/files/list\?directory\=/mods -H "Authorization: Bearer $TOKEN" | jq -r ".data[] | .attributes.name" | grep "sfcraft")
echo "Fetch: $MOD"
if [ -n "$MOD" ]; then
echo "Update target: $MOD"
special_curl "$API_ENDPOINT/api/client/servers/$SERVER_ID/files/delete" -H "Content-Type: application/json" -H "Accept: application/json" -X POST -H "Authorization: Bearer $TOKEN" -d "{\"root\": \"/mods\", \"files\": [\"$MOD\"]}"
echo "Deleted."
fi
echo "Uploading $UPLOAD"
SIGNED_URL=$(special_curl $API_ENDPOINT/api/client/servers/$SERVER_ID/files/upload -H "Authorization: Bearer $TOKEN" | jq -r ".attributes.url")
if [ -z "$SIGNED_URL" ]; then
echo "!!! CANNOT FETCH SIGNED URL !!!"
exit
fi
special_curl "$SIGNED_URL&directory=/mods" -X POST -F "files=@$UPLOAD"
echo "Uploaded!"