How to create Windows compatible rar sfx archive on Linux - linux

I want to create a rar SFX archive that can be executed on Windows, using Linux. Suppose I want to put in the archive the file myprog.exe and automatically execute the file when the archive is extracted.
I've created a init script (myinit.txt)
;The comment below contains SFX script commands
Path=%TEMP%
Setup=tftpd32.exe
TempMode
Silent=1
Overwrite=1
Then I created the archive with the following commands:
rar a -sfx archive.exe myprog.exe
rar c archive.exe < myinit.txt
Now if I open archive.exe with Winrar I can see my file and all the Option I set correctly. The problem is that if I try to execute the file (with double click) I get an error:
program too bit to fit in memory
I suppose the problem is that the file doesn't have the layout of a Windows executable.
Searching around I found that zip has an option -A that can be used to fix this problem. Is there a way to to that with rar?

Found the solution! The problem was clearly the sfx module. I searched in WinRAR program files in my Windows machine and found the Windows Default.SFX. I copied that file on my linux machine in the same directory in which I was creating the archive, renaming it to windows.sfx. At this point I run:
> rar a -sfxwindows.sfx archive.exe myprog.exe
> rar c archive.exe < myinit.txt
and it worked!
Just another tip: the file myinit.txt must be written using the Windows newline convention.
Only one thing is still missing: the possibility to set an icon for the archive. Windows documentation show a -iicon option that is missing in the linux doc.

That should work:
rar a -sfxdefault.sfx myexeforwindows.exe myprog.exe

Related

NodeJS archive manager

