#!/bin/sh
# This code is in the Public Domain.
apppath="${1}"
# Fedora needs a "view source" command. This is a crude first shot at it.
# I suspect the real solution is to write a pyton module that interacts with yum directly.
# Goal: a command that gets you to the source code for any binary(file?) on a fedora system.
# example: /cfg/fedora_yum_edit_source_for_command.sh /bin/hostname
#almost working, see TODO below
ls -alh "${apppath}"
test -e "${apppath}" || exit 1
package=$(repoquery -qf --qf %{name} "${apppath}")
echo "package=${package}"
test -n "${package}" || exit 1
echo "making first folder"
mkdir "${package}" && cd "${package}" || exit 1
yumdownloader --source "${package}" || exit 1
rpmname=`ls *.src.rpm`
test -n "${rpmname}" || exit 1
echo "making second folder"
mkdir "${rpmname}_dir" || exit 1
cd "${rpmname}_dir" || exit 1
rpm2cpio ../*.src.rpm | cpio -idmv
ls --color -alh .
# TODO:
# Example:
# /cfg/fedora_yum_edit_source_for_command.sh /bin/readlink
#
# after getting the rpm decompressed, we still
# need to decompress (for example coreutils-8.12.tar.xz)
# and open readlink.c
# Example:
# /cfg/fedora_yum_edit_source_for_command.sh /bin/fgrep
# cat grep/grep-2.9-3.fc16.src.rpm_dir/grep.spec | grep xz
# Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz
# we need %{version} to know what file name to decompress
# then... we need to map the binary back to it's source .c file...
# then add the option to import the source tree into eclipse or other IDE
# graph's and cool pictures.