Newer
Older
#!/bin/bash -e
. /usr/share/debconf/confmodule
DAP_CHAINS_NAME="cellframe"
DAP_APP_NAME="$DAP_CHAINS_NAME-node"
DAP_PREFIX="/opt/$DAP_APP_NAME"
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
DAP_CFG_TPL="$DAP_PREFIX/share/configs/$DAP_APP_NAME.cfg.tpl"
# Store write config to new if present smth
DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
# Check profile.d symlink
[ -e "/etc/profile.d/$DAP_APP_NAME.sh" ] && ln -sf $DAP_PREFIX/share/profile.d/$DAP_APP_NAME.sh /etc/profile.d/$DAP_APP_NAME.sh
# Init node config
if [ -e "$DAP_CFG" ]; then
DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg.dpkg-new"
else
DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
fi
cat $DAP_CFG_TPL > $DAP_CFG || true
db_get cellframe-node/debug_mode || true
sed -i "s/{DEBUG_MODE}/$RET/" $DAP_CFG || true
db_get cellframe-node/auto_online || true
sed -i "s/{AUTO_ONLINE}/$RET/" $DAP_CFG || true
db_get cellframe-node/debug_stream_headers || true
sed -i "s/{DEBUG_STREAM_HEADERS}/$RET/" $DAP_CFG || true
db_get cellframe-node/server_enabled || true
sed -i "s/{SERVER_ENABLED}/$RET/" $DAP_CFG || true
db_get cellframe-node/server_port || true
sed -i "s/{SERVER_PORT}/$RET/" $DAP_CFG || true
db_get cellframe-node/server_addr || true
sed -i "s/{SERVER_ADDR}/$RET/" $DAP_CFG || true
# Init kelvin-testnet
NET_NAME="kelvin-testnet"
db_get cellframe-node/kelvin_testnet_enable || true
if [ "$RET"="true" ]; then
DAP_CFG_NET="$DAP_PREFIX/etc/network/$NET_NAME.cfg"
DAP_CFG_NET_TPL="$DAP_PREFIX/share/configs/network/$NET_NAME.cfg.tpl"
DAP_NET_CFG=""
if [ -e "$DAP_CFG_NET" ]; then
DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.dpkg-new"
else
DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg"
fi
cat $DAP_CFG_NET_TPL > $DAP_NET_CFG || true
db_get cellframe-node/kelvin_testnet_node_type || true
NODE_TYPE=$RET
sed -i "s/{NODE_TYPE}/$NODE_TYPE/" $DAP_NET_CFG || true
fi
mkdir -p $DAP_PREFIX/var/log || true
cat /etc/passwd| grep cellframe-node || adduser --system --no-create-home --group --home /opt/cellframe-node cellframe-node
echo "[*] Check /etc/systemd/system/$DAP_APP_NAME.service file..."
if [ -f /etc/systemd/system/$DAP_APP_NAME.service ]; then
echo "[*] Restarting $DAP_APP_NAME to implement changes"
systemctl --system stop $DAP_APP_NAME >> /dev/null|| true
systemctl daemon-reload || true
systemctl --system start $DAP_APP_NAME || true
else
echo "[!] Installing $DAP_APP_NAME as systemd service (haven't found /etc/systemd/system/$DAP_APP_NAME.service)"
ln -sf $DAP_PREFIX/share/$DAP_APP_NAME.service /etc/systemd/system/$DAP_APP_NAME.service || true
systemctl --system enable $DAP_PREFIX/share/$DAP_APP_NAME.service || true
# systemctl --system start $DAP_APP_NAME
echo "[ ] Execute 'systemctl start $DAP_APP_NAME' to start $DAP_APP_NAME service"
#USERMAN=`users | awk '{print $1}'`
adduser --system --no-create-home --group --home /opt/cellframe-node cellframe-node || true
#usermod -aG $DAP_CHAINS_NAME `users | awk '{print $1}'`
for username in $(cat /etc/passwd | grep "/home" | cut -d ':' -f1); do
usermod -aG cellframe-node $username
done
mkdir -p $DAP_PREFIX/var/{run,lib/ca,lib/wallet,lib/global_db}
touch $DAP_PREFIX/var/run/cellframe-node.pid
#chown -R $USERMAN:$USERMAN $DAP_PREFIX
for filename in $(find $DAP_PREFIX); do
if [ -d $filename ]; then
chmod 0775 $filename
else
chmod 0664 $filename
fi
done
chmod 0774 $DAP_PREFIX/bin/*
echo "[*] Done"
fi