Skip to content

Commit

Permalink
fingers crossed
Browse files Browse the repository at this point in the history
  • Loading branch information
Esgariot committed Jan 9, 2017
1 parent 31acb60 commit 4c6c657
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This will become a beautiful parser and generator for preseed file for debian an

2. Po pobraniu uruchomieniu kernela i załadowaniu ramdisku z serwera tftp uruchomionego przez dnsmasq system szuka drzewa katalogów związanych z dystrybucją.
Znajduje wszystko, czego potrzebuje dzięki serwerowi vsftp (z jakiegoś powodu dnsmasqowy tftp nie udostępnia plików jako "normalny" ftp, tylko dla PXE).
W korzeniu serwera ftp jest katalog ```/<distro>/<wypakowane-iso>/``` z którego pobiera pliki host na którym jest uruchomiona instalacja. Można też przeprowadzić instalację przez Internet i nie udostępniać całej dystrybucji na serwerze, ale ma to bardzo małe szanse powodzenia przez duże opóźnienie, które nie jest brane pod uwagę przez dracut
W korzeniu serwera ftp jest katalog ```/<distro>/<wypakowane-iso>``` z którego pobiera pliki host na którym jest uruchomiona instalacja. Można też przeprowadzić instalację przez Internet i nie udostępniać całej dystrybucji na serwerze, ale ma to bardzo małe szanse powodzenia przez duże opóźnienie, które nie jest brane pod uwagę przez dracut
3. Żeby to wszystko zautomatyzować do parametrów kernela RedHatowych dystrybucji dodaję ```ks= <ścieżka-do-pliku-kickstart>```
4. Wszystko powyższe można zrobić manualnie, mój skrypt pykickxe.py dąży do zautomatyzowania tego ( z różną skutecznością ). Np. wybór pliku kickstart, kernela i parametrów
kernela odbywa się na zasadzie złożenia pliku kickstart, znalezieniu znaczników do zastąpienia zaczynających się od ```$``` w ```/pxelinux.cfg/autoinstall.menu``` i skopiowania pliku kickstart do ```/util/```
Expand Down
71 changes: 32 additions & 39 deletions ks.cfg
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
#Generated by Kickstart Configurator
#platform=AMD64 or Intel EM64T
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'pl2'
# Root password
rootpw --iscrypted $1$ZIgQqPR3$OY8ivoaWxmw56pWomI9Xl/
# Use network installation
url --url="ftp://192.168.0.1/centos"
# System language
lang pl_PL
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --enforcing

#System language
lang en_US
#Language modules to install
langsupport pl_PL --default=en_US
#System keyboard
keyboard us
#System mouse
mouse
#System timezone
timezone --utc Europe/Warsaw
#Root password
rootpw --iscrypted $1$z0BY0NkL$Necy0Mqj6AYqatrm9Pi.Y.
#Initial user
user justuser --fullname "delete me later" --iscrypted --password $1$tmQA0Jxc$/QUItyxu8npyxjoKgEgBv0
#Reboot after installation
# Network information
network --bootproto=dhcp --device=enp0s3
# Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Use Web installation
url --url ftp://192.168.0.1/debian/kickstart
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
clearpart --all --initlabel
#System authorization infomation
auth --useshadow --enablemd5
#Network information
network --bootproto=dhcp --device=eth0
#Firewall configuration
firewall --disabled
#X Window System configuration information
xconfig --depth=32 --resolution=1024x768 --defaultdesktop=KDE --startxonboot
#Run the Setup Agent on first boot
firstboot --enable
# System timezone
timezone Europe/Warsaw --isUtc
# System bootloader configuration
bootloader --location=none
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
43 changes: 43 additions & 0 deletions pykickxe.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Pykickxe config file that will be parsed using python's 2.7 ConfigParser

[DEFAULT]
last_updated = 09.01.17
ftp_root = /srv/tftp/
ftp_url = ftp://192.168.0.1
default_distro = centos
default_autocfg = %(default_distro)s/ks.cfg
default_kernel = %(default_distro)s/images/vmlinuz
default_append =
pxe_cfgPath = ./pxeappend.cfg

