@Zer0Cool said in Script/Program to Batch Copy ISO Contents for PXE Boot?:
From my perspective, the tricky part in a bash script would be how to identify each iso and properly “categorize” it to create the desired dir/subdirs.
That is exactly the most difficult part. Let’s use the Debian DVD ISOs as an example, and let’s use Python instead of bash.
Here’s the debian DVD download page, it’s just basic HTML. This won’t be the same for other sites. You’ll need to code your own parsing for each site. You can see the ISO links at the bottom. https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/
Scripting to find the links in here is somewhat challenging because it’s html instead of something designed to be programmatically read like JSON.
But anyway, install python2 and pip on your fog server. Then use pip to install requests like pip install requests
Then create this file:
import requests
import os
result = requests.get('https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/')
# Get just the text from the page.
text = result.text
# Split text on new lines into a list.
lines = text.splitlines()
# Iterate through each line, see if it has .iso in it or not. If so, add it to the ISOs list.
isos = []
for line in lines:
if '.iso' in line:
isos.append(line)
# Done with the lines list, delete it.
del lines
# Further splitting. Cut off first unneeded text from the link.
trimmedIsoText = []
for iso in isos:
iso = iso.split('<a href="')[1]
# Cut off the last unnecessary part of the line.
iso = iso.split('">')[0]
trimmedIsoText.append(iso)
# Done with the isos list, delete it.
del isos
# Define a downloads directory.
downloadDir = "/root"
# Create a list called isos.
isos = []
# Going to put objects into the list.
for iso in trimmedIsoText:
# Create a full link
link = 'https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/' + iso
# Add the link to the list, along with it's filename.
downloadPath = os.path.join(downloadDir,iso)
isos.append({"link":link,"filename":downloadPath})
# Done with the trimmed isos text, delete it.
del trimmedIsoText
for iso in isos:
# Download the link to the filesystem.
response = requests.get(iso["link"], stream=True)
total_size = int(response.headers.get('content-length', 0))
print "Downloading '" + str(total_size) + "' bytes from " + iso["link"]
with open(iso["filename"], 'wb') as writer:
for chunk in response.iter_content(chunk_size=128):
writer.write(chunk)
Run that file with python, and it should start downloading to root’s home directory. The way you’d run it with python would be python <file>
Of course, there is more logic needed to determine if you already have a particular ISO or not, putting it into the right spot, mounting the ISO (use python’s subprocess.popen() for that), and adding it to FOG’s boot menu maybe. All that other stuff, I leave up to you. Go learn some python and enjoy the fruits it’ll bring you.