rendered paste body#!/bin/sh
# name get-sources.sh
# This script produces a bash script that understand conditionnals
# from a spec file to download the rights sources from a URL
#
# Created May 29 2007
# author kwizart < kwizart at gmail.com >
#
echo -n "Enter your spec file and press [ENTER]: "
read spec_file
if [ -f $spec_file ] ; then
echo $spec_file "ok"
else
echo "Error" $spec_file "was not found from this directory"
exit 1
fi
# Cut out the header of the spec file until BuildRoot
echo "#!/bin/sh" > $spec_file-temp1
echo "cat > $spec_file.get-sources.sh << EOF " >> $spec_file-temp1
echo "#!/bin/sh" >> $spec_file-temp1
cat -s $spec_file | tr -s '[ ]+' ' ' | tr -s '[\t]' ' ' >> $spec_file-temp1
sed -i -e 's|BuildRoot:|EOF\nexit\n|' $spec_file-temp1
sh $spec_file-temp1
# Convert the script file to make it understand conditionnals
sed -i -e 's|%ifarch \(.*\)|if [ -e "\1" ] ; then|' $spec_file.get-sources.sh
sed -i -e 's|%if \(.*\)|if [ "\1" = "1" ] ; then|' $spec_file.get-sources.sh
sed -i -e 's|%else|else|' $spec_file.get-sources.sh
sed -i -e 's|%endif|fi|' $spec_file.get-sources.sh
# Fix unneeded stuff that will prevent convertion
sed -i -e 's|%define kmodtool||' $spec_file.get-sources.sh
# Convert the defines
sed -i -e 's|%define \([^ ]*\) \(.*\)|\1=\2|g' $spec_file.get-sources.sh
sed -i -e 's|Version|version|' $spec_file.get-sources.sh
sed -i -e 's|Name|name|' $spec_file.get-sources.sh
sed -i -e 's|Release|release|' $spec_file.get-sources.sh
# Remove uneeded stuff
sed -i -e 's|kmodtool|#kmodtool|' $spec_file.get-sources.sh
sed -i -e 's|Source10|#Source10|' $spec_file.get-sources.sh
sed -i -e 's|%{!?kversion: ||g' $spec_file.get-sources.sh
sed -i -e 's|%{!?kvariants: ||g' $spec_file.get-sources.sh
sed -i -e 's|%{!?|#|g' $spec_file.get-sources.sh
sed -i -e 's|%{?|#|g' $spec_file.get-sources.sh
sed -i -e 's|Summary|#|' $spec_file.get-sources.sh
sed -i -e 's|URL|#|' $spec_file.get-sources.sh
sed -i -e 's|License|#|' $spec_file.get-sources.sh
sed -i -e 's|Group|#|' $spec_file.get-sources.sh
# Make it donwload sources and patches if url is present
sed -i -e 's|Source[0-9]: http://|wget -q -N http://|g' $spec_file.get-sources.sh
sed -i -e 's|Source[0-9]: ftp://|wget -q -N ftp://|g' $spec_file.get-sources.sh
sed -i -e 's|Patch[0-9]: http://|wget -q -N http://|g' $spec_file.get-sources.sh
sed -i -e 's|Patch[0-9]: ftp://|wget -q -N ftp://|g' $spec_file.get-sources.sh
# Convert the variables
sed -i -e 's|: |=|g' $spec_file.get-sources.sh
sed -i -e 's|%|$|g' $spec_file.get-sources.sh
sed -i -e 's|{||g' $spec_file.get-sources.sh
sed -i -e 's|}||g' $spec_file.get-sources.sh
# Finish and print then exec
echo "exit 0" >> $spec_file.get-sources.sh
#cat $spec_file.get-sources.sh |more
sh $spec_file.get-sources.sh
# Cleanning
rm -f $spec_file-temp1
rm -f $spec_file.get-sources.sh