Skip to content

Commit

Permalink
linuxmuster-import-devices: subprocess improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyBasher committed Feb 19, 2024
1 parent 10f7bb3 commit 95e27be
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions sbin/linuxmuster-import-devices
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from functions import getBootImage, getDevicesArray, getGrubOstype, getGrubPart
from functions import getStartconfOsValues, getStartconfOption
from functions import getStartconfPartnr, getStartconfPartlabel, getSubnetArray
from functions import isValidHostIpv4, getLinboVersion, printScript, readTextfile
from functions import setGlobalStartconfOption, writeTextfile
from functions import setGlobalStartconfOption, subProc, writeTextfile


def usage():
Expand Down Expand Up @@ -67,14 +67,14 @@ printScript(os.path.basename(__file__), 'begin')
# do sophomorix-devices first
msg = 'Starting sophomorix-device syntax check:'
printScript(msg)
result = subprocess.check_call('sophomorix-device --dry-run', shell=True)
result = subProc('sophomorix-device --dry-run')
msg = 'sophomorix-device finished '
if result != 0:
if not result:
printScript(msg + ' errors detected!')
sys.exit(result)
sys.exit(1)

printScript(msg + ' OK!')
subprocess.call('sophomorix-device --sync', shell=True)
subProc('sophomorix-device --sync')


# functions begin
Expand All @@ -93,7 +93,7 @@ def doGrubCfg(startconf, group, kopts):
# if cache is not defined provide a forced netboot cfg
if cacheroot is None:
netboottpl = constants.LINBOTPLDIR + '/grub.cfg.forced_netboot'
subprocess.call('cp ' + netboottpl + ' ' + grubcfg, shell=True)
subProc('cp ' + netboottpl + ' ' + grubcfg)
return 'not yet configured!'
# create return message
if os.path.isfile(grubcfg):
Expand Down Expand Up @@ -154,8 +154,7 @@ def doLinboStartconf(group):
msg1 = 'present'
else:
msg1 = 'not yet configured!'
subprocess.call('cp ' + constants.LINBODIR
+ '/start.conf ' + startconf, shell=True)
subProc('cp ' + constants.LINBODIR + '/start.conf ' + startconf)
# read values from start.conf
group_s = getStartconfOption(startconf, 'LINBO', 'Group')
serverip_s = getStartconfOption(startconf, 'LINBO', 'Server')
Expand Down Expand Up @@ -323,8 +322,8 @@ def doSchoolSpecificGroupLinksAndGetPxeGroups(school='default-school'):
# look up all links for all schools and place them in the correct place
def doAllGroupLinks():
# delete old config links
subprocess.call(['find', constants.LINBODIR, '-maxdepth', '1', '-name', 'start.conf-*', '-type', 'l', '-exec', 'rm', '{}', ';'])
subprocess.call(['find', constants.LINBOGRUBDIR + '/hostcfg', '-maxdepth', '1', '-name', '*.cfg', '-type', 'l', '-exec', 'rm', '{}', ';'])
subProc("find " + constants.LINBODIR + " -maxdepth 1 -name start.conf-\* -type l -exec rm '{}' \;")
subProc("find " + constants.LINBOGRUBDIR + "/hostcfg -maxdepth 1 -name \*.cfg -type l -exec rm '{}' \;")

linksConfBasedir = constants.LINBODIR + "/boot/links"
for schoolLinksConf in listdir(linksConfBasedir):
Expand Down Expand Up @@ -375,29 +374,14 @@ if len(hookscripts) > 0:
hookscript = hookpath + '/' + h
msg = '* ' + h + ' '
printScript(msg, '', False, False, True)
output = subprocess.getoutput(hookscript)
output = subprocess.check_output(hookscript).decode('utf-8')
if output != '':
print(output)

# restart services
printScript('', 'begin')
printScript('Restarting services:')
service = 'isc-dhcp-server'
subprocess.call('service ' + service + ' restart', shell=True)
# wait one second before service check
time.sleep(1)
rc = 0
msg = '* ' + service + ' '
printScript(msg, '', False, False, True)
state = subprocess.check_call(
'systemctl is-active --quiet ' + service, shell=True)
if state == 0:
printScript(' OK!', '', True, True, False, len(msg))
else:
printScript(' Failed!', '', True, True, False, len(msg))
rc = 1
printScript('Restarting dhcp service:')
subProc('service isc-dhcp-server restart')

# end message
printScript(os.path.basename(__file__), 'end')

sys.exit(rc)

0 comments on commit 95e27be

Please sign in to comment.