Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
NavyStack committed Feb 3, 2024
1 parent 4a86d19 commit c7b3cec
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/Update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,18 @@ jobs:
with:
commit_message: "[BOT] [AWS] changes - ${{ steps.amazon-extract-timestamp.outputs.amazon_utc }}"
push_options: '--force'

- name: Run Bing Script
run: |
chmod +x ./bingbot/start.sh
./bingbot/start.sh
- name: Extract Timestamp from File (Bing)
id: bingbot-extract-timestamp
run: echo "bingbot_utc=$(<./bingbot/timestamp.txt)" >> "$GITHUB_OUTPUT"

- name: Git Auto Commit (Bing)
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "[BOT] [Bing] changes - ${{ steps.bingbot-extract-timestamp.outputs.bingbot_utc }}"
push_options: '--force'
66 changes: 66 additions & 0 deletions bingbot/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

set -euo pipefail
set -x

# Define file paths
json_file="/tmp/bingbot.json"
timestamp_file="bingbot/timestamp.txt"

ipv4_file="/tmp/bingbot-ipv4.txt"
ipv4_comma_output="bingbot/ipv4_comma.txt"
ipv4_output="bingbot/ipv4.txt"

# ipv6 not provided

# Check if the timestamp_file exists and remove it if it does
if [ -e "$timestamp_file" ]; then
rm "$timestamp_file"
echo "Step 0: File $timestamp_file removed successfully."
else
echo "Step 0: File $timestamp_file does not exist. Skip."
fi

# Download public BingBot IP ranges
if curl -s https://www.bing.com/toolbox/bingbot.json > "$json_file"; then
echo "Step 1: Data fetched from BingBot IP ranges using curl successfully."
else
echo "Step 1: Failed to download BingBot IP ranges using curl." >&2
exit 1
fi

# Extract creationTime from JSON and convert to UTC
timestamp=$(jq -r '.creationTime' "$json_file")
bingbot_utc=$(date -d "$timestamp" -u +"%Y-%m-%dT%H:%M:%S.000000Z")

# Save timestamp to file
echo "$bingbot_utc" > "$timestamp_file"

# Save IPv4 addresses and check if the jq command was successful
if jq '.prefixes[] | [.ipv4Prefix][] | select(. != null)' -r "$json_file" > "$ipv4_file"; then
echo "Step 2: IPv4 addresses extracted successfully."
else
echo "Step 2: Error: Failed to extract IPv4 addresses using jq."
exit 1
fi

# Sort and remove duplicates for IPv4 and check if the sort command was successful
if sort -V "$ipv4_file" | uniq > "$ipv4_output"; then
echo "Step 4: IPv4 addresses sorted and duplicates removed successfully."
else
echo "Step 4: Error: Failed to sort IPv4 addresses."
exit 1
fi

# Save IPv4 addresses with comma separation and check if the jq and sort commands were successful
if jq -r '.prefixes[] | [.ipv4Prefix][] | select(. != null)' "$json_file" | sort -V | uniq | paste -sd "," - > "$ipv4_comma_output"; then
echo "Step 6: IPv4 addresses processed for comma separation successfully."
else
echo "Step 6: Failed to process IPv4 addresses for comma separation."
exit 1
fi

# Clean up temporary files
rm "$json_file" "$ipv4_file"

echo "BingBot Complete!"
2 changes: 1 addition & 1 deletion googlebot/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi
if curl -s https://developers.google.com/search/apis/ipranges/googlebot.json > "$json_file"; then
echo "Step 1: Data fetched from GoogleBot IP ranges using curl successfully."
else
echo "Step 1: Failed to download ORACLE IP ranges using curl." >&2
echo "Step 1: Failed to download GoogleBot IP ranges using curl." >&2
exit 1
fi

Expand Down

0 comments on commit c7b3cec

Please sign in to comment.