Exemple #1
0
from functions import setupComment
from functions import backupCfg

print ('### ' + os.path.basename(__file__))

# read INIFILE, get schoolname
i = configparser.ConfigParser()
i.read(constants.SETUPINI)
adminpw = i.get('setup', 'adminpw')
serverip = i.get('setup', 'serverip')

# rsyncd secrets
configfile = '/etc/rsyncd.secrets'

# create filedata
filedata = setupComment() + '\n' + 'linbo:' + adminpw + '\n'

# write configfile
try:
    with open(configfile, 'w') as outfile:
        outfile.write(filedata)
except:
    print('Cannot write ' + configfile + '!')
    exit(1)

# permissions
os.system('chmod 600 ' + configfile)

# restart services
os.system('service rsync restart')
        sys.exit(1)
    else:
        msg = 'Saving admin password to setup.ini '
        printScript(msg, '', False, False, True)
        rc = modIni(constants.SETUPINI, 'setup', 'adminpw', adminpw)
        if rc == True:
            printScript(' Success!', '', True, True, False, len(msg))
        else:
            printScript(' Failed!', '', True, True, False, len(msg))
            sys.exit(1)

# write linbo auth data to rsyncd.secrets
msg = 'Creating rsync secrets file '
printScript(msg, '', False, False, True)
configfile = '/etc/rsyncd.secrets'
filedata = setupComment() + '\n' + 'linbo:' + adminpw + '\n'
try:
    with open(configfile, 'w') as outfile:
        outfile.write(filedata)
    # set permissions
    subProc('chmod 600 ' + configfile, logfile)
    # enable rsync service
    subProc('systemctl enable rsync.service', logfile)
    # restart rsync service
    subProc('service rsync stop', logfile)
    subProc('service rsync start', logfile)
    printScript(' Success!', '', True, True, False, len(msg))
except:
    printScript(' Failed!', '', True, True, False, len(msg))
    sys.exit(1)
Exemple #3
0
        if (f in do_not_overwrite and os.path.isfile(target)):
            printScript(' Success!', '', True, True, False, len(msg))
            continue
        for value in defaults.options('setup'):
            placeholder = '@@' + value + '@@'
            if placeholder in filedata:
                filedata = filedata.replace(placeholder,
                                            setup.get('setup', value))
        # set LINBODIR
        if '@@linbodir@@' in filedata:
            filedata = filedata.replace('@@linbodir@@', constants.LINBODIR)
        # backup file
        if f not in do_not_backup:
            backupCfg(target)
        with open(target, 'w') as outfile:
            outfile.write(setupComment())
            outfile.write(filedata)
        printScript(' Success!', '', True, True, False, len(msg))
    except:
        printScript(' Failed!', '', True, True, False, len(msg))
        sys.exit(1)

# restart network interface
msg = 'Restarting network '
printScript(msg, '', False, False, True)
try:
    subProc('service networking restart', logfile)
    printScript(' Success!', '', True, True, False, len(msg))
except:
    printScript(' Failed!', '', True, True, False, len(msg))
    sys.exit(1)
Exemple #4
0
    sys.exit(1)

# modify config data
msg = 'Modifying dhcp configuration '
printScript(msg, '', False, False, True)
try:
    # replace old setup comment
    filedata = re.sub(r'# modified by linuxmuster-setup.*\n', '', filedata)
    # add newline at the end
    if not filedata[-1] == '\n':
        filedata = filedata + '\n'
    # set INTERFACES to value from inifile
    filedata = re.sub(r'\nINTERFACES=.*\n', '\nINTERFACES="' + iface + '"\n',
                      filedata)
    # set comment
    filedata = setupComment() + filedata
    # backup original configfile
    backupCfg(configfile)
    printScript(' Success!', '', True, True, False, len(msg))
except:
    printScript(' Failed!', '', True, True, False, len(msg))
    sys.exit(1)

# write changes
msg = 'Writing back dhcp configuration '
printScript(msg, '', False, False, True)
try:
    with open(configfile, 'w') as outfile:
        outfile.write(filedata)
    printScript(' Success!', '', True, True, False, len(msg))
except: