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
#
#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
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"} = ;
$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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 用PYTHON初次編寫小工具心得Python
- wp7 toolkit編譯錯誤 Xap packaging failed編譯AI
- 自己手寫的JS小工具JS
- 【Scala】Scala之Packaging and ImportsImport
- 個人寫的一個小工具 laravel生成介面文件Laravel
- 小工具實戰-Python 實現小工具輸出字串大小寫轉換、字串統計、編解碼、MD5 加密Python字串加密
- golang寫的web application 怎麼優雅的更新?GolangWebAPP
- 用Node.js寫的看股票的命令列小工具Node.js命令列
- Python配合Redis寫個Remember小工具PythonRedisREM
- Rust 寫一個簡易 CLI 小工具Rust
- 從頭編寫指令碼: 為 IBM WebSphere Application Server 建立 Jython 管理指令碼指令碼IBMWebAPPServer
- HTML Email的編寫HTMLAI
- 編寫更好的CSSCSS
- 手寫一個同步服務端時間的小工具服務端
- 用golang寫個格式化go檔案的小工具Golang
- pg的function的編寫Function
- Oracle ADR packaging incidents(打包事件)OracleIDE事件
- 編寫自己的 TypeScript CLITypeScript
- 如何編寫最佳的DockerfileDocker
- 桌面下雪程式的編寫
- 配置檔案的編寫
- Dockerfile編寫Docker
- 編寫DockerFileDocker
- Billy Belceb病毒編寫教程(DOS篇)---病毒編寫所需的軟體
- 1149 Dangerous Goods Packaging (25分)Go
- 用 actix-Web 2.0-α 寫了一個小工具Web
- PHP 編寫基本的 Socket 程式PHP
- 編寫高效能的JavaScriptJavaScript
- 編寫可維護的JSJS
- 【譯】如何更好的編寫CSSCSS
- 如何編寫優雅的DockerfileDocker
- 面試關於 MySQL 的編寫面試MySql
- Windows 專案的 CMakeLists 編寫Windows
- 編寫自己的Webpack LoaderWeb
- 如何最有效的編寫SQLSQL
- 編寫最基本的APT DemoAPT
- 編寫Ansj的Solr外掛Solr
- 編寫更好的CSS程式碼CSS