solaris Application Packaging 编写的小工具

本小工具用于将目录或文件封装为流文件 pkg格式

以下为源码:

[@more@]

#!/usr/bin/perl
###########################################
#
# Automated processes to create SUN packages
# You can run this script after you did a 'make install' in the chrooted
# environment. Run it from the /packagename-1.0/usr/local/ directory
#
#Author: Tony Liu Date:2012/07/14
#History:

############################################
# rm exist already pkg info

$find = "/usr/bin/find";
$pkgproto = "/usr/bin/pkgproto";
$pkgmk = "/usr/bin/pkgmk";
$pkgtrans = "/usr/bin/pkgtrans";
$temp = "/tmp/prototype$$";
$prototype = "prototype";
$pkginfo = "pkginfo";
$rootapth = "/";
$pkgdir="/var/spool/pkg";


if (-e $pkgdir) {
system("rm -R $pkgdir");
system("mkdir $pkgdir");
}else
{
system("mkdir $pkgdir");
}
if (-e "/$pkginfo") {
unlink("/$pkginfo");
}
if (-e "/$prototype") {
unlink("/$prototype");
}
# Sanitycheck

$pwd = `pwd`;
if ($pwd =~ '/usr/local') {
$pwd = $`;
}
$propwd= `pwd`;
if ($propwd =~ '/usr/local') {
$propwd = $`;
}
chomp $propwd;
#$propwd=substr($propwd,1,length($propwd));
die "Wrong location, please cd to /usr/local/ and run again.n" if ($pwd eq "");

system ("$find . -print | $pkgproto > $temp");
open (PREPROTO,"< $temp") || die "Unable to read prototype information ($!)n";
open (PROTO,"> $prototype") || die "Unable to write file prototype ($!)n";
print PROTO "i pkginfo=./$pkginfon";


while () {
# Read the prototype information from /tmp/prototype$$
chomp;
$thisline = $_;
if ($thisline =~ " prototype ") {
# We don't need that line
} elsif ($thisline =~ "^[fd] ") {
# Change the ownership for files and directories
($dir, $none, $file, $mode, $user, $group) = split / /,$thisline;

print PROTO "$dir $none $propwd/$file $mode $user $groupn";
} else {
# Symlinks and other stuff should be printed as well ofcourse
print PROTO "$thislinen";
}
}
close PROTO;
close PREPROTO;

# Clean up
unlink $temp || warn "Unable to remove tempfile ($!)n";

# Now we can start building the package
#
# First get some info

$thispackage = `basename $pwd`;
if ($thispackage =~ '-') {
$default{"name"} = $`;
$default{"version"} = $';
chomp $default{"version"};
} else {
$default{"name"} = $thispackage;
chomp $default{"name"};
$default{"version"} = "1.0";
}
$default{"pkg"} = "UMC" . substr($default{"name"},0,4);
$default{"arch"} = `uname -m`;
chomp $default{"arch"};
$default{"category"} = "application";
$default{"vendor"} = "GNU";
#$default{"email"} = dba.tonyliu@gmail.com;
$default{"desc"} = "$pkg";
$login = getlogin();
($user, $passwd, $uid, $gid, $quota, $default{"pstamp"}, $userInfo, $userHome, $loginShell) = getpwnam ($login);
$default{"pstamp"} = "Jasper Aukes" if ($default{"pstamp"} eq "");
$os = `uname -r`;
$os =~ '.';
$os = "sol$'";
chomp $os;
$default{"basedir"} = "/";

# Check for correctness of guessed values by userinput

%questions = (
pkg => "Please give the name for this package",
name => "Now enter the real name for this package",
arch => "What architecture did you build the package on?",
version => "Enter the version number of the package",
category => "What category does this package belong to?",
vendor => "Who is the vendor of this package?",
#email => "Enter the email adress for contact",
desc => "Please write this package description info",
pstamp => "Enter your own name",
#basedir => "What is the basedir this package will install into?",
packagename => "How should i call the packagefile?",
);

@vars = qw(pkg name arch version category vendor desc pstamp packagename);
foreach $varname (@vars) {
$default{"$varname"} = "$name-$version-$os-$arch" if ($varname eq "packagename");
getvar($varname);
}
$classes = "none";

# Create the pkginfo file
print "nNow creating $pkginfo filen";
open (PKGINFO,"> $pkginfo") || die "Unable to open $pkginfo for writingi ($!)n";
print PKGINFO "PKG="$pkg"n";
print PKGINFO "NAME="$name"n";
print PKGINFO "ARCH="$arch"n";
print PKGINFO "VERSION="$version"n";
print PKGINFO "CATEGORY="$category"n";
print PKGINFO "VENDOR="$vendor"n";
#print PKGINFO "EMAIL="$email"n";
print PKGINFO "DESC="$desc"n";
print PKGINFO "PSTAMP="$pstamp"n";
print PKGINFO "BASEDIR="$basedir"n";
print PKGINFO "CLASSES="$classes"n";
close PKGINFO;
print "Done.n";


# Build the package
system ("mv $prototype $rootapth");
system ("mv $pkginfo $rootapth");
print "Building packagen";
system ("(cd /;$pkgmk -r $rootapth)");
system ("(cd /var/spool/pkg;pkgchk -vd . $pkg;$pkgtrans -s `pwd` /tmp/$packagename.pkg)");
print "Done. (/tmp/$packagename.pkg)n";

if (-e $pkgdir) {
system("rm -R $pkgdir");
system("mkdir $pkgdir");
}else
{
system("mkdir $pkgdir");
}
if (-e "/$pkginfo") {
unlink("/$pkginfo");
}
if (-e "/$prototype") {
unlink("/$prototype");
}

# The subroutines

sub getvar {
my $questionname = "@_";
print "$questions{$questionname} [$default{"$questionname"}]: ";
my $answer = ;
chomp $answer;
$$questionname = $answer;
$$questionname = $default{$questionname} if ($$questionname eq "");
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24870090/viewspace-1058996/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24870090/viewspace-1058996/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值