Skip to content

Instantly share code, notes, and snippets.

@fasheng
Last active August 29, 2015 14:02
Show Gist options
  • Save fasheng/7038d3e78479c2e679d2 to your computer and use it in GitHub Desktop.
Save fasheng/7038d3e78479c2e679d2 to your computer and use it in GitHub Desktop.
Get debian package information through parsing Sources.gz
#!/bin/bash
_pkgsite="http://packages.linuxdeepin.com"
pkgsite="${_pkgsite}/deepin"
deepin_debian_source="${pkgsite}/dists/trusty/main/source/Sources.gz"
tmp_source_file="/tmp/sources"
download_debian_source() {
curl --retry 3 --retry-delay 3 -o "${tmp_source_file}".gz "${deepin_debian_source}"
gunzip -f "${tmp_source_file}".gz
}
grep_block() {
local keyword="$1"; shift
local files=$@
awk -v keyword="${keyword}" 'BEGIN{RS="\n\n"} $0 ~ keyword{print ""; print; n++}' $files
}
# $pkg_version, $pkg_directory, $pkg_sha256sum
get_pkg_info() {
local pkgname=$1
pkg_info=$(grep_block "Package: ${pkgname}" "${tmp_source_file}")
pkg_version=$(echo "$pkg_info" | grep -m1 "^Version:" | awk '{print $2}')
pkg_directory=$(echo "$pkg_info" | grep -m1 "^Directory:" | awk '{print $2}')
pkg_file="${pkgname}_${pkg_version}.tar.gz"
pkg_fileurl="${pkgsite}/${pkg_directory}/${pkg_file}"
pkg_sha256sum=$(echo "$pkg_info" | awk 'BEGIN{RS="Checksums-Sha256:"}{if(NR==2){print}}' | grep "${pkg_file}" | awk '{print $1}')
# fix package version
pkg_version_fixed="${pkg_version%~*}"
pkg_version_fixed="${pkg_version_fixed/-/_}"
echo "pkg_version: ${pkg_version}"
echo "pkg_version_fixed: ${pkg_version_fixed}"
echo "pkg_directory: ${pkg_directory}"
echo "pkg_file: ${pkg_file}"
echo "pkg_fileurl: ${pkg_fileurl}"
echo "pkg_sha256sum: ${pkg_sha256sum}"
}
download_debian_source
get_pkg_info "$1"
@fasheng
Copy link
Author

fasheng commented Jul 1, 2014

Run get_debian_package_info startdde will print:

pkg_version: 0.1-20140624165058~1d45d395a1
pkg_version_fixed: 0.1_20140624165058
pkg_directory: pool/main/s/startdde
pkg_file: startdde_0.1-20140624165058~1d45d395a1.tar.gz
pkg_fileurl: http://packages.linuxdeepin.com/deepin/pool/main/s/startdde/startdde_0.1-20140624165058~1d45d395a1.tar.gz
pkg_sha256sum: 3704d86de79074a4146d65cab17b062a080af472d6f9ee262f9a06c6b8ef6efe

Full example to see https://github.com/fasheng/arch-deepin/blob/master/aur/update.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment