Skip to content

Commit 67d1eb2

Browse files
committed
feat(i2p): add start/stop helpers and npm scripts (#35)
1 parent 065638c commit 67d1eb2

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

scripts/print_i2p_hostname

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
PROJECT_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))/.."
4+
KEYS_FILE="$PROJECT_ROOT/.nostr/i2p/data/nostream.dat"
5+
6+
if [ ! -f "$KEYS_FILE" ]; then
7+
echo "I2P destination keys not found. Is the i2pd container running?"
8+
echo "Expected: $KEYS_FILE"
9+
exit 1
10+
fi
11+
12+
# i2pd writes a binary .dat file for tunnel keys. The base32 hostname is
13+
# derived from the public key portion, but extracting it from the binary
14+
# format is non-trivial without a helper. Instead, read it from the i2pd
15+
# web console or container logs.
16+
echo "I2P destination keys exist at: $KEYS_FILE"
17+
echo ""
18+
echo "To find your .b32.i2p address, use one of these methods:"
19+
echo " 1. docker exec i2pd cat /home/i2pd/data/nostream.dat | head -c 391 | base32 | tr '[:upper:]' '[:lower:]' | tr '+/' '-~'"
20+
echo " 2. Check the i2pd web console at http://127.0.0.1:7070/?page=i2p_tunnels"
21+
echo " 3. docker logs i2pd 2>&1 | grep -i 'nostream'"

scripts/start_with_i2p

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
PROJECT_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))/.."
3+
DOCKER_COMPOSE_FILE="${PROJECT_ROOT}/docker-compose.yml"
4+
DOCKER_COMPOSE_I2P_FILE="${PROJECT_ROOT}/docker-compose.i2p.yml"
5+
I2P_DATA_DIR="$PROJECT_ROOT/.nostr/i2p/data"
6+
NOSTR_CONFIG_DIR="${PROJECT_ROOT}/.nostr"
7+
SETTINGS_FILE="${NOSTR_CONFIG_DIR}/settings.yaml"
8+
DEFAULT_SETTINGS_FILE="${PROJECT_ROOT}/resources/default-settings.yaml"
9+
CURRENT_DIR=$(pwd)
10+
11+
if [[ ${CURRENT_DIR} =~ /scripts$ ]]; then
12+
echo "Please run this script from the Nostream root folder, not the scripts directory."
13+
echo "To do this, change up one directory, and then run the following command:"
14+
echo "./scripts/start_with_i2p"
15+
exit 1
16+
fi
17+
18+
if [ "$EUID" -eq 0 ]
19+
then echo "Error: Nostream should not be run as root."
20+
exit 1
21+
fi
22+
23+
if [[ ! -d "${NOSTR_CONFIG_DIR}" ]]; then
24+
echo "Creating folder ${NOSTR_CONFIG_DIR}"
25+
mkdir -p "${NOSTR_CONFIG_DIR}"
26+
fi
27+
28+
if [[ ! -f "${SETTINGS_FILE}" ]]; then
29+
echo "Copying ${DEFAULT_SETTINGS_FILE} to ${SETTINGS_FILE}"
30+
cp "${DEFAULT_SETTINGS_FILE}" "${SETTINGS_FILE}"
31+
fi
32+
33+
mkdir -p $I2P_DATA_DIR
34+
35+
docker compose \
36+
-f $DOCKER_COMPOSE_FILE \
37+
-f $DOCKER_COMPOSE_I2P_FILE \
38+
up --build --remove-orphans $@

scripts/stop

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
PROJECT_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))/.."
33
DOCKER_COMPOSE_FILE="${PROJECT_ROOT}/docker-compose.yml"
44
DOCKER_COMPOSE_TOR_FILE="${PROJECT_ROOT}/docker-compose.tor.yml"
5+
DOCKER_COMPOSE_I2P_FILE="${PROJECT_ROOT}/docker-compose.i2p.yml"
56
DOCKER_COMPOSE_LOCAL_FILE="${PROJECT_ROOT}/docker-compose.local.yml"
67

78
docker compose \
89
-f $DOCKER_COMPOSE_FILE \
910
-f $DOCKER_COMPOSE_TOR_FILE \
11+
-f $DOCKER_COMPOSE_I2P_FILE \
1012
-f $DOCKER_COMPOSE_LOCAL_FILE \
1113
down $@

0 commit comments

Comments
 (0)