Anti-installation implementation of the Sun Solaris installation package

Source: Internet
Author: User
Tags exit chmod mkdir

At work, it is sometimes necessary to migrate some of the Solaris packages that have already been installed, or to modify the packages that have been installed, but cannot find the original installation package. When the system is upgraded, sometimes it often involves a backup problem for the original system, which requires some tools that can back up the original installation package and install on the new system. The Solaris itself does not provide a direct tool for package porting.

However, when Solaris installs its own generic pkg package, it produces two documents/records related to the installation package, respectively, in/var/sadm/pkg/and/var/sadm/install/contents, by parsing the two documents, You can implement a reverse installation of the Solaris package, which is especially useful when implementing a system upgrade.

The following script will produce a compressed system installation package in the current running directory, copy/paste to the Solaris machine, and then enter the name of the package you want to reverse install. Everyone is welcome to test.

#!/bin/ksh
##########################################################
#
# Copyright (c) 2002 Chinaunix.net--Solaris
#
# Module Description::
# Script to create Sun packages from existing installation
#
##########################################################
# [Global Parameters]
#===============================================
Main_dir= ' pwd '
pro_dir= $MAIN _dir/process
pkg_dir= $MAIN _dir/package
Sys_dir=/var/sadm/pkg
Cnt_file=/var/sadm/install/contents
Id= '/usr/bin/id | Awk-f= ' {print $} ' | Awk-f\ (' {print $} '
Ver=sol ' Uname-r | cut-d.-f2,2 '
Grep=/bin/grep
# awk can not handle long line with many fileds.
# in Solaris, use ' Nawk ' or ' gawk ' instead.
Awk=/bin/nawk
Gzip=/bin/gzip
Mkdir=/bin/mkdir
Chmod=/bin/chmod
Chown=/bin/chown
Cp=/bin/cp
Mv=/bin/mv
Pkgmk=/bin/pkgmk
Pkgtrans=/bin/pkgtrans
# [Functions]
#==================================================================
function Mk_dir
{
$MKDIR-P $PRO _dir/$3
$CHMOD $ $PRO _dir/$3
$CHOWN $5:$6 $PRO _dir/$3
}
function Cp_file
{
$CP-P $ $PRO _dir/$3
$CHMOD $ $PRO _dir/$3
$CHOWN $5:$6 $PRO _dir/$3
}
# [Main]
#==================================================================
If [${id}!= 0]
Then
echo ""
echo "only Root User allow to run this script." Exit ... "
Sleep 1
echo ""
Exit 1
Fi
echo ""
echo "Please enter package name for your want to create, then press ENTER:"
echo "Enter Package name: \c"
Read Pkgname
Pkg_name= $pkgname
if [!-D $SYS _dir/$PKG _name]; Then
echo ""
echo "This Package doesn ' t exist!!! Please check the name and try Again! "
echo ""
Exit 1
Fi
if [!-D $PRO _dir]; Then
$MKDIR $PRO _dir
Fi
if [!-D $PKG _dir]; Then
$MKDIR $PKG _dir
Fi
# Producing part of Prototype file
$GREP $PKG _name $CNT _file | $GREP-V ^#.* >; $PRO _dir/cnt_pkg
$AWK ' {print $2,$3,$1,$4,$5,$6} ' $PRO _dir/cnt_pkg >; $PRO _dir/prototmp
$GREP ^d $PRO _dir/prototmp >; $PRO _dir/protodir
$GREP ^f $PRO _dir/prototmp >;>; $PRO _dir/protofile
Rm-f $PRO _dir/prototmp
Rm-f $PRO _dir/cnt_pkg
# Producing Pkginfo file
CP $SYS _dir/$PKG _name/pkginfo $PRO _dir
# Making directory with permission
I=0
While Ifs= ' read line
Todo
t[$i]= $line
((i=i+1))
Mk_dir $line
Done < $PRO _dir/protodir
# Copying file to Spool directory
I=0
While Ifs= ' read line
Todo
t[$i]= $line
((i=i+1))
Cp_file $line
Done < $PRO _dir/protofile
# Producing Prototype file
Cat $PRO _dir/protodir >; $PRO _dir/prototype
Cat $PRO _dir/protofile >;>; $PRO _dir/prototype
(echo "I Pkginfo"; Cat $PRO _dir/prototype) >; $PRO _dir/prototmp
MV $PRO _dir/prototmp $PRO _dir/prototype
Rm-f $PRO _dir/protodir
Rm-f $PRO _dir/protofile
# Now let's make the package
$PKGMK-O-R $PRO _dir-d $PRO _dir-f $PRO _dir/prototype
$PKGTRANS-S $PRO _dir $PKG _dir/$PKG _name-$VER-pkg $PKG _name
$GZIP-F $PKG _dir/$PKG _name-$VER-pkg
RM-RF $PRO _dir

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.