| 1 |
package UML::Package; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use UML::Config; |
| 7 |
use UML::Utils; |
| 8 |
use ConfigPatcher::Main; |
| 9 |
|
| 10 |
sub pack_rootfs { |
| 11 |
|
| 12 |
my $vhost_name = shift; |
| 13 |
my $skel_name = shift; |
| 14 |
|
| 15 |
|
| 16 |
my $vhost = get_host_cfg($vhost_name); |
| 17 |
my %vhost = %{$vhost}; |
| 18 |
my $skel = get_skel_cfg($skel_name); |
| 19 |
my %skel = %{$skel}; |
| 20 |
|
| 21 |
my $vhost_path = get_host_basepath($vhost_name); |
| 22 |
|
| 23 |
my $cmd; |
| 24 |
|
| 25 |
my $skel_base = UML::Config::get_skel_base($skel_name); |
| 26 |
my $host_base = UML::Config::get_host_basepath($vhost_name); |
| 27 |
|
| 28 |
my $rootfs_name = $vhost{'rootfs'}; |
| 29 |
my $rootfs_path = "$vhost_path/rootfs/$rootfs_name"; |
| 30 |
my $skel_rootfs = UML::Config::get_skel_rootfs_path($skel_name); |
| 31 |
|
| 32 |
# checking for existance of packed skel |
| 33 |
if (-f "$skel_rootfs.tar.gz") { |
| 34 |
print "rootfs-skel already exists (\"$skel_rootfs\"), will not overwrite!", "\n"; |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
# create skel-structure |
| 39 |
$cmd = "mkdir -p $skel_base/ && mkdir $skel_base/patches/ && mkdir $skel_base/tmp/ && mkdir $skel_base/mnt/ && mkdir $skel_base/mnt/rootfs/"; |
| 40 |
askCmd("do it", $cmd, "creating skel-directory-structure"); |
| 41 |
|
| 42 |
# copy to skel ... |
| 43 |
# ... root-fs |
| 44 |
$cmd = "cp $rootfs_path $skel_base/tmp/"; |
| 45 |
askCmd("do it", $cmd, "copying rootfs to skel/tmp/"); |
| 46 |
# ... patches |
| 47 |
$cmd = "cp -R ../../etc/uml/patches/ $skel_base/"; |
| 48 |
askCmd("do it", $cmd, "copying patches to skel/patches/"); |
| 49 |
|
| 50 |
# mount rootfs |
| 51 |
$cmd = "mount $skel_base/tmp/$rootfs_name $skel_base/mnt/rootfs/ -o loop"; |
| 52 |
askCmd("do it", $cmd, "mounting rootfs at skel/tmp/"); |
| 53 |
|
| 54 |
# modify/prepare/configure copy of root-fs |
| 55 |
logAction("applying patches to rootfs"); |
| 56 |
#if (ask("apply changes? (y|n)")) { |
| 57 |
%ConfigPatcher::Main::vhost = %vhost; |
| 58 |
preparePatches("$skel_base/patches/uml_genskel_patchlist.txt", "$skel_base/mnt/rootfs"); |
| 59 |
#} |
| 60 |
|
| 61 |
# unmount rootfs |
| 62 |
$cmd = "umount $skel_base/tmp/$rootfs_name"; |
| 63 |
askCmd("do it", $cmd, "unmounting rootfs"); |
| 64 |
|
| 65 |
# packing file |
| 66 |
$cmd = "tar -czf $skel_rootfs.tar.gz --directory=$skel_base/tmp/ $rootfs_name"; |
| 67 |
askCmd("do it", $cmd, "packing rootfs"); |
| 68 |
|
| 69 |
# clearing /tmp |
| 70 |
$cmd = "rm $skel_base/tmp/*"; |
| 71 |
askCmd("do it", $cmd, "clearing skel/tmp/"); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
#sub pack_datafs { |
| 76 |
# my $datafs = "$vhost_path/datafs/$vhost{'datafs'}"; |
| 77 |
# my $skel_datafs = UML::Config::get_skel_datafs_path($skel_name); |
| 78 |
# my $host_base = UML::Config::get_host_basepath($vhost_name); |
| 79 |
# if (-f "$skel_datafs.tar.gz") { |
| 80 |
# print "datafs-skel already exists (\"$skel_datafs\"), will not overwrite!", "\n"; |
| 81 |
# return; |
| 82 |
# } |
| 83 |
# #$cmd = "gzip $datafs && mv $datafs.gz $skel_datafs"; |
| 84 |
# #$cmd = "tar -czf $skel_datafs.tar.gz $datafs"; |
| 85 |
# $cmd = "tar -czf $skel_datafs.tar.gz --directory=$host_base/datafs $vhost{'datafs'}"; |
| 86 |
# print "uml_package.pl will issue this command:", "\n"; |
| 87 |
# askCmd("do it", $cmd); |
| 88 |
# # print "trying to package datafs of \"$vhost_name\"", "\n"; |
| 89 |
#} |
| 90 |
|
| 91 |
sub bundle_patches { |
| 92 |
my $skel_name = shift; |
| 93 |
|
| 94 |
my $skel_base = UML::Config::get_skel_base($skel_name); |
| 95 |
|
| 96 |
my $cmd; |
| 97 |
|
| 98 |
#$cmd = "cd $skel_base/patches && tar -cz --directory=tmp/ -f src/rootfs.tar.gz rootfs/"; |
| 99 |
$cmd = "tar -czf /home/service/etc/uml/patches/src/rootfs.tar.gz --directory=/home/service/etc/uml/patches/tmp/ rootfs/"; |
| 100 |
askCmd("do it", $cmd, "bundling configure-patches for rootfs"); |
| 101 |
|
| 102 |
#$cmd = "cd $skel_base/patches && tar -cz --directory=tmp/ -f src/datafs.tar.gz datafs/"; |
| 103 |
$cmd = "tar -czf /home/service/etc/uml/patches/src/datafs.tar.gz --directory=/home/service/etc/uml/patches/tmp/ datafs/"; |
| 104 |
askCmd("do it", $cmd, "bundling configure-patches for datafs"); |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
sub patches2pkg { |
| 109 |
|
| 110 |
my $skel_name = shift; |
| 111 |
|
| 112 |
my $skel_base = UML::Config::get_skel_base($skel_name); |
| 113 |
|
| 114 |
my $cmd; |
| 115 |
|
| 116 |
$cmd = "cp -R /home/service/etc/uml/patches/ $skel_base/"; |
| 117 |
askCmd("do it", $cmd, "copying patches to skel"); |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
1; |