Andrew Fyfe wrote:
makepkg2's use of fakeroot was a bit hackish, it's now very hackish in
makepkg3. It also kicks up a few strange bugs (flyspray #6208) because
it's being used where it shouldn't be. So I've rewritten/reordered
makepkg to reduce the amount of time spent in fakeroot. Specificly it's
now only used for...
fake_install() (if it exists. See below)
build() (if there's no fake_install)
tidy_install()
- remove docs
- move/compress man pages
- strip binaries/libraries
- remove libtool files
- remove empty directories
create_package()
- create .PKGINFO & .FILELIST
- tar it all up
everything else is run outside of fakeroot.
Attached are 6 patches to clean up fakeroot. I've split them up into
separate patches to make it's easier to read. It's mostly white space
and moving code from one end of the script to the other.
Patches 1-4 reorder and clean up makepkg in preperation for the cleaner
method of running fakeroot.
Patch 5 is the new fakeroot implementation.
Patch 6 is the fake_install implementation.
See the top of each patch for a more detailed outline of the changes.
Apply the patches in this order...
[1] pacman-cvs-chksums.patch
[2] pacman-cvs-create_package.patch
[3] pacman-cvs-tidy_install.patch
[4] pacman-cvs-run_build.patch
[5] pacman-cvs-fakeroot.patch
[6] pacman-cvs-fake_install.patch
When I get the chance I'll make patches for the other features/fixes
I've added to makepkg.
Andrew
------------------------------------------------------------
revno: 2
committer: Andrew Fyfe
branch nick: feature_chksums
timestamp: Sat 2007-03-24 03:52:10 +0000
message:
* Cleaned up and reordered generate/validate checksum code
* Renamed GENINTEG to _GENERATE_CHKSUMS
=== modified file 'scripts/makepkg'
--- old/scripts/makepkg 2007-03-24 03:49:27 +0000
+++ new/scripts/makepkg 2007-03-24 03:51:07 +0000
@@ -41,7 +41,7 @@
DEP_SRC=0
SUDO=0
FORCE=0
-GENINTEG=0
+_GENERATE_CHKSUMS='n'
INSTALL=0
NOBUILD=0
NODEPS=0
@@ -445,7 +445,7 @@
--force) FORCE=1 ;;
--nobuild) NOBUILD=1 ;;
--nocolor) USE_COLOR="n" ;;
- --geninteg) GENINTEG=1 ;;
+ --geninteg) _GENERATE_CHKSUMS='y';;
--rmdeps) RMDEPS=1 ;;
--repackage) REPKG=1 ;;
--log) LOGGING=1 ;;
@@ -466,7 +466,7 @@
d) NODEPS=1 ;;
e) NOEXTRACT=1 ;;
f) FORCE=1 ;;
- g) GENINTEG=1 ;;
+ g) _GENERATE_CHKSUMS='y';;
h)
usage
exit 0
@@ -582,7 +582,7 @@
fi
if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}" \
- -a "$FORCE" = "0" -a "$GENINTEG" = "0" ]; then
+ -a "$FORCE" = "0" -a $_GENERATE_CHKSUMS = 'n' ]; then
if [ "$INSTALL" = "1" ]; then
warning "a package has already been built, installing existing package."
installpackage
@@ -621,7 +621,7 @@
msg "Making package: $pkgname $pkgver-$pkgrel ($(date))"
# fix flyspray bug #5973
-if [ "$NODEPS" = "1" -o "$GENINTEG" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then
+if [ "$NODEPS" = "1" -o $_GENERATE_CHKSUMS = 'y' -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then
if [ "$NODEPS" = "1" ]; then
warning "skipping dependency checks"
fi
@@ -712,84 +712,82 @@
fi
done
+if [ $_GENERATE_CHKSUMS = 'y' ]; then
+ msg "Generating checksums for source files..."
+ plain ""
+
+ for integ in ${INTEGRITY_CHECK[@]}; do
+ integ="$(echo $integ | tr [:upper:] [:lower:])"
+ case "$integ" in
+ md5|sha1|sha256|sha384|sha512) : ;;
+ *) error "Invalid integrity algorithm '$integ' specified."; exit 1;; # $E_CONFIG_ERROR
+ esac
+
+ if [ ! $(type -p "${integ}sum") ]; then
+ error "Cannot fin the '${integ}sum' program."
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+
+ ct=0
+ numsrc=${#source[@]}
+ echo -n "${integ}sums=("
+
+ for netfile in ${source[@]}; do
+ file="$(strip_url "$netfile")"
+ sum="$(${integ}sum "$file" | cut -d ' ' -f 1)"
+ [ $ct -gt 0 ] && echo -ne "\t "
+ echo -n "'$sum'"
+ ct=$(($ct+1))
+ [ $ct -lt $numsrc ] && echo
+ done
+
+ echo ")"
+ done
+
+ exit 0 # $E_OK
+fi
+
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
warning "Skipping source integrity checks -- using existing src/ tree"
else
- # TODO we end up checking $GENINTEG 3 times, could probably be refactored
- if [ "$GENINTEG" = "1" ]; then
- msg "Generating checksums for source files"
- plain ""
- fi
-
for integ in ${INTEGRITY_CHECK[@]}; do
- integ="$(echo $integ | tr A-Z a-z)"
+ integ="$(echo $integ | tr [:upper:] [:lower:])"
case "$integ" in
- md5) integrity_name="md5sum" ;;
- sha1) integrity_name="sha1sum" ;;
- sha256) integrity_name="sha256sum" ;;
- sha384) integrity_name="sha384sum" ;;
- sha512) integrity_name="sha512sum" ;;
- *) error "Invalid integrity algorithm '$integ' specified"; exit 1;;
+ md5|sha1|sha256|sha384|sha512) : ;;
+ *) error "Invalid integrity algorithm '$integ' specified"; exit 1;; # $E_CONFIG_ERROR
esac
- if [ ! $(type -p $integrity_name) ]; then
- error "Cannot find the $integrity_name program."
- exit 1
+
+ if [ ! $(type -p "${integ}sum") ]; then
+ error "Cannot find the ${integ}sum program."
+ exit 1 # $E_MISSING_PROGRAM
fi
- #Generate integrity checks
- if [ "$GENINTEG" = "1" ]; then
- ct=0
- numsrc=${#source[@]}
- for netfile in "${source[@]}"; do
- file=$(strip_url "$netfile")
- sum=$(eval "$integrity_name '$file' | cut -d' ' -f 1")
- if [ $ct -eq 0 ]; then
- echo -n "${integrity_name}s=("
- else
- echo -ne "\t "
- fi
- echo -n "'$sum'"
- ct=$(($ct+1))
- if [ $ct -eq $numsrc ]; then
- echo ')'
- else
- echo
- fi
+ integrity_sums=($(eval echo \${${integrity_name}s[@]}))
+ if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
+ msg "Validating source files with ${integ}sums"
+ errors=0
+ idx=0
+ for file in "${source[@]}"; do
+ file="$(strip_url "$netfile")"
+ echo -n " $file ... " >&2
+ if echo "${integrity_sums[$idx]} $file" | ${integ}sum --status -c -; then
+ echo "Passed" >&2
+ else
+ echo "FAILED" >&2
+ errors=1
+ fi
+ idx=$(($idx+1))
done
- #Validate integrity checks
- else
- integrity_sums=($(eval echo \${${integrity_name}s[@]}))
-
- if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
- msg "Validating source files with ${integrity_name}s"
- errors=0
- idx=0
- for netfile in "${source[@]}"; do
- file=$(strip_url "$netfile")
- echo -n " $file ... " >&2
- echo "${integrity_sums[$idx]} $file" | $integrity_name -c - >/dev/null 2>&1
- if [ $? -ne 0 ]; then
- echo "FAILED" >&2
- errors=1
- else
- echo "Passed" >&2
- fi
- idx=$(($idx+1))
- done
- if [ $errors -gt 0 ]; then
- error "One or more files did not pass the validity check!"
- exit 1
- fi
- else
- warning "Integrity checks ($integ) are missing or incomplete."
+ if [ $errors -gt 0 ]; then
+ error "One or more files did not pass the validity check!"
+ exit 1 # TODO: error code
fi
+ else
+ warning "Integrity checks ($integ) are missing or incomplete."
fi
done
- if [ "$GENINTEG" = "1" ]; then
- plain ""
- exit 0
- fi
+ unset integ integrity_sums errors idx file
fi
#Extract sources
------------------------------------------------------------
revno: 2
committer: Andrew Fyfe
branch nick: feature_create_package
timestamp: Sat 2007-03-24 03:55:00 +0000
message:
* moved create package commands into create_package ()
* cleaned up create_package ()
=== modified file 'scripts/makepkg'
--- old/scripts/makepkg 2007-03-24 03:49:27 +0000
+++ new/scripts/makepkg 2007-03-24 03:54:24 +0000
@@ -348,6 +348,98 @@
fi
}
+create_package () {
+ cd "$startdir/pkg"
+ msg "Creating package..."
+
+ # get some package meta info
+ # fix flyspray bug 6468 -- Localized dates for build/install date
+ local builddate="$(LC_ALL=C ; LANG=C ; date -u +"%Y-%m-%dT%T%:z")"
+ if [ "$PACKAGER" != "" ]; then
+ local packager="$PACKAGER"
+ else
+ local packager="Arch Linux (http://www.archlinux.org)"
+ fi
+ local size=$(du -sb | awk '{print $1}')
+
+ # build a filelist - do this first to keep meta files out of the list
+ msg2 "Generating .FILELIST file..."
+ tar -cvf /dev/null * | sort >.FILELIST
+
+ # write the .PKGINFO file
+ msg2 "Generating .PKGINFO file..."
+ echo "# Generated by makepkg $myver" >.PKGINFO
+ echo "# $(LC_ALL=C; LANG=C; date -u)" >>.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
+
+ local it
+ 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 "Please add a license line to your ${_BUILD_SCRIPT}!"
+ plain "example for GPL'ed software: license=('GPL')."
+ fi
+
+ local comp_files
+
+ # check for an install script
+ if [ "$install" != "" ]; then
+ msg2 "Copying install script..."
+ cp "$startdir/$install" .INSTALL
+ comp_files="${comp_files} .INSTALL"
+ fi
+
+ # do we have a changelog?
+ if [ -f "$startdir/ChangeLog" ]; then
+ msg2 "Copying package change log"
+ cp "$startdir/ChangeLog" .CHANGELOG
+ comp_files="${comp_files} .CHANGELOG"
+ fi
+
+
+ # tar it up
+ msg2 "Compressing package..."
+
+ local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}"
+ comp_files="${comp_files} .PKGINFO .FILELIST"
+
+ if ! tar -czf $pkg_file $comp_files *; then
+ error "Failed to create package file."
+ exit 1 # TODO: error code
+ fi
+}
+
installpackage() {
if [ "$INSTALL" = "1" -a "$SUDO" = "1" ]; then
msg "Installing package with pacman -U..."
@@ -979,92 +1071,7 @@
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 "Generating .FILELIST file..."
-cd "$startdir/pkg"
-tar cvf /dev/null * | sort >.FILELIST
-
-# write the .PKGINFO file
-msg "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 "Please add a license line to your $BUILDSCRIPT!"
- plain "example for GPL'ed software: license=('GPL')."
-fi
-
-# check for an install script
-if [ "$install" != "" ]; then
- msg "Copying install script..."
- cp "$startdir/$install" "$startdir/pkg/.INSTALL"
-fi
-
-# do we have a changelog?
-have_changelog=0
-if [ -f "$startdir/ChangeLog" ]; then
- msg "Copying package changelog"
- cp "$startdir/ChangeLog" "$startdir/pkg/.CHANGELOG"
- have_changelog=1
-fi
-
-# tar it up
-msg "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 "Failed to create package file."
- exit 1
-fi
+create_package
cd "$startdir"
if [ "$CLEANUP" = "1" ]; then
------------------------------------------------------------
revno: 10
committer: Andrew Fyfe
branch nick: feature_fake_install
timestamp: Sat 2007-03-24 06:48:03 +0000
message:
* Added support for fake_install()
=== modified file 'scripts/makepkg'
--- old/scripts/makepkg 2007-03-24 06:14:55 +0000
+++ new/scripts/makepkg 2007-03-24 06:47:43 +0000
@@ -833,7 +833,12 @@
if [ "$REPKG" = "1" ]; then
warning "Skipping build."
else
- run_build build
+ if [ "$(type -t fake_install)" != "function" ]; then
+ run_build build
+ else
+ run_build fake_install
+ fi
+
tidy_install
fi
@@ -1080,11 +1085,16 @@
warning "Skipping build."
else
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 "Entering fakeroot environment..."
cd "$startdir"
------------------------------------------------------------
revno: 9
committer: Andrew Fyfe
branch nick: feature_fakeroot
timestamp: Sat 2007-03-24 06:14:55 +0000
message:
* renamed INFAKEROOT to _IN_FAKEROOT
------------------------------------------------------------
revno: 7
committer: Andrew Fyfe
branch nick: feature_fakeroot
timestamp: Sat 2007-03-24 06:09:11 +0000
message:
* reduced time in fakeroot to only build() tidy_install() and create_package()
* removed fakeroot hack from...
installpackage()
removedeps()
handledeps()
* cleaned up...
installpackage()
removedeps()
------------------------------------------------------------
revno: 5
committer: Andrew Fyfe
branch nick: feature_fakeroot
timestamp: Sat 2007-03-24 05:14:30 +0000
message:
* added yn_question () - Asks the user a yes/no question.
returns 0 for yes or y and 1 for anything else.
* moved fakeroot/permissions check up.
* added check for in proper use of '-F' option.
* added warning about running makepkg as root.
* moved sudo check to just after fakeroot/permissions check.
=== modified file 'scripts/makepkg'
--- old/scripts/makepkg 2007-03-24 06:25:38 +0000
+++ new/scripts/makepkg 2007-03-24 06:14:32 +0000
@@ -49,16 +49,10 @@
RMDEPS=0
REPKG=0
_LOG_BUILD='n'
+_IN_FAKEROOT='n'
PACMAN_OPTS=
-#determine if we are running with fakeroot
-if [ "$1" = "-F" ]; then
- INFAKEROOT=1
- shift
-else
- INFAKEROOT=0
-fi
### SUBROUTINES ###
@@ -196,7 +190,7 @@
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
@@ -209,21 +203,11 @@
if [ "$DEP_BIN" = "1" -a "$SUDO" = "1" ]; then
# install missing deps from binary packages (using pacman -S and sudo)
msg "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 "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 "Installing missing dependencies..."
@@ -321,29 +305,23 @@
# fix flyspray bug #5923
removedeps() {
+ [ "$RMDEPS" = "0" ] && return
+ [ "$SUDO" = "0" -a $EUID -gt 0 ] && return
# runtimedeps and buildtimedeps are set when resolving deps
local deplist="$runtimedeps $buildtimedeps"
- local depstrip=""
local striplist=""
+ [ -z "$deplist" ] && return
+
+ local dep
for dep in $deplist; do
- depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||')
- striplist="$striplist $depstrip"
+ striplist="$striplist $(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')"
done
- if [ "$RMDEPS" = "1" -a "$SUDO" = "1" -a -n "$deplist" ]; then
- msg "Removing installed dependencies..."
- if [ "$INFAKEROOT" = "1" ]; then
- export FAKEROOTKEY2=$FAKEROOTKEY
- unset FAKEROOTKEY
- fi
+ msg "Removing installed dependencies..."
+ if [ "$SUDO" = "1" ]; then
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 "Removing installed dependencies..."
+ else
pacman $PACMAN_OPTS -Rs $striplist
fi
}
@@ -564,24 +542,16 @@
}
installpackage() {
- if [ "$INSTALL" = "1" -a "$SUDO" = "1" ]; then
- msg "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
- elif [ "$INSTALL" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" ]; then
- msg "Installing package with pacman -U..."
- pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}
- exit $?
+ [ "$INSTALL" = "0" ] && return
+ [ "$SUDO" = "0" -a $EUID -gt 0 ] && return
+ local ret=0
+ msg "Installing package with pacman -U..."
+ if [ "$SUDO" = "1" ]; then
+ sudo pacman $PACMAN_OPTS -U "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}" || ret=$?
+ else
+ pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT} || ret=$?
fi
+ exit $ret
}
usage() {
@@ -673,7 +643,7 @@
exit 1
;;
-*)
- while getopts "bcCdefghiLmop:rRsS-" opt; do
+ while getopts "bcCdefFghiLmop:rRsS-" opt; do
case $opt in
b) DEP_SRC=1 ;;
c) CLEANUP=1 ;;
@@ -681,6 +651,7 @@
d) NODEPS=1 ;;
e) NOEXTRACT=1 ;;
f) FORCE=1 ;;
+ F) _IN_FAKEROOT='y';;
g) _GENERATE_CHKSUMS='y';;
h)
usage
@@ -713,12 +684,6 @@
shift
done
-# check for sudo
-if [ "$SUDO" = "1" -a ! "$(type -p sudo)" ]; then
- error "Cannot find the sudo binary! Is sudo installed?"
- exit 1
-fi
-
if [ "$CLEANCACHE" = "1" ]; then
#fix flyspray feature request #5223
if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
@@ -749,6 +714,60 @@
fi
fi
+if [ $_IN_FAKEROOT = 'n' ]; then
+ if [ $EUID -eq 0 ]; then
+ # Warn those who like to live dangerously.
+ warning "Running makepkg as root is a \033[1;31mBAD\033[1;37m idea!"
+ plain ""
+ plain "Running makepkg as root can result in permanent, catastropic damage to "
+ plain "your system."
+ plain ""
+ if ! yn_question "Are you sure you want to continue? [N/y]"; then
+ error "Aborting..."
+ exit 1 # $E_USER_ABORT
+ fi
+ elif [ $(check_buildenv fakeroot) = 'y' ]; then
+ if [ ! $(type -p fakeroot) ]; then
+ warning "Fakeroot is not installed. Building as an unprivileged user"
+ plain "will result in non-root ownership of the packaged files. Install"
+ plain "the fakeroot package to correctly build as a non-root user."
+ plain ""
+ if ! yn_question "Are you sure you want to continue? [N/y]"; then
+ error "Aborting..."
+ exit 1 # $E_USER_ABORT
+ fi
+ fi
+ else
+ warning "Running makepkg as an unprivileged user will result in non-root"
+ plain "ownership of the packaged files. Try using the fakeroot environment by"
+ plain "placing 'fakeroot' in the BUILDENV array in /etc/makepkg.conf"
+ plain ""
+ if ! yn_question "Are you sure you want to continue? [N/y]"; then
+ error "Aborting..."
+ exit 1 # $E_USER_ABORT
+ fi
+ fi
+else
+ if [ -z "$FAKEROOTKEY" ]; then
+ error "Do not use the '-F' option. This option is only for use by makepkg."
+ exit 1 # TODO: error code
+ fi
+fi
+
+if [ "$SUDO" = "1" ]; then
+ if [ ! "$(type -p sudo)" ]; then
+ error "Can not find the sudo binary! Is sudo installed?"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+elif [ $EUID -gt 0 -a "$INSTALL" = "1" ]; then
+ # TODO: Should this be an error and exit?
+ warning "makepkg will not be able to install this package as an unprivilaged user."
+ plain "Use the --usesudo (or -s) option to install this package after it has been"
+ plain "build."
+ plain ""
+ sleep 3
+fi
+
unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums force
unset replaces depends conflicts backup source install build makedepends
unset options noextract
@@ -808,29 +827,20 @@
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 "Entering fakeroot environment"
- fakeroot -- $0 -F $ARGLIST
- exit $?
- else
- warning "Fakeroot is not installed. Building as an unprivileged user"
- plain "will result in non-root ownership of the packaged files. Install"
- plain "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 [ $_IN_FAKEROOT = 'y' ]; then
+ if [ "$REPKG" = "1" ]; then
+ warning "Skipping build."
else
- warning "Running makepkg as an unprivileged user will result in non-root"
- plain "ownership of the packaged files. Try using the fakeroot environment"
- plain "by placing 'fakeroot' in the BUILDENV array in makepkg.conf."
- plain ""
- sleep 1
+ run_build build
+ tidy_install
fi
+
+ create_package
+
+ msg "Leaveing fakeroot environment."
+ exit 0 # $E_OK
fi
msg "Making package: $pkgname $pkgver-$pkgrel ($(date))"
@@ -1057,23 +1067,35 @@
if [ "$NOBUILD" = "1" ]; then
msg "Sources are ready."
exit 0
-elif [ "$REPKG" = "1" ]; then
- warning "Skipping build"
else
# check for existing pkg directory
- if [ -d "$startdir/pkg" ]; then
+ if [ -d "$startdir/pkg" -a "$REPKG" = "0" ]; then
msg "Removing existing pkg/ directory..."
rm -rf "$startdir/pkg"
fi
mkdir -p "$startdir/pkg"
- run_build build
+ if [ $EUID -eq 0 ]; then
+ if [ "$REPKG" = "1" ]; then
+ warning "Skipping build."
+ else
+ run_build build
+ tidy_install
+ fi
+
+ create_package
+ else
+ msg "Entering fakeroot environment..."
+ cd "$startdir"
+
+ ret=0
+ fakeroot -- $0 -F $ARGLIST || ret=$?
+ [ $ret -ne 0 ] && exit $ret
+
+ unset ret
+ fi
fi
-tidy_install
-
-create_package
-
cd "$startdir"
if [ "$CLEANUP" = "1" ]; then
msg "Cleaning up..."
------------------------------------------------------------
revno: 3
committer: Andrew Fyfe
branch nick: feature_run_build
timestamp: Sat 2007-03-24 05:37:34 +0000
message:
* moved the build commands to run_build ().
* cleaned up run_build ().
* renamed LOGGING to _LOG_BUILD
* simplified the 'set -e' check. Idealy the whole script should run with
'set -e' enabled.
=== modified file 'scripts/makepkg'
--- old/scripts/makepkg 2007-03-24 03:49:27 +0000
+++ new/scripts/makepkg 2007-03-24 05:37:22 +0000
@@ -48,7 +48,7 @@
NOEXTRACT=0
RMDEPS=0
REPKG=0
-LOGGING=0
+_LOG_BUILD='n'
PACMAN_OPTS=
@@ -348,6 +348,71 @@
fi
}
+run_build () {
+ if [ "$(type -t $1)" != "function" ]; then
+ error "Unknown function '$1'."
+ error "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"
+ 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 distcc) != '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
+
+ msg "Running '$1'..."
+ cd "$startdir/src"
+
+ # Some locales can break builds.
+ local _LC_ALL="$LC_ALL" ; LC_ALL='C'
+ local _LANG="$LANG" ; LANG='C'
+ umask 0022
+
+ local ret=0
+ if [ $_LOG_BUILD = 'y' ]; then
+ local build_log="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-${1}.log"
+ if [ -f "$build_log" ]; then
+ local i=1
+ while true; do
+ if [ -f "${build_log}.$i" ]; then
+ i=$(($i+1))
+ else
+ break
+ fi
+ done
+ mv "$build_log" "${build_log}.$i"
+ fi
+
+ msg2 "'$1' will be logged to $build_log"
+ (set -e; $1 2>&1) | tee "$build_log" || ret=${PIPESTATUS[0]}
+ else
+ (set -e; $1 2>&1) || ret=$?
+ fi
+
+ # restore locales
+ export LC_ALL="$_LC_ALL"
+ export LANG="$_LANG"
+
+ if [ $ret -gt 0 ]; then
+ error "'$1' FAILED. Aborting..."
+ removedeps
+ exit 2 # TODO: error code
+ fi
+}
+
installpackage() {
if [ "$INSTALL" = "1" -a "$SUDO" = "1" ]; then
msg "Installing package with pacman -U..."
@@ -448,7 +513,7 @@
--geninteg) GENINTEG=1 ;;
--rmdeps) RMDEPS=1 ;;
--repackage) REPKG=1 ;;
- --log) LOGGING=1 ;;
+ --log) _LOG_BUILD='y';;
--help)
usage
exit 0
@@ -472,7 +537,7 @@
exit 0
;;
i) INSTALL=1 ;;
- L) LOGGING=1 ;;
+ L) _LOG_BUILD='y';;
m) USE_COLOR="n" ;;
o) NOBUILD=1 ;;
p) BUILDSCRIPT=$OPTARG ;;
@@ -854,70 +919,7 @@
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 "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=$?
-
- 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"
- [ $set_e -eq 1 ] && set +e
-
- if [ ${PIPESTATUS[0]} -gt 0 ]; then
- error "Build Failed. Aborting..."
- removedeps
- exit 2
- fi
- else
- #use 'errexit' to bail on syntax error
- [ $set_e -eq 1 ] && set -e
- build 2>&1
- [ $set_e -eq 1 ] && set +e
- if [ $? -gt 0 ]; then
- error "Build Failed. Aborting..."
- removedeps
- exit 2
- fi
- fi
+ run_build build
fi
if [ "$(check_option docs)" = "n" ]; then
------------------------------------------------------------
revno: 2
committer: Andrew Fyfe
branch nick: feature_tidy_install
timestamp: Sat 2007-03-24 03:53:42 +0000
message:
* moved the following into tidy_install ()
- Remove info/doc files
- Move usr/share/man files to usr/man
- Compress man pages
- Strip binaries and libraries
- Remove libtool files
- Remove empty directories
* cleaned up tidy_install ()
* added 'LC_ALL=C LANG=C' to find commands for stripping binaries and
libraries. Fixes issues with greps not working on different locales.
=== modified file 'scripts/makepkg'
--- old/scripts/makepkg 2007-03-24 03:49:27 +0000
+++ new/scripts/makepkg 2007-03-24 03:52:44 +0000
@@ -348,6 +348,64 @@
fi
}
+tidy_install () {
+ cd "$startdir/pkg"
+ msg "Tidying install..."
+
+ if [ $(check_option docs) = 'n' ]; then
+ msg2 "Removing info/doc files..."
+ #fix flyspray bug #5021
+ rm -rf ${DOC_DIRS[@]}
+ fi
+
+ if [ -d usr/share/man ]; then
+ msg2 "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
+
+ msg2 "Compressing man pages..."
+ local manpage ext file link
+ find {usr{,/local},opt/*}/man -type f 2>/dev/null | while read manpage ; do
+ ext="${manpage##*.}"
+ file="${manpage##*/}"
+ if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then
+ # update symlinks to this manpage
+ 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 "$manpage"
+ fi
+ done
+
+ if [ $(check_option strip) = 'y' ]; then
+ msg2 "Stripping debugging symbols from libraries..."
+ LC_ALL=C LANG=C \
+ find {.,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 "Stripping symbols from binaries..."
+ LC_ALL=C LANG=C \
+ find {.,usr{,/local}.opt/*}/{bin,sbin} -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"
+ fi
+
+ if [ $(check_option libtool) = 'n' ]; then
+ msg2 "Removing libtool .la files..."
+ find -type f -name "*.la" -exec rm -f -- '{}' ';'
+ fi
+
+ if [ $(check_option emptydirs) = 'n' ]; then
+ msg2 "Removing empty directories..."
+ find -depth -type d -empty -delete
+ fi
+}
+
installpackage() {
if [ "$INSTALL" = "1" -a "$SUDO" = "1" ]; then
msg "Installing package with pacman -U..."
@@ -920,64 +978,7 @@
fi
fi
-if [ "$(check_option docs)" = "n" ]; then
- # remove info/doc files
- msg "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 "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 "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 "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 "Removing libtool .la files..."
- find pkg -type f -name "*.la" -exec rm -f -- '{}' \;
-fi
-
-# remove empty directories
-if [ "$(check_option emptydirs)" = "n" ]; then
- msg "Removing empty directories..."
- cd "$startdir/pkg"
- find -depth -type d -empty -delete;
-fi
+tidy_install
# get some package meta info
builddate=$(LC_ALL= ; LANG= ; date -u "+%a %b %e %H:%M:%S %Y")