######### #File: /cfg/fedora_yum_edit_source_for_command.sh ######### #!/bin/sh apppath="${1}" #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:" (a epoch) appended to the package name by "yum whatprovedes") # another broken example: # /cfg/fedora_yum_edit_source_for_command.sh /bin/rvi # working example: /bin/hostname # /cfg/fedora_yum_edit_source_for_command.sh /bin/hostname ls -alh "${apppath}" test -e "${apppath}" || exit 1 #expect is necessary because of a few corner cases where #the package description is longer than 80 col's and yum #detects you are piping it's output and wraps to 80 lines... #making it hard to match a line because there is a extra newline package=$(expect -c "spawn yum whatprovides ${1} ; expect" | awk -v x='Repo :' '$0 ~ x { print ll } { ll = $0}' | 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 . # 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