A big reorganization which splits out the packaging specfic parts of the script.

The existing solaris/sysv support was split into it's own file
Support for Irix 'inst' packages was added. This is working but I'm not
completely sure that the .tardist format is generated correctly.
This commit is contained in:
Tom G. Christensen 2003-07-25 15:50:55 +00:00
parent 2c6a932f12
commit 9e870ace11
2 changed files with 457 additions and 0 deletions

290
buildpkg.packaging.irix Normal file
View File

@ -0,0 +1,290 @@
#
# Function library for buildpkg framework
# It adds support for creating Irix packages in 'inst' format
#
# Define tool programs
# *only* platform specific packaging tools should be listed here
# generic tools go in buildpkg.functions
GENDIST=/usr/sbin/gendist
# Configuration vars
imageconf=$buildpkgbase/scripts/image.conf
subsysconf=$buildpkgbase/scripts/subsys.conf
idbfile=$metadir/$topdir.idb
specfile=$metadir/$topdir.spec
# Other
# Comment these 4 declarations to get it to run with ksh
declare -a pc # Array of product categories (image.subsys)
declare -a pd # Array of matching descriptions
declare -a pctop # Array of toplevel product categories (image)
declare -a pdtop # Array of matching descriptions
#override defaults
pkgprefix=sb_
pkgname=$pkgprefix$topdir
os=irix`$UNAME -r`
cpu=mips3
distfile=$topdir-$version-$pkgver.tgc-$os-$cpu-$pkgdirdesig.tardist
META_CLEAN="$topdir.spec $topdir.idb"
#####################################################
# Internal helper functions
#####################################################
indent4=" "
indent8=" "
indent12=" "
# fix_ver(): "normalize" a version-pkgver pair
# params: $1=version
# Removes any '.' and '-' characters from a version string
fix_ver()
{
local ver=`echo $1 | $SED -e 's/\.//g' -e 's/-//g'`
echo $ver
}
# spec_header()
# param: $1=product name $2=description
spec_header()
{
echo "product $1"
echo "$indent4 id \"$2\""
}
spec_footer()
{
echo "endproduct"
}
# spec_img_header()
# param: $1=image name $2=image description $3=version
spec_img_header()
{
local nver=$(fix_ver $3)
echo "$indent4 image $1"
echo "$indent8 id \"$2\""
echo "$indent8 version $nver"
echo "$indent8 order 9999"
}
# spec_img_footer()
spec_img_footer()
{
echo "$indent4 endimage"
}
# spec_subsys()
# param: $1=image $2=subsys $3=description
spec_subsys()
{
echo "$indent8 subsys $2 default"
echo "$indent12 id \"$3\""
echo "$indent12 replaces self"
echo "$indent12 exp $pkgname.$1.$2"
echo "$indent8 endsubsys"
}
# compute_octal()
# Description: Computes the octal value from a permission list (_rwxrwxrwx)
# param: $1=permission list
# Caveats: It won't pickup sticky bit and mandatory locking bit
compute_octal()
{
perm=$1
v=0; d1=0; d2=0; d3=0; d4=0
# User part
if [ "${perm:1:1}" == "r" ]; then
let "v = v + 4" # set read bit
fi
if [ "${perm:2:1}" == "w" ]; then
let "v = v + 2" # set write bit
fi
if [ "${perm:3:1}" == "x" ]; then
let "v = v + 1" # set executable bit
elif [ "${perm:3:1}" == "s" ]; then
let "v = v + 1" # set executable bit
let "d1 = d1 + 4" # Set setuid bit
fi
d2=$v; v=0
# Group part
if [ "${perm:4:1}" == "r" ]; then
let "v = v + 4" # set read bit
fi
if [ "${perm:5:1}" == "w" ]; then
let "v = v + 2" # set write bit
fi
if [ "${perm:6:1}" == "x" ]; then
let "v = v + 1" # set executable bit
elif [ "${perm:6:1}" == "s" ]; then
let "v = v + 1" # set executable bit
let "d1 = d1 + 2" # Set setgid bit
fi
d3=$v; v=0;
# Other part
if [ "${perm:7:1}" == "r" ]; then
let "v = v + 4" # set read bit
fi
if [ "${perm:8:1}" == "w" ]; then
let "v = v + 2" # set write bit
fi
if [ "${perm:9:1}" == "x" ]; then
let "v = v + 1" # set executable bit
fi
d4=$v; v=0
echo $d1$d2$d3$d4
}
# add_files()
# Create IDB entries for all files in a specfic product category
# Takes the following parameters
# $1 = dirname to descend into
# $2 = product_category to assign files
# $3 = permissions to set on the files we find
# $4 = user
# $5 = group
add_files()
{
local perm=$3
local FILES=`$FIND $1/* -type f -print`
for i in $FILES
do
if [ "$3" == "keep" ]; then
permlist=`$LS -l $i | $CUT -d " " -f 1`
perm=$(compute_octal $permlist)
fi
echo "f $perm $4 $5 ${topinstalldir:1}/$i $i $pkgname.$2" >>$idbfile
done
FILES=`$FIND $1/* -type l -print`
for i in $FILES
do
if [ "$3" == "keep" ]; then
permlist=`$LS -l $i | $CUT -d " " -f 1`
perm=`compute_octal $permlist`
fi
local temp=`$LS -l $i|$CUT -d '>' -f 2`
local symval=${temp# }
echo "l $perm $4 $5 $i $i $pkgname.$2 symval($symval)" >>$idbfile
done
}
# fetch_imageconf(): Fetch a list of toplevel image entries with descriptions
# params: none
# Discard the ones that we don't have any subsystems for FIXME!
fetch_imageconf()
{
pctopidx=0
while read image desc
do
pctop[$pctopidx]=$image
pdtop[$pctopidx]=$desc
let "pctopidx = $pctopidx + 1"
done < $imageconf
}
##################################
# "external" functions
##################################
# create_idb(): Create the .idb file
# params: none
# Read each line in the subsys config file
# and check if we have a $dir in our staging area
create_idb()
{
local index=0
local found=0
while read dir pdcat perm user group desc
do
found=0
if [ -d $dir ]; then # This exists
add_files $dir $pdcat $perm $user $group
for i in ${pc[@]} # If $pdcat is already there then don't add it again
do
if [ "$i" = "$pdcat" ]; then
found=1
break # It's already there so skip out
fi
done
if [ $found -eq 0 ]; then
pc[$index]=$pdcat
pd[$index]=$desc
let "index = $index + 1"
fi
fi
done < $subsysconf
$SORT +4u -6 < $idbfile > $metadir/idbtemp
mv $metadir/idbtemp $metadir/$idbfile
$RM -f $metadir/idbtemp
}
# create_spec(): Create the .spec file.
# params: none
# Uses pkgname & pkgdesc variables
# Iterate through pctop and for each iteration find
# all entries in pc belonging to that image
#
create_spec()
{
fetch_imageconf
spec_header $pkgname "$name $version-$pkgver" > $specfile
pcsize=${#pc[@]}
for i in ${pctop[@]}
do
pcidx=0
spec_img_header $i "${pdtop[$pcidx]}" $version-$pkgver >> $specfile
while [ "$pcidx" -lt "$pcsize" ]
do
rv=`$EXPR match "${pc[$pcidx]}" ''$i''`
if [ ! "$rv" -eq 0 ]; then # We got a hit!
spec_subsys $i `echo ${pc[$pcidx]}|$CUT -d . -f 2` "${pd[$pcidx]}" >> $specfile
fi
let "pcidx = $pcidx + 1"
done
spec_img_footer >> $specfile
done
spec_footer >> $specfile
}
# make_dist(): Create inst image
# params: $1=[shortroot]
# Run gendist to create the instimage
make_dist()
{
local arg1=${1-'x'}
if [ "$arg1" == "shortroot" ]; then
sbase=$stagedir
else
sbase=$stagedir/$topinstalldir
fi
local disttmp=/tmp/disttmp$$
$MKDIR $disttmp
$GENDIST -rbase $topinstalldir -sbase $sbase -idb $idbfile -spec $specfile -dist $disttmp
setdir $disttmp
$VTAR -cf $distdir/$distfile $pkgname*
setdir stage
$RM -rf $disttmp
}
# generic_pack(): Build package using files from 'install' stage
# params: $1 - indicating whether or not the root is complete as described below
# We expect generic_install to have made $stagedir the "root" dir
# in that all paths below will be complete (ie. /usr/local/bin and not
# just bin) *unless* $1=shortroot.
generic_pack()
{
clean meta
setdir stage
create_idb
create_spec
# Verify if $1 is defined
local arg1=${1-'x'}
case $arg1 in
'x') make_dist # arg1 was undefined
;;
'shortroot') make_dist shortroot
;;
'*') error $E_BAD_ARGS generic_pack
;;
esac
}

