Last active
August 29, 2015 14:02
-
-
Save fasheng/7038d3e78479c2e679d2 to your computer and use it in GitHub Desktop.
Get debian package information through parsing Sources.gz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
get_debian_package_info startdde
will print:Full example to see https://github.com/fasheng/arch-deepin/blob/master/aur/update.sh