Skip to content

Commit

Permalink
- Added counting api which counts the times the script was executes
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Nov 25, 2024
1 parent f8c4985 commit 25cf6b0
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion mcserver_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@
#GitHub : https://github.com/officialrealTM/mcserver_installer
###################################################################

## START OF COUNTING FUNCTIONS
CONFIG_FILE="/root/mcserver_installer/.mcserver_installer_config"
API_BASE_URL="https://api.realtm.de"

get_api_key() {
local api_key=""
if [ -f "$CONFIG_FILE" ]; then
api_key=$(cat "$CONFIG_FILE")
else
# Generate new API key and parse the JSON response properly
response=$(curl -s -X POST "$API_BASE_URL/generate-key")
api_key=$(echo "$response" | grep -o '"apiKey":"[^"]*"' | cut -d'"' -f4)
if [ -n "$api_key" ]; then
echo "$api_key" > "$CONFIG_FILE"
chmod 600 "$CONFIG_FILE"
else
echo "Failed to generate API key" >&2
return 1
fi
fi
echo "$api_key"
}

increment_counter() {
local api_key=$(get_api_key)
if [ -n "$api_key" ]; then
response=$(curl -s -X POST "$API_BASE_URL/increment" \
-H "X-API-Key: $api_key" \
-H "Content-Type: application/json")
echo "$response"
fi
}
## END OF COUNTING FUNCTIONS

## START OF FUNCTIONS

function choose_type {
Expand Down Expand Up @@ -3638,7 +3672,7 @@ distro_check () {
}

## Script Version
scriptversion="14.2"
scriptversion="15.0"
##

## Latest Version
Expand Down

0 comments on commit 25cf6b0

Please sign in to comment.