-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_daemon
58 lines (46 loc) · 1.63 KB
/
container_daemon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
set -e
user=ipfs
repo="$IPFS_PATH"
if [ `id -u` -eq 0 ]; then
echo "Changing user to $user"
# ensure folder is writable
su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo"
# restart script with new privileges
exec su-exec "$user" "$0" "$@"
fi
# 2nd invocation with regular user
ipfs version
if [ -e "$repo/config" ]; then
echo "Found IPFS fs-repo at $repo"
else
case "$IPFS_PROFILE" in
"") INIT_ARGS="" ;;
*) INIT_ARGS="--profile=$IPFS_PROFILE" ;;
esac
ipfs init $INIT_ARGS
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
ipfs config --json 'Addresses.Swarm' '["/ip4/0.0.0.0/tcp/4001", "/ip6/::/tcp/4001", "/ip4/0.0.0.0/udp/4001/quic", "/ip6/::/udp/4001/quic", "/ip4/0.0.0.0/tcp/8081/ws", "/ip6/::/tcp/8081/ws"]'
# Set up the swarm key, if provided
SWARM_KEY_FILE="$repo/swarm.key"
SWARM_KEY_PERM=0400
# Create a swarm key from a given environment variable
if [ ! -z "$IPFS_SWARM_KEY" ] ; then
echo "Copying swarm key from variable..."
echo -e "$IPFS_SWARM_KEY" >"$SWARM_KEY_FILE" || exit 1
chmod $SWARM_KEY_PERM "$SWARM_KEY_FILE"
fi
# Unset the swarm key variable
unset IPFS_SWARM_KEY
# Check during initialization if a swarm key was provided and
# copy it to the ipfs directory with the right permissions
# WARNING: This will replace the swarm key if it exists
if [ ! -z "$IPFS_SWARM_KEY_FILE" ] ; then
echo "Copying swarm key from file..."
install -m $SWARM_KEY_PERM "$IPFS_SWARM_KEY_FILE" "$SWARM_KEY_FILE" || exit 1
fi
# Unset the swarm key file variable
unset IPFS_SWARM_KEY_FILE
fi
exec ipfs "$@"