#!/bin/sh
##
## OpenPKG Binary Bootstrap Package (self-extracting shell script)
## Copyright (c) 2000-2007 OpenPKG Foundation e.V.
## Copyright (c) 2000-2007 Ralf S. Engelschall
##
## Permission to use, copy, modify, and distribute this software for
## any purpose with or without fee is hereby granted, provided that
## the above copyright notice and this permission notice appear in all
## copies.
##
## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
## SUCH DAMAGE.
##
# configuration
l_me="$0"
o_help=no
o_version=no
o_tar=no
l_prefix='/kolab'
l_musr='kolab'
l_mgrp='kolab'
l_platform="ix86-debian4.0"
l_release="CURRENT"
l_version="20070606"
# establish standard environment
PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin"
LC_CTYPE=C
export LC_CTYPE
umask 022
# parse command line options
for opt
do
case $opt in
-*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
*) arg='' ;;
esac
case $opt in
-h | --help ) o_help=yes ;;
-v | --version ) o_version=yes ;;
-t | --tar ) o_tar=yes ;;
--prefix=* ) l_prefix=$arg ;;
* ) o_help=yes ;;
esac
done
if [ ".$o_version" = .no -a ".$l_prefix" = . ]; then
o_help=yes
fi
if [ ".$o_help" = .yes ]; then
echo "Usage: sh $l_me" 2>&1
echo " [--prefix=] [-t|--tar]" 2>&1
echo " [-h|--help] [-v|--version]" 2>&1
exit 1
fi
# make sure all essential installation tools are available
for tool in sed mkdir dd tar chown chgrp; do
found=no
case $tool in
/* )
if [ -f $tool ]; then
found=yes
fi
;;
* )
for p in `IFS=:; echo $PATH`; do
if [ -f "$p/$tool" ]; then
found=yes
break
fi
done
;;
esac
if [ ".$found" = .no ]; then
echo "$l_me:ERROR: unable to find installation tool \"$tool\"" 1>&2
exit 1
fi
done
# optionally extract the embedded tarball only
if [ ".$o_tar" = .yes ]; then
tmpdir="${TMPDIR-/tmp}/openpkg.$$"
( umask 077 && mkdir $tmpdir) || exit 1
dd if=$l_me bs=8192 skip=8 2>/dev/null |\
( cd $tmpdir || exit 1
tar xf - 2>/dev/null || exit 1
./openpkg.bzip2 -d -c openpkg.tar.bz2
) || exit 1
rm -rf $tmpdir
exit 0
fi
# display version and copyright header
echo "OpenPKG ${l_release} Binary Bootstrap Package, version ${l_version}"
echo "Built for prefix ${l_prefix} on target platform ${l_platform}"
if [ ".$o_version" = .yes ]; then
exit 0
fi
# determine current username
cusr=`(id -un) 2>/dev/null ||\
(id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
(whoami) 2>/dev/null ||\
(who am i | cut "-d " -f1) 2>/dev/null ||\
echo ${LOGNAME-"NN"}`
# running the embedded %pre script for hooking into the system environment
echo "++ hooking OpenPKG instance into system environment"
prefix="$l_prefix"
susr='root'; sgrp='root'
musr='kolab'; mgrp='kolab'
rusr='kolab-r'; rgrp='kolab-r'
nusr='kolab-n'; ngrp='kolab-n'
suid=''; sgid=''
muid='19414'; mgid='19414'
ruid='19415'; rgid='19415'
nuid='19416'; ngid='19416'
set -- 1 # emulate RPM's $1 when executing scripts
# ---- BEGIN EMBEDDED %pre SCRIPT ----
# always performed for upgrades and because it doesn't harm!
# [ ".$1" != .1 ] && exit 0
# this procedure is only usable with root privileges
# (for non-root installations it is not required at all)
cusr=`(id -un) 2>/dev/null ||\
(id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
(whoami) 2>/dev/null ||\
(who am i | cut "-d " -f1) 2>/dev/null ||\
echo $LOGNAME`
# determine runtime details (for both inside and outside RPM!!)
# - bootstrapping: $xxx is set from aux.wrapbin.sh
# - upgrading new: ${[smrn]{usr,grp}} is set via rpmmacros
# - upgrading old: ${[smrn]{usr,grp}} is not set at all
[ ".$susr" = . ] && susr="${susr+""}${susr-root}"
[ ".$sgrp" = . ] && sgrp="${sgrp+""}${sgrp-wheel}"
[ ".$musr" = . ] && musr="${musr+""}${musr-${fsusr}}"
[ ".$mgrp" = . ] && mgrp="${mgrp+""}${mgrp-${fsgrp}}"
[ ".$rusr" = . ] && rusr="${rusr+""}${rusr-${fsusr}-r}"
[ ".$rgrp" = . ] && rgrp="${rgrp+""}${rgrp-${fsgrp}-r}"
[ ".$nusr" = . ] && nusr="${nusr+""}${nusr-${fsusr}-n}"
[ ".$ngrp" = . ] && ngrp="${ngrp+""}${ngrp-${fsgrp}-n}"
[ ".$suid" = . ] && suid="${suid+""}"
[ ".$sgid" = . ] && sgid="${sgid+""}"
[ ".$muid" = . ] && muid="${muid+""}"
[ ".$mgid" = . ] && mgid="${mgid+""}"
[ ".$ruid" = . ] && ruid="${ruid+""}"
[ ".$rgid" = . ] && rgid="${rgid+""}"
[ ".$nuid" = . ] && nuid="${nuid+""}"
[ ".$ngid" = . ] && ngid="${ngid+""}"
# if any of these optional params are not used we won't have a
# corresponding macro either, so make use of one conditionally
[ ".$suid" = . ] && [ ".${suid+set}" = .set ] && suid="${suid+""}"
[ ".$sgid" = . ] && [ ".${sgid+set}" = .set ] && sgid="${sgid+""}"
[ ".$muid" = . ] && [ ".${muid+set}" = .set ] && muid="${muid+""}"
[ ".$mgid" = . ] && [ ".${mgid+set}" = .set ] && mgid="${mgid+""}"
[ ".$ruid" = . ] && [ ".${ruid+set}" = .set ] && ruid="${ruid+""}"
[ ".$rgid" = . ] && [ ".${rgid+set}" = .set ] && rgid="${rgid+""}"
[ ".$nuid" = . ] && [ ".${nuid+set}" = .set ] && nuid="${nuid+""}"
[ ".$ngid" = . ] && [ ".${ngid+set}" = .set ] && ngid="${ngid+""}"
# determine prefix
[ ".$prefix" = . ] && prefix="${prefix}"
prefix=`echo "$prefix" | sed -e 's;//*;/;g' -e 's;/$;;'`
# register instance in presence file
presence="/etc/openpkg"
exists=`cat $presence 2>/dev/null | egrep "^ *${prefix} *\$"`
if [ ".$exists" = . ]; then
( umask 022
echo "${prefix}" >>$presence
) 2>/dev/null || true
fi
# determine user/group ids
for class in s m r n; do
eval "xusr=\"\$${class}usr\""
eval "xgrp=\"\$${class}grp\""
eval "xuid=\"\$${class}uid\""
eval "xgid=\"\$${class}gid\""
if [ ".$xuid" = . ]; then
xuid=`(getent passwd "${xusr}"; \
grep "^${xusr}:" /etc/passwd; \
ypmatch "${xusr}" passwd; \
nismatch "${xusr}" passwd; \
nidump passwd . | grep "^${xusr}:") 2>/dev/null | \
sed -e 'q' | awk -F: '{ print $3; }'`
if [ ".$xuid" = . ]; then
# seek for a reasonably uid/gid pair
xuid=1000
ok=0
while [ ".$ok" = .0 ]; do
eval "u_exists=\$u_exists_$xuid"
if [ ".$u_exists" = . ]; then
u_exists=`(getent passwd; cat /etc/passwd; ypcat passwd; niscat passwd; nidump passwd .) 2>/dev/null |\
grep "^[^:]*:[^:]*:$xuid:"`
fi
eval "g_exists=\$g_exists_$xuid"
if [ ".$g_exists" = . ]; then
g_exists=`(getent group; cat /etc/group; ypcat group; niscat group; nidump group .) 2>/dev/null |\
grep "^[^:]*:[^:]*:$xuid:"`
fi
if [ ".$u_exists" = . -a ".$g_exists" = . ]; then
ok=1
break
fi
xuid=`expr $xuid + 1`
done
eval "u_exists_$xuid=yes"
eval "g_exists_$xuid=yes"
fi
fi
if [ ".$xgid" = . ]; then
xgid=`(getent group "${xgrp}"; \
grep "^${xgrp}:" /etc/group; \
ypmatch "${xgrp}" group; \
nismatch "${xgrp}" group; \
nidump group . | grep "^${xgrp}:") 2>/dev/null | \
sed -e 'q' | awk -F: '{ print $3; }'`
if [ ".$xgid" = . ]; then
xgid="$xuid"
fi
fi
eval "${class}uid=\"$xuid\""
eval "${class}gid=\"$xgid\""
done
# determine platform id
s=`(uname -s) 2>/dev/null` || s='Unknown'
r=`(uname -r) 2>/dev/null` || r='0.0'
plid="${s}/${r}"
# add entry to /etc/shells
shell="${prefix}/lib/openpkg/bash"
if [ -f /etc/shells ]; then
exists=`cat /etc/shells 2>/dev/null | grep "^$shell"`
if [ ".$exists" = . ]; then
if [ ".$cusr" != ".root" ]; then
echo "openpkg:WARNING: skipping addition of $shell to /etc/shells" 1>&2
echo "openpkg:WARNING: (would require root-privileges)" 1>&2
else
echo "${shell}" >>/etc/shells
fi
fi
fi
# clear pending deferred actions
rm -f ${prefix}.pre-group-process.sh ${prefix}.pre-post-process.sh >/dev/null 2>&1
# create the hierarchy user/group
for req in "superuser:${susr}:${suid}:${sgrp}:${sgid}" \
"management:${musr}:${muid}:${mgrp}:${mgid}" \
"restricted:${rusr}:${ruid}:${rgrp}:${rgid}" \
"non-privileged:${nusr}:${nuid}:${ngrp}:${ngid}"; do
# split request into class/usr/uid/grp/gid
OIFS="$IFS"; IFS=":"; set -- $req; IFS="$OIFS"
class="$1"; usr="$2"; uid="$3"; grp="$4"; gid="$5"
# check whether user already exists
exists=`(getent passwd "$usr"; \
grep "^$usr:" /etc/passwd; \
ypmatch "$usr" passwd; \
nismatch "$usr" passwd; \
nidump passwd . | grep "^$usr:") 2>/dev/null | \
sed -e 'q'`
if [ ".$exists" = . ]; then
if [ ".$cusr" != ".root" ]; then
echo "openpkg:WARNING: skipping creation of OpenPKG $class user $usr" 1>&2
echo "openpkg:WARNING: (would require root-privileges)" 1>&2
else
# add entry to passwd database
realname="${prefix} OpenPKG ($class)"
case "$plid" in
FreeBSD/* | NetBSD/* )
file=/etc/master.passwd
entry="${usr}:*:${uid}:${gid}::0:0:${realname}:${prefix}:${shell}"
update="(PATH=\$PATH:/usr/sbin; pwd_mkdb -p /etc/master.passwd)"
;;
Linux/* )
file=/etc/passwd
entry="${usr}:*:${uid}:${gid}:${realname}:${prefix}:${shell}"
update="(PATH=\$PATH:/usr/sbin; pwconv)"
;;
SunOS/5.* | UnixWare/* )
file=/etc/passwd
entry="${usr}:*:${uid}:${gid}:${realname}:${prefix}:${shell}"
update="(PATH=\$PATH:/usr/sbin; pwconv)"
;;
AIX/* )
# intentionally do nothing here
:
;;
OSF1/V5.* )
file=/etc/passwd
entry="${usr}:*:${uid}:${gid}:${realname}:${prefix}:${shell}"
update="(PATH=\$PATH:/usr/sbin; mkpasswd /etc/passwd)"
;;
HP-UX/* )
file=/etc/passwd
entry="${usr}:*:${uid}:${gid}:${realname}:${prefix}:${shell}"
update=":"
;;
Darwin/* )
# intentionally do nothing here
:
;;
IRIX*/6.* )
file=/etc/passwd
entry="${usr}:*:${uid}:${gid}:${realname}:${prefix}:${shell}"
if [ -f /etc/shadow ]
then update="(PATH=\$PATH:/sbin; pwconv)"
else update=":"
fi
;;
esac
case "$plid" in
Darwin/* )
niutil -create . "/users/${usr}"
niutil -createprop . "/users/${usr}" passwd "*"
niutil -createprop . "/users/${usr}" uid "${uid}"
niutil -createprop . "/users/${usr}" gid "${gid}"
niutil -createprop . "/users/${usr}" realname "${realname}"
niutil -createprop . "/users/${usr}" home "${prefix}"
niutil -createprop . "/users/${usr}" shell "${shell}"
;;
AIX/* )
mkuser id="${uid}" gecos="${realname}" home="${prefix}" "${usr}"
cp /etc/security/login.cfg /etc/security/login.cfg.bak && \
sed -e "/^usw:/,/^[^ ]/s;\\( *shells =.*\\) *\$;\\1,$shell;" \
/etc/security/login.cfg && \
rm -f /etc/security/login.cfg.bak >/dev/null 2>&1
# defer both the setting of the primary group and the shell,
# as they do not exist at this stage of processing.
echo "chuser pgrp=\"${grp}\" \"${usr}\"" >>${prefix}.pre-group-process.sh
echo "chuser shell=\"${shell}\" \"${usr}\"" >>${prefix}.pre-post-process.sh
;;
* )
cp $file $file.bak && \
(grep -v '^+:' $file.bak; echo $entry; grep '^+:' $file.bak) >$file
rm -f $file.bak >/dev/null 2>&1
eval $update
[ $? -ne 0 ] && exit $?
;;
esac
fi
fi
# check whether group already exists
exists=`(getent group "$grp"; \
grep "^$grp:" /etc/group; \
ypmatch "$grp" group; \
nismatch "$grp" group; \
nidump group . | grep "^$grp:") 2>/dev/null | \
sed -e 'q'`
if [ ".$exists" = . ]; then
if [ ".$cusr" != ".root" ]; then
echo "openpkg:WARNING: skipping creation of OpenPKG $class group $grp" 1>&2
echo "openpkg:WARNING: (would require root-privileges)" 1>&2
else
case "$plid" in
Darwin/* )
niutil -create . "/groups/${grp}"
niutil -createprop . "/groups/${grp}" gid "${gid}"
niutil -createprop . "/groups/${grp}" users "${usr}"
;;
AIX/* )
mkgroup id="${gid}" users="${usr}" "${grp}"
;;
* )
# add entry to group database
file=/etc/group
entry="${grp}:*:${gid}:${usr}"
cp $file $file.bak && \
(grep -v '^+:' $file.bak; echo $entry; grep '^+:' $file.bak) >$file
rm -f $file.bak >/dev/null 2>&1
;;
esac
fi
fi
done
# optional group processing (deferred adjustment of primary group)
if [ -f ${prefix}.pre-group-process.sh ]; then
sh ${prefix}.pre-group-process.sh
rm -f ${prefix}.pre-group-process.sh
fi
# invalidate passwd and group tables from Name Service Cache Daemon to
# ensure chown/chgrp works immediately after pwconv on Linux and Solaris
if [ -x /usr/sbin/nscd ]; then
/usr/sbin/nscd -i passwd >/dev/null 2>&1 || true
/usr/sbin/nscd -i group >/dev/null 2>&1 || true
fi
# create the startup/shutdown transfer script
name=`echo "$prefix" | sed -e 's;/;;g'`
if [ ".$cusr" != ".root" ]; then
echo "openpkg:WARNING: skipping creation of system run-command hooks" 1>&2
echo "openpkg:WARNING: (would require root-privileges)" 1>&2
else
case "$plid" in
FreeBSD/4.* )
if [ ! -f /etc/rc.d/${name}.sh ]; then
# make sure /etc/rc.d exists
if [ ! -d /etc/rc.d ]; then
mkdir /etc/rc.d
fi
# make sure /etc/rc.d is activated
( . /etc/defaults/rc.conf
. /etc/rc.conf
found=0
for p in ${local_startup-x}; do
if [ ".$p" = "./etc/rc.d" ]; then
found=1
break
fi
done
if [ ".$found" = .0 ]; then
cp -p /etc/rc.conf /etc/rc.conf.bak
( grep -v local_startup /etc/rc.conf.bak
echo "local_startup=\"/etc/rc.d $local_startup\""
) >/etc/rc.conf
rm -f /etc/rc.conf.bak >/dev/null 2>&1
fi
) || exit $?
# install transfer script
rm -f /etc/rc.d/${name}.sh >/dev/null 2>&1
( echo "#!/bin/sh"
echo "##"
echo "## ${name}.sh -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >/etc/rc.d/${name}.sh
chmod 755 /etc/rc.d/${name}.sh
fi
;;
FreeBSD/* )
if [ -f /etc/rc.d/${name}.sh ]; then
# remove old transfer script (for upgrading from FreeBSD 4 only)
rm -f /etc/rc.d/${name}.sh >/dev/null 2>&1
fi
if [ ! -f /etc/rc.d/openpkg-${name} ]; then
# install transfer script
rm -f /etc/rc.d/openpkg-${name} >/dev/null 2>&1
( echo "#!/bin/sh"
echo "##"
echo "## openpkg-${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "# PROVIDE: openpkg-${name}"
echo "# REQUIRE: LOGIN"
echo "# KEYWORD: shutdown"
echo ""
echo ". /etc/rc.subr"
echo ""
echo "name=\"openpkg_${name}\""
echo "start_cmd=\"openpkg_rc_all start\""
echo "stop_cmd=\"openpkg_rc_all stop\""
echo "restart_cmd=\"openpkg_rc_all stop start\""
echo ""
echo "openpkg_rc_all () {"
echo " if [ -f ${prefix}/etc/rc ]; then"
echo " ${prefix}/etc/rc all \"\$@\""
echo " fi"
echo "}"
echo ""
echo "load_rc_config \$name"
echo "run_rc_command \"\$1\""
echo ""
) >/etc/rc.d/openpkg-${name}
chmod 755 /etc/rc.d/openpkg-${name}
fi
;;
NetBSD/* )
if [ ! -f /etc/rc.d/${name} ]; then
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo "## PROVIDE: ${name}"
echo "## REQUIRE: DAEMON LOGIN NETWORK SERVERS"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo " restart ) exec ${prefix}/etc/rc all stop start ;;"
echo " status ) ;;"
echo "esac"
) >/etc/rc.d/${name}
chmod 755 /etc/rc.d/${name}
fi
;;
Linux/* )
if [ -f /etc/gentoo-release ]; then
if [ ! -f /etc/init.d/openpkg-${name} ]; then
# install transfer script
( echo "#!/sbin/runscript"
echo "##"
echo "## openpkg-${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "depend() {"
echo " after *"
echo "}"
echo ""
echo "checkconfig() {"
echo " [ -f ${prefix}/etc/rc ] || return 1"
echo " case $1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo " esac"
echo "}"
echo ""
echo "start() {"
echo " checkconfig || return 1"
echo " ebegin "Starting OpenPKG ${prefix} hierarchy""
echo " exec ${prefix}/etc/rc all start"
echo " eend 0"
echo "}"
echo ""
echo "stop() {"
echo " checkconfig || return 1"
echo " ebegin "Stopping OpenPKG ${prefix} hierarchy""
echo " exec ${prefix}/etc/rc all stop"
echo " eend 0"
echo "}"
) >/etc/init.d/openpkg-${name}
chmod 755 /etc/init.d/openpkg-${name}
/sbin/rc-update add openpkg-${name} default
fi
else
# sroot: script root directory
# lroot: link root directory
if [ -f /etc/debian_version ]; then
sroot=/etc/init.d
lroot=/etc/rc%d.d
elif [ -f /etc/redhat-release -o -f /etc/mandrake-release ]; then
sroot=/etc/rc.d/init.d
lroot=/etc/rc.d/rc%d.d
elif [ -f /etc/SuSE-release ]; then
sroot=/etc/init.d
lroot=/etc/init.d/rc%d.d
elif [ -f /etc/slackware-version ]; then
sroot=/etc/rc.d
lroot=/etc/rc.d/rc%d.d
name="rc.${name}"
for i in 0 1 2 3 4 5 6; do
l=`echo $lroot | sed -e "s;%d;$i;"`
if [ ! -d $l ]; then
mkdir $l 2>&1 || true
fi
done
else
echo "WARNING: you are not running one of the supported standard" 1>&2
echo "WARNING: Linux platforms (Debian, RedHat, Mandrake, SuSE, Gentoo)." 1>&2
echo "WARNING: Guessing the location of the system init scripts!" 1>&2
sroot=""
lroot=""
for sr in /etc/rc.d/init.d /etc/init.d /sbin/init.d; do
if [ -d $sr ]; then
sroot="$sr"
break
fi
done
for lr in /etc/rc.d/rc2.d /etc/rc2.d /sbin/init.d/rc2.d; do
if [ -d $lr ]; then
lroot="`echo $lr | sed -e 's;2;%d;'`"
break
fi
done
if [ ".$sroot" = . -o ".$lroot" = . ]; then
echo "ERROR: Failed to guess the location of the system init scripts!" 1>&2
exit 1
fi
fi
if [ ! -f $sroot/${name} ]; then
# install transfer script
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >$sroot/${name}
chmod 755 $sroot/${name}
# create corresponding symbolic links
for i in 2 3 4 5; do
ln -s $sroot/${name} `echo $lroot | sed -e "s;%d;$i;"`/S99${name}
done
for i in 0 1 6; do
ln -s $sroot/${name} `echo $lroot | sed -e "s;%d;$i;"`/K00${name}
done
fi
fi
;;
SunOS/5.* )
if [ ! -f /etc/init.d/${name} ]; then
# install transfer script
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >/etc/init.d/${name}
chmod 755 /etc/init.d/${name}
# create corresponding symbolic links
( cd /etc
ln init.d/${name} rc3.d/S99${name}
ln init.d/${name} rc0.d/K00${name}
ln init.d/${name} rc1.d/K00${name}
) || exit $?
fi
;;
UnixWare/* )
if [ ! -f /etc/init.d/${name} ]; then
# install transfer script
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >/etc/init.d/${name}
chmod 755 /etc/init.d/${name}
# create corresponding symbolic links
( cd /etc
ln init.d/${name} rc2.d/S99${name}
ln init.d/${name} rc0.d/K00${name}
ln init.d/${name} rc1.d/K00${name}
) || exit $?
fi
;;
AIX/* )
if [ ! -f /etc/init.d/${name} ]; then
# install transfer script
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >/etc/init.d/${name}
chmod 755 /etc/init.d/${name}
# create corresponding symbolic links
( cd /etc/rc.d
ln -s ../../init.d/${name} rc2.d/S99${name}
) || exit $?
fi
;;
OSF1/V5.* )
if [ ! -f /sbin/init.d/${name} ]; then
# install transfer script
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >/sbin/init.d/${name}
chmod 755 /sbin/init.d/${name}
# create corresponding symbolic links
( cd /sbin
ln -s ../init.d/${name} rc3.d/S99${name}
ln -s ../init.d/${name} rc0.d/K00${name}
) || exit $?
fi
;;
HP-UX/* )
if [ ! -f /sbin/init.d/${name} ]; then
# install transfer script
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >/sbin/init.d/${name}
chmod 755 /sbin/init.d/${name}
# create corresponding symbolic links
( cd /sbin
ln -s ../init.d/${name} rc2.d/S900${name}
ln -s ../init.d/${name} rc1.d/K100${name}
) || exit $?
fi
;;
Darwin/* )
darwin_rc_dir="/System/Library/StartupItems/${name}"
if [ ! -d ${darwin_rc_dir} ]; then
mkdir ${darwin_rc_dir}
fi
# make sure hierarchy is activated in /etc/hostconfig
# FIXME: cs: simple and bad code here without any detection of existing entries
echo "OPENPKG_${name}=-YES-" >>/etc/hostconfig
# install transfer script
if [ ! -f ${darwin_rc_dir}/${name} ]; then
rm -f ${darwin_rc_dir}/${name} >/dev/null 2>&1
( echo "#!/bin/sh"
echo "##"
echo "## ${darwin_rc_dir}/${name}"
echo "## -- startup transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo ""
echo ". /etc/rc.common"
echo ""
echo "if [ \"\${OPENPKG_${name}:=-NO-}\" = \"-YES-\" ]; then"
echo " ConsoleMessage \"OpenPKG ${prefix} hierarchy\""
echo " ${prefix}/etc/rc all start"
echo "fi"
) >${darwin_rc_dir}/${name}
chmod 755 ${darwin_rc_dir}/${name}
fi
# install startup parameter list
if [ ! -f ${darwin_rc_dir}/StartupParameters.plist ]; then
rm -f ${darwin_rc_dir}/StartupParameters.plist >/dev/null 2>&1
( echo "{"
echo " Description = \"OpenPKG ${prefix} hierarchy\";"
echo " Provides = (\"OpenPKG ${prefix}\");"
echo " Requires = (\"Disks\", \"Network Configuration\", \"Resolver\");"
echo " Uses = (\"Cron\");"
echo " OrderPreference = \"Last\";"
echo " Messages ="
echo " {"
echo " start = \"Starting OpenPKG ${prefix} hierarchy\";"
echo " stop = \"Stopping OpenPKG ${prefix} hierarchy\";"
echo " };"
echo "}"
) >${darwin_rc_dir}/StartupParameters.plist
chmod 644 ${darwin_rc_dir}/StartupParameters.plist
fi
;;
IRIX*/6.* )
if [ ! -f /etc/init.d/${name} ]; then
# install transfer script
( echo "#!/bin/sh"
echo "##"
echo "## ${name} -- startup/shutdown transfer script for OpenPKG ${prefix} hierarchy"
echo "##"
echo ""
echo "[ ! -f ${prefix}/etc/rc ] && exit 0"
echo "case \$1 in"
echo " start ) exec ${prefix}/etc/rc all start ;;"
echo " stop ) exec ${prefix}/etc/rc all stop ;;"
echo "esac"
) >/etc/init.d/${name}
chmod 755 /etc/init.d/${name}
# create corresponding links
( cd /etc
ln -f init.d/${name} rc2.d/S99${name}
ln -f init.d/${name} rc0.d/K00${name}
) || exit $?
fi
;;
esac
fi
# create the cron transfer entries
if [ ".$cusr" != ".root" ]; then
echo "openpkg:WARNING: skipping creation of system cron hooks" 1>&2
echo "openpkg:WARNING: (would require root-privileges)" 1>&2
else
case "$plid" in
FreeBSD/* | Linux/* | Darwin/* )
if [ -f /etc/slackware-version ]; then
exists=`crontab -l | grep "$prefix/etc/rc"`
if [ ".$exists" = . ]; then
EDITOR=/tmp/vipw.$$
VISUAL="$EDITOR"
export EDITOR
export VISUAL
( echo "#!/bin/sh"
echo "( echo \"# \""
echo " echo \"# chronological tasks of ${prefix} OpenPKG hierarchy\""
echo " echo \"0 0 1 * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly\""
echo " echo \"0 0 * * 0 [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly\""
echo " echo \"0 0 * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily\""
echo " echo \"0 * * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly\""
echo " echo \"0,15,30,45 * * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly\""
echo " echo \"# \""
echo ") >>\$1"
) >$EDITOR
chmod a+x $EDITOR
( PATH="$PATH:/usr/bin"; crontab -e ) || exit $?
rm -f $EDITOR
fi
else
exists=`grep "$prefix/etc/rc" /etc/crontab`
if [ ".$exists" = . ]; then
( echo "# "
echo "# chronological tasks of ${prefix} OpenPKG hierarchy"
echo "0 0 1 * * root [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly"
echo "0 0 * * 0 root [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly"
echo "0 0 * * * root [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily"
echo "0 * * * * root [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly"
echo "*/15 * * * * root [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly"
echo "# "
) >>/etc/crontab
fi
fi
;;
SunOS/5.* | OSF1/V5.* | NetBSD/* | HP-UX/* | UnixWare/* | AIX/* )
exists=`crontab -l | grep "$prefix/etc/rc"`
if [ ".$exists" = . ]; then
EDITOR=/tmp/vipw.$$
VISUAL="$EDITOR"
export EDITOR
export VISUAL
( echo "#!/bin/sh"
echo "( echo \"# \""
echo " echo \"# chronological tasks of ${prefix} OpenPKG hierarchy\""
echo " echo \"0 0 1 * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly\""
echo " echo \"0 0 * * 0 [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly\""
echo " echo \"0 0 * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily\""
echo " echo \"0 * * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly\""
echo " echo \"0,15,30,45 * * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly\""
echo " echo \"# \""
echo ") >>\$1"
) >$EDITOR
chmod a+x $EDITOR
( PATH="$PATH:/usr/bin"; crontab -e ) || exit $?
rm -f $EDITOR
fi
;;
IRIX*/6.* )
exists=`crontab -l | grep "$prefix/etc/rc"`
if [ ".$exists" = . ]; then
( crontab -l
echo "# "
echo "# chronological tasks of ${prefix} OpenPKG hierarchy"
echo "0 0 1 * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all monthly"
echo "0 0 * * 0 [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all weekly"
echo "0 0 * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all daily"
echo "0 * * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all hourly"
echo "0,15,30,45 * * * * [ -f ${prefix}/etc/rc ] && ${prefix}/etc/rc all quarterly"
echo "# "
) | /usr/bin/crontab || exit $?
fi
;;
esac
fi
# remember what OpenPKG RPM version was installed, so we can
# correctly upgrade the RPM database in the %post section (see below).
if [ -d ${prefix}/RPM/DB ]; then
if [ -x "${prefix}/bin/openpkg" -a -x "${prefix}/libexec/openpkg/rpm" ]; then
# OpenPKG 2.0
rpm="${prefix}/bin/openpkg rpm"
else
# OpenPKG 1.x
rpm="${prefix}/bin/rpm"
fi
rm -f ${prefix}/RPM/DB/.version >/dev/null 2>&1 || true
$rpm --version |\
sed -e 's;^;X;' \
-e 's;^X[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$;\1;' \
-e 's;^X[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;' \
-e 's;^X.*$;4.0;' \
>${prefix}/RPM/DB/.version
fi
# ---- END EMBEDDED %pre SCRIPT ----
# make sure prefix/root directory exists
# and has correct permissions and owner/group
if [ ! -d $l_prefix ]; then
# create prefix/root directory from scratch
echo "++ creating OpenPKG instance root directory \"$l_prefix\""
d=''
for c in `IFS=/; echo $l_prefix`; do
d="$d/$c"
if [ ! -d $d ]; then
mkdir $d || exit 1
chmod 755 $d || exit 1
if [ ".$cusr" = .root ]; then
chown $musr $d >/dev/null 2>&1 || true
chgrp $mgrp $d >/dev/null 2>&1 || true
fi
fi
done
else
# adjust already existing prefix/root directory
echo "++ fixating OpenPKG instance root directory \"$l_prefix\""
( cd $l_prefix || exit 1
chmod 755 . || exit 1
if [ ".$cusr" = .root ]; then
chown $musr . >/dev/null 2>&1 || true
chgrp $mgrp . >/dev/null 2>&1 || true
fi
) || exit 1
fi
# extract and install binary distribution files
echo "++ extracting OpenPKG binary distribution"
dd if=$l_me bs=8192 skip=8 2>/dev/null |\
(cd $l_prefix; tar xf - 2>/dev/null)
echo "++ installing OpenPKG binary distribution"
( cd $l_prefix || exit 1
./openpkg.bzip2 -d -c openpkg.tar.bz2 | ./openpkg.tar xf - 2>/dev/null
rm -f openpkg.tar openpkg.bzip2 openpkg.tar.bz2 >/dev/null 2>&1 || true
) || exit 1
# fixate installation files
# (ATTENTION: order of chgrp/chown and chmod is important because of "set-UID" bits)
echo "++ fixating OpenPKG instance filesystem hierarchy"
( echo 'fixate () {'
echo ' chgrp "$3" "$4"'
echo ' chown "$2" "$4"'
echo ' chmod "$1" "$4"'
echo '}'
$l_prefix/bin/openpkg --keep-privileges rpm -q openpkg \
--qf '[fixate %7.7{FILEMODES:octal} %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} ::%{FILENAMES:shescape}\n]' |\
grep -v '(none)' | sed 's/^fixate .../fixate /' | sed -e "s; ::\\(.\\)/kolab; \\1$l_prefix;"
) | sh 2>/dev/null || true
# running the embedded %post script
echo "++ post-processing OpenPKG bootstrap installation"
prefix="$l_prefix"
susr='root'; sgrp='root'
musr='kolab'; mgrp='kolab'
rusr='kolab-r'; rgrp='kolab-r'
nusr='kolab-n'; ngrp='kolab-n'
suid=''; sgid=''
muid='19414'; mgid='19414'
ruid='19415'; rgid='19415'
nuid='19416'; ngid='19416'
set -- 1 # emulate RPM's $1 when executing scripts
# ---- BEGIN EMBEDDED %post SCRIPT ----
# optional post-processing from "pre" section
if [ -f ${prefix}.pre-post-process.sh ]; then
sh ${prefix}.pre-post-process.sh
rm -f ${prefix}.pre-post-process.sh
fi
# update or initially create OpenPKG UUID configuration
${prefix}/bin/openpkg uuid update >/dev/null 2>&1 || true
# determine new and old OpenPKG RPM version
V_rpm_new="%{V_rpm}"
if [ -f ${prefix}/RPM/DB/.version ]; then
V_rpm_old="`cat ${prefix}/RPM/DB/.version`"
rm -f ${prefix}/RPM/DB/.version >/dev/null 2>&1 || true
else
V_rpm_old="4.0"
fi
# make sure all RPM database files are present and that their
# attributes are correct, etc. This is not a database rebuild
# operation, so this is fully harmless and can be done always.
${prefix}/lib/openpkg/rpmdb --quiet --fixate
# check RPM database for upgrade requirements
if [ ".$1" = .2 -a ".$V_rpm_old" != ".$V_rpm_new" ]; then
# RPM 4.0/4.1 does not allow concurrent database access, so we
# cannot upgrade the database immediately from here (because
# we are still running within the execution context of the
# old RPM which in turn has the database locked) and instead
# have to just drop a note to the administrator about database
# upgrading. RPM 4.2 in general allows concurrent database
# access, but the whole stuff is too risky here, too.
( echo "You are upgrading the OpenPKG bootstrap from a previous"
echo "RPM $V_rpm_old based version to this RPM $V_rpm_new based"
echo "version. The RPM database in ${prefix}/RPM/DB/ can still"
echo "be used, but it is strongly recommended to upgrade it as"
echo "soon as possible to the latest Berkeley-DB format files by"
echo "executing the command:"
echo " \$ ${prefix}/bin/openpkg rpm --db-rebuild"
echo "In case of problems with the RPM database you can always"
echo "execute the command:"
echo " \$ ${prefix}/bin/openpkg rpm --db-cleanup"
) | ${prefix}/lib/openpkg/rpmtool msg -b -t warn
fi
# system command overriding support
# ATTENTION: THIS BETTER SHOULD BE REPLACED WITH A MORE GENERIC
# BUILD COMMAND OVERRIDE SOLUTION!
if [ ! -d ${prefix}/lib/openpkg/override ]; then
mkdir ${prefix}/lib/openpkg/override >/dev/null 2>&1 || true
fi
chown ${musr}:${mgrp} ${prefix}/lib/openpkg/override >/dev/null 2>&1 || true
case "`cat ${prefix}/etc/openpkg/platform`" in
*-*-debian* | *-*-ubuntu* )
# FIXME: Evil hack to workaround build problems under Debian
# (at least 3.1) (and similar platforms) where a Debian
# install-info(8) exists which is both API and functionally
# incompatible to the de-facto standardized install-info(8)
# command from GNU Texinfo.
if [ ! -f ${prefix}/lib/openpkg/override/install-info ]; then
( echo "#!/bin/sh"
echo "echo 'OpenPKG: NOTICE: install-info(8) command execution overridden'"
echo "exit 0"
) >${prefix}/lib/openpkg/override/install-info
chmod 775 ${prefix}/lib/openpkg/override/install-info
fi
;;
*-*-macosx* | *-*-darwin* )
# FIXME: Evil hack to workaround the fact that Mac OS X'
# linker by default prefers the /usr/lib libraries and does
# not honor the -L options the way one would expect it.
gcc="`${prefix}/lib/openpkg/shtool path gcc`"
cc="`${prefix}/lib/openpkg/shtool path cc`"
ld="`${prefix}/lib/openpkg/shtool path ld`"
if [ ".$gcc" != . -a ! -f ${prefix}/lib/openpkg/override/gcc ]; then
( echo "#!/bin/sh"
echo "case \" \$* \" in"
echo " *\" -c \"* | *\" -E \"* ) exec $gcc \"\$@\" ;;"
echo " * ) exec $gcc -Wl,-search_paths_first \"\$@\" ;;"
echo "esac"
) >${prefix}/lib/openpkg/override/gcc
chmod 775 ${prefix}/lib/openpkg/override/gcc
fi
if [ ".$cc" != . -a ! -f ${prefix}/lib/openpkg/override/cc ]; then
( echo "#!/bin/sh"
echo "case \" \$* \" in"
echo " *\" -c \"* | *\" -E \"* ) exec $gcc \"\$@\" ;;"
echo " * ) exec $cc -Wl,-search_paths_first \"\$@\" ;;"
echo "esac"
) >${prefix}/lib/openpkg/override/cc
chmod 775 ${prefix}/lib/openpkg/override/cc
fi
if [ ".$ld" != . -a ! -f ${prefix}/lib/openpkg/override/ld ]; then
( echo "#!/bin/sh"
echo "exec $ld -search_paths_first \"\$@\""
) >${prefix}/lib/openpkg/override/ld
chmod 775 ${prefix}/lib/openpkg/override/ld
fi
;;
esac
# FIXME: hack to workaround problems in environments with too few
# development tools. ATTENTION: see one paragraph above.
if [ ! -d ${prefix}/lib/openpkg/fallback ]; then
mkdir ${prefix}/lib/openpkg/fallback >/dev/null 2>&1 || true
fi
chown ${musr}:${mgrp} ${prefix}/lib/openpkg/fallback >/dev/null 2>&1 || true
# check for "openpkg" executable from the OpenPKG Community series
# print license if not OSS, otherwise register with openpkg.org
community_version=`${prefix}/bin/openpkg --license 2>/dev/null | \
sed -e 'q' | egrep '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*-C'`
if [ ".$community_version" = . ]; then
( echo ""
echo "NOTICE: This OpenPKG bootstrap package is based on an \"openpkg\""
echo "executable which is covered by the following terms of use:"
echo "______________________________________________________________________________"
echo ""
${prefix}/bin/openpkg --license | sed -e '1d'
) | ${prefix}/lib/openpkg/rpmtool msg -b -t notice
else
${prefix}/bin/openpkg register /dev/null 2>&1 || true
fi
# ---- END EMBEDDED %post SCRIPT ----
# display final information
( echo "Congratulations!"
echo ""
echo "You have successfully installed an OpenPKG ${l_release} instance"
echo "under prefix ${l_prefix} on target platform ${l_platform}."
echo ""
echo "For details about this OpenPKG instance, run any of the"
echo "following typical OpenPKG RPM query commands:"
echo ""
echo " \$ ${l_prefix}/bin/openpkg rpm -qa"
echo " \$ ${l_prefix}/bin/openpkg rpm -qi openpkg"
echo " \$ ${l_prefix}/bin/openpkg rpm -qlv openpkg"
echo ""
echo "To check the integrity of the entire OpenPKG instance,"
echo "run the following OpenPKG RPM verify command:"
echo ""
echo " \$ ${l_prefix}/bin/openpkg rpm -Va"
echo ""
echo "To install software packages into this OpenPKG instance, run"
echo "the following two OpenPKG RPM build commands for each package:"
echo ""
echo " \$ ${l_prefix}/bin/openpkg rpm --rebuild /path/to/foo-*.src.rpm"
echo " \$ ${l_prefix}/bin/openpkg rpm -Uvh ${l_prefix}/RPM/PKG/foo-*.rpm"
echo ""
echo "To remove a software package later, just run:"
echo ""
echo " \$ ${l_prefix}/bin/openpkg rpm -e foo"
echo ""
echo "To remove the whole OpenPKG instance under prefix ${l_prefix},"
echo "just remove every package as shown above. As you finally"
echo "remove the package \"openpkg\", the OpenPKG instance itself"
echo "will be unlinked from the system and removed as well."
echo ""
echo "Thank you for flying OpenPKG..."
echo " Ralf S. Engelschall"
echo " The OpenPKG Project"
echo " openpkg@openpkg.org"
) | $l_prefix/lib/openpkg/rpmtool msg -b -t info
# die explicitly just before the shell would discover
# that we carry mega-bytes of data with us... ;-)
exit 0
# the distribution tarball is appended in raw format directly to the
# end of this script, just leaded by padding whitespaces which make
# sure that the tarball data starts at the pre-defined offset of 64KB.
# This allows us to unpack the tarball by just skipping the leading
# 64KB (= 8192*8, see above).
openpkg.tar 0000755 0000000 0000000 00000705564 10632213446 011754 0 ustar root root ELF p4 < 4 ( 4 44 4 44 Y Y ` ` H HH PtdX , , Qtd /lib/ld-linux.so.2 GNU m ] - V
_ 8 S ~ } { J l K r ; W 2 b Y M e H B g = x d v c Z w R U [ ` ^ : ) t &