[generate-self-extracting-archive] Cleanup and improve error handling

Increase the max extract offset and add some input sanity checks
Make the output file executable

Test: Ran manually with various license inputs
Bug: 125451157
Change-Id: Id76d55479366f1d9b8906e6d04c1a6db8d4d8285
diff --git a/tools/generate-self-extracting-archive.py b/tools/generate-self-extracting-archive.py
index f0b7568..5a193ab 100755
--- a/tools/generate-self-extracting-archive.py
+++ b/tools/generate-self-extracting-archive.py
@@ -91,7 +91,7 @@
       break
     dst.write(b)
 
-_MAX_OFFSET_WIDTH = 8
+_MAX_OFFSET_WIDTH = 20
 def _generate_extract_command(start, end, extract_name):
   """Generate the extract command.
 
@@ -119,6 +119,10 @@
 
 
 def main(argv):
+  if len(argv) != 5:
+    print 'generate-self-extracting-archive.py expects exactly 4 arguments'
+    sys.exit(1)
+
   output_filename = argv[1]
   input_archive_filename = argv[2]
   comment = argv[3]
@@ -129,6 +133,14 @@
   with open(license_filename, 'r') as license_file:
     license = license_file.read()
 
+  if not license:
+    print 'License file was empty'
+    sys.exit(1)
+
+  if 'SOFTWARE LICENSE AGREEMENT' not in license:
+    print 'License does not look like a license'
+    sys.exit(1)
+
   comment_line = '# %s\n' % comment
   extract_name = os.path.basename(input_archive_filename)
 
@@ -161,5 +173,9 @@
       trailing_zip.seek(0)
       _pipe_bytes(trailing_zip, output)
 
+  umask = os.umask(0)
+  os.umask(umask)
+  os.chmod(output_filename, 0o777 & ~umask)
+
 if __name__ == "__main__":
   main(sys.argv)