master
text 55 lines 1.5 KB
Raw
1 #!/bin/sh
2 set -e
3
4 user=ipfs
5 repo="$IPFS_PATH"
6
7 if [ "$(id -u)" -eq 0 ]; then
8 echo "Changing user to $user"
9 # ensure folder is writable
10 gosu "$user" test -w "$repo" || chown -R -- "$user" "$repo"
11 # restart script with new privileges
12 exec gosu "$user" "$0" "$@"
13 fi
14
15 # 2nd invocation with regular user
16 ipfs version
17
18
19 if [ -e "$repo/config" ]; then
20 echo "Found IPFS fs-repo at $repo"
21 else
22 ipfs init ${IPFS_PROFILE:+"--profile=$IPFS_PROFILE"}
23 ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
24 ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
25
26 # Set up the swarm key, if provided
27
28 SWARM_KEY_FILE="$repo/swarm.key"
29 SWARM_KEY_PERM=0400
30
31 # Create a swarm key from a given environment variable
32 if [ -n "$IPFS_SWARM_KEY" ] ; then
33 echo "Copying swarm key from variable..."
34 printf "%s\n" "$IPFS_SWARM_KEY" >"$SWARM_KEY_FILE" || exit 1
35 chmod $SWARM_KEY_PERM "$SWARM_KEY_FILE"
36 fi
37
38 # Unset the swarm key variable
39 unset IPFS_SWARM_KEY
40
41 # Check during initialization if a swarm key was provided and
42 # copy it to the ipfs directory with the right permissions
43 # WARNING: This will replace the swarm key if it exists
44 if [ -n "$IPFS_SWARM_KEY_FILE" ] ; then
45 echo "Copying swarm key from file..."
46 install -m $SWARM_KEY_PERM "$IPFS_SWARM_KEY_FILE" "$SWARM_KEY_FILE" || exit 1
47 fi
48
49 # Unset the swarm key file variable
50 unset IPFS_SWARM_KEY_FILE
51 fi
52
53 find /container-init.d -maxdepth 1 \( -type f -o -type l \) -iname '*.sh' -print0 | sort -z | xargs -n 1 -0 -r container_init_run
54
55 exec ipfs "$@"