[go: up one dir, main page]

Menu

[r5]: / trunk / cdrom.repmod  Maximize  Restore  History

Download this file

70 lines (62 with data), 1.7 kB

#!/bin/sh

APK_CACHE=${APK_CACHE:-"$ROOT/var/cache/apk"}
PKGS_URL="$APK_PATH/Packages.sha1.gz"
PKGS_FILE="$APK_CACHE/Packages.sha1.gz"

# create the cache dir if it does not exist
mkdir -p $APK_CACHE

# update the repository
# find and install the Packages.sha1.gz
# VERBOSE is a global flag.
rep_init() {
	local pkg mounted_path
	media_mount $PKGS_URL
	mounted_path=`get_mounted_path $PKGS_URL`
	# if no path was returned, something went bad during mount. exit now...
	[ -z "$mounted_path" ] && exit 1
	# path where the verfified packages are
	PKGFILES_PATH=`dirname $mounted_path`
	if [ "$KEEP_CACHE" ] ; then
		#we are keeping the cache so we install the Packages file
		[ "$vflag" ] && eecho "Installing $PKGS_URL"
		cp $mounted_path $PKGS_FILE || exit 1
	else
		# we are not keeping cache so just read the packages file
		# directly from cdrom.
		PKGS_FILE=$mounted_path
		if [ ! -f $PKGS_FILE ] ; then
			eecho "$PKGS_FILE not found. Aborting."
			exit 1
		fi
	fi
}

# Download the package list and return the complete package name available
# parameters: 
#	$1 : package name
rep_find_pkg() {
	local pkg pkgv
	pkg="$1"
	zcat "$PKGS_FILE" | grep " $pkg-[0-9].*" | awk "{print \$2}" | tail -n 1
}

# Return the path to the downloaded file
# Parameters: package 
rep_fetch_pkg() {
	local pkg pkgv pkgpath
	# since we install packages directly from mounted media, just return
	pkg=$1
	pkgv=`rep_find_pkg $pkg`
	if [ -z "$pkgv" ] ; then
		eecho "$pkg not found in $APK_PATH"
		exit 1
	fi
	pkgpath="$PKGFILES_PATH/$pkgv"
	if [ -f "$pkgpath" ] ; then
		echo $pkgpath
	else
		eecho "$pkgpath was not found. Aborting."
		exit 1
	fi
}

rep_cleanup() {
	media_umount $MEDIA
	[ -z "$KEEP_CACHE" ] && rm -f $APK_CACHE/Packages.sha1.gz
}