Skip to content

Instantly share code, notes, and snippets.

@mauricioprado00
Last active November 4, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioprado00/d96c5c2947a62042bac8f49ae8ea13f1 to your computer and use it in GitHub Desktop.
Save mauricioprado00/d96c5c2947a62042bac8f49ae8ea13f1 to your computer and use it in GitHub Desktop.
pull debian package (or ubuntu, or whatever)
# obtains debian packages
# Examples:
# gimp on current directory from debian 6
# curl -L https://goo.gl/jruRgy | bash -s gimp
# gimp on directory gimp-install-dir
# curl -L https://goo.gl/jruRgy | bash -s gimp gimp-install-dir
# only partial package of gimp (/usr/bin)
# curl -L https://goo.gl/jruRgy | bash -s gimp gimp-install-dir ./usr/bin/
# only partial package of gimp (/usr/bin /usr/lib)
# curl -L https://goo.gl/jruRgy | bash -s gimp gimp-install-dir './usr/bin/ ./usr/lib/'
# firefox from linux mint sonya (upstream package)
# curl -L https://goo.gl/jruRgy | bash -s firefox firefox-from-mint '' http://packages.linuxmint.com/ sonya '' upstream/binary
# gimp from ubuntu xenial
# curl -L https://goo.gl/jruRgy | bash -s gimp gimp-from-xenial '' http://archive.ubuntu.com/ubuntu xenial '' universe
package=${1}
target_dir=${2:-.}
files=${3} # ./usr/sbin/debootstrap
if [ -z "${package}" ]; then
package=debootstrap
files=./usr/sbin/debootstrap
fi
distro_url=${4:-http://archive.debian.org/debian}
branch=${5:-Debian-6.0}
arch=${6:-i386}
content_filter=${7:-main/binary}
branch_url="${distro_url}/dists/${branch}"
release_url="${branch_url}/Release"
# obtain release content from distro
release_contents=$(curl ${release_url} | egrep 'Packages' | grep ${arch} | grep ${content_filter})
valid_packages_url=''
# main upstream import backport romeo universe multiverse
# check valid provided url for packages
while read -r release_content; do
packages_url=$(set -- ${release_content}; echo $3)
http_code=$(curl --silent --output /dev/null --head --write-out %{http_code} ${branch_url}/${packages_url})
if [ "${http_code}" -ne '200' ]; then
"non reachable ${branch_url}/${packages_url}"
else
valid_packages_url=${packages_url}
break
fi
done <<< "$release_contents"
if [ -z "${valid_packages_url}" ]; then
echo "could not obtain packages url for ${arch} branch ${branch} from distribution ${distro_url}" 1>&2
exit 1
fi
echo "Found packages ${valid_packages_url}"
# retrieve and extract package list
decompress='cat --'
if [[ ${valid_packages_url} =~ .bz2$ ]]; then
decompress='bzip2 -d'
elif [[ ${valid_packages_url} =~ .gz ]]; then
decompress='gunzip'
fi
packages=$(curl ${branch_url}/${packages_url} | ${decompress})
# look for requested package
filename=$(cat <<PACKAGES | egrep -A20 '^Package: '$(echo $package | sed 's/[]\.|$(){}?+*^]/\\&/g')'$' | grep '^Filename' | head -n1
${packages}
PACKAGES
)
set -- $filename
filename=$2
if [ -z "${filename}" ]; then
echo "could not find package ${package}" 1>&2
exit 2
fi
echo "Found package ${filename}"
# retrieve and unpackage
mkdir -p ${target_dir}/temp >/dev/null 2>&1
pushd ${target_dir}/temp
curl ${distro_url}/${filename} > package.deb
ar x package.deb
echo 'Package content: '
find . -type f | sed 's#^# > #g'
cd ..
tar -xvf temp/data.tar.* ${files}
if [ $? -ne 0 ]; then
echo "could not extract specified files from package ($files)" 1>&2
echo "actual content of package: " 1>&2
tar -tf temp/data.tar.* | sed 's#^# > #g' 1>&2
fi
rm -Rf temp
cat <<PACKAGES > packages
${packages}
PACKAGES
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment