[go: up one dir, main page]

Menu

[r6]: / trunk / file.repmod  Maximize  Restore  History

Download this file

55 lines (47 with data), 1.2 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 the Packages.sha1.gz
# VERBOSE is a global flag.
rep_init() {
	PKGS_FILE=`echo "$PKGS_URL" | sed 's=^.*:/*=/='`
	PKGFILES_PATH=`dirname $PKGS_FILE`
	if [ ! -f $PKGS_FILE ] ; then
		eecho "$PKGS_FILE not found. Aborting."
		exit 1
	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() {
	[ -z "$KEEP_CACHE" ] && rm -f $APK_CACHE/Packages.sha1.gz
}