1#!/usr/bin/ksh
2# Licensed to the Apache Software Foundation (ASF) under one or more
3# contributor license agreements.  See the NOTICE file distributed with
4# this work for additional information regarding copyright ownership.
5# The ASF licenses this file to You under the Apache License, Version 2.0
6# (the "License"); you may not use this file except in compliance with
7# the License.  You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17#
18
19# minstallp.ksh # create an installp image of ${NAME} (defined in aixinfo)
20# from TEMPDIR using mkinstallp (part of bos.adt.insttools)
21
22[[ $# == 0 ]] && echo $0: Syntax error && echo "Syntax: $0 <BaseDirectory>" && exit -1
23
24umask 022
25TEMPDIR=$1
26BASE=`pwd`
27cd ${TEMPDIR}
28[[ $? != 0 ]] && echo $0: ${TEMPDIR} -- bad directory && exit -1
29
30# clean up side-effects from DEBUG passes - usr/local might be there as
31# a circular link i.e. usr/local points at /usr/local
32# as we are not using /usr/local for ASF packaging, remove it!
33# mkinstallp seems to make usr/local -> /usr/local 
34[[ -f usr/local ]] && rm -f usr/local && echo removed unexpected usr/local !!
35[[ -L usr/local ]] && rm -f usr/local && echo removed unexpected usr/local !!
36[[ -d usr/local ]] && rm -rf usr/local && echo removed unexpected usr/local !!
37
38# use the aixinfo for PKG NAME VERSION etc labels
39cd ${BASE}
40. build/aix/aixinfo
41# INFO=${BASE}/build/aix/.info
42# mkdir -p $INFO
43INFO=${BASE}/build/aix
44template=${INFO}/${PKG}.${NAME}.${VERSION}.template
45>$template
46
47# mkinstallp template definitions
48# TODO: add AIX oslevel/uname information for package filename
49package=$PKG
50name=$NAME
51vrmf=$VERSION
52release=$RELEASE
53descr="$NAME version ${VERSION} for $ARCH ${VENDOR}"
54
55# copy LICENSE information
56# TODO: setup template so that license acceptance is required
57# TODO: add Copyright Information for display during install
58mkdir -p ${TEMPDIR}/usr/swlag/en_US
59cp ${BASE}/LICENSE ${TEMPDIR}/usr/swlag/en_US/${PKG}.${NAME}.la
60
61cd ${TEMPDIR}
62# remove files we do not want as "part" possibly
63# left-over from a previous packaging
64rm -rf .info lpp_name tmp usr/lpp
65[[ $? -ne 0 ]] && echo $cmd: cleanup error && pwd && ls -ltr && exit -1
66
67#if we are going to add extra symbolic links - do it now
68[[ -r build/aix/aixlinks ]] && ksh build/aix/aixlinks
69
70# get the directory sizes in blocks
71for d in etc opt var
72do
73	if [[ -d $d/${NAME} ]]
74	then
75		set `du -s $d/${NAME}`
76	else
77		[[ -d $d ]] && set `du -s $d`
78	fi
79	# make sure the argument exists before using setting values
80	if [[ -d $d ]]
81	then
82		eval nm$d=/"$2"
83		let sz$d=$1
84	fi
85done
86
87files=./${NAME}.${VERSION}
88cd ${TEMPDIR}/..
89find ${files} -type d -exec chmod og+rx {} \;
90chmod -R go+r ${files}
91chown -R 0.0 ${files}
92
93cat - <<EOF >>$template
94Package Name: ${PKG}.${NAME}
95Package VRMF: ${VERSION}.${RELEASE}
96Update: N
97Fileset
98  Fileset Name: ${PKG}.${NAME}.rte
99  Fileset VRMF: ${VERSION}.${RELEASE}
100  Fileset Description: ${descr}
101  USRLIBLPPFiles
102  EOUSRLIBLPPFiles
103  Bosboot required: N
104  License agreement acceptance required: N
105  Name of license agreement: 
106  Include license files in this package: N
107  Requisites:
108EOF
109
110[[ $szetc -ne 0 ]] && echo "        Upsize: ${nmetc} $szetc;" >> $template
111[[ $szopt -ne 0 ]] && echo "        Upsize: ${nmopt} $szopt;" >> $template
112[[ $szvar -ne 0 ]] && echo "        Upsize: ${nmvar} $szvar;" >> $template
113echo "  USRFiles" >> $template
114
115# USR part -- i.e. files in /usr and /opt
116cd ${TEMPDIR}/..
117find ${files}/usr/swlag ${files}/opt \
118	| sed -e s#^${files}## | sed -e "/^$/d" >>$template
119echo "  EOUSRFiles" >> $template
120
121if [[ $szetc -gt 0 || $szvar -gt 0 ]]
122then
123INSTROOT=${TEMPDIR}/usr/lpp/${PKG}.${NAME}/inst_root
124mkdir -p ${INSTROOT}
125cd ${TEMPDIR}
126[[ $szetc -gt 0 ]] && find ./etc -type d | backup -if - | (cd ${INSTROOT}; restore -xqf -) >/dev/null
127[[ $szvar -gt 0 ]] && find ./var -type d | backup -if - | (cd ${INSTROOT}; restore -xqf -) >/dev/null
128cat - <<EOF >>$template
129  ROOT Part: Y
130  ROOTFiles
131EOF
132
133# ROOT part 
134cd ${TEMPDIR}/..
135find ${files}/etc ${files}/var \
136	| sed -e s#^${files}## | sed -e "/^$/d" >>$template
137else
138# no ROOT parts to include
139cat - <<EOF >>$template
140  ROOT Part: N
141  ROOTFiles
142EOF
143fi
144cat - <<EOF >>$template
145  EOROOTFiles
146  Relocatable: N
147EOFileset
148EOF
149# man pages as seperate fileset
150cd ${TEMPDIR}
151if [[ -d usr/share/man ]]
152then
153	# manual pages, space required calculation
154	set `du -s usr/share/man`
155	szman=$1
156	descr="$NAME ${VERSION} man pages ${VENDOR}"
157	cat - <<EOF >>$template
158Fileset
159  Fileset Name: ${PKG}.${NAME}.man.en_US
160  Fileset VRMF: ${VERSION}.${RELEASE}
161  Fileset Description: ${descr}
162  USRLIBLPPFiles
163  EOUSRLIBLPPFiles
164  Bosboot required: N
165  License agreement acceptance required: N
166  Name of license agreement:
167  Include license files in this package: N
168  Requisites:
169EOF
170
171	echo "        Upsize: /usr/share/man ${szman};" >> $template
172	echo "  USRFiles" >> $template
173	cd ${TEMPDIR}/..
174	find ${files}/usr/share | sed -e s#^${files}## | sed -e "/^$/d" >>$template
175	cat - <<EOF >>$template
176  EOUSRFiles
177  ROOT Part: N
178  ROOTFiles
179  EOROOTFiles
180  Relocatable: N
181EOFileset
182EOF
183fi
184
185# use mkinstallp to create the fileset. result is in ${TEMPDIR}/tmp
186# must actually sit in TEMPDIR for ROOT part processing to succeed
187# also - need "empty" directories to exist, as they do not get copied
188# in the inst_root part
189cd ${TEMPDIR}
190mkinstallp -d ${TEMPDIR} -T ${template}
191[[ $? -ne 0 ]] && echo mkinstallp returned error status && exit -1
192
193# copy package to build/aix
194# create TOC
195cp ${TEMPDIR}/tmp/$PKG.$NAME.$VERSION.0.bff ${BASE}/build/aix
196cd ${BASE}/build/aix
197rm -f $PKG.$NAME.$VERSION.$ARCH.I
198mv $PKG.$NAME.$VERSION.0.bff $PKG.$NAME.$ARCH.$VERSION.I
199rm -f .toc
200inutoc .
201