#Goal: a command that gets you to the source code for any binary on a fedora system.
#example: /cfg/fedora_yum_edit_source_for_command.sh /bin/hostname
#broken example: //cfg/fedora_yum_edit_source_for_command.sh usr/libexec/postfix/smtp
#(broken due to the "2:" appended to the package name by yum whatprovedes)
#sequence of scripts from the lowest level up:
##################
#File: /cfg/text_run_command_and_force_wide_output.expect
##################
#!/usr/bin/expect -f
#this is necessary because yum detects if you are piping it's output and wraps to 80 lines... making it hard to match a line beacuse the description of long enough caused a extra newline
spawn {*}$argv
expect
##################
#File: /cfg/fedora_yum_whatprovides.sh
##################
#!/bin/sh
/cfg/text_run_command_and_force_wide_output.expect yum whatprovides "${1}"
##################
#File: /cfg/fedora_yum_edit_source_for_command.sh
##################
#!/bin/sh
apppath="${1}"
ls -alh "${apppath}"
test -e "${apppath}" || exit 1
package=$(/cfg/fedora_yum_whatprovides.sh "${1}" | /cfg/text_match_previous_line.sh 'Repo :' | head -n 1 | cut -d ':' -f 1 | cut -d ' ' -f 1)
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 .