# remember to use helpText with raw parser!
help_text = This program requires that the root from where pxe gets files has following structure: <distro>/<~copied content of iso image~> for everything, especially <distro>/images/pxeboot for kernel and ramdisk, kickstart file in <distro>/ks.cfg or passed manually, (will get copied to util/ks.cfg)


[debian]
name = Debian
dir = debian
auto_file =
auto_param = preseed\=
kernel = %(dir)s/linux
append = initrd\=%(dir)/initrd.gz
url =


[fedora]
name = Fedora
dir = fedora
auto_file = %(dir)s/ks.cfg
auto_param = ks=
kernel = %(dir)s/images/pxeboot/vmlinuz
append = initrd=%(dir)s/initrd.img inst.repo=%(ftp_url)s/%(dir)s devfs=nomount
url =

[centos]
name = CentOS
dir = centos
auto_file = %(dir)s/ks.cfg
auto_param = ks=
kernel = %(dir)s/images/pxeboot/vmlinuz
append = initrd=%(dir)s/initrd.img method=%(ftp_url)s/%(dir)s devfs=nomount ip=dhcp
url =
104 changes: 69 additions & 35 deletions pykickxe.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import argparse
import pykickxe_conf
import os
import ConfigParser


def listConfig(): # TODO: Implement listConfig #p3
return


def downloadFromURL(args): # TODO: Implement download #p1
distroURL = ''
if 'debian' == args.distro:
distroURL = pykickxe_conf.debianURL
elif 'fedora' == args.distro:
distroURL = pykickxe_conf.fedoraURL
else:
print args.distro + ' is not supported'
return
if args.verbose is True:
print 'downloading ' + args.distro + ' from ' + distroURL
def downloadFromURL(args, config): # TODO: Implement download #p1
# TODO: check if wget present #p2
distroURL = config.get(args.distro, 'url', 1)
os.system('wget ' + distroURL)
filePath = os.path.split(distroURL)
# urllib.urlretrieve(distroURL) # TODO: Decide on this or wget #p3
Expand All @@ -27,23 +18,63 @@ def downloadFromURL(args): # TODO: Implement download #p1
return filePath


def copyToTftp():
os.system('cp ./tftproot/. ' + pykickxe_conf.tftpRoot)
def copyFiles(args, config):
os.system('rsync --progress -av ./tftproot/* ' + args.tftp_root)


def writeToMenu():
menuPath = pykickxe_conf.tftpRoot + 'pxelinux.cfg/autoinstall.menu'
def replaceLine(filePath, srcText, destText):
workingFile = open(filePath, 'r+')
original = workingFile.read()
modified = original.replace(srcText, destText)
workingFile.seek(0)
workingFile.write(modified)
workingFile.close()
return


def writeToMenu(args, config):
menuPath = './tftproot/pxelinux.cfg/'
# menuFile = open(menuPath + 'autoinstall.menu.source', 'r')
# targetMenuFile = open(menuPath + 'autoinstall.menu', 'w')
autoconfig_file = config.get(args.distro, 'auto_file', 0)
if args.auto_cfg is not None:
autoconfig_file = args.auto_cfg
os.system('cp ' + autoconfig_file + ' ./tftproot/util/auto.cfg')
autoconfig_file = '/util/auto.cfg'
menuIn = menuPath + 'autoinstall.menu.source'
menuOut = menuPath + 'autoinstall.menu'
os.system('cp ' + menuIn + ' ' + menuOut)
replaceLine(
menuOut,
'$DISTRO_NAME',
config.get(args.distro, 'name', 0))
replaceLine(
menuOut,
'$KERNEL',
config.get(args.distro, 'kernel', 0))
replaceLine(
menuOut,
'$APPEND',
config.get(args.distro, 'append', 0))
replaceLine(
menuOut,
'$KS',
config.get(args.distro, 'auto_param', 0) + autoconfig_file)
return


