@@ -16,20 +16,71 @@ mkdir -p "$out"/bin
16
16
cp $runtimeScript " $out " /bin/nix-portable.zip
17
17
chmod +w " $out " /bin/nix-portable.zip
18
18
19
+ file_name=runtimeScript.sh
20
+ file_name_size_hex=$( printf " %04x" ${# file_name} | tac -rs ..)
21
+ file_name_hex=$( echo -n " $file_name " | xxd -p)
22
+
23
+ # note: zip fails to extract the file because the local file header comes after the file contents
24
+
19
25
# Local file header
20
- sizeA=$( printf " %08x" $( stat -c " %s" " $out " /bin/nix-portable.zip) | tac -rs ..)
21
- echo 504b 0304 0000 0000 0000 0000 0000 0000 | xxd -r -p >> " $out " /bin/nix-portable.zip
22
- echo 0000 0000 0000 0000 0000 0200 0000 4242 | xxd -r -p >> " $out " /bin/nix-portable.zip
26
+ local_file_header_offset_hex=$( printf " %08x" $( stat -c " %s" " $out " /bin/nix-portable.zip) | tac -rs ..)
27
+ {
28
+ echo 50 4b 03 04 # Local file header signature
29
+ echo 00 00 # Version needed to extract (minimum)
30
+ echo 00 00 # General purpose bit flag
31
+ echo 00 00 # Compression method
32
+ echo 00 00 # File last modification time
33
+ echo 00 00 # File last modification date
34
+ echo 00 00 00 00 # CRC-32 of uncompressed data
35
+ echo 00 00 00 00 # Compressed size
36
+ echo 00 00 00 00 # Uncompressed size
37
+ echo $file_name_size_hex # File name length (n)
38
+ echo 00 00 # Extra field length (m)
39
+ echo $file_name_hex # File name
40
+ # Extra field
41
+ } | xxd -r -p >> " $out " /bin/nix-portable.zip
23
42
24
43
# Central directory file header
25
- sizeB=$( printf " %08x" $( stat -c " %s" " $out " /bin/nix-portable.zip) | tac -rs ..)
26
- echo 504b 0102 0000 0000 0000 0000 0000 0000 | xxd -r -p >> " $out " /bin/nix-portable.zip
27
- echo 0000 0000 0000 0000 0000 0000 0200 0000 | xxd -r -p >> " $out " /bin/nix-portable.zip
28
- echo 0000 0000 0000 0000 0000 " $sizeA " 4242 | xxd -r -p >> " $out " /bin/nix-portable.zip
44
+ central_directory_file_header_offset_hex=$( printf " %08x" $( stat -c " %s" " $out " /bin/nix-portable.zip) | tac -rs ..)
45
+ {
46
+ echo 50 4b 01 02 # Central directory file header signature
47
+ echo 00 00 # Version made by
48
+ echo 00 00 # Version needed to extract (minimum)
49
+ echo 00 00 # General purpose bit flag
50
+ echo 00 00 # Compression method
51
+ echo 00 00 # File last modification time
52
+ echo 00 00 # File last modification date
53
+ echo 00 00 00 00 # CRC-32 of uncompressed data
54
+ echo 00 00 00 00 # Compressed size
55
+ echo 00 00 00 00 # Uncompressed size
56
+ echo $file_name_size_hex # File name length (n)
57
+ echo 00 00 # Extra field length (m)
58
+ echo 00 00 # File comment length (k)
59
+ echo 00 00 # Disk number where file starts (or 0xffff for ZIP64)
60
+ echo 00 00 # Internal file attributes
61
+ echo 00 00 00 00 # External file attributes
62
+ echo " $local_file_header_offset_hex " # Relative offset of local file header
63
+ echo $file_name_hex # File name
64
+ # Extra field
65
+ # File comment
66
+ } | xxd -r -p >> " $out " /bin/nix-portable.zip
67
+
68
+ # 62 -> 3e 00 00 00
69
+ central_directory_size_hex=$( printf " %08x" $(( 46 + ${# file_name} )) | tac -rs ..)
29
70
30
71
# End of central directory record
31
- echo 504b 0506 0000 0000 0000 0100 3000 0000 | xxd -r -p >> " $out " /bin/nix-portable.zip
32
- echo " $sizeB " 0000 0000 0000 0000 0000 0000 | xxd -r -p >> " $out " /bin/nix-portable.zip
72
+ {
73
+ echo 50 4b 05 06 # End of central directory signature
74
+ echo 00 00 # Number of this disk
75
+ echo 00 00 # Disk where central directory starts
76
+ echo 00 00 # Number of central directory records on this disk
77
+ echo 01 00 # Total number of central directory records
78
+ echo $central_directory_size_hex # Size of central directory (bytes)
79
+ echo " $central_directory_file_header_offset_hex " # Offset of start of central directory, relative to start of archive
80
+ echo 00 00 # Comment length
81
+ # Comment
82
+ echo 00 00 00 00 00 00 00 00 00 00 # 10 null bytes (?)
83
+ } | xxd -r -p >> " $out " /bin/nix-portable.zip
33
84
34
85
unzip -vl " $out " /bin/nix-portable.zip
35
86
0 commit comments