aboutsummarylogtreecommitdiffstats
path: root/go-swarm.install
blob: 52d78bf90e2b5e59e83ee7d77cc26134920e1fe3 (plain)
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
post_install () {
	if [ -f /var/lib/bzz/.swarm-pass ]; then
		echo "you already have a Swarm data dir. I'll leave it alone ;)"
		return 0
	fi

	mkdir -p /var/lib/bzz/.ethereum/keystore
	gethbin=$(which geth)
	if [ ! -z $gethbin ]; then
		echo "generating wallet with geth"
		tmpkey=$(mktemp -d)
		pushd ${tmpkey}
		dd if=/dev/urandom of=.swarm-pass bs=1 count=64
		geth --datadir /var/lib/bzz/.ethereum --password ${tmpkey}/.swarm-pass account new
		install -v -D -m600 .swarm-pass /var/lib/bzz/.swarm-pass
		popd
		rm -vrf ${tmpkey}
	elif [ -x /usr/local/bin/swarm-genkey ]; then
		echo "generating wallet with swarm-genkey"
		tmpkey=$(mktemp -d)
		pushd ${tmpkey}
		/usr/local/bin/swarm-genkey
		install -v -D -m600 .swarm-pass /var/lib/bzz/.swarm-pass
		install -v -D -m600 UTC* /var/lib/bzz/.ethereum/keystore/
		popd
		rm -vrf ${tmpkey}
	else
		echo "Missing optional dependencies required to automatically generate a ethereum wallet for the swarm node"
		echo "You will not be able to run a node with it"
		echo "You can generate it manually later using go-ethereum or the swarm-genkey.py script provided this package, provided dependencies are met"
	fi

	echo "setting up variables for systemd service"
	account=$(ls /var/lib/bzz/.ethereum/keystore | sed -e 's/^.*--\([a-fA-F0-9]*\)$/\1/')
	echo "SWARM_ACCOUNT=$account" > /etc/systemd/system/swarm.service.d/42-swarm.conf
	echo "SWARM_PASSWORD=/var/lib/bzz/.swarm-pass" >> /etc/systemd/system/swarm.service.d/42-swarm.conf

	chown -v bzz:bzz /var/lib/bzz -R
	chmod 700 /var/lib/bzz/.ethereum/keystore 
}