#!/bin/bash source ScriptFunctions Import File Import Log Import OptionParser Import GoboLinux Import Array ### Options ################################################################### scriptDescription="Update a recipe to a new version." scriptCredits="Copyright (C) 2003, Hisham Muhammad - Released under the GNU GPL." helpOnNoArguments=yes scriptUsage=" (url)" scriptNotes="Optimistically, it assumes only the version number has changed, "\ "and the compilation process is still identical. The generated recipe is "\ "better understood as a 'template' for the new version recipe." scriptExample='Allegro 4.1.12, NewVersion --source 0.9.7 Wine 0.9.14' Add_Option_Entry "s" "source" "Recipe version number to use as a base for the new version" "" Add_Option_Entry "n" "former-name" "App name of the Recipe to use as a base. Only necessary if it's different from the name of the new Recipe" "" Parse_Options "$@" Parse_Conf Compile.conf Import Compile unset packagename versionnumber Check_Dir_Variable compileLocalRecipesDir [ -z "$ROOTLESS_GOBOLINUX" ] && [ ! -w "$compileLocalRecipesDir" -o ! -x "$compileLocalRecipesDir" ] && $sudo_exec chown `whoami` "${compileLocalRecipesDir}" if [ -z "$(Arg 2)" ] then Die "Please specify a package and version number. See --help." fi app="$(Arg 1)" newversion="$(Arg 2)" newurl="$(Arg 3)" [ -z "$ROOTLESS_GOBOLINUX" -a -d "$compileLocalRecipesDir/$app" ] && [ ! -w "$compileLocalRecipesDir/$app" -o ! -x "$compileLocalRecipesDir/$app" ] && $sudo_exec chown `whoami` "$compileLocalRecipesDir/$app" [ -z "$ROOTLESS_GOBOLINUX" -a -d "$compileLocalRecipesDir/$app/$newversion" ] && [ ! -w "$compileLocalRecipesDir/$app/$newversion" -o ! -x "$compileLocalRecipesDir/$app/$newversion" ] && $sudo_exec chown -R `whoami` "$compileLocalRecipesDir/$app/$newversion" if Is_Entry "former-name" then srcApp="`Entry "former-name"`" else srcApp="$app" fi if Is_Entry "source" then sourceVersion="`Entry "source"`" else sourceVersion='' fi Log_Normal "Locating a recipe for $srcApp..." rawrecipe=`FindPackage --type=recipe "$srcApp" "$sourceVersion" 2> /dev/null` [ "$rawrecipe" ] || Die "Could not find a recipe for $srcApp" Log_Normal "Found recipe for $srcApp at $rawrecipe" bakedrecipedir=`GetRecipe $rawrecipe` [ "$bakedrecipedir" ] || Die "Error getting recipe" Log_Normal "Recipe placed in $bakedrecipedir" [ -f "$bakedrecipedir/Recipe" ] || Die "$bakedrecipedir/Recipe not found" oldrecipe=$bakedrecipedir/Recipe source $oldrecipe if Is_Entry "former-name" then packagename="$app" else packagename=`Get_Token "$bakedrecipedir" "/" "-2"` fi oldversionandrevision=`Get_Token "$bakedrecipedir" "/" "-1"` oldversion=`String_Version "$oldversionandrevision"` oldrecipedir="$bakedrecipedir" if [ "$oldversion" = "$newversion" -a ! "$newurl" ] || [ "$newversion" = "$oldversionandrevision" -a ! "$newurl" ] then Die "Current version is already $newversion." elif [ "$cvs" -o "$svn" -o "$git" -o "$bzr" -o "$hg" ] then Die "NewVersion does not support upgrading cvs/svn/git/bzr/hg recipes." fi Log_Normal "Creating recipe for $packagename $newversion based on $oldversionandrevision." destinationDir="$compileLocalRecipesDir" newrecipedir="$destinationDir/$packagename/$newversion" mkdir -p "$destinationDir/$packagename" if [ "$oldrecipedir" = "$newrecipedir" ] then Log_Question "There is already a recipe for $packagename $newversion, at" Log_Question "$oldrecipedir" if ! Ask "Create another?" then exit 0 fi else cp -R "$oldrecipedir" "$newrecipedir" fi cd "$newrecipedir" || Die "Failed creating new recipe dir." [ -e "Recipe" ] || Die "Recipe file not found." grep -v '# Recipe for version' Recipe > Recipe.old if [ "$compileRecipeAuthor" != "" ] then echo "# Recipe for version $newversion by $compileRecipeAuthor, on" `date` > Recipe cat Recipe.old >> Recipe else Log_Terse "Please fill in the 'compileRecipeAuthor' variable in $goboSettings/Compile/Compile.conf" mv Recipe.old Recipe fi if [ "$newurl" ] then # TODO: generalize mirror system newurl=`echo "$newurl" | sed 's|http://.*\.dl.sourceforge.net/sourceforge/|$httpSourceforge/|'` newurl=`echo "$newurl" | sed 's|ftp://ftp\.gnu\.org/gnu/|$ftpGnu/|'` source Recipe switchurls="s|$url|$newurl|g;" switchurls="${switchurls}s|^url=.*$|url=\"$newurl\"|g;" fi # convert old recipe type to new recipe type # recipe type compileprogram is renamed to configure sed -i 's/is_\(.*\)=yes/recipe_type=\1/ s/compileprogram/configure/' Recipe Update_Recipe() { recipedir=$1 arch=$2 Quiet pushd $recipedir # Version-specific data should be stripped out mv Recipe Recipe.old sed "s:${oldversion%_bin}:${newversion%_bin}:g;${switchurls}" Recipe.old |\ awk ' BEGIN { skip=0; } /^file_md5s=\([^)]*$/ { skip=2; } /^file_sizes=\([^)]*$/ { skip=2; } /^file_md5s=\(.*\)$/ { skip=1; } /^file_sizes=\(.*\)$/ { skip=1; } /^file_md5=.*$/ { skip=1; } /^file_size=.*$/ { skip=1; } /^\)$/ { skip--; } { if (skip<1) print; else if (skip==1) skip=0; } ' >> Recipe rm Recipe.old unset url urls file files source Recipe if [ "$newurl" ] then [ -z "$arch" ] && url="$newurl" || Log_Terse "Not updating $arch arch with passed URL. Please check." fi if Starts_With "http:" $url then Quiet pushd "$compileArchivesDir" Log_Normal "Checking URL '$url'..." quietflag="--quiet" Boolean "verbose" && unset quietflag if ! wget -t 5 $quietflag --spider "$url" then Log_Terse "URL may be invalid. Please check." fi Quiet popd fi if ls *.patch &> /dev/null then Log_Terse "This recipe contains $arch patches. Please check if they still apply." fi if [ "$url" -o "$urls" ] then Log_Normal "Downloading source code..." if ! FetchArchive "$recipedir/Recipe" then rm -rf "$recipedir" Die "Could not download $arch source code, aborting." fi if [ "$url" ] then [ -z "${file}" ] && file="`basename $url`" filesize="`Get_Size $compileArchivesDir/$file`" filemd5="`Get_MD5 $compileArchivesDir/$file`" sed -i "s,\(^url=.*\),\1\nfile_size=$filesize\nfile_md5=$filemd5,g" "$recipedir/Recipe" else # There are multiple URLs echo "file_sizes=(" > file_sizes.tmp echo "file_md5s=(" > file_md5s.tmp Zip ' [ -z "$file" ] && file="`basename $url`" echo "`Get_Size $compileArchivesDir/$file`" >> file_sizes.tmp echo "`Get_MD5 $compileArchivesDir/$file`" >> file_md5s.tmp ' urls url files file echo ")" >> file_sizes.tmp echo ")" >> file_md5s.tmp cat Recipe file_sizes.tmp file_md5s.tmp > Recipe.new mv -f Recipe.new Recipe rm -f file_sizes.tmp file_md5s.tmp fi fi Quiet popd } Update_Recipe $newrecipedir "" for arch in ${compileSupportedArchitectures[@]} do if [ -f $newrecipedir/$arch/Recipe ] then Update_Recipe $newrecipedir/$arch $arch fi done Log_Normal "Recipe template for $packagename $newversion created" Log_Normal "Printing result ($newrecipedir/Recipe):" cat "$newrecipedir/Recipe" >&$normalFD for arch in ${compileSupportedArchitectures[@]} do if [ -f $newrecipedir/$arch/Recipe ] then Log_Normal "Printing recipe for $arch architecture:" cat "$newrecipedir/$arch/Recipe" >&$normalFD fi done Log_Normal "Done"