header.sh 713 B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. INTERPRETER_UNDER_TEST="$1"
  3. if [[ ! -x "${INTERPRETER_UNDER_TEST}" ]]; then
  4. echo "Interpreter must be the command line argument."
  5. exit 4
  6. fi
  7. EXECUTABLE="$0" exec "${INTERPRETER_UNDER_TEST}" -E - <<END_OF_PYTHON
  8. import os
  9. import zipfile
  10. namespace = {}
  11. filename = os.environ['EXECUTABLE']
  12. print(f'Opening {filename} as a zipfile.')
  13. with zipfile.ZipFile(filename, mode='r') as exe_zip:
  14. for file_info in exe_zip.infolist():
  15. data = exe_zip.read(file_info)
  16. exec(data, namespace, namespace)
  17. break # Only use the first file in the archive.
  18. print('Favorite number in executable:', namespace["FAVORITE_NUMBER"])
  19. ### Archive contents will be appended after this file. ###
  20. END_OF_PYTHON