I need to get the content of archives and then I want to uncompress the selected one - but I dont want to uncompress the archives to know what's in it. I'd like to list and uncompress at least zip and rar, but (if that's possible) I don't want to be limited to only these two.
Can you advise good npm modules or other projects to achieve this?
Here's what I came up with:
zip
I found node-zip can only unzip files, but not list archive content.
rar
The best solution seems node-rar, but I can't install it on Windows.
node-uncompress This does what it says: It's an "Command-line wrapper for uncompressing various file types." So there is again no possibility to list archive content.
Currently I try to get node-uncompress to list files and hopefully it must never run cross-platform.
Solution:
I am now using 7zip with the node module node-7z instead of trying to get every archive working on its own. The corresponding site is: https://www.npmjs.com/package/node-7z
This library uses the OS independent archive manager 7zip. On Windows 7za is used. "7za.exe (a = alone) is a standalone version of 7-Zip". I've tested it on Windows and Ubuntu and it works great.
Update:
At Windows: Somehow I just got it working by adding 7za to the Path variables - not by adding 7za.exe to the "the same directory of your package.json file." like the description says.
Update 2:
On Windows 7za, that's referred in the node-7z post, cannot handle .rar-archives. So I'm using the "casual" 7-zip instead of 7za.exe. I just renamed the commanline 7z.exe to 7za.exe and added the 7-zip folder to the Path Variables.

Open a text file with a dot in the file path

Is this even possible? I am trying to script this install of IBM Clearcase and the path to it is like:
../disk1/InstallerImage_linux_gtk.x86/install.xml
The script barfs at the .x86 and it says "No such file or directory."
So I tried to just do vim ../disk1/InstallerImage_linux_gtk.x86/install.xml in a terminal and it opens the .x86 like a folder and allows you to select a file to edit instead of opening it directly.
Is there a way around this? Would the only way be to rename the folder before, do the sed voodoo and then move it back with the . in the name?
I guess I missed the obvious. I guess I could cd to the directory first and then do sed -i '' install.xml.
More info:
RHEL 6.5
Bash Script
You need to script a silent ClearCase installation, using one of the sample response files for Rational ClearCase.
That would avoid the need to open any file in vim.
See "Installing silently", which involves the following steps:
Run a silent install of Installation Manager using the Installation Manager installer.
Obtain a copy of the product response file and update it for your environment. If you want to record a response file using Installation Manager, see the Installation Manager information center for instructions.
Run a silent install of the Rational product using the Installation Manager.
I think you have created a file with a seriously strange file name. Do this:
$ cd /path/to/where/you/run/the/script/from
$ file ..
$ file ../disk1
$ file ../disk1/InstallerImage_linux_gtk.x86
$ file ../disk1/InstallerImage_linux_gtk.x86/install.xml
Every component of the relative path (beginning with "..") must be a directory. Only the final line should claim to be an ordinary file.

Zip files corrupt over 4 gigabytes - No warnings or errors - Did I lose my data?

I created a bunch of zip files on my computer (Mac OS X) using a command like this:
zip -r bigdirectory.zip bigdirectory
Then, I saved these zip files somewhere and deleted the original directories.
Now, when I try to extract the zip files, I get this kind of error:
$ unzip -l bigdirectory.zip
Archive: bigdirectory.zip
warning [bigdirectory.zip]: 5162376229 extra bytes at beginning or within zipfile
(attempting to process anyway)
error [bigdirectory.zip]: start of central directory not found;
zipfile corrupt.
(please check that you have transferred or created the zipfile in the
appropriate BINARY mode and that you have compiled UnZip properly)
I have since discovered that this could be because zip can't handle files over a certain size, maybe 4 gigs. At least I read that somewhere.
But why would the zip command let me create these files? The zip file in question is 9457464293 bytes and it let me make many more like this with absolutely no errors.
So clearly it can create these files.
I really hope my files aren't lost. I've learned my lesson and in the future I will check my archives before deleting the original files, and I'll probably also use another file format like tar/gzip.
For now though, what can I do? I really need my files.
Update
Some people have suggested that my unzip tool did not support big enough files (which is weird, because I used the builtin OS X zip and unzip). At any rate, I installed a new unzip from homebrew, and lo and behold, I do get a different error now:
$ unzip -t bigdirectory.zip
testing: bigdirectory/1.JPG OK
testing: bigdirectory/2.JPG OK
testing: bigdiretoryy/3.JPG OK
testing: bigdirectory/4.JPG OK
:
:
file #289: bad zipfile offset (local header sig): 4294967295
(attempting to re-compensate)
file #289: bad zipfile offset (local header sig): 4294967295
file #290: bad zipfile offset (local header sig): 9457343448
file #291: bad zipfile offset (local header sig): 9457343448
file #292: bad zipfile offset (local header sig): 9457343448
file #293: bad zipfile offset (local header sig): 9457343448
:
:
This is really worrisome because I need these files back. And there were definitely no errors upon creation of this zip file using the system zip tool. In fact, I made several of these at the same time and now they are all exhibiting the same problem.
If the file really is corrupt, how do I fix it?
Or, if it is not corrupt, how do I extract it?
Unzip below 6 seemingly fails, use
jar -xf <zipfile>
if you have java installed, or yet another unzip before you write the file off.
See: https://serverfault.com/questions/235139/how-to-unzip-files-bigger-than-4gb
Try 7z x
I had the same issue with unzip %x on Linux for a .zip file larger than 4GB, compounded with a only DEFLATED entries can have EXT descriptor error.
The command 7z x resolved all my issues though.
Be careful though, the command 7z x will extract all files with a path rooted in the current directory. The option -o allows to specify an output directory.
I had a similar problem backing up a 12GB directory before performing a hard disk format. Funnily enough I used the same command as you.
I read around and found suggestions to run:
zip -F
and
zip -FF
to try to fix the file.
Unfortunately these did not work and I still received errors.
After looking around some more, I found the ditto command and it worked perfectly against my original (untouched) zip file:
ditto -x -k original-file.zip dst-directory
-x to extract an archive
-k Specifies it to be a PKZip archive instead of the default CPIO
After using this command, I successfully extracted all of the files.
The built-in macOS Archive Utility (which is the default used when you select something in Finder and go to File -> Compress "<item>") also creates "corrupt" archives when a file in the archive is over 4 gigabytes in size, the size of the archive itself is over 4 gigabytes or you are trying to compress more than 65536 files into a single zip. This happens because it doesn't use the Zip64 extension format.
This is mentioned on https://apple.stackexchange.com/questions/221020/large-zip-files-created-in-os-x-cannot-be-opened-in-windows and is well covered in the "Apple Archive Utility (and ditto) and very large ZIP archives" 2009 blog post for the now defunct Springy utility. You can also see the 7-Zip folks are aware of the Apple tools creating corrupt zips issue too.
But why would the zip command let me create these files?
Strictly speaking, the original zip format only supports archives up to 2^32 bytes (4GiB) and which do not contain files that were originally larger than 4GiB and you there must be less than 65535 files. Because the command line version of the Infozip command tools shipped with OSX up to version OSX 10.11 (El Capitan) was no newer than 5.52, it could only produce non-conformant archives if you forced it to exceed the original zip format limits. Infozip 6.0 and above know how to make Zip64 archives and that standard has much higher limits. The Infozip 6.0 command line tools started shipping with macOS 10.12 (Sierra). In 2014 when the question was originally asked the newest OSX was 10.10 (Yosemite).
As stated above, even in macOS 10.15 (Catalina) the GUI Archive Utility still creates such "corrupt" zips.
If the file really is corrupt, how do I fix it?
It's corrupt in the sense that its non-conformant and will cause a lot of conformant tools to choke. You could extract (it see below) and then compress again with a tool that knows how to make Zip64 files...
Or, if it is not corrupt, how do I extract it?
Technically, all of the data from the files that have been compressed is still in the archive but the headers that allow fast listing of the zip's content are broken. Such zips can be a struggle to work with when using other tools (even testing such a zip with the command line unzip tool on the same version of macOS can indicate issues like invalid compressed data to inflate / bad zipfile offset (local header sig)).
To get at the files of such zips you need to use a program that will quietly just extract whatever was compressed without checking for conformance or trying to check/list the files. Examples of tools that can do this are:
macOS Archive Utility GUI tool
macOS command line tool ditto
7-zip
Java's jar tool
Infozip based tools won't be able to work with or repair such zip files once you've made such a problem zip file.
you can use
zip -FF corrupted.zip --out fixed.zip
replace corrupted.zip by your zip with issues
replace fixed.zip by the name of new .zip file fixed
I have faced exactly the same issue when I tried to unzip zip files of huge sizes (~7GB). I was damn sure that there was no error while copying the zip files to the server. (I double-checked it with rsync).
Depending on your situation, the solution is:
1) If you're doing this in a local machine, right click on the zip file and give Extract Here, this will work for (.zip) files of any size.
2) If your zip files are in a remote server, first load the server filesystem locally using sftp (sftp://username#server.url.address.com). After that just navigate to the directory and again do the same thing as you did in (1). i.e. right click on the zip file and extract it.
Might not be the best solution but that's one way of doing it.

Self Installing Zip Archives ( run app after extracting )

I'm creating an self extracting archive using unzipsfx.exe and with command:
cat unzipsfx.exe archive.zip > Installer.exe
I need to execute an exe from archive.zip after Installer.exe extracts content.
Need to do that from PHP installed on Linux.
I can use exec function from PHP but need to know what to execute.
Self-extracting archives are proper executable files, and if you're creating an .exe file, it's a Windows executable, and you can't execute it under Linux.
(If there is a way to execute it anyway [virtualization, Wine, etc.] then you need to execute the executable file itself.)

How can a zip-file via NSIS be unzipped and the NSIS-scriptfile into folder be executed automatically?

I am writting a NSIS-script for installs of the programs and put into folder. The folder is zipped via NSIS. I want, that someone clicks once the zip-file and it will be unzipped and executed the NSIS-script into folder. But how?
Update: I explain again. NSIS has the compiler for NSIS script and Installer based on ZIP! Firstly, I write a NSIS script to install some programs in a folder. Executing the NSIS script is working! I dont want to send the folder, but I want to send only one file. So I am using the Installer based on ZIP to zip the folder. But if I click the zipped file, it will be unzipped on desktop without executing the NSIS script into folder. So I have to click the NSIS script into folder. That I dont want! I want to click only on zipped file and it will be unzipped and executed automatically the NSIS script. Clearly?
.zip files cannot execute code.
NOTE: The ZIP2EXE NSIS tool uses makensis internally, it is just a helper application that creates simple installers.
Your question is confusing, but I believe that what you want to do is create a self extracting archive that contains multiple files and run and NSIS installer contained in that archive it is unpacked.
You can do this with 7zip.
It's easiest to do this with a dos batch file. Open notepad and create "selfinstall.bat"
Add the following;
(
ECHO ;!#Install#!UTF-8!
ECHO Title="My Installer"
ECHO BeginPrompt="Do you want to run the installer?"
ECHO ExecuteFile="Setup.exe"
ECHO ;!#InstallEnd#!
) > temp.$$$
This sets up the information that the self extracter needs such as it's title (My Installer) and the name of the executable to run (Setup.exe)
Then, add the lines to create your zip file
7z a -r files.7z myfolder
where myfolder is the name of the folder that has all the files.
Now, add the installer - Make sure that the installer (Setup.exe) is in the root of the .7z file
7z a files.7z Setup.exe
Then, copy the self extracter and the 7z to a single executable file
copy /b 7z.sfx + temp.$$$ + files.7z "Install.exe"
Then delete your temp files
del files.7z
del temp.$$$
I adapted this from a script I saw here; http://www.911cd.net/forums//index.php?showtopic=18845
For more information on the .SFX modules see here; http://7zsfx.info/en/
There's also a sourceforge project for a GUI to accomplish this; http://sourceforge.net/projects/sfx-maker/

Resources