167
buildpkg.packaging.solaris Normal file
View File

@ -0,0 +1,167 @@
#
# Function library for buildpkg framework
# It adds support for creating Solaris packages in 'sysv' format
#
# Define tool programs
# *only* platform specific tools should be listed here
# generic tools go in buildpkg.functions
PKGMK=/usr/bin/pkgmk
PKGTRANS=/usr/bin/pkgtrans
PKGPROTO=/usr/bin/pkgproto
# Override generic location
STRIP=/usr/ccs/bin/strip
META_CLEAN="prototype prototype.in pkginfo"
# Define defaults
# pkginfo information.
# The following 3 vars will be used when constructing the pkginfo file
# Override as necessary.
pkgcat="application" # A reasonable default
pkgvendor="http://change/me/please"
pkgdesc="mumble mubmle... hmm someone forgot to fill this out!"
cpu=sparcv9
os=sol`$UNAME -r`
# Distfiles should be named like this
# <name>-<version>-<pkgver>.sb-<os>-<cpu>-<pkgdirdesig>
# ie: libmad-0.14.2b-1.sb-sol5.8-sparcv9-local
distfile=$topdir-$version-$pkgver.sb-$os-$cpu-$pkgdirdesig
#####################################################
# "external" functions
#####################################################
# make_pkg(): Create the final package
# params: none
#
make_pkg()
{
echo "Creating package and transferring it to datastream format"
$PKGMK -r `pwd` -d $buildpkgbase/$topdir -o -f $metadir/prototype
$PKGTRANS -o -s $buildpkgbase/$topdir $distdir/$distfile $pkgname
echo "Done. Package was created as $distfile"
}
# pack_info(): Create the pkginfo file
# params: none
# Will create the pkginfo file with pkginfo.in as a template
# Both the template and the result will be in $metadir
# Substitutions will be done on pkgname,version,pkgver,name & topinstalldir
# they will be replaced with the value of their variable counterparts
pack_info()
{
$SED -e "s#%%pkgname%%#$pkgname#g" \
-e "s#%%version%%#$version#g" \
-e "s#%%pkgcat%%#$pkgcat#g" \
-e "s#%%pkgvendor%%#$pkgvendor#g" \
-e "s#%%pkgver%%#$pkgver#g" \
-e "s#%%name%%#$name#g" \
-e "s#%%topinstalldir%%#$topinstalldir#g" \
-e "s#%%pkgdesc%%#$pkgdesc#g" \
$metadir/pkginfo.in > $metadir/pkginfo
}
# prototype(): Create a prototype file for pkgmk
# params: $1 = owner $2 = group $3 = [script|noscript]
# $1 & $2 will list the owner and group that is to be applied to all files
# pkginfo and depend (if it exists) will automatically be added to prototype file
# $3 will define whether or not to automatically include any post/pre scripts found
# in $topdir/meta. Pr. default postinstall,preinstall,postremove,preremove are the filenames
# it will look for.
# $3 can be omitted and in that case prototype will behave as if $3=noscript
prototype()
{
local owner=$1
local group=$2
$FIND . -print|$PKGPROTO > $metadir/prototype.in
$CAT $metadir/prototype.in | $AWK -v owner="$owner" -v group="$group" \
'{ $5=owner; $6=group; print; }' > $metadir/prototype
add_meta_file pkginfo "$metadir/pkginfo"
# If a dependency file is available then use it
[ -r $metadir/depend ] && add_meta_file depend "$metadir/depend"
case $3 in
'script') [ -r $metadir/preinstall ] && add_meta_file preinstall "$metadir/preinstall"
[ -r $metadir/postinstall ] && add_meta_file postinstall "$metadir/postinstall"
[ -r $metadir/preremove ] && add_meta_file preremove "$metadir/preremove"
[ -r $metadir/postremove ] && add_meta_file postremove "$metadir/postremove"
;;
'noscript') ;;
esac
}
# add_meta_file(): add a metafile entry to the prototype file
# params: $1 = keyword $2 = filename
# Additions will be done to the file $metadir/prototype
add_meta_file()
{
local arg1=${1-'x'}
if [ "$arg1" == "x" ]; then
error $E_MISSING_ARGS add_meta_file
fi
local arg2=${2-'x'}
if [ "$arg2" == "x" ]; then
error $E_MISSING_ARGS add_meta_file
fi
if [ -r "$arg2" ]; then
echo "i $arg1=$arg2" >> $metadir/prototype
else
error $E_BAD_FILE add_meta_file
fi
}
# add_file(): add a file entry to the prototype file
# params: $1 = owner $2 = group $3 = permissions $4 = filename
# Additions will be done to the file $metadir/prototype
# $4 must be relative to $stagedir$prefix (or just $stagedir if using shortroot)
# We will not check for the existence of $4
add_file()
{
local arg1=${1-'x'}
if [ "$arg1" == "x" ]; then
error $E_MISSING_ARGS add_meta
fi
local arg2=${2-'x'}
if [ "$arg2" == "x" ]; then
error $E_MISSING_ARGS add_meta
fi
local arg3=${3-'x'}
if [ "$arg2" == "x" ]; then
error $E_MISSING_ARGS add_meta
fi
if [ -r "$arg4" ]; then
echo "f none $arg4 $3 $1 $2" >> $metadir/prototype
else
error $E_BAD_FILE add_meta_file
fi
}
#####################################################
# Define generic functions for different build stages
#####################################################
# generic_pack(): Build package using files from 'install' stage
# params: $1 - indicating whether or not the root is complete as described below
# We expect generic_install to have made $stagedir the "root" dir
# in that all paths below will be complete (ie. /usr/local/bin and not
# just bin) *unless* $1=shortroot.
generic_pack()
{
clean meta
# Verify if $1 is defined
local arg1=${1-'x'}
case $arg1 in
'x') setdir "$stagedir$prefix" # arg1 was undefined
;;
'shortroot') setdir "$stagedir"
;;
'*') error $E_BAD_ARGS generic_pack
esac
pack_info
prototype root bin script
make_pkg
}