split system files into to_system and <boxtyp>_system
- install.py checks for both - fix hostname
This commit is contained in:
45
install.py
45
install.py
@ -3,6 +3,7 @@
|
||||
|
||||
- copy files from to_system into system directories
|
||||
- set host name / network settings from boxtools/cfg file
|
||||
- and many more
|
||||
"""
|
||||
|
||||
if bytes == str:
|
||||
@ -12,18 +13,39 @@ import sys
|
||||
import os
|
||||
import filecmp
|
||||
import shutil
|
||||
import serial
|
||||
import re
|
||||
import types
|
||||
import socket
|
||||
from subprocess import Popen, PIPE
|
||||
from ipaddress import IPv4Interface
|
||||
from os.path import join, getmtime, exists, basename
|
||||
from utils import BoxInfo, check_service, unix_cmd, change_firewall
|
||||
|
||||
if os.geteuid() != 0:
|
||||
exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting.")
|
||||
|
||||
def exit():
|
||||
print('please restart sudo ./install.py again')
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
import serial
|
||||
except ImportError:
|
||||
if 'yes'.startswith(input('install pyserial? [y]')):
|
||||
os.system('pip3 install --break-system-packages pyserial')
|
||||
serial = None
|
||||
|
||||
try:
|
||||
from utils import BoxInfo, check_service, unix_cmd, change_firewall
|
||||
except ImportError:
|
||||
if 'yes'.startswith(input('install netifaces? [y]')):
|
||||
os.system('pip3 install --break-system-packages netifaces')
|
||||
serial = None
|
||||
|
||||
if serial is None:
|
||||
print('please restart sudo ./install.py again')
|
||||
exit()
|
||||
|
||||
|
||||
TOOLS = BoxInfo.TOOLS
|
||||
|
||||
more_info = False
|
||||
@ -108,10 +130,10 @@ pip_requirements = {
|
||||
|
||||
|
||||
box = BoxInfo()
|
||||
box.hostname_changed = False
|
||||
dhcp_server_cfg = []
|
||||
|
||||
TO_SYSTEM = f'{TOOLS}/{box.typ}_system'
|
||||
os.chdir(TO_SYSTEM)
|
||||
TO_SYSTEM = [f'{TOOLS}/to_system', f'{TOOLS}/{box.typ}_system']
|
||||
|
||||
|
||||
def do_cmd(command):
|
||||
@ -151,7 +173,7 @@ def router(firewall=False, **opts):
|
||||
if not opts:
|
||||
return None
|
||||
try:
|
||||
os.remove(join(TO_SYSTEM, 'etc/nftables.conf'))
|
||||
os.remove(join(TO_SYSTEM[0], 'etc/nftables.conf'))
|
||||
with open(f'{TOOLS}/requirements.txt') as f:
|
||||
pip_requirements['root']['tools'] = f.read()
|
||||
except FileNotFoundError:
|
||||
@ -333,6 +355,8 @@ def create_if(name, cfg):
|
||||
|
||||
|
||||
def walk(action):
|
||||
for rootpath in TO_SYSTEM:
|
||||
os.chdir(rootpath)
|
||||
for dirpath, _, files in os.walk('.'):
|
||||
syspath = dirpath[1:] # remove leading '.'
|
||||
action.dirpath = dirpath
|
||||
@ -449,11 +473,13 @@ def handle_config():
|
||||
cfgfile = BoxInfo.CFGPATH % (newhostname, box.id)
|
||||
with open(cfgfile, 'w') as f:
|
||||
f.write(template)
|
||||
if cfgfile != BoxInfo.CFGPATH % (newhostname, box.id):
|
||||
if box.hostname_changed or cfgfile != BoxInfo.CFGPATH % (newhostname, box.id):
|
||||
box.hostname_changed = True
|
||||
if cfgfile:
|
||||
newhostname = basename(cfgfile).rpartition('_')[0]
|
||||
if doit:
|
||||
os.system('sh sethostname.sh')
|
||||
print('bash sethostname.sh')
|
||||
os.system(f'bash {TOOLS}/sethostname.sh')
|
||||
else:
|
||||
if cfgfile:
|
||||
print('replace host name %r by %r' % (box.hostname, newhostname))
|
||||
@ -497,8 +523,13 @@ def handle_config():
|
||||
print('change dhcpd.conf')
|
||||
to_start['isc-dhcp-server'] = 'restart'
|
||||
show.dirty = True
|
||||
try:
|
||||
replace_in_file('/etc/default/isc-dhcp-server',
|
||||
r'INTERFACESv4="(.*)"', ' '.join([n for n in box.macaddr if n != box.main_if]))
|
||||
except FileNotFoundError:
|
||||
if 'yes'.startswith(input('install isc-dhcp-server? [y]')):
|
||||
os.system('apt-get install isc-dhcp-server')
|
||||
exit()
|
||||
elif doit:
|
||||
check_service('isc-dhcp-server', False)
|
||||
content = []
|
||||
|
Reference in New Issue
Block a user