Files
zzzot-tracker-hack/setup.sh

113 lines
3.8 KiB
Bash
Raw Permalink Normal View History

2024-10-05 18:24:28 -04:00
#! /usr/bin/env sh
tagList() {
for torrent in i2psnark/*.torrent; do
filename=$(echo $torrent | sed 's|.torrent||g')
title=$(echo $filename | sed 's|-| |g' | sed 's|i2psnark/||g')
tags=$(echo $title | sed 's|\.| |g' | sed 's|@| |g')
for tag in $tags; do
for tag in $tags; do
echo " <a class=\"$tag lvix1\" href=\"#$tag\">$tag</a>"
done
done
done
}
generatePage() {
echo "<!doctype html>"
echo "<html lang=en>"
echo "<head>"
echo "<meta charset=utf-8>"
echo "<title>Torrent Index</title>"
echo "<script src=\"script.js\"></script>"
echo "<style>"
echo "div {"
echo " display: \"inline\";"
echo "}"
echo "</style>"
echo "</head>"
echo "<body>"
cd "$SHARE"
echo " <div class=\"tags\">Tags:"
2024-10-05 18:24:28 -04:00
tagList | sort -u
echo " </div>"
2024-10-05 18:24:28 -04:00
for torrent in i2psnark/*.torrent; do
transmission-edit -a "http://$zzzot_announce/a" "$torrent" 2> "$BACK/err" 1> "$BACK/log"
2024-10-05 18:24:28 -04:00
filename=$(echo $torrent | sed 's|.torrent||g')
title=$(echo $filename | sed 's|-| |g' | sed 's|i2psnark/||g')
tags=$(echo $title | sed 's|\.| |g' | sed 's|@| |g')
echo " <div id="$filename" class=\"lvix2 $tags\">"
2024-10-05 18:24:28 -04:00
echo " <a href=\"$torrent\">$title</a></br>"
echo " <div class=\"tags\">Tags:"
for tag in $tags; do
echo " <a class=\"$tag lvix1\" href=\"#$tag\">$tag</a>"
2024-10-05 18:24:28 -04:00
done
echo " </div>"
echo " </div>"
done
cd $BACK
echo "</body>"
echo "</html>"
}
script(){
echo 'window.addEventListener("load", function () {
setupTags();
function setupTags() {
let els = document.querySelectorAll(".lvix1");
for (let el of els)
el.addEventListener("click", function () {
let divset = document.querySelectorAll(".lvix2");
for (let div of divset) div.style.display = "none";
let cl = el.classList[0];
let divs = document.querySelectorAll("." + cl);
for (let div of divs) div.style.display = "inline";
showTags();
});
}
function showTags() {
let els = document.querySelectorAll(".lvix1");
for (let el of els) {
el.style.display = "inline";
2024-10-05 18:24:28 -04:00
}
}
});
'
2024-10-05 18:24:28 -04:00
}
if [ ! -f script.js ]; then
script | tee script.js
fi
if [ $(whoami) = "i2psvc" ]; then
if [ ! -d /var/lib/i2p/i2p-config/plugins/zzzot/eepsite/docroot ]; then
echo "zzzot directory does not exist, did you read the instructions?"
exit 1
fi
if [ ! -d /var/lib/i2p/i2p-config/plugins/zzzot/eepsite/docroot/i2psnark ]; then
echo "symlinking snark dir"
ln -sf /var/lib/i2p/i2p-config/i2psnark /var/lib/i2p/i2p-config/plugins/zzzot/eepsite/docroot/i2psnark
fi
export BACK=$(pwd)
export SHARE=/var/lib/i2p/i2p-config/plugins/zzzot/eepsite/docroot/
generatePage | tee /var/lib/i2p/i2p-config/plugins/zzzot/eepsite/docroot/index.html
cp script.js /var/lib/i2p/i2p-config/plugins/zzzot/eepsite/docroot/script.js
2024-10-05 18:24:28 -04:00
else
if [ ! -d "$HOME/.i2p/plugins/zzzot/eepsite/docroot" ]; then
echo "zzzot directory does not exist, did you read the instructions?"
exit 1
fi
if [ -d "$HOME/.i2p/i2psnark" ]; then
if [ ! -d "$HOME/.i2p/plugins/zzzot/eepsite/docroot/i2psnark" ]; then
echo "symlinking snark dir"
ln -sf "$HOME/.i2p/i2psnark" "$HOME/.i2p/plugins/zzzot/eepsite/docroot/i2psnark"
fi
export BACK=$(pwd)
export SHARE="$HOME/.i2p/plugins/zzzot/eepsite/docroot/"
generatePage | tee "$HOME/.i2p/plugins/zzzot/eepsite/docroot/index.html"
cp script.js "$HOME/.i2p/plugins/zzzot/eepsite/docroot/script.js"
2024-10-05 18:24:28 -04:00
else
echo "i2psnark directory does not exist, did you install I2P using a \`.deb\`?"
exit 1
fi
fi