def parseArgs():
def parseArgs(configFIle):
"""Parser for cli arguements"""
config = ConfigParser.SafeConfigParser()
config.read(configFile)
parser = argparse.ArgumentParser(
prog='Pykickxe',
description='a Python PXE and autoinstall tool')
description='a Python PXE and autoinstall tool',
epilog=config.get('DEFAULT', 'help_text', 1))
parser.add_argument(
'distro',
type=str,
choices=pykickxe_conf.distroList,
choices=config.sections(),
help='pick a linux distro to download, unpack and append '
'the PXE config to (Debian or Fedora for now)')
parser.add_argument(
Expand All @@ -58,33 +89,36 @@ def parseArgs():
action='store_true')
parser.add_argument(
'-v',
'--verbose',
'--verbose (also not really working)',
help='print some of what this is doing at any moment',
action='store_true')
parser.add_argument(
'-t',
'--tftp_root',
type=str,
default=pykickxe_conf.tftpRoot,
default=config.get('DEFAULT', 'ftp_root', 0),
help='pass an absolute path to tftp root directory')
parser.add_argument(
'--ks_cfg',
'--auto_cfg',
type=str,
default=pykickxe_conf.ks_cfgPath,
help='pass an absolute path to Kickstart file')
parser.add_argument(
'--pxe_cfg',
type=str,
default=pykickxe_conf.pxe_cfgPath,
help='pass an absolute path to pxe file with entry to append')
# parser.add_argument(
# '--pxe_cfg',
# type=str,
# default=pykickxe_conf.pxe_cfgPath,
# help='pass an absolute path to pxe file with entry to append')
args = parser.parse_args()
return args
return args, config


# pykickxe main
args = parseArgs() # TODO: Add sensible options and check exclusivity #p3
if args.list is True:
listConfig()
if args.download is True:
filePath = downloadFromURL(args)
copyToTftp()
if __name__ == "__main__":
configFile = 'pykickxe.conf'
# TODO: Add sensible options and check exclusivity #p3
args, config = parseArgs(configFile)
if args.list is True:
listConfig()
if args.download is True:
filePath = downloadFromURL(args)
writeToMenu(args, config)
copyFiles(args, config)
15 changes: 2 additions & 13 deletions pykickxe_conf.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# TODO: WRewrite #p1
lastCheckedDate = '03.01.17'
tftpRoot = '/srv/tftp/'
pxe_cfgPath = './pxeappend.cfg'
ks_cfgPath = './ks.cfg'
import ConfigParser

distroList = ['debian', 'fedora']
fedoraURL = (
"http://ftp.icm.edu.pl/pub/Linux/fedora/"
"linux/releases/25/Workstation/x86_64/os/images/pxeboot/*") # doesnt work
debianURL = (
"http://ftp.nl.debian.org/debian/dists/jessie/"
"main/installer-amd64/current/images/netboot/"
"netboot.tar.gz")
cfg = ConfigParser.SafeConfigParser()
10 changes: 0 additions & 10 deletions tftproot/pxelinux.cfg/autoinstall.menu
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
MENU TITLE Autoinstall
PATH util/
DEFAULT util/menu.c32
TIMEOUT 20
ONTIMEOUT Proceeding
ONERROR COM32 reboot.c32

LABEL Proceed
KERNEL centos/vmlinuz
APPEND initrd=centos/initrd.img method=ftp://192.168.0.1/centos/ISO devfs=nomount ip=dhcp
10 changes: 10 additions & 0 deletions tftproot/pxelinux.cfg/autoinstall.menu.source
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MENU TITLE Autoinstall
PATH util/
DEFAULT util/menu.c32
TIMEOUT 20
ONTIMEOUT Proceeding
ONERROR COM32 reboot.c32

LABEL Automatic $DISTRO_NAME Installer
KERNEL $KERNEL
APPEND $APPEND $KS
8 changes: 2 additions & 6 deletions tftproot/pxelinux.cfg/default
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ LABEL Debian

LABEL Fedora
KERNEL fedora/vmlinuz
APPEND initrd=fedora/initrd.img inst.repo=ftp://192.168.0.1/fedora/ISO devfs=nomount
APPEND initrd=fedora/initrd.img inst.repo=ftp://192.168.0.1/fedora/ devfs=nomount

LABEL CentOS
KERNEL centos/vmlinuz
APPEND initrd=centos/initrd.img method=ftp://192.168.0.1/centos/ISO devfs=nomount ip=dhcp

LABEL OpenSUSE
KERNEL opensuse/?
APPEND ?
APPEND initrd=centos/initrd.img method=ftp://192.168.0.1/centos/ devfs=nomount ip=dhcp

0 comments on commit 4c6c657

Please sign in to comment.