~dricottone/huttese-apk

9713d0de27d72a4b8a1566f318a9ba17d4a5a885 — Drew DeVault 5 years ago 6a7a82e
pkgkit: fix removal of previous version
1 files changed, 28 insertions(+), 5 deletions(-)

M pkgkit
M pkgkit => pkgkit +28 -5
@@ 161,6 161,24 @@ print_pkgver() {
	echo "$pkgver"
}

mirror_ver() (
	mirror="$1"
	pkg="$2"
	apk policy "$pkg" | while read -r line
	do
		case "$line" in
			*:)
				ver="${line%:}"
				ver="${ver## }"
				;;
			*$mirror*)
				echo "$ver"
				;;
		esac
	done
	echo none
)

upload_pkg() (
	repo="$1"
	pkg="$2"


@@ 169,14 187,19 @@ upload_pkg() (
	path="$remote_path/$repo/$arch"
	ssh "$remote" mkdir -p "$path"

	prev_ver=$(apk search -x "$pkg" | cut -c$((${#pkg}+2))-)
	prev_pkgver=$(printf "%s" "$prev_ver" | cut -d'-' -f1)
	prev_pkgrel=$(printf "%s" "$prev_ver" | cut -d'-' -f2 | cut -d'r' -f2-)
	url=$(echo "$remote" | cut -d@ -f2)
	prev_ver=$(mirror_ver "$url" "$pkg")

	set -x
	if [ "$prev_ver" != "none" ]
	then
		prev_pkgver=$(printf "%s" "$prev_ver" | cut -d'-' -f1)
		prev_pkgrel=$(printf "%s" "$prev_ver" | cut -d'-' -f2 | cut -d'r' -f2-)
		ssh "$remote" rm -f "$path/$pkg-$prev_pkgver-r$prev_pkgrel.apk"
	fi
	pkgver="$(get_pkgvar pkgver)"
	pkgrel="$(get_pkgvar pkgrel)"

	set -x
	ssh "$remote" rm -f "$path/$pkg-$prev_pkgver-r$prev_pkgrel.apk"
	rsync --blocking-io -rsP \
		~/packages/"$repo/$arch/$pkg-$pkgver-r$pkgrel.apk" "$remote":"$path/"
	set +x