forked from erigontech/erigon-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade Shell Script and update README
- Loading branch information
1 parent
487873d
commit 1a3f05f
Showing
2 changed files
with
74 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,13 @@ | ||
## Welcome to GitHub Pages | ||
## Erigon Snapshot | ||
|
||
You can use the [editor on GitHub](https://github.com/ledgerwatch/erigon-snapshot/edit/main/README.md) to maintain and preview the content for your website in Markdown files. | ||
This repo contains the snapshot data used when syncing Erigon with snapshots enabled. | ||
|
||
Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files. | ||
## Generating Magnet Links | ||
|
||
### Markdown | ||
This repo contains a shell script that can be used to generate [Magnet Links](https://en.wikipedia.org/wiki/Magnet_URI_scheme) | ||
|
||
Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for | ||
By default it will download and generate magnet links for Ethereum Mainnet, you can override this with the `--network` argument. | ||
|
||
```markdown | ||
Syntax highlighted code block | ||
Valid networks are what you see in this repo. | ||
|
||
# Header 1 | ||
## Header 2 | ||
### Header 3 | ||
|
||
- Bulleted | ||
- List | ||
|
||
1. Numbered | ||
2. List | ||
|
||
**Bold** and _Italic_ and `Code` text | ||
|
||
[Link](url) and  | ||
``` | ||
|
||
For more details see [Basic writing and formatting syntax](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax). | ||
|
||
### Jekyll Themes | ||
|
||
Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/ledgerwatch/erigon-snapshot/settings/pages). The name of this theme is saved in the Jekyll `_config.yml` configuration file. | ||
|
||
### Support or Contact | ||
|
||
Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://support.github.com/contact) and we’ll help you sort it out. | ||
Tested with Linux and OSX (wget or curl required) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,87 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Default to mainnet | ||
NETWORK="mainnet" | ||
|
||
# Get script arguments and set variables | ||
while [ "$1" != "" ]; do | ||
case $1 in | ||
# Set Network | ||
-n | --network) | ||
shift | ||
NETWORK=$1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
# Convert network to lowercase | ||
NETWORK=$(echo "$NETWORK" | tr '[:upper:]' '[:lower:]') | ||
|
||
# Try to use wget, if not available try to use curl | ||
if ! command -v wget &> /dev/null; then | ||
if ! command -v curl &> /dev/null; then | ||
echo "wget or curl is required to download files" | ||
exit 1 | ||
else | ||
DOWNLOADER="curl -fso" | ||
fi | ||
else | ||
DOWNLOADER="wget -qO" | ||
fi | ||
|
||
# Function for URL encoding the trackers | ||
rawurlencode() { | ||
local string="${1}" | ||
local strlen=${#string} | ||
local encoded="" | ||
local pos c o | ||
|
||
for (( pos=0 ; pos<strlen ; pos++ )); do | ||
c=${string:$pos:1} | ||
case "$c" in | ||
[-_.~a-zA-Z0-9] ) o="${c}" ;; | ||
* ) printf -v o '%%%02x' "'$c" | ||
esac | ||
encoded+="${o}" | ||
done | ||
echo "${encoded}" # You can either set a return variable (FASTER) | ||
local string="${1}" | ||
local strlen=${#string} | ||
local encoded="" | ||
local pos c o | ||
|
||
for ((pos = 0; pos < strlen; pos++)); do | ||
c=${string:$pos:1} | ||
case "$c" in | ||
[-_.~a-zA-Z0-9]) o="${c}" ;; | ||
*) printf -v o '%%%02x' "'$c" ;; | ||
esac | ||
encoded+="${o}" | ||
done | ||
echo "${encoded}" | ||
} | ||
|
||
# Name of snapshot file | ||
SNAPSHOTFILE="erigon_snapshots_${NETWORK}.toml" | ||
|
||
# Download TOML file | ||
wget -O erigon_torrents.toml https://raw.githubusercontent.com/ledgerwatch/erigon-snapshot/main/mainnet.toml | ||
URL="https://raw.githubusercontent.com/ledgerwatch/erigon-snapshot/main/${NETWORK}.toml" | ||
${DOWNLOADER} ${SNAPSHOTFILE} ${URL} | ||
if [ $? -ne 0 ]; then | ||
echo "Failed to download ${URL}" | ||
exit 1 | ||
fi | ||
|
||
# Remove quotes from TOML file | ||
sed -ie 's|["'\'']||g' ${SNAPSHOTFILE} | ||
|
||
# Download Trackers | ||
wget -O trackers_best.txt https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt | ||
URL="https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt" | ||
${DOWNLOADER} trackers_best.txt ${URL} | ||
if [ $? -ne 0 ]; then | ||
echo "Failed to download ${URL}" | ||
exit 1 | ||
fi | ||
|
||
# Remove empty lines from trackers file | ||
sed -i '/^[[:space:]]*$/d' trackers_best.txt | ||
sed -ie '/^[[:space:]]*$/d' trackers_best.txt | ||
|
||
# Generate trackers string | ||
TRACKERS="" | ||
for LINE in $(cat trackers_best.txt) | ||
do | ||
for LINE in $(cat trackers_best.txt); do | ||
TRACKERS="${TRACKERS}&tr=$(rawurlencode $LINE)" | ||
done | ||
|
||
# Echo out all the magnet links with trackers | ||
cat erigon_torrents.toml | while read LINE | ||
do | ||
NAME=$(echo $LINE | awk '{print $1}' | sed "s/'//g") | ||
HASH=$(echo $LINE | awk '{print $3}' | sed "s/'//g") | ||
cat ${SNAPSHOTFILE} | while read LINE; do | ||
NAME=$(echo $LINE | awk '{print $1}') | ||
HASH=$(echo $LINE | awk '{print $3}') | ||
echo "magnet:?xt=urn:btih:${HASH}&dn=${NAME}${TRACKERS}" | ||
done | ||
done |