I have a war file foo.war in my current working directory. I have a MANIFEST.MF file, too.
ls .
foo.war MANIFEST.MF
Within foo.war, there is a file foo/META-INF/MANIFEST.MF.
I want to replace that file inside the war with the file in my working directory.
I think zip can be used to do this, but I don't understand the zip documentation.
What would be the correct usage?
How can I verify that it was done correctly?
How would I do that with jar?
After experimenting a while I found this solution:
#! /bin/bash
set -e
apt-get install -y zip
apt-get install -y unzip
rm -f foo.war
cp foo.original.war foo.war
touch META-INF/MANIFEST.MF
zip -f foo.war META-INF/MANIFEST.MF
rm -f test
unzip -p foo.war META-INF/MANIFEST.MF >test
#Uncomment next line to test verification:
#echo "X" >>test
if diff test META-INF/MANIFEST.MF; then
echo "OK."
else
ERR=$?
echo "Failed (diff exit code $ERR)."
exit 1
fi
zip seems to replace the file only if the time stamp is new enough. What "new enough" exactly means, is still unclear to me.
I extracted the MANIFEST.MF file from zip using unzip -p foo.war META-INF/MANIFEST.MF >test
I use the exit code of diff to verify MANIFEST.MF has really been replaced.
zip spits out the warning: "zip warning: Local Entry CRC does not match CD: META-INF/MANIFEST.MF" The meaning of this warning is unclear to me.
Do I really have to put MANIFEST.MF inside the META-INF folder or is there a possibility to specify the source location of the file that should be replaced?
I don't like that "touch". Is there a way to force the replacement without fiddling with timestamps?
What about character encoding, unusual file names and line endings?
Try placing the MANIFEST.MF in a directory called foo/META-INF/
then run:
zip -f foo.war foo/META-INF/MANIFEST.MF
to verify the file run:
unzip -l foo.war
use the same for .jar files
Related
I've been trying to archive files after compilation matching the wildcard **/dist when I look into my _work folder of my GitHub action worker, I see the files and if I run the zip command from shell, it works fine, but in action, it throws an error saying it can't find any files matching
zip error: Nothing to do! (try: zip -qq -r archive.zip . -i **/dist)
Yet when I run directly in the runner ls -la **/dist I get a list of over 200 files
I was also able to reproduce the issue by adding the command inside my package.json then when I run yarn archive I get the same issue as GitHub action
"archive": "pwd && ls -la **/dist && zip -r **/dist",
Output of yarn archive
yarn run v1.22.19
$ pwd && ls -la **/dist && zip -r **/dist
/home/mathieu_auclair/actions-runner/_work/server/server
ls: cannot access '**/dist': No such file or directory
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
It is about how the shell will interpret the wildcards used.
I would try and put the set of commands ls -la **/dist && zip -r **/dist in a bash executable script starting with #!/bin/bash, and call said script instead of chaining commands with '**'.
The OP MathieuAuclair confirms in the comments:
Indeed, I was able to fix it by making the zip command specification more detailed, I guess it's compatible between both interpretations
zip -r archive.zip . --include **/dist/**
What I did were as follows step by step:
Git clone go-ethereum project to my local PC. It is located in
D:\GOPATH\src\github.com\ethereum\go-ethereum. It is the source code
of go-ethereum
Note: The OS is windows 7. Go has already been installed. And GOPATH env has already been set to "D:\GOPATH"
cd /d D:\GOPATH\src\github.com\ethereum\go-ethereum. Then execute
"go install". Some exe files were genereated under D:\GOPATH\bin
directory, and many pkg file with suffix .a were generated under
D:\GOPATH\pkg directory. Everything seems no problem.
Execute "go clean -n -r -i github.com/ethereum/go-ethereum..." to
remove all the generated exe files and .a files. But something very
interesting happened:
In the command's log, it showed that some files are deleted, but actually they are not deleted from disk.
For example, event.a exists under D:\GOPATH\pkg\windows_amd64\github.com\ethereum\go-ethereum, but the log of "git clean" shows:"rm -f D:\GOPATH\pkg\windows_amd64\github.com\ethereum\go-ethereum\event.a"
The detailed information is in the attached images.
It is very strange. The log does not match with the actual result:
A small segment of go clean command is as follows(since there are more than 1300 lines in log, I can not paste all of it):
cd D:\GOPATH\src\github.com\ethereum\go-ethereum\event
rm -f event.test event.test.exe
rm -f D:\GOPATH\pkg\windows_amd64\github.com\ethereum\go-ethereum\event.a
cd D:\GOPATH\src\github.com\ethereum\go-ethereum\common\mclock
rm -f mclock.test mclock.test.exe
rm -f D:\GOPATH\pkg\windows_amd64\github.com\ethereum\go-ethereum\common\mclock.a
cd D:\GOPATH\src\github.com\ethereum\go-ethereum\vendor\github.com\aristanetworks\goarista\monotime
rm -f monotime.test monotime.test.exe
rm -f D:\GOPATH\pkg\windows_amd64\github.com\ethereum\go-ethereum\vendor\github.com\aristanetworks\goarista\monotime.a
cd D:\GOPATH\src\github.com\ethereum\go-ethereum\accounts\abi
rm -f abi.test abi.test.exe
rm -f D:\GOPATH\pkg\windows_amd64\github.com\ethereum\go-ethereum\accounts\abi.a
cd D:\GOPATH\src\github.com\ethereum\go-ethereum\accounts\abi\bind
rm -f bind.test bind.test.exe
rm -f D:\GOPATH\pkg\windows_amd64\github.com\ethereum\go-ethereum\accounts\abi\bind.a
But some of the files remain:
The correct answer is actually provided by #Peter in comment. As Peter said "The -n flag causes clean to print the remove commands it would execute, but not run them."
I tried "-x" instead of "-n", and it works well. Thanks Peter. But you posted your answer in comment section, so I have to post your answer here and close this question.
I am using chef to write a recipe that installs mysql connector, extracts it and moves the .jar to the /lib folder.
bash "install_mysql-connector" do
user "root"
cwd "/opt/tomcat/lib/"
code <<-EOH
wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.29.tar.gz
tar -zxvf mysql-connector-java-5.1.29.tar.gz
EOH
end
bash "setting_mysql-connector" do
user "root"
cwd "/opt/tomcat/lib/mysql-connector-java-5.1.29"
code <<-EOH
mv mysql-connector-java-5.1.29-bin.jar /opt/tomcat/lib/
rm -rf mysql-connector-java-5.1.29.tar.gz
EOH
end
Is there a way of combining these two so they run under the same bash?
I also tried extracting JUST the mysql-connector-java-5.1.29-bin.jar from the tar.gz file using
tar -zxvf mysql-connector-java-5.1.29.tar.gz -C /opt/tomcat/lib mysql-connector-java-5.1.29-bin.jar
Is something missing from this?
How about this? Extract the jar file out of .tar.gz and save under /opt/tomcat/lib directly?
tar -zxvf mysql-connector-java-5.1.29.tar.gz mysql-connector-java-5.1.29-bin.jar -O > /opt/tomcat/lib/mysql-connector-java-5.1.29-bin.jar
There is something which I am missing or might be the whole case. So I am trying to download NCDC data from NCDC Datasets and unable to do it the unix box.
The command which I have used this far are
wget ftp://ftp.ncdc.noaa.gov:21/pub/data/noaa/1901/029070-99999-1901.gz">029070-99999-1901.gz
This is for one file, but will be very happy if I can downlaod the entire parent directory.
You seem to have a lonely " just before the >
to download everything you can try this command to get the whole directory content
wget -r ftp://ftp.ncdc.noaa.gov:21/pub/data/noaa/1901/*
for i in {1990..1993}
do
echo "$i"
cd /home/chile/data
# -nH Disable generation of host-prefixed directories
# -nd all files will get saved to the current directory
# -np Do not ever ascend to the parent directory when retrieving recursively.
# -R index.html*,227070*.gz* don't download files with this regex
wget -r -nH -nd -np -R *.html,999999-99999-$i.gz* http://www1.ncdc.noaa.gov/pub/data/noaa/$i/
/data/noaa/$i/
done
I have a pkg file created by Install Maker for Mac.
I want to replace one file in pkg. But I must do this under Linux system, because this is a part of download process. When user starts to download file server must replace one file in pkg.
I have a solution how unpack pkg and replace a file but I dont know how pack again to pkg.
http://emresaglam.com/blog/1035
http://ilostmynotes.blogspot.com/2012/06/mac-os-x-pkg-bom-files-package.html
Packages are just .xar archives with a different extension and a specified file hierarchy. Unfortunately, part of that file hierarchy is a cpio.gz archive of the actual installables, and usually that's what you want to edit. And there's also a Bom file that includes information on the files inside that cpio archive, and a PackageInfo file that includes summary information.
If you really do just need to edit one of the info files, that's simple:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
# edit stuff
xar -cf ../Foo-new.pkg *
But if you need to edit the installable files:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc |cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o | gzip -c > Payload
mkbom Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar -cf ../Foo-new.pkg
I believe you can get mkbom (and lsbom) for most linux distros. (If you can get ditto, that makes things even easier, but I'm not sure if that's nearly as ubiquitously available.)
Here is a bash script inspired by abarnert's answer which will unpack a package named MyPackage.pkg into a subfolder named MyPackage_pkg and then open the folder in Finder.
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
pkgutil --expand "$filename" "$dirname"
cd "$dirname"
tar xvf Payload
open .
Usage:
pkg-upack.sh MyPackage.pkg
Warning: This will not work in all cases, and will fail with certain files, e.g. the PKGs inside the OSX system installer. If you want to peek inside the pkg file and see what's inside, you can try SuspiciousPackage (free app), and if you need more options such as selectively unpacking specific files, then have a look at Pacifist (nagware).
You might want to look into my fork of pbzx here: https://github.com/NiklasRosenstein/pbzx
It allows you to stream pbzx files that are not wrapped in a XAR archive. I've experienced this with recent XCode Command-Line Tools Disk Images (eg. 10.12 XCode 8).
pbzx -n Payload | cpio -i
In addition to what #abarnert said, I today had to find out that the default cpio utility on Mountain Lion uses a different archive format per default (not sure which), even with the man page stating it would use the old cpio/odc format. So, if anyone stumbles upon the cpio read error: bad file format message while trying to install his/her manipulated packages, be sure to include the format in the re-pack step:
find ./Foo.app | cpio -o --format odc | gzip -c > Payload
#shrx I've succeeded to unpack the BSD.pkg (part of the Yosemite installer) by using "pbzx" command.
pbzx <pkg> | cpio -idmu
The "pbzx" command can be downloaded from the following link:
pbzx Stream Parser
If you are experiencing errors during PKG installation following the accepted answer, I will give you another procedure that worked for me (please note the little changes to xar, cpio and mkbom commands):
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc | cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o --format odc --owner 0:80 | gzip -c > Payload
mkbom -u 0 -g 80 Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar --compression none -cf ../Foo-new.pkg
The resulted PKG will have no compression, cpio now uses odc format and specify the owner of the file as well as mkbom.
Bash script to extract pkg: (Inspired by this answer:https://stackoverflow.com/a/23950738/16923394)
Save the following code to a file named pkg-upack.sh on the $HOME/Downloads folder
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
mkdir "$dirname"
# pkgutil --expand "$filename" "$dirname"
xar -xf "$filename" -C "$dirname"
cd "$dirname"/*.pkg
pwd
# tar xvf Payload
cat Payload | gunzip -dc |cpio -i
# cd usr/local/bin
# pwd
# ls -lt
# cp -i * $HOME/Downloads/
Uncomment the last four lines, if you are using a rudix package.
Usage:
cd $HOME/Downloads
chmod +x ./pkg-upack.sh
./pkg-upack.sh MyPackage.pkg
This was tested with the ffmpeg and mawk package from rudix.org (https://rudix.org) search for ffmpeg and mawk packages on this site.
Source : My open source projects : https://sourceforge.net/u/nathan-sr/profile/