Skip to content

Instantly share code, notes, and snippets.

@sjenning
Created January 21, 2020 20:32
Show Gist options
  • Save sjenning/04dedeff2594c09ef1d8292e7b1eaae7 to your computer and use it in GitHub Desktop.
Save sjenning/04dedeff2594c09ef1d8292e7b1eaae7 to your computer and use it in GitHub Desktop.
Extracts a filesystem from an ignition file
#!/usr/bin/env python3
import json
import os
import sys
import base64
ign_file = open(sys.argv[1])
ign_json = json.load(ign_file)
ign_file.close()
for file in ign_json['storage']['files']:
path = file['path']
contents = file['contents']['source'].split(',')[1]
os.makedirs('ign-root' + os.path.dirname(path), exist_ok=True)
out_file = open('ign-root' + path, "wb+")
out_file.write(base64.b64decode(contents))
out_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment