[go: up one dir, main page]

Menu

[r4]: / trunk / apk_add  Maximize  Restore  History

Download this file

155 lines (131 with data), 3.6 kB

#!/bin/sh 

VERSION=0.0.9

# I'd like to implement those:
#
# * -v      Turn on verbose output.
#   -I      If any installation scripts (pre-install or post-install) exist
#           for a given package, do not execute them.
#   -n      Don't actually install a package, just report the steps that
#           would be taken if it was.
#   -r      Use the remote fetching feature.  This will determine the appro-
#           priate objformat and release and then fetch and install the pack-
#           age.


#read the apklib funfctions
. ${APKLIBS:="/lib/apk"}/apkfuncs.sh

install_package() {
	local v pkgfile
	pkgfile=$1
	pkgv=`basename ${pkgfile} .apk`
	listfile=${APKDB}/${pkgv}.list
	preinst=${PKGMETA}/${pkgv}.pre-install
	postinst=${PKGMETA}/${pkgv}.post-install

	if ! all_installed | grep "^$pkgv" > /dev/null ; then
	
		# create file list
		tar -ztf ${pkgfile} > ${listfile}
		opwd=`pwd`
		cd $ROOT

		# install dependencies if needed
		if [ "$rflag" ] ; then
			flags=""
			[ "$vflag" ] && flags=" -v "
			[ "$nflag" ] && flags="$flag -n"
			[ "$Iflag" ] && flags="$flag -I"
			for i in `get_depend ${pkgfile}`; do
				if ! all_installed | grep "^pkgv" > /dev/null
				then
					DEPFOR="(as dependency for $pkgv) "\
						apk_add -r $flags $i	
				fi
			done
		fi

		# verbose output *after* deps are installed
		[ "$vflag" ] || [ "$nflag" ] && echo "installing $pkgv $DEPFOR"
		# look for a .pre-inst file and execute if it exist
		if [ ! "$Iflag" ] && grep $preinst $listfile >/dev/null; then
			[ "$vflag" ] && echo "executing $preinst" >&2
			if [ ! "$nflag" ] ; then
				tar -C ${ROOT} -zpOxf $pkgfile ./$preinst | sh
			fi
		fi

		# unpack the package
		if [ "$nflag" ] ; then
			[ "$vflag" ] && v="-v"
			tar -C ${ROOT} $v -ztf ${pkgfile}
		else
			tar -C ${ROOT} -zxpf ${pkgfile}
			#create sha1 sums
			create_sha1sum $pkgv
			create_config_sha1sum $pkgv
		fi
	
		# run postinstall if it exists
		if [ ! "$Iflag" ] && [ -f $postinst ] ; then
			[ "$vflag" ] && echo "executing $postinst"
			[ ! "$nflag" ] && sh "$postinst"
		fi

		# compress the meta data
		[ ! "$nflag" ] && compress_meta $pkgv
		cd $opwd
	fi
}

eecho() {
	echo "$*" >&2
}

usage() {
	eecho "apk_add $VERSION"
	eecho "usage: apk_add [ -v ] [ PACKAGE [ ...]] | PACKAGE [ ... ]"
	eecho "   -I           If any installation scripts (pre-install or post-install) exist"
	eecho "                for a given package, do not execute them."
	eecho "   -n           Don't actually install a package, just report the steps that"
	eecho "                would be taken if it was."
	eecho "   -v           Turn on verbose output."
	eecho "   -r           Use the remote fetching feature."
#	eecho "   -h           Display this help"
#	echo "   -f PKGFILE   Install packages listed in PKGFILE"

	exit 1
}

#parse args here
unset vflag
unset rflag
unset Iflag
unset nflag
#set -- `getopt hIvrnf: "$@"`
set -- `getopt hIvrn "$@"`
[ $# -lt 1 ] && exit 1	# getopt failed
while [ $# -gt 0 ] ; do
	case "$1" in 
		-h) usage;;
		-v) vflag="on";;
		-r) rflag="on";;
		-I) Iflag="on";;
		-n) nflag="on";;
		--) shift; break;;
		-*) usage;;
		*)  break;;
	esac
	shift
done
		

# create the apkdb dir if it does not exist
mkdir -p ${APKDB}

if [ "$rflag" ] ;then
	 load_repmod
	 rep_init
fi

unset pkglist
while [ $# -gt 0 ] ; do
	if [ "$rflag" ] ; then
		pkglist="$pkglist `rep_fetch_pkg $1`" || exit 1
	else
		if [ -f "$1" ] ; then
			pkglist="$pkglist $1"
		else
			eecho "Cannot find package $1. Aborting."
			exit 1
		fi
	fi
	shift
done

for i in $pkglist ; do
	install_package $i
done

[ "$rflag" ] && rep_cleanup
exit 0