#!/usr/bin/env tclsh set prog modpkg set pbfields {pkgname pkgver pkgrel pkgdesc pkgbase epoch url license install changelog source noextract md5sums sha1sums sha256sums sha384sums sha512sums groups arch backup depends makedepends checkdepends optdepends conflicts provides replaces options} set pbfuncs {build check package} set dotfuncs {pre_install post_install pre_upgrade post_upgrade pre_remove post_remove} proc scanfields {inchan} { global pkgdata seek $inchan 0 set fld {} while {[gets $inchan line] >= 0} { if {$fld eq {}} { set fld $line } elseif {$line eq {}} { set pkgdata($fld) $vals set fld {} set vals {} } else { lappend vals $line } } if {$fld != {}} { set pkgdata($fld) $vals } } proc printfields {outchan} { global pkgdata foreach {fld vals} [array get pkgdata] { puts $outchan [join [concat $fld $vals] "\n"] puts "" } } if {$argc != 1} { puts stderr "usage: $prog \[path to modifier script\] < PKGDATA > PKGDATA.new" exit 2 } set mod [lindex $argv 0] if {! [file exists $mod]} { puts stderr "$prog: error: mod file does not exist" exit 1 } set modch [open $mod] scanfields stdin set modi [interp create -safe $mod] foreach {name vals} [array get pkgdata] { if {$name in $pbfuncs} { $modi eval set $name $val } } $modi eval { proc trimbash {code} { set code [string trim $code] set lines [split $code "\n"] for {set i 0} {$i < [llength $lines]} {incr $i} { set ln [string trim [lindex $lines $i]] set ln [concat [string repeat " " 2] $ln "\n"] linsert $lines $i $ln } return [join $lines ""] } proc fappend {name code} { if {! $name in $pbfuncs} { puts stderr "$prog: error: $name is not a permitted PKGBUILD func" exit 2 } exec "putpkgtree PKGBUILD $name body" << [trimbash $code] } proc fprepend {name code} { if {! $name in $pbfuncs} { puts stderr "$prog: error: $name is not a permitted PKGBUILD func" exit 2 } exec "putpkgtree PKGBUILD $name beg" << [trimbash $code] } } $modi eval [read $modch] foreach name $pbfields { if {[$modi eval info exists $name]} { set pkgdata($name) [$modi eval set $name] } } printfields stdout