Kaydet (Commit) 0dfd266d authored tarafından Alperen Saylar's avatar Alperen Saylar

Upload New File

üst b8de6c5c
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import re
import json
import os
import sys
import socket
def dosyayaYazma(yazilacaklar):
file = open("a.cfg", "a")
file.write(yazilacaklar + "\n")
file.close()
CONFIG_ARRAY = ["d-i debian-installer/locale",
"d-i keymap select",
"d-i keyboard-configuration/xkb-keymap select",
"d-i netcfg/choose_interface select",
"d-i netcfg/hostname string",
"d-i netcfg/dhcp_timeout string",
"d-i netcfg/get_ipaddress string",
"d-i netcfg/get_netmask string",
"d-i netcfg/get_gateway string",
"d-i netcfg/get_nameservers string",
"d-i netcfg/confirm_static boolean",
"d-i mirror/protocol string",
"d-i mirror/country string",
"d-i mirror/http/hostname string",
"d-i mirror/http/directory string",
"d-i mirror/http/proxy string",
"d-i passwd/root-login",
"d-i passwd/root-password password",
"d-i passwd/root-password-again password",
"d-i passwd/user-fullname string",
"d-i passwd/username string",
"d-i passwd/user-password string",
"d-i passwd/user-password-again string",
"d-i passwd/user-default-groups string",
"d-i clock-setup/utc boolean",
"d-i time/zone string",
"d-i clock-setup/ntp boolean",
"d-i clock-setup/ntp-server",
"d-i partman-auto/method string",
"d-i partman-lvm/device_remove_lvm boolean",
"d-i partman-md/device_remove_md boolean",
"d-i partman-lvm/confirm boolean",
"d-i partman-lvm/confirm_nooverwrite boolean",
"d-i partman-md/confirm boolean",
"d-i partman-partitioning/confirm_write_new_label boolean",
"d-i partman/choose_partition select",
"d-i partman/confirm boolean",
"d-i partman/confirm_nooverwrite boolean",
"d-i apt-setup/non-free boolean",
"d-i apt-setup/contrib boolean",
"d-i apt-setup/services-select multiselect",
"d-i apt-setup/security_host string",
"d-i apt-setup/volatile_host string",
"tasksel tasksel/first multiselect",
"d-i pkgsel/include string",
"d-i grub-installer/only_debian boolean",
"d-i grub-installer/bootdev string",
"d-i finish-install/reboot_in_progress note",
"d-i finish-install/keep-consoles boolean true",
]
bash_command = "cat /home/test/pardus_preseed.cfg"
output = subprocess.run(bash_command, shell=True, stdout=subprocess.PIPE).stdout
config_string = output.decode('utf-8-sig')
config_dict = {}
#print(config_string)
for config in CONFIG_ARRAY:
config_dict[config] = re.findall(config + " .* (.*)", config_string)
#print(json.dumps(config_dict))
def ipvalid(ip):
# Spliting by "."
ip = ip.split(".")
ip = list(filter(None, ip))
# Checking for the corner cases
for i in ip:
if len(i) > 3 or int(i) < 0 or int(i) > 255:
return False
elif len(i) > 1 and int(i) == 0:
return False
elif len(i) > 1 and int(i) != 0 and i[0] == '0':
return False
return True
########
yazi1 = "d-i debian-installer/locale string tr_TR.UTF-8"
dosyayaYazma(yazi1)
##Keymap
while True:
keymap = input("Keymap select [Y/N]: ")
if (keymap == "Y"):
key=str(input("Keymap [tr,us]: "))
key.lower()
for i in CONFIG_ARRAY:
if (i == "d-i keymap select"):
yazilacak = i + " " + key.lower()
dosyayaYazma(yazilacak)
break
elif(keymap == "N"):
yazi2 = "d-i keymap select tr"
dosyayaYazma(yazi2)
break
else:
print("Please enter the letter Y or N")
pass
##Keyboard
while True:
keyboard = input("Keyboard select [Y/N]: ")
if (keyboard == "Y"):
key2=str(input("Keyboard [tr,us]: "))
key2.lower()
for i in CONFIG_ARRAY:
if (i == "d-i keyboard-configuration/xkb-keymap select"):
yazilacak = i + " " + key2.lower()
dosyayaYazma(yazilacak)
break
elif(keyboard == "N"):
yazi3 = "d-i keyboard-configuration/xkb-keymap select tr"
dosyayaYazma(yazi3)
break
else:
print("Please enter the letter Y or N")
pass
##Netcfg
yazi4="""d-i netcfg/choose_interface select auto
d-i netcfg/choose_interface select enp0s3
d-i netcfg/hostname string testhostname
d-i netcfg/dhcp_timeout string 120"""
dosyayaYazma(yazi4)
#bash_command1 = r"sed -ri 's/(d-i netcfg\/get_ipaddress string).*/\1 {:s}/g' /home/test/pardus_preseed.cfg".format(ipaddress)
#subprocess.run(bash_command1, shell=True, executable="/bin/bash")
#bash_command2 = r"sed -ri 's/(d-i netcfg\/get_netmask string).*/\1 {:s}/g' /home/test/pardus_preseed.cfg".format(netmask)
#subprocess.run(bash_command2, shell=True, executable="/bin/bash")
#bash_command3 = r"sed -ri 's/(d-i netcfg\/get_gateway string).*/\1 {:s}/g' /home/test/pardus_preseed.cfg".format(gateway)
#subprocess.run(bash_command3, shell=True, executable="/bin/bash")
#bash_command4 = r"sed -ri 's/(d-i netcfg\/get_nameservers string).*/\1 {:s}/g' /home/test/pardus_preseed.cfg".format(nameserver)
#subprocess.run(bash_command4, shell=True, executable="/bin/bash")
#IPv4 example
while True:
torf = input("Set IP to Static? [Y/N]: ")
if (torf == "Y"):
while True:
print("Please only enter numbers(Exp:123.123.123.123)")
ipaddress=input("IP Address: ")
if(ipvalid(ipaddress)==True):
print(ipvalid(ipaddress))
break
elif(ipvalid(ipaddress)==False):
print("Last chance please enter data as in the example")
ipaddress=input("IP Address: ")
print(ipvalid(ipaddress))
break
while True:
print("Please only enter numbers(Exp:123.123.123.123)")
netmask =input("Netmask: ")
if(ipvalid(netmask)==True):
print(ipvalid(netmask))
break
elif(ipvalid(netmask)==False):
print("Last chance please enter data as in the example")
netmask=input("Netmask: ")
print(ipvalid(netmask))
break
while True:
print("Please only enter numbers(Exp:123.123.123.123)")
gateway =input("Gateway: ")
if(ipvalid(gateway)==True):
print(ipvalid(gateway))
break
elif(ipvalid(gateway)==False):
print("Last chance please enter data as in the example")
gateway=input("Gateway: ")
print(ipvalid(gateway))
break
while True:
print("Please only enter numbers(Exp:123.123.123.123)")
nameserver =input("Nameserver: ")
if(ipvalid(nameserver)==True):
print(ipvalid(nameserver))
break
elif(ipvalid(nameserver)==False):
print("Last chance please enter data as in the example")
nameserver=input("Nameserver: ")
print(ipvalid(nameserver))
break
for i in CONFIG_ARRAY:
if(i == "d-i netcfg/get_ipaddress string"):
yazilacak = i + " " + str(ipaddress)
dosyayaYazma(yazilacak)
elif(i == "d-i netcfg/get_netmask string"):
yazilacak = i + " " + str(netmask)
dosyayaYazma(yazilacak)
elif(i == "d-i netcfg/get_gateway string"):
yazilacak = i + " " + str(gateway)
dosyayaYazma(yazilacak)
elif(i == "d-i netcfg/get_nameservers string"):
yazilacak = i + " " + str(nameserver)
dosyayaYazma(yazilacak)
yazi = "d-i netcfg/confirm_static boolean true"
dosyayaYazma(yazi)
break
elif(torf == "N"):
config_dict["d-i netcfg/confirm_static boolean"] = ['false']
yazi = "d-i netcfg/confirm_static boolean false"
dosyayaYazma(yazi)
break
else:
print("Please enter the letter Y or N")
pass
### Mirror settings
yazi5="""d-i mirror/protocol string http
d-i mirror/country string manual
d-i mirror/http/hostname string http.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string """
dosyayaYazma(yazi5)
##Account setup
while True:
root = input("Skip creation of a root account Y/N:")
if (root == "Y"):
yazi7 = "d-i passwd/root-login boolean true"
dosyayaYazma(yazi7)
rp = input("root-password: ")
rpa = input("root-password-again: ")
for i in CONFIG_ARRAY:
if(i == "d-i passwd/root-password password"):
yazilacak = i + " " + rp
dosyayaYazma(yazilacak)
elif (i == "d-i passwd/root-password-again password"):
yazilacak = i + " " + rpa
dosyayaYazma(yazilacak)
break
elif (root == "N"):
yazi6 = "d-i passwd/root-login boolean false"
dosyayaYazma(yazi6)
break
print("To create a normal user account")
uf = input("user-fullname: ")
un = input("username: ")
up = input("user-password: ")
upa = input("user-password-again: ")
for i in CONFIG_ARRAY:
if (i == "d-i passwd/user-fullname string"):
yazilacak = i + " " + uf
dosyayaYazma(yazilacak)
elif (i == "d-i passwd/username string"):
yazilacak = i + " " + un
dosyayaYazma(yazilacak)
elif(i == "d-i passwd/user-password string"):
yazilacak = i + " " + up
dosyayaYazma(yazilacak)
elif(i == "d-i passwd/user-password-again string"):
yazilacak = i + " " + up
dosyayaYazma(yazilacak)
### Clock and time zone setup
yazi10 = """d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern
d-i clock-setup/ntp boolean true
"""
dosyayaYazma(yazi10)
### Partitioning
yazi11="""d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
#This makes partman automatically partition without confirmation.
d-i partman-md/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true"""
dosyayaYazma(yazi11)
### Apt setup
yazi12="""d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
d-i apt-setup/services-select multiselect security, updates
d-i apt-setup/security_host string security.debian.org
d-i apt-setup/volatile_host string volatile.debian.org"""
dosyayaYazma(yazi12)
### Package selection
yazi13="""tasksel tasksel/first multiselect standart
# Individual additional packages to install
d-i pkgsel/include string xfce4 firefox-esr
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/sda
# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note
d-i finish-install/keep-consoles boolean true"""
dosyayaYazma(yazi13)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment