-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·127 lines (102 loc) · 2.96 KB
/
configure
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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# check root
if [ ! "$(id -u)" == "0" ]; then
echo "must be root to run install script"
exit 1
fi
# source directory
source_dir=$(cd "$(dirname "${BASH_SOURCE[0]}" )"; pwd)
electrum_config="/etc/electrum-vior.conf"
function read_config()
{
text=$1
echo `grep -e ^$text $electrum_config |awk -F\= '{print $2}' | tail -n 1| tr -d ' '`
}
function write_config()
{
sed -i -s "s#$1 =.*#$1 = $2#" $electrum_config
}
# create config file
if [ ! -f $electrum_config ]; then
echo "Creating config file"
cp $source_dir"/electrum-vior.conf.sample" $electrum_config
fi
# read username
user=$(read_config "username")
if ! [ "$user" ]; then
read -p "username for running daemon (default: electrum) " -r
if [ $REPLY ]; then
user=$REPLY
else
user="electrum"
fi
write_config "username" $user
fi
# create user
if [ ! id -u $user >/dev/null 2>&1 ]; then
echo "adding user $user"
useradd $user
echo "$user hard nofile 65536" >> /etc/security/limits.conf
echo "$user soft nofile 65536" >> /etc/security/limits.conf
fi
# read path from config
default_path="/var/electrum-vior-server"
path=$(read_config "path")
if ! [ "$path" ]; then
read -p "Path for database (default: $default_path) " -r
if [ $REPLY ]; then
path=$REPLY
else
path=$default_path
fi
write_config "path" $default_path
fi
# read path from config
default_logfile="/var/log/electrum-vior.log"
logfile=$(read_config "logfile")
if ! [ "$logfile" ]; then
read -p "Path of logfile (default: $default_logfile) " -r
if [ $REPLY ]; then
logfile=$REPLY
else
logfile=$default_logfile
fi
write_config "logfile" $default_logfile
fi
# remove directory if it exists and is empty
if [ -d $path ]; then
rmdir $path --ignore-fail-on-non-empty
fi
# download database
if [ ! -d $path ]; then
echo "Database not found in $path."
read -p "Do you want to download it from the Electrum foundry to $path ? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
mkdir -p $path
wget -O - "http://foundry.electrum-vior.org/leveldb-dump/electrum-fulltree-100-latest.tar.gz" | tar --extract --gunzip --strip-components 1 --directory $path --file -
fi
fi
# set owner
chown -R $user:$user $path
# create log file
logfile=$(read_config "logfile")
if ! [ -f $logfile ]; then
touch $logfile
chown $user:$user $logfile
fi
bitcoind_user=$(read_config "bitcoind_user")
if ! [ "$bitcoind_user" ]; then
read -p "rpcuser (from your viorcoin.conf file): " -r
write_config "bitcoind_user" $REPLY
fi
bitcoind_password=$(read_config "bitcoind_password")
if ! [ "$bitcoind_password" ]; then
read -p "rpcpassword (from your viorcoin.conf file): " -r
write_config "bitcoind_password" $REPLY
fi
# finish
echo "Configuration written to $electrum_config."
echo "Please edit this file to finish the configuration."
echo "If you have not done so, please run 'python setup.py install'"
echo "Then, run 'electrum-vior-server' to start the daemon"