[pacman-dev] makepkg: Reduced fakeroot usage patches
Take 3 :p Fakeroot patches rediffed after the gettext changes were added. Andrew
Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 17a500b..59f6d99 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -356,6 +356,95 @@ removedeps() { fi } +create_package () { + # get some package meta info + builddate=$(LC_ALL= ; LANG= ; date -u "+%a %b %e %H:%M:%S %Y") + if [ "$PACKAGER" != "" ]; then + packager="$PACKAGER" + else + packager="Arch Linux (http://www.archlinux.org)" + fi + size=$(du -cb "$startdir/pkg" | tail -n 1 | awk '{print $1}') + + # build a filelist - do this first to keep meta files out of the list + msg "$(gettext "Generating .FILELIST file...")" + cd "$startdir/pkg" + tar cvf /dev/null * | sort >.FILELIST + + # write the .PKGINFO file + msg "$(gettext "Generating .PKGINFO file...")" + cd "$startdir/pkg" + echo "# Generated by makepkg $myver" >.PKGINFO + echo -n "# " >>.PKGINFO + date >>.PKGINFO + echo "pkgname = $pkgname" >>.PKGINFO + echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO + echo "pkgdesc = $pkgdesc" >>.PKGINFO + echo "url = $url" >>.PKGINFO + echo "builddate = $builddate" >>.PKGINFO + echo "packager = $packager" >>.PKGINFO + echo "size = $size" >>.PKGINFO + if [ "$CARCH" != "" ]; then + echo "arch = $CARCH" >>.PKGINFO + fi + + for it in "${license[@]}"; do + echo "license = $it" >>.PKGINFO + done + for it in "${replaces[@]}"; do + echo "replaces = $it" >>.PKGINFO + done + for it in "${groups[@]}"; do + echo "group = $it" >>.PKGINFO + done + for it in "${depends[@]}"; do + echo "depend = $it" >>.PKGINFO + done + for it in "${conflicts[@]}"; do + echo "conflict = $it" >>.PKGINFO + done + for it in "${provides[@]}"; do + echo "provides = $it" >>.PKGINFO + done + for it in "${backup[@]}"; do + echo "backup = $it" >>.PKGINFO + done + + # TODO maybe remove this at some point + # warn if license array is not present or empty + if [ "$license" = "" ]; then + warning "$(eval_gettext "Please add a license line to your \$BUILDSCRIPT!")" + plain "$(gettext "example for GPL\'ed software: license=(\'GPL\').")" + fi + + # check for an install script + if [ "$install" != "" ]; then + msg "$(gettext "Copying install script...")" + cp "$startdir/$install" "$startdir/pkg/.INSTALL" + fi + + # do we have a changelog? + have_changelog=0 + if [ -f "$startdir/ChangeLog" ]; then + msg "$(gettext "Copying package changelog")" + cp "$startdir/ChangeLog" "$startdir/pkg/.CHANGELOG" + have_changelog=1 + fi + + # tar it up + msg "$(gettext "Compressing package...")" + cd "$startdir/pkg" + + pkg_file="$PKGDEST/$pkgname-$pkgver-$pkgrel-${CARCH}.${PKGEXT}" + comp_files=".PKGINFO .FILELIST ${install:+.INSTALL}" + [ $have_changelog -eq 1 ] && comp_files=".CHANGELOG $comp_files" + + if ! tar czf $pkg_file $comp_files *; then + error "$(gettext "Failed to create package file.")" + exit 1 + fi +} + installpackage() { if [ "$INSTALL" = "1" -a "$SUDO" = "1" ]; then msg "$(gettext "Installing package with pacman -U...")" @@ -987,92 +1076,7 @@ if [ "$(check_option emptydirs)" = "n" ]; then find -depth -type d -empty -delete; fi -# get some package meta info -builddate=$(LC_ALL= ; LANG= ; date -u "+%a %b %e %H:%M:%S %Y") -if [ "$PACKAGER" != "" ]; then - packager="$PACKAGER" -else - packager="Arch Linux (http://www.archlinux.org)" -fi -size=$(du -cb "$startdir/pkg" | tail -n 1 | awk '{print $1}') - -# build a filelist - do this first to keep meta files out of the list -msg "$(gettext "Generating .FILELIST file...")" -cd "$startdir/pkg" -tar cvf /dev/null * | sort >.FILELIST - -# write the .PKGINFO file -msg "$(gettext "Generating .PKGINFO file...")" -cd "$startdir/pkg" -echo "# Generated by makepkg $myver" >.PKGINFO -echo -n "# " >>.PKGINFO -date >>.PKGINFO -echo "pkgname = $pkgname" >>.PKGINFO -echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO -echo "pkgdesc = $pkgdesc" >>.PKGINFO -echo "url = $url" >>.PKGINFO -echo "builddate = $builddate" >>.PKGINFO -echo "packager = $packager" >>.PKGINFO -echo "size = $size" >>.PKGINFO -if [ "$CARCH" != "" ]; then - echo "arch = $CARCH" >>.PKGINFO -fi - -for it in "${license[@]}"; do - echo "license = $it" >>.PKGINFO -done -for it in "${replaces[@]}"; do - echo "replaces = $it" >>.PKGINFO -done -for it in "${groups[@]}"; do - echo "group = $it" >>.PKGINFO -done -for it in "${depends[@]}"; do - echo "depend = $it" >>.PKGINFO -done -for it in "${conflicts[@]}"; do - echo "conflict = $it" >>.PKGINFO -done -for it in "${provides[@]}"; do - echo "provides = $it" >>.PKGINFO -done -for it in "${backup[@]}"; do - echo "backup = $it" >>.PKGINFO -done - -# TODO maybe remove this at some point -# warn if license array is not present or empty -if [ "$license" = "" ]; then - warning "$(eval_gettext "Please add a license line to your \$BUILDSCRIPT!")" - plain "$(gettext "example for GPL\'ed software: license=(\'GPL\').")" -fi - -# check for an install script -if [ "$install" != "" ]; then - msg "$(gettext "Copying install script...")" - cp "$startdir/$install" "$startdir/pkg/.INSTALL" -fi - -# do we have a changelog? -have_changelog=0 -if [ -f "$startdir/ChangeLog" ]; then - msg "$(gettext "Copying package changelog")" - cp "$startdir/ChangeLog" "$startdir/pkg/.CHANGELOG" - have_changelog=1 -fi - -# tar it up -msg "$(gettext "Compressing package...")" -cd "$startdir/pkg" - -pkg_file="$PKGDEST/$pkgname-$pkgver-$pkgrel-${CARCH}.${PKGEXT}" -comp_files=".PKGINFO .FILELIST ${install:+.INSTALL}" -[ $have_changelog -eq 1 ] && comp_files=".CHANGELOG $comp_files" - -if ! tar czf $pkg_file $comp_files *; then - error "$(gettext "Failed to create package file.")" - exit 1 -fi +create_package cd "$startdir" if [ "$CLEANUP" = "1" ]; then -- 1.5.0.6
Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 59f6d99..5ec5e03 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -357,26 +357,26 @@ removedeps() { } create_package () { + cd "$startdir"/pkg + msg "$(gettext "Creating package...")" + # get some package meta info - builddate=$(LC_ALL= ; LANG= ; date -u "+%a %b %e %H:%M:%S %Y") + local builddate=$(LC_ALL= LANG= date -u "+%a %b %e %H:%M:%S %Y") if [ "$PACKAGER" != "" ]; then - packager="$PACKAGER" + local packager="$PACKAGER" else - packager="Arch Linux (http://www.archlinux.org)" + local packager="Arch Linux (http://www.archlinux.org)" fi - size=$(du -cb "$startdir/pkg" | tail -n 1 | awk '{print $1}') + local size=$(du -sb | awk '{print $1}') # build a filelist - do this first to keep meta files out of the list - msg "$(gettext "Generating .FILELIST file...")" - cd "$startdir/pkg" - tar cvf /dev/null * | sort >.FILELIST + msg2 "$(gettext "Generating .FILELIST file...")" + tar -cvf /dev/null * | sort >.FILELIST # write the .PKGINFO file - msg "$(gettext "Generating .PKGINFO file...")" - cd "$startdir/pkg" + msg2 "$(gettext "Generating .PKGINFO file...")" echo "# Generated by makepkg $myver" >.PKGINFO - echo -n "# " >>.PKGINFO - date >>.PKGINFO + echo "# $(LC_ALL= LANG= date -u)" >>.PKGINFO echo "pkgname = $pkgname" >>.PKGINFO echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO echo "pkgdesc = $pkgdesc" >>.PKGINFO @@ -388,6 +388,7 @@ create_package () { echo "arch = $CARCH" >>.PKGINFO fi + local it for it in "${license[@]}"; do echo "license = $it" >>.PKGINFO done @@ -417,31 +418,32 @@ create_package () { plain "$(gettext "example for GPL\'ed software: license=(\'GPL\').")" fi + local comp_files + # check for an install script + # TODO: should we include ${pkgname}.install if it exists and $install is unset? if [ "$install" != "" ]; then - msg "$(gettext "Copying install script...")" - cp "$startdir/$install" "$startdir/pkg/.INSTALL" + msg2 "$(gettext "Copying install script...")" + cp "$startdir/$install" .INSTALL + comp_files="$comp_files .INSTALL" fi # do we have a changelog? - have_changelog=0 if [ -f "$startdir/ChangeLog" ]; then - msg "$(gettext "Copying package changelog")" - cp "$startdir/ChangeLog" "$startdir/pkg/.CHANGELOG" - have_changelog=1 + msg2 "$(gettext "Copying package changelog")" + cp "$startdir/ChangeLog" .CHANGELOG + comp_files="$comp_files .CHANGELOG" fi # tar it up - msg "$(gettext "Compressing package...")" - cd "$startdir/pkg" + msg2 "$(gettext "Compressing package...")" - pkg_file="$PKGDEST/$pkgname-$pkgver-$pkgrel-${CARCH}.${PKGEXT}" - comp_files=".PKGINFO .FILELIST ${install:+.INSTALL}" - [ $have_changelog -eq 1 ] && comp_files=".CHANGELOG $comp_files" + local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}" + comp_files="$comp_files .PKGINFO .FILELIST" - if ! tar czf $pkg_file $comp_files *; then + if ! tar -czf "$pkg_file" $comp_files *; then error "$(gettext "Failed to create package file.")" - exit 1 + exit 1 # TODO: error code fi } -- 1.5.0.6
The following sets of commands were moved into tidy_install() * Remove info/doc files. * Move usr/share/man to usr/man * Compress man pages. * Strip debug symbols from binaries/libraries. * Remove libtool *.la files. * Remove empty directories. Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 5ec5e03..03d8eb1 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -356,6 +356,67 @@ removedeps() { fi } +tidy_install () { + if [ "$(check_option docs)" = "n" ]; then + # remove info/doc files + msg "$(gettext "Removing info/doc files...")" + cd "$startdir/pkg" + #fix flyspray bug #5021 + rm -rf ${DOC_DIRS[@]} + fi + + # move /usr/share/man files to /usr/man + if [ -d $startdir/pkg/usr/share/man ]; then + cd "$startdir" + mkdir -p pkg/usr/man + cp -a pkg/usr/share/man/* pkg/usr/man/ + rm -rf pkg/usr/share/man + fi + + # compress man pages + msg "$(gettext "Compressing man pages...")" + find "$startdir"/pkg/{usr{,/local},opt/*}/man -type f 2>/dev/null | while read i ; do + ext="${i##*.}" + fn="${i##*/}" + if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then + # update symlinks to this manpage + find "$startdir"/pkg/{usr{,/local},opt/*}/man -lname "$fn" 2> /dev/null | while read ln ; do + rm -f "$ln" + ln -sf "${fn}.gz" "${ln}.gz" + done + # compress the original + gzip -9 "$i" + fi + done + + cd "$startdir" + + # strip binaries + if [ "$(check_option strip)" = "y" ]; then + msg "$(gettext "Stripping debugging symbols from libraries...")" + find pkg/{,usr,usr/local,opt/*}/lib -type f -not -name "*.dll" -not -name "*.exe" \ + -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 \ + | grep -v "No such file" | grep -v "format not recognized" + msg "$(gettext "Stripping symbols from binaries...")" + find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -not -name "*.dll" -not -name "*.exe" \ + -exec /usr/bin/strip '{}' \; 2>&1 \ + | grep -v "No such file" | grep -v "format not recognized" + fi + + # remove libtool (.la) files + if [ "$(check_option libtool)" = "n" ]; then + msg "$(gettext "Removing libtool .la files...")" + find pkg -type f -name "*.la" -exec rm -f -- '{}' \; + fi + + # remove empty directories + if [ "$(check_option emptydirs)" = "n" ]; then + msg "$(gettext "Removing empty directories...")" + cd "$startdir/pkg" + find -depth -type d -empty -delete; + fi +} + create_package () { cd "$startdir"/pkg msg "$(gettext "Creating package...")" @@ -1019,64 +1080,7 @@ else fi fi -if [ "$(check_option docs)" = "n" ]; then - # remove info/doc files - msg "$(gettext "Removing info/doc files...")" - cd "$startdir/pkg" - #fix flyspray bug #5021 - rm -rf ${DOC_DIRS[@]} -fi - -# move /usr/share/man files to /usr/man -if [ -d $startdir/pkg/usr/share/man ]; then - cd "$startdir" - mkdir -p pkg/usr/man - cp -a pkg/usr/share/man/* pkg/usr/man/ - rm -rf pkg/usr/share/man -fi - -# compress man pages -msg "$(gettext "Compressing man pages...")" -find "$startdir"/pkg/{usr{,/local},opt/*}/man -type f 2>/dev/null | while read i ; do - ext="${i##*.}" - fn="${i##*/}" - if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then - # update symlinks to this manpage - find "$startdir"/pkg/{usr{,/local},opt/*}/man -lname "$fn" 2> /dev/null | while read ln ; do - rm -f "$ln" - ln -sf "${fn}.gz" "${ln}.gz" - done - # compress the original - gzip -9 "$i" - fi -done - -cd "$startdir" - -# strip binaries -if [ "$(check_option strip)" = "y" ]; then - msg "$(gettext "Stripping debugging symbols from libraries...")" - find pkg/{,usr,usr/local,opt/*}/lib -type f -not -name "*.dll" -not -name "*.exe" \ - -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 \ - | grep -v "No such file" | grep -v "format not recognized" - msg "$(gettext "Stripping symbols from binaries...")" - find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -not -name "*.dll" -not -name "*.exe" \ - -exec /usr/bin/strip '{}' \; 2>&1 \ - | grep -v "No such file" | grep -v "format not recognized" -fi - -# remove libtool (.la) files -if [ "$(check_option libtool)" = "n" ]; then - msg "$(gettext "Removing libtool .la files...")" - find pkg -type f -name "*.la" -exec rm -f -- '{}' \; -fi - -# remove empty directories -if [ "$(check_option emptydirs)" = "n" ]; then - msg "$(gettext "Removing empty directories...")" - cd "$startdir/pkg" - find -depth -type d -empty -delete; -fi +tidy_install create_package -- 1.5.0.6
Added 'LC_ALL= LANG=' to find commands for stripping symbols from binaries/libraries. This stops the greps failing if LC_ALL or LANG != en_US|C|POSIX. Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 03d8eb1..e4af2a1 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -357,62 +357,60 @@ removedeps() { } tidy_install () { + cd "$startdir"/pkg + msg2 "$(gettext "Tidying install...")" + if [ "$(check_option docs)" = "n" ]; then - # remove info/doc files - msg "$(gettext "Removing info/doc files...")" - cd "$startdir/pkg" + msg2 "$(gettext "Removing info/doc files...")" #fix flyspray bug #5021 rm -rf ${DOC_DIRS[@]} fi - # move /usr/share/man files to /usr/man - if [ -d $startdir/pkg/usr/share/man ]; then - cd "$startdir" - mkdir -p pkg/usr/man - cp -a pkg/usr/share/man/* pkg/usr/man/ - rm -rf pkg/usr/share/man + if [ -d usr/share/man ]; then + msg2 "$(gettext "Moving usr/share/man files to usr/man")" + mkdir -p usr/man + cp -a usr/share/man/* usr/man/ + rm -rf usr/share/man fi - # compress man pages - msg "$(gettext "Compressing man pages...")" - find "$startdir"/pkg/{usr{,/local},opt/*}/man -type f 2>/dev/null | while read i ; do - ext="${i##*.}" - fn="${i##*/}" + msg2 "$(gettext "Compressing man pages...")" + local manpage ext file link + find {usr{,/local},opt/*}/man -type f 2>/dev/null | while read manpage ; do + ext="${manpage##*.}" + fn="${manpage##*/}" if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then # update symlinks to this manpage - find "$startdir"/pkg/{usr{,/local},opt/*}/man -lname "$fn" 2> /dev/null | while read ln ; do - rm -f "$ln" - ln -sf "${fn}.gz" "${ln}.gz" + find {usr{,/local},opt/*}/man -lname "$file" 2>/dev/null | while read link ; do + rm -f "$link" + ln -sf "${file}.gz" "${link}.gz" done # compress the original - gzip -9 "$i" + gzip -9 "$manpage" fi done - cd "$startdir" - - # strip binaries if [ "$(check_option strip)" = "y" ]; then - msg "$(gettext "Stripping debugging symbols from libraries...")" + msg2 "$(gettext "Stripping debugging symbols from libraries...")" + LC_ALL= LANG= \ + find {.,usr,usr/local,opt/*}/lib -type f -not -name "*.dll" -not -name "*.exe" \ find pkg/{,usr,usr/local,opt/*}/lib -type f -not -name "*.dll" -not -name "*.exe" \ - -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 \ - | grep -v "No such file" | grep -v "format not recognized" - msg "$(gettext "Stripping symbols from binaries...")" - find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -not -name "*.dll" -not -name "*.exe" \ - -exec /usr/bin/strip '{}' \; 2>&1 \ - | grep -v "No such file" | grep -v "format not recognized" + -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 \ + | grep -v "No such file" | grep -v "format not recognized" + + msg2 "$(gettext "Stripping symbols from binaries...")" + LC_ALL= LANG= \ + find {.,usr,usr/local,opt/*}/{bin,sbin} -type f -not -name "*.dll" -not -name "*.exe" \ + -exec /usr/bin/strip '{}' \; 2>&1 \ + | grep -v "No such file" | grep -v "format not recognized" fi - # remove libtool (.la) files if [ "$(check_option libtool)" = "n" ]; then - msg "$(gettext "Removing libtool .la files...")" - find pkg -type f -name "*.la" -exec rm -f -- '{}' \; + msg2 "$(gettext "Removing libtool .la files...")" + find -type f -name "*.la" -exec rm -f -- '{}' \; fi - # remove empty directories if [ "$(check_option emptydirs)" = "n" ]; then - msg "$(gettext "Removing empty directories...")" - cd "$startdir/pkg" + msg2 "$(gettext "Removing empty directories...")" find -depth -type d -empty -delete; fi } -- 1.5.0.6
Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index e4af2a1..1fd7cf9 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -356,6 +356,68 @@ removedeps() { fi } +run_build () { + # use distcc if it is requested (check buildenv and PKGBUILD opts) + if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then + [ -d /usr/lib/distcc/bin ] && export PATH=/usr/lib/distcc/bin:$PATH + elif [ "$(check_option distcc)" = "n" ]; then + # if it is not wanted, clear the makeflags too + export MAKEFLAGS="" + fi + + # use ccache if it is requested (check buildenv and PKGBUILD opts) + if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then + [ -d /usr/lib/ccache/bin ] && export PATH=/usr/lib/ccache/bin:$PATH + fi + + # clear user-specified makeflags if requested + if [ "$(check_option makeflags)" = "n" ]; then + export MAKEFLAGS="" + fi + + # build + msg "$(gettext "Starting build()...")" + + # some applications (eg, blackbox) will not build with some languages + unset LC_ALL LANG + umask 0022 + + #check for "exit on syntax error" shell option + echo $SHELLOPTS | grep errexit 2>&1 >/dev/null + set_e=$? + + ret=0 + if [ "$LOGGING" = "1" ]; then + BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" + if [ -f "$BUILDLOG" ]; then + i=1 + while true; do + if [ -f "$BUILDLOG.$i" ]; then + i=$(($i +1)) + else + break + fi + done + mv "$BUILDLOG" "$BUILDLOG.$i" + fi + + #use 'errexit' to bail on syntax error + [ $set_e -eq 1 ] && set -e + build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} + [ $set_e -eq 1 ] && set +e + else + #use 'errexit' to bail on syntax error + [ $set_e -eq 1 ] && set -e + build 2>&1 || ret=$? + [ $set_e -eq 1 ] && set +e + fi + if [ $ret -gt 0 ]; then + error "$(gettext "Build Failed. Aborting...")" + removedeps + exit 2 + fi +} + tidy_install () { cd "$startdir"/pkg msg2 "$(gettext "Tidying install...")" @@ -1017,65 +1079,7 @@ else fi mkdir -p "$startdir/pkg" - # use distcc if it is requested (check buildenv and PKGBUILD opts) - if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then - [ -d /usr/lib/distcc/bin ] && export PATH=/usr/lib/distcc/bin:$PATH - elif [ "$(check_option distcc)" = "n" ]; then - # if it is not wanted, clear the makeflags too - export MAKEFLAGS="" - fi - - # use ccache if it is requested (check buildenv and PKGBUILD opts) - if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then - [ -d /usr/lib/ccache/bin ] && export PATH=/usr/lib/ccache/bin:$PATH - fi - - # clear user-specified makeflags if requested - if [ "$(check_option makeflags)" = "n" ]; then - export MAKEFLAGS="" - fi - - # build - msg "$(gettext "Starting build()...")" - - # some applications (eg, blackbox) will not build with some languages - unset LC_ALL LANG - umask 0022 - - #check for "exit on syntax error" shell option - echo $SHELLOPTS | grep errexit 2>&1 >/dev/null - set_e=$? - - ret=0 - if [ "$LOGGING" = "1" ]; then - BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" - if [ -f "$BUILDLOG" ]; then - i=1 - while true; do - if [ -f "$BUILDLOG.$i" ]; then - i=$(($i +1)) - else - break - fi - done - mv "$BUILDLOG" "$BUILDLOG.$i" - fi - - #use 'errexit' to bail on syntax error - [ $set_e -eq 1 ] && set -e - build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} - [ $set_e -eq 1 ] && set +e - else - #use 'errexit' to bail on syntax error - [ $set_e -eq 1 ] && set -e - build 2>&1 || ret=$? - [ $set_e -eq 1 ] && set +e - fi - if [ $ret -gt 0 ]; then - error "$(gettext "Build Failed. Aborting...")" - removedeps - exit 2 - fi + run_build fi tidy_install -- 1.5.0.6
Restore LC_ALL and LANG after running build(). Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 1fd7cf9..75832f1 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -359,7 +359,7 @@ removedeps() { run_build () { # use distcc if it is requested (check buildenv and PKGBUILD opts) if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then - [ -d /usr/lib/distcc/bin ] && export PATH=/usr/lib/distcc/bin:$PATH + [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH" elif [ "$(check_option distcc)" = "n" ]; then # if it is not wanted, clear the makeflags too export MAKEFLAGS="" @@ -367,7 +367,7 @@ run_build () { # use ccache if it is requested (check buildenv and PKGBUILD opts) if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then - [ -d /usr/lib/ccache/bin ] && export PATH=/usr/lib/ccache/bin:$PATH + [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH" fi # clear user-specified makeflags if requested @@ -375,22 +375,23 @@ run_build () { export MAKEFLAGS="" fi - # build msg "$(gettext "Starting build()...")" + cd "$startdir"/src # some applications (eg, blackbox) will not build with some languages + local _LC_ALL="$LC_ALL" + local _LANG="$LANG" unset LC_ALL LANG umask 0022 - #check for "exit on syntax error" shell option - echo $SHELLOPTS | grep errexit 2>&1 >/dev/null - set_e=$? + # check for "exit on syntax error" shell option + echo $SHELLOPTS | grep errexit 2>&1 >/dev/null; set_e=$? - ret=0 + local ret=0 if [ "$LOGGING" = "1" ]; then BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" if [ -f "$BUILDLOG" ]; then - i=1 + local i=1 while true; do if [ -f "$BUILDLOG.$i" ]; then i=$(($i +1)) @@ -401,7 +402,7 @@ run_build () { mv "$BUILDLOG" "$BUILDLOG.$i" fi - #use 'errexit' to bail on syntax error + # use 'errexit' to bail on syntax error [ $set_e -eq 1 ] && set -e build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} [ $set_e -eq 1 ] && set +e @@ -411,10 +412,15 @@ run_build () { build 2>&1 || ret=$? [ $set_e -eq 1 ] && set +e fi + + # restore LC_ALL & LANG + export LC_ALL="$_LC_ALL" + export LANG="$_LANG" + if [ $ret -gt 0 ]; then error "$(gettext "Build Failed. Aborting...")" removedeps - exit 2 + exit 2 # $E_BUILD_FAILED # TODO: error code fi } -- 1.5.0.6
Only the following functions now run inside fakeroot * run_build() * tidy_install() * create_package() Added check for inproper use of '-F' option. Added yn_question() function. Asks the user a simple yes/no question. Returns 0=yes 1=no. Added warning if makepkg is run as root. Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 75832f1..a50e795 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -49,6 +49,7 @@ DEP_BIN=0 DEP_SRC=0 SUDO=0 FORCE=0 +INFAKEROOT=0 GENINTEG=0 INSTALL=0 NOBUILD=0 @@ -60,14 +61,6 @@ LOGGING=0 PACMAN_OPTS= -#determine if we are running with fakeroot -if [ "$1" = "-F" ]; then - INFAKEROOT=1 - shift -else - INFAKEROOT=0 -fi - ### SUBROUTINES ### plain() { @@ -110,6 +103,24 @@ error() { fi } +yn_question () { + if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + echo -en " \033[1;1m$1\033[1;0m " >&2 + else + echo -n " $1 " >&2 + fi + + local answer + read answer + answer="$(echo $answer | tr [:upper:] [:lower:])" + + if [ "$answer" = 'y' -o "$answer" = 'yes' ]; then + return 0 + else + return 1 + fi +} + strip_url() { echo "$1" | sed 's|^.*://.*/||g' } @@ -685,7 +696,7 @@ while [ "$#" -ne "0" ]; do exit 1 ;; -*) - while getopts "bcCdefghiLmop:rRsS-" opt; do + while getopts "bcCdefFghiLmop:rRsS-" opt; do case $opt in b) DEP_SRC=1 ;; c) CLEANUP=1 ;; @@ -693,6 +704,7 @@ while [ "$#" -ne "0" ]; do d) NODEPS=1 ;; e) NOEXTRACT=1 ;; f) FORCE=1 ;; + F) INFAKEROOT=1 ;; g) GENINTEG=1 ;; h) usage @@ -761,6 +773,46 @@ if [ "$CLEANCACHE" = "1" ]; then fi fi +if [ "$INFAKEROOT" = "0" ]; then + if [ $EUID -eq 0 ]; then + # Warn those who like to live dangerously. + warning "$(gettext "Running makepkg as root is a BAD idea!")" + plain "" + plain "$(gettext "Running makepkg as root can result in permanent, catastropic damage to ")" + plain "$(gettext "your system.")" + plain "" + if ! yn_question "$(gettext "Are you sure you want to continue? [N/y]")"; then + error "$(gettext "Aborting...")" + exit 1 # $E_USER_ABORT + fi + elif [ "$(check_buildenv fakeroot)" = "y" ]; then + if [ ! $(type -p fakeroot) ]; then + warning "$(gettext "Fakeroot is not installed. Building as an unprivileged user")" + plain "$(gettext "will result in non-root ownership of the packaged files. Install")" + plain "$(gettext "the fakeroot package to correctly build as a non-root user.")" + plain "" + if ! yn_question "$(gettext "Are you sure you want to continue? [N/y]")"; then + error "Aborting..." + exit 1 # $E_USER_ABORT + fi + fi + else + warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")" + plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")" + plain "$(gettext "placing 'fakeroot' in the BUILDENV array in /etc/makepkg.conf")" + plain "" + if ! yn_question "$(gettext "Are you sure you want to continue? [N/y]")"; then + error "$(gettext "Aborting...")" + exit 1 # $E_USER_ABORT + fi + fi +else + if [ "$FAKEROOTKEY" = "" ]; then + error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" + exit 1 # TODO: error code + fi +fi + unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums force unset replaces depends conflicts backup source install build makedepends unset options noextract @@ -820,29 +872,20 @@ if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}" \ fi fi -# Enter the fakeroot environment if necessary. This will call the makepkg -# script again as the fake root user. We detect this by passing a sentinel -# option (-F) to makepkg. -if [ "$EUID" != "0" ]; then - if [ "$(check_buildenv fakeroot)" = "y" ]; then - if [ $(type -p fakeroot) ]; then - msg "$(gettext "Entering fakeroot environment")" - fakeroot -- $0 -F $ARGLIST - exit $? - else - warning "$(gettext "Fakeroot is not installed. Building as an unprivileged user")" - plain "$(gettext "will result in non-root ownership of the packaged files. Install")" - plain "$(gettext "the fakeroot package to correctly build as a non-root user.")" - plain "" - sleep 1 - fi +# Run the bear minimum in fakeroot +# fix flyspray bug 6208 -- using makepkg with fakeroot gives an error +if [ "$INFAKEROOT" = "1" ]; then + if [ "$REPKG" = "1" ]; then + warning "$(gettext "Skipping build.")" else - warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")" - plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment")" - plain "$(gettext "by placing 'fakeroot' in the BUILDENV array in makepkg.conf.")" - plain "" - sleep 1 - fi + run_build + tidy_install + fi + + create_package + + msg "$(gettext "Leaveing fakeroot environment.")" + exit 0 # $E_OK fi date=$(date) @@ -1075,22 +1118,34 @@ fi if [ "$NOBUILD" = "1" ]; then msg "$(gettext "Sources are ready.")" exit 0 -elif [ "$REPKG" = "1" ]; then - warning "$(gettext "Skipping build")" else # check for existing pkg directory - if [ -d "$startdir/pkg" ]; then + if [ -d "$startdir/pkg" -a "$REPKG" = "0" ]; then msg "$(gettext "Removing existing pkg/ directory...")" rm -rf "$startdir/pkg" fi mkdir -p "$startdir/pkg" - run_build -fi + if [ $EUID -eq 0 ]; then + if [ "$REPKG" = "1" ]; then + warning "$(gettext "Skipping build.")" + else + run_build + tidy_install + fi + + create_package + else + msg "$(gettext "Entering fakeroot environment...")" + cd "$startdir" -tidy_install + ret=0 + fakeroot -- $0 -F $ARGLIST || ret=$? + [ $ret -ne 0 ] && exit $ret -create_package + unset ret + fi +fi cd "$startdir" if [ "$CLEANUP" = "1" ]; then -- 1.5.0.6
Removed fakeroot hacks from * handledeps() * removedeps() * installpackage() Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index a50e795..54b9f12 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -215,7 +215,7 @@ handledeps() { local depstrip="" local striplist="" local haveperm=0 - if [ \( "$EUID" = "0" -a "$INFAKEROOT" != "1" \) -o "$SUDO" = 1 ]; then + if [ "$EUID" = "0" -o "$SUDO" = 1 ]; then haveperm=1 fi @@ -228,21 +228,11 @@ handledeps() { if [ "$DEP_BIN" = "1" -a "$SUDO" = "1" ]; then # install missing deps from binary packages (using pacman -S and sudo) msg "$(gettext "Installing missing dependencies...")" - if [ "$INFAKEROOT" = "1" ]; then - # kinda hacky, but we need to make pacman think that we're NOT - # in fakeroot so it will go ahead and install the dependencies. - FAKEROOTKEY2=$FAKEROOTKEY - unset FAKEROOTKEY - fi sudo pacman $PACMAN_OPTS -S $striplist if [ $? -eq 1 ]; then error "$(gettext "Pacman failed to install missing dependencies.")" exit 1 fi - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY=$FAKEROOTKEY2 - unset FAKEROOTKEY2 - fi elif [ "$DEP_BIN" = "1" ]; then # install missing deps from binary packages (using pacman -S) msg "$(gettext "Installing missing dependencies...")" @@ -352,15 +342,7 @@ removedeps() { if [ "$RMDEPS" = "1" -a "$SUDO" = "1" -a -n "$deplist" ]; then msg "$(gettext "Removing installed dependencies...")" - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY2=$FAKEROOTKEY - unset FAKEROOTKEY - fi sudo pacman $PACMAN_OPTS -Rs $striplist - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY=$FAKEROOTKEY2 - unset FAKEROOTKEY2 - fi elif [ "$RMDEPS" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" -a -n "$deplist" ]; then msg "$(gettext "Removing installed dependencies...")" pacman $PACMAN_OPTS -Rs $striplist @@ -588,17 +570,8 @@ create_package () { installpackage() { if [ "$INSTALL" = "1" -a "$SUDO" = "1" ]; then msg "$(gettext "Installing package with pacman -U...")" - if [ "$INFAKEROOT" = "1" ]; then - FAKEROOTKEY2=$FAKEROOTKEY - unset FAKEROOTKEY - fi sudo pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT} - local exitcode=$? - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY=$FAKEROOTKEY2 - unset FAKEROOTKEY2 - fi - exit $exitcode + exit $? elif [ "$INSTALL" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" ]; then msg "$(gettext "Installing package with pacman -U...")" pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT} -- 1.5.0.6
Modified run_build() so it can be used to run other functions. Added support for fake_install(). If a PKGBUILD contains a fake_install() function, build() will be run as the user calling makepkg and fake_install() will be called inside fakeroot. Otherwise build() will be run inside fakeroot as normal. Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 54b9f12..daff198 100755 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -350,6 +350,12 @@ removedeps() { } run_build () { + if [ "$(type -t $1)" != "function" ]; then + error "$(gettext_eval "Unknown function '\${1}'.")" + error "$(gettext "Aborting...")" + exit 1 # TODO: error code + fi + # use distcc if it is requested (check buildenv and PKGBUILD opts) if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH" @@ -368,7 +374,7 @@ run_build () { export MAKEFLAGS="" fi - msg "$(gettext "Starting build()...")" + msg "$(gettext_eval "Starting \${1}()...")" cd "$startdir"/src # some applications (eg, blackbox) will not build with some languages @@ -382,7 +388,7 @@ run_build () { local ret=0 if [ "$LOGGING" = "1" ]; then - BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" + BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-${1}.log" if [ -f "$BUILDLOG" ]; then local i=1 while true; do @@ -397,12 +403,12 @@ run_build () { # use 'errexit' to bail on syntax error [ $set_e -eq 1 ] && set -e - build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} + $1 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} [ $set_e -eq 1 ] && set +e else #use 'errexit' to bail on syntax error [ $set_e -eq 1 ] && set -e - build 2>&1 || ret=$? + $1 2>&1 || ret=$? [ $set_e -eq 1 ] && set +e fi @@ -851,7 +857,12 @@ if [ "$INFAKEROOT" = "1" ]; then if [ "$REPKG" = "1" ]; then warning "$(gettext "Skipping build.")" else - run_build + if [ "$(type -t fake_install)" != "function" ]; then + run_build build + else + run_build fake_install + fi + tidy_install fi @@ -1103,12 +1114,17 @@ else if [ "$REPKG" = "1" ]; then warning "$(gettext "Skipping build.")" else - run_build + run_build build + [ "$(type -t fake_install)" = "function" ] && run_build fake_install tidy_install fi create_package else + if [ "$REPKG" = "0" -a "$(type -t fake_install)" = "function" ]; then + run_build build + fi + msg "$(gettext "Entering fakeroot environment...")" cd "$startdir" @@ -1124,7 +1140,9 @@ cd "$startdir" if [ "$CLEANUP" = "1" ]; then msg "$(gettext "Cleaning up...")" rm -rf src pkg - rm -rf ${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log* + rm -f ${pkgname}-${pkgver}-${pkgrel}-${CARCH}-build.log* + [ "$(type -t fake_install)" = "function" ] && + rm -f ${pkgname}-${pkgver}-${pkgrel}-${CARCH}-fake_install.log* fi removedeps -- 1.5.0.6
participants (1)
-
Andrew Fyfe