Created
December 2, 2025 00:40
-
-
Save bczhc/b14f947aa0251e544650781d05f6e971 to your computer and use it in GitHub Desktop.
Wplace diff server files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| aria2c -x16 -s16 "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env ruby | |
| require 'shellwords' | |
| require 'pathname' | |
| LIST_FILE = './list' | |
| DIFF_OUT_DIR = './diffs' | |
| # @return [Array<String>] | |
| def urls(archive_name) | |
| `gh release -R murolem/wplace-archives view #{Shellwords.escape archive_name} --json assets | jq '.assets[].url' -r` | |
| .chomp.split("\n") | |
| end | |
| def extract_datetime_string(name) | |
| regex = /(20\d{2}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}Z)/ | |
| fail unless regex.match? name | |
| name.scan(regex)[0][0] | |
| end | |
| # @return [Array<String>] | |
| def all_archives | |
| names = `gh release -R murolem/wplace-archives list -L 5000 | cut -f1 | sort` | |
| .chomp.split("\n") | |
| names.map do |x| | |
| extract_datetime_string x | |
| end | |
| end | |
| def fetch_tarball(name) | |
| puts "Fetching #{name}..." | |
| urls = urls name | |
| lines = "set -e\n" | |
| urls.each do |url| | |
| lines += "curl -sL #{Shellwords.escape url}\n" | |
| end | |
| File.write("curl.sh", lines) | |
| system "bash curl.sh | pv | gzip -d > #{Shellwords.escape name}.tar" or fail | |
| "#{name}.tar" | |
| end | |
| puts "Fetching list of archives..." | |
| File.write(LIST_FILE, all_archives.join("\n")) | |
| names = File.readlines(LIST_FILE, chomp: true) | |
| fail unless names.length >= 2 | |
| diff_output_dir = DIFF_OUT_DIR | |
| unless File.exist? diff_output_dir | |
| Dir.mkdir diff_output_dir | |
| end | |
| puts "Clearing old files..." | |
| system 'rm -rfv *.tar' | |
| system "rm -rfv #{Shellwords.escape DIFF_OUT_DIR}/.tmp*" | |
| latest = Dir.children(DIFF_OUT_DIR).sort.last | |
| latest = extract_datetime_string latest | |
| latest_snapshot_index = names.find_index(latest) | |
| fail if latest_snapshot_index == nil | |
| names = names.drop(latest_snapshot_index) | |
| if names.length < 2 | |
| puts 'No more snapshots to be processed; sleep and exit' | |
| sleep(24*3600) | |
| exit 0 | |
| end | |
| first_archive = fetch_tarball("world-#{names[0]}") | |
| parent = first_archive | |
| names.each_cons(2) do |pair| | |
| diff_target = fetch_tarball("world-#{pair[1]}") | |
| puts "Diffing: #{parent} -> #{diff_target}" | |
| diff_file_name = "#{pair[1]}.diff" | |
| diff_file_path = File.join(DIFF_OUT_DIR, diff_file_name) | |
| if File.exist? diff_file_path | |
| puts "Skipped #{diff_file_name}" | |
| next | |
| end | |
| cmd = "~/archive-tool diff #{Shellwords.escape parent} #{Shellwords.escape diff_target} #{Shellwords.escape diff_file_path}" | |
| puts "CMD: #{cmd}" | |
| system cmd or fail | |
| system "gzip #{Shellwords.escape diff_file_path}" or fail | |
| system "./upload #{Shellwords.escape diff_file_path}.gz" or fail | |
| system "rm -rf #{Shellwords.escape diff_file_path}.gz" or fail | |
| system "rm #{Shellwords.escape parent}" or fail | |
| parent = diff_target | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| count=0 | |
| max=2 | |
| while [ $count -lt $max ]; do | |
| ./auto-diff | |
| sleep 180 | |
| ((count++)) | |
| echo "Current count: $count" | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| threshold=500 | |
| while :; do | |
| avail_disk=`df / -B1 --output=avail | tail -n1`; disk_mb=$((avail_disk/1048576)); [ $disk_mb -lt $threshold ] && ./create-issue 'disk_mb low!'" $disk_mb MiB" && exit 0 | |
| echo $disk_mb MiB | |
| sleep 1 | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| [ $# -eq 0 ] && echo 'Usage: cmd <title>' && exit 1 | |
| title="$1" | |
| echo | gh -R bczhc/wplace-diffs issue create --title "$title" -b '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| INTERVAL=${1:-15} | |
| while true; do | |
| timestamp=$(date +%s) | |
| free_mem=$(grep MemAvailable /proc/meminfo | awk '{print $2 * 1024}') | |
| free_disk=$(df --output=avail -B1 / | tail -n 1) | |
| jq -n --compact-output \ | |
| --argjson timestamp "$timestamp" \ | |
| --argjson free_mem "$free_mem" \ | |
| --argjson free_disk "$free_disk" \ | |
| '{timestamp: $timestamp, free_memory: $free_mem, free_disk: $free_disk}' | |
| sleep "$INTERVAL" | |
| done | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| [ $# -eq 0 ] && echo 'Usage: cmd <file>' && exit 0 | |
| counter=0 | |
| max=3 | |
| while :; do | |
| [ $counter -eq $max ] && exit 1 | |
| if (echo | gh release -R bczhc/wplace-diffs create "$(basename "$1")" "$1"); then | |
| exit 0 | |
| else | |
| ((++counter)) | |
| fi | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment