add wizard

This commit is contained in:
Jeff Becker 2018-07-25 14:32:16 +10:00
parent 4dd7b2843f
commit 10ee52a0cd
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
root=$(dirname $(realpath -L $0))
if [ ! -d v ] ; then
echo "setting up wizard for the first time..."
python3 -m venv v && v/bin/pip install -r "$root/requirements.txt" &> /dev/null || echo "failed"
fi
v/bin/python "$root/lokinet.py"

45
contrib/wizard/lokinet.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python3
from configparser import ConfigParser as Config
import netifaces
import ipaddress
import os
def yield_public_addresses():
for ifname in netifaces.interfaces():
addrs = netifaces.ifaddresses(ifname)
if netifaces.AF_INET in addrs:
for addr in addrs[netifaces.AF_INET]:
ip = addr['addr']
if not ipaddress.ip_address(ip).is_private:
yield ifname, ip
def genconf(rootdir):
conf = Config()
conf['router'] = {
'threads': '2',
'net-threads': '1',
'contact-file': os.path.join(rootdir, 'self.signed'),
'transport-privkey': os.path.join(rootdir, 'transport.key'),
'identity-privkey': os.path.join(rootdir, 'identity.key')
}
conf['netdb'] = {
'dir': os.path.join(rootdir, 'netdb')
}
conf['bind'] = {}
for ifname, ip in yield_public_addresses():
conf['bind'][ifname] = '1090'
print("using public address {}".format(ip))
else:
print("we don't have any public addresses on this machine")
return
return conf
def main():
conf = genconf(os.path.realpath('.'))
if conf:
with open('daemon.ini', 'w') as f:
conf.write(f)
if __name__ == '__main__':
main()

View File

@ -0,0 +1 @@
netifaces==0.10.7