2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 09:36:41 +00:00

Merge pull request #1694 from immarvin/onpackimg

[packimage -m -c]:  supress the verbose info of rootimg decompression; add tar "--no-recursion" option in packimage; correct the path of gnu tar to be "/bin/tar" in genimage
This commit is contained in:
Xiaopeng Wang 2016-08-15 10:51:40 +08:00 committed by GitHub
commit 538fa0349a
10 changed files with 52 additions and 28 deletions

View File

@ -23,7 +23,7 @@ SYNOPSIS
\ **packimage [-v| -**\ **-version]**\
\ **packimage**\ \ *imagename*\
\ **packimage**\ [\ **-m | -**\ **-method**\ \ *cpio|tar*\ ] [\ **-c | -**\ **-compress**\ \ *gzip|pigz|xz*\ ] \ *imagename*\
***********
@ -62,9 +62,9 @@ OPTIONS
\ **-a**\ Architecture (ppc64,x86_64,etc)
\ **-m**\ Archive Method (cpio,tar,squashfs, default is cpio)
\ **-m| -**\ **-method**\ Archive Method (cpio,tar,squashfs, default is cpio)
\ **-c**\ Compress Method (pigz,gzip,xz, default is pigz)
\ **-c| -**\ **-compress**\ Compress Method (pigz,gzip,xz, default is pigz/gzip)
************
@ -90,6 +90,14 @@ EXAMPLES
packimage rhels7.1-x86_64-netboot-compute
2. To pack the osimage rhels7.1-x86_64-netboot-compute with "tar" to archive and "pigz" to compress:
.. code-block:: perl
packimage -m tar -c pigz rhels7.1-x86_64-netboot-compute
*****
FILES

View File

@ -8,7 +8,7 @@ B<packimage [-h| --help]>
B<packimage [-v| --version]>
B<packimage> I<imagename>
B<packimage> [B<-m>|B<--method> I<cpio|tar>] [B<-c>|B<--compress> I<gzip|pigz|xz>] I<imagename>
=head1 DESCRIPTION
@ -36,9 +36,9 @@ B<-p> Profile (compute,service)
B<-a> Architecture (ppc64,x86_64,etc)
B<-m> Archive Method (cpio,tar,squashfs, default is cpio)
B<-m| --method> Archive Method (cpio,tar,squashfs, default is cpio)
B<-c> Compress Method (pigz,gzip,xz, default is pigz)
B<-c| --compress> Compress Method (pigz,gzip,xz, default is pigz/gzip)
=head1 RETURN VALUE
@ -53,6 +53,9 @@ B<-c> Compress Method (pigz,gzip,xz, default is pigz)
packimage rhels7.1-x86_64-netboot-compute
2. To pack the osimage rhels7.1-x86_64-netboot-compute with "tar" to archive and "pigz" to compress:
packimage -m tar -c pigz rhels7.1-x86_64-netboot-compute
=head1 FILES

View File

@ -79,7 +79,7 @@ sub process_request {
@ARGV = @{$args};
}
if (scalar(@ARGV) == 0) {
$callback->({ info => ["Usage:\n packimage <imagename>\n packimage [-h| --help]\n packimage [-v| --version]"] });
$callback->({ info => ["Usage:\n packimage [-m| --method=cpio|tar] [-c| --compress=gzip|pigz|xz] <imagename>\n packimage [-h| --help]\n packimage [-v| --version]"] });
return 0;
}
@ -114,7 +114,7 @@ sub process_request {
return 0;
}
if ($help) {
$callback->({ info => ["Usage:\n packimage <imagename>\n packimage [-h| --help]\n packimage [-v| --version]"] });
$callback->({ info => ["Usage:\n packimage [-m| --method=cpio|tar] [-c| --compress=gzip|pigz|xz] <imagename>\n packimage [-h| --help]\n packimage [-v| --version]"] });
return 0;
}
@ -468,8 +468,12 @@ sub process_request {
}
$suffix = $method.".".$suffix;
unlink("$destdir/rootimg.$suffix");
unlink("$destdir/rootimg.sfs");
unlink("$destdir/rootimg.cpio.xz");
unlink("$destdir/rootimg.cpio.gz");
unlink("$destdir/rootimg.tar.xz");
unlink("$destdir/rootimg.tar.gz");
if ($method =~ /cpio/) {
if (!$exlistloc) {
$excludestr = "find . -xdev -print0 | cpio -H newc -o -0 | $compress -c - > ../rootimg.$suffix";
@ -484,14 +488,14 @@ sub process_request {
$oldmask = umask 0077;
} elsif ($method =~ /tar/) {
if (!$exlistloc) {
$excludestr = "find . -xdev -print0 | tar --selinux --xattrs-include='*' --null -T - -c | $compress -c - > ../rootimg.$suffix";
$excludestr = "find . -xdev -print0 | tar --selinux --xattrs-include='*' --no-recursion --use-compress-program=$compress --null -T - -cf ../rootimg.$suffix";
} else {
chdir("$rootimg_dir");
system("$excludestr >> $xcat_packimg_tmpfile");
if ($includestr) {
system("$includestr >> $xcat_packimg_tmpfile");
}
$excludestr = "cat $xcat_packimg_tmpfile| tar --selinux --xattrs-include='*' -T - -c | $compress -c - > ../rootimg.$suffix";
$excludestr = "cat $xcat_packimg_tmpfile| tar --selinux --xattrs-include='*' --no-recursion --use-compress-program=$compress -T - -cf ../rootimg.$suffix";
}
$oldmask = umask 0077;
} elsif ($method =~ /squashfs/) {
@ -507,9 +511,18 @@ sub process_request {
$callback->({ error => ["Invalid archive method '$method' requested"], errorcode => [1] });
return 1;
}
chdir("$rootimg_dir");
my $outputmsg = `$excludestr`;
$callback->({ info => ["$outputmsg"] });
my $outputmsg = `$excludestr 2>&1`;
unless($?){
$callback->({ info => ["$outputmsg"] });
}else{
$callback->({ info => ["$outputmsg"] });
$callback->({ error => ["packimage failed while running: \n $excludestr"], errorcode => [1] });
system("rm -rf $xcat_packimg_tmpfile");
return 1;
}
if ($method =~ /cpio/) {
chmod 0644, "$destdir/rootimg.$suffix";
if ($dotorrent) {

View File

@ -106,9 +106,9 @@ elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then
cd $NEWROOT
echo -n "Extracting root filesystem:"
if [ -r /rootimg.tar.gz ]; then
tar --selinux --xattrs-include='*' -zxvf /rootimg.tar.gz
tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz
elif [ -r /rootimg.tar.xz ]; then
tar --selinux --xattrs-include='*' -Jxvf /rootimg.tar.xz
tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz
fi
$NEWROOT/etc/init.d/localdisk
echo Done

View File

@ -110,9 +110,9 @@ elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then
[ "$xcatdebugmode" > "0" ] && logger -t xcat -p debug "Extracting root filesystem:"
echo -n "Extracting root filesystem:"
if [ -r /rootimg.tar.gz ]; then
tar --selinux --xattrs-include='*' -zxvf /rootimg.tar.gz
tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz
elif [ -r /rootimg.tar.xz ]; then
tar --selinux --xattrs-include='*' -Jxvf /rootimg.tar.xz
tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz
fi
$NEWROOT/etc/init.d/localdisk
[ "$xcatdebugmode" > "0" ] && logger -t xcat -p debug "Done...."

View File

@ -1640,9 +1640,9 @@ EOMS
print $inifile " cd \$NEWROOT\n";
print $inifile " echo -n \"Extracting root filesystem:\"\n";
print $inifile " if [ -r /rootimg.tar.gz ]; then\n";
print $inifile " tar --selinux --xattrs-include='*' -zxvf /rootimg.tar.gz\n";
print $inifile " tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz\n";
print $inifile " elif [ -r /rootimg.tar.xz ]; then\n";
print $inifile " tar --selinux --xattrs-include='*' -Jxvf /rootimg.tar.xz\n";
print $inifile " tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz\n";
print $inifile " fi\n";
print $inifile " echo Done\n";
print $inifile "else\n";

View File

@ -108,9 +108,9 @@ elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then
[ "$xcatdebugmode" > "0" ] && logger -t xcat -p debug "Extracting root filesystem:"
echo -n "Extracting root filesystem:"
if [ -r /rootimg.tar.gz ]; then
tar --selinux --xattrs-include='*' -zxvf /rootimg.tar.gz
tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz
elif [ -r /rootimg.tar.xz ]; then
tar --selinux --xattrs-include='*' -Jxvf /rootimg.tar.xz
tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz
fi
$NEWROOT/etc/init.d/localdisk
[ "$xcatdebugmode" > "0" ] && logger -t xcat -p debug "Done...."

View File

@ -1658,9 +1658,9 @@ EOMS
print $inifile " cd \$NEWROOT\n";
print $inifile " echo -n \"Extracting root filesystem:\"\n";
print $inifile " if [ -r /rootimg.tar.gz ]; then\n";
print $inifile " tar --selinux --xattrs-include='*' -zxvf /rootimg.tar.gz\n";
print $inifile " tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz\n";
print $inifile " elif [ -r /rootimg.tar.xz ]; then\n";
print $inifile " tar --selinux --xattrs-include='*' -Jxvf /rootimg.tar.xz\n";
print $inifile " tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz\n";
print $inifile " fi\n";
print $inifile " echo Done\n";
print $inifile "else\n";

View File

@ -64,9 +64,9 @@ elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then
cd $NEWROOT
echo -n "Extracting root filesystem:"
if [ -r /rootimg.tar.gz ]; then
tar --selinux --xattrs-include='*' -zxvf /rootimg.tar.gz
tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz
elif [ -r /rootimg.tar.xz ]; then
tar --selinux --xattrs-include='*' -Jxvf /rootimg.tar.xz
tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz
fi
echo Done
elif [ -r /rootimg-statelite.gz ]; then

View File

@ -1480,9 +1480,9 @@ EOMS
print $inifile " ([ \"\$xcatdebugmode\" = \"1\" ] || [ \"\$xcatdebugmode\" = \"2\" ]) && logger -t xcat -p debug \"Extracting root filesystem:\"\n";
print $inifile " echo -n \"Extracting root filesystem:\"\n";
print $inifile " if [ -r /rootimg.tar.gz ]; then\n";
print $inifile " tar --selinux --xattrs-include='*' -zxvf /rootimg.tar.gz\n";
print $inifile " /bin/tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz\n";
print $inifile " elif [ -r /rootimg.tar.xz ]; then\n";
print $inifile " tar --selinux --xattrs-include='*' -Jxvf /rootimg.tar.xz\n";
print $inifile " /bin/tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz\n";
print $inifile " fi\n";
print $inifile " ([ \"\$xcatdebugmode\" = \"1\" ] || [ \"\$xcatdebugmode\" = \"2\" ]) && logger -t xcat -p debug \"Done...\"\n";
print $inifile " echo Done\n";
@ -1624,7 +1624,7 @@ EOMS
}
# add rsync for statelite
foreach ("usr/bin/dig", "bin/busybox", "bin/bash", "sbin/mount.nfs", "usr/bin/rsync", "sbin/insmod", "sbin/udevd", "sbin/udevadm", "sbin/modprobe", "sbin/blkid", "sbin/depmod", "usr/bin/wget", "usr/bin/xz", "usr/bin/gzip", "usr/bin/tar") {
foreach ("usr/bin/dig", "bin/busybox", "bin/bash", "sbin/mount.nfs", "usr/bin/rsync", "sbin/insmod", "sbin/udevd", "sbin/udevadm", "sbin/modprobe", "sbin/blkid", "sbin/depmod", "usr/bin/wget", "usr/bin/xz", "bin/gzip", "bin/tar") {
getlibs($_);
push @filestoadd, $_;
}