Move common functions to a shared file

* common.sh is included on build time
* most functions are copied from makepkg
This commit is contained in:
Pierre Schmitz 2011-11-01 15:33:08 +01:00
parent 7c78599a61
commit aaa68e49e8
14 changed files with 252 additions and 171 deletions

View File

@ -50,9 +50,11 @@ ARCHBUILD_LINKS = \
all: $(BINPROGS) $(SBINPROGS) bash_completion zsh_completion all: $(BINPROGS) $(SBINPROGS) bash_completion zsh_completion
edit = sed -e "s|@pkgdatadir[@]|$(DESTDIR)$(PREFIX)/share/devtools|g"
%: %.in %: %.in
@echo "GEN $@" @echo "GEN $@"
@sed -e "s|@pkgdatadir[@]|$(DESTDIR)$(PREFIX)/share/devtools|g" "$<" >"$@" @m4 -P $@.in | $(edit) >$@
@chmod a-w "$@" @chmod a-w "$@"
@chmod +x "$@" @chmod +x "$@"

View File

@ -1,6 +1,9 @@
#!/bin/bash #!/bin/bash
base_packages=(base base-devel sudo) m4_include(lib/common.sh)
# FIXME: temporary added curl until pacman 4.0 moves to [core]
base_packages=(base base-devel sudo curl)
cmd="${0##*/}" cmd="${0##*/}"
if [[ "${cmd%%-*}" == 'multilib' ]]; then if [[ "${cmd%%-*}" == 'multilib' ]]; then
@ -31,16 +34,15 @@ while getopts 'cr:' arg; do
done done
if [[ "$EUID" != '0' ]]; then if [[ "$EUID" != '0' ]]; then
echo 'This script must be run as root.' die 'This script must be run as root.'
exit 1
fi fi
if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
echo "Creating chroot for [${repo}] (${arch})..." msg "Creating chroot for [${repo}] (${arch})..."
for copy in "${chroots}/${repo}-${arch}"/*; do for copy in "${chroots}/${repo}-${arch}"/*; do
[[ -d $copy ]] || continue [[ -d $copy ]] || continue
echo "Deleting chroot copy '$(basename "${copy}")'..." msg2 "Deleting chroot copy '$(basename "${copy}")'..."
# Lock the copy # Lock the copy
exec 9>"${copy}.lock" exec 9>"${copy}.lock"
@ -71,5 +73,5 @@ else
"${chroots}/${repo}-${arch}/root" "${chroots}/${repo}-${arch}/root"
fi fi
echo "Building in chroot for [${repo}] (${arch})..." msg "Building in chroot for [${repo}] (${arch})..."
setarch "${arch}" makechrootpkg -c -r "${chroots}/${repo}-${arch}" setarch "${arch}" makechrootpkg -c -r "${chroots}/${repo}-${arch}"

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
m4_include(lib/common.sh)
scriptname=${0##*/} scriptname=${0##*/}
if [ "$1" = '' ]; then if [ "$1" = '' ]; then
@ -13,8 +15,7 @@ case $scriptname in
communityco) communityco)
SVNURL="svn+ssh://aur.archlinux.org/srv/svn-packages";; SVNURL="svn+ssh://aur.archlinux.org/srv/svn-packages";;
*) *)
echo "error: couldn't find svn url for $scriptname" die "error: couldn't find svn url for $scriptname"
exit 1
;; ;;
esac esac

View File

@ -1,18 +1,16 @@
#!/bin/bash #!/bin/bash
abort() { m4_include(lib/common.sh)
echo ${1:-'archrelease: Cancelled'}
exit 1
}
if [[ -z $1 ]]; then if [[ -z $1 ]]; then
abort 'Usage: archrelease <repo>...' echo 'Usage: archrelease <repo>...'
exit 1
fi fi
# TODO: validate repo is really repo-arch # TODO: validate repo is really repo-arch
if [[ ! -f PKGBUILD ]]; then if [[ ! -f PKGBUILD ]]; then
abort 'archrelease: PKGBUILD not found' die 'archrelease: PKGBUILD not found'
fi fi
trunk=${PWD##*/} trunk=${PWD##*/}
@ -21,24 +19,24 @@ trunk=${PWD##*/}
# such as 'gnome-unstable' # such as 'gnome-unstable'
IFS='/' read -r -d '' -a parts <<< "$PWD" IFS='/' read -r -d '' -a parts <<< "$PWD"
if [[ "${parts[@]:(-2):1}" == "repos" ]]; then if [[ "${parts[@]:(-2):1}" == "repos" ]]; then
abort 'archrelease: Should not be in repos dir (try from trunk/)' die 'archrelease: Should not be in repos dir (try from trunk/)'
fi fi
unset parts unset parts
if [[ $(svn status -q) ]]; then if [[ $(svn status -q) ]]; then
abort 'archrelease: You have not committed your changes yet!' die 'archrelease: You have not committed your changes yet!'
fi fi
pushd .. >/dev/null pushd .. >/dev/null
IFS=$'\n' read -r -d '' -a known_files < <(svn ls -r HEAD "$trunk") IFS=$'\n' read -r -d '' -a known_files < <(svn ls -r HEAD "$trunk")
for file in "${known_files[@]}"; do for file in "${known_files[@]}"; do
if [[ ${file:(-1)} = '/' ]]; then if [[ ${file:(-1)} = '/' ]]; then
abort "archrelease: subdirectories are not supported in package directories!" die "archrelease: subdirectories are not supported in package directories!"
fi fi
done done
for tag in "$@"; do for tag in "$@"; do
echo -n "copying ${trunk} to ${tag}..." stat_busy "copying ${trunk} to ${tag}"
if [[ -d repos/$tag ]]; then if [[ -d repos/$tag ]]; then
declare -a trash declare -a trash
@ -55,12 +53,12 @@ for tag in "$@"; do
# copy all files at once from trunk to the subdirectory in repos/ # copy all files at once from trunk to the subdirectory in repos/
svn copy -q -r HEAD ${known_files[@]/#/$trunk/} "repos/$tag/" svn copy -q -r HEAD ${known_files[@]/#/$trunk/} "repos/$tag/"
echo 'done' stat_done
done done
echo -n "releasing package..." stat_busy "releasing package"
printf -v tag_list ", %s" "$@"; tag_list="${tag_list#, }" printf -v tag_list ", %s" "$@"; tag_list="${tag_list#, }"
svn commit -q -m "archrelease: copy ${trunk} to $tag_list" || abort svn commit -q -m "archrelease: copy ${trunk} to $tag_list" || abort
echo 'done' stat_done
popd >/dev/null popd >/dev/null

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
m4_include(lib/common.sh)
if [ "$1" = '' ]; then if [ "$1" = '' ]; then
echo 'Usage: archrm <path to checkout>' echo 'Usage: archrm <path to checkout>'
exit 1 exit 1

View File

@ -1,11 +1,12 @@
#!/bin/bash #!/bin/bash
m4_include(lib/common.sh)
# Source makepkg.conf; fail if it is not found # Source makepkg.conf; fail if it is not found
if [[ -r '/etc/makepkg.conf' ]]; then if [[ -r '/etc/makepkg.conf' ]]; then
source '/etc/makepkg.conf' source '/etc/makepkg.conf'
else else
echo '/etc/makepkg.conf not found!' die '/etc/makepkg.conf not found!'
exit 1
fi fi
# Source user-specific makepkg.conf overrides # Source user-specific makepkg.conf overrides
@ -14,8 +15,7 @@ if [[ -r ~/.makepkg.conf ]]; then
fi fi
if [[ ! -f PKGBUILD ]]; then if [[ ! -f PKGBUILD ]]; then
echo 'This must be run in the directory of a built package.' die 'This must be run in the directory of a built package.'
exit 1
fi fi
. PKGBUILD . PKGBUILD
@ -28,33 +28,26 @@ TEMPDIR=$(mktemp -d --tmpdir checkpkg-script.XXXX)
cd "$TEMPDIR" cd "$TEMPDIR"
for _pkgname in "${pkgname[@]}"; do for _pkgname in "${pkgname[@]}"; do
if [[ -z ${epoch} ]] ; then pkgfile=${_pkgname}-$(get_full_version $_pkgname)-${CARCH}${PKGEXT}
pkgfile=${_pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}
else
pkgfile=${_pkgname}-${epoch}:${pkgver}-${pkgrel}-${CARCH}${PKGEXT}
fi
if [[ -f "$STARTDIR/$pkgfile" ]]; then if [[ -f "$STARTDIR/$pkgfile" ]]; then
ln -s "$STARTDIR/$pkgfile" "$pkgfile" ln -s "$STARTDIR/$pkgfile" "$pkgfile"
elif [[ -f "$PKGDEST/$pkgfile" ]]; then elif [[ -f "$PKGDEST/$pkgfile" ]]; then
ln -s "$PKGDEST/$pkgfile" "$pkgfile" ln -s "$PKGDEST/$pkgfile" "$pkgfile"
else else
echo "File \"$pkgfile\" doesn't exist" die "File \"$pkgfile\" doesn't exist"
exit 1
fi fi
pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname") pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname")
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Couldn't download previous package for $_pkgname." die "Couldn't download previous package for $_pkgname."
exit 1
fi fi
oldpkg=${pkgurl##*://*/} oldpkg=${pkgurl##*://*/}
if [[ ${oldpkg##*/} = ${pkgfile##*/} ]]; then if [[ ${oldpkg##*/} = ${pkgfile##*/} ]]; then
echo "The built package ($_pkgname) is the one in the repo right now!" die "The built package ($_pkgname) is the one in the repo right now!"
exit 1
fi fi
if [[ ! -f $oldpkg ]]; then if [[ ! -f $oldpkg ]]; then
@ -83,8 +76,8 @@ for _pkgname in "${pkgname[@]}"; do
done done
cd .. cd ..
else else
echo "No soname differences for $_pkgname." msg "No soname differences for $_pkgname."
fi fi
done done
echo "Files saved to $TEMPDIR" msg "Files saved to $TEMPDIR"

View File

@ -1,40 +1,22 @@
#!/bin/bash #!/bin/bash
abort() { m4_include(lib/common.sh)
echo ${1:-'Cancelled'}
exit 1
}
getpkgfile() { getpkgfile() {
if [[ ${#} -ne 1 ]]; then if [[ ${#} -ne 1 ]]; then
echo 'ERROR: No canonical package found!' >&2 die 'ERROR: No canonical package found!'
exit 1
elif [ ! -f "${1}" ]; then elif [ ! -f "${1}" ]; then
echo "ERROR: Package ${1} not found!" >&2 die "ERROR: Package ${1} not found!"
exit 1
fi fi
echo ${1} echo ${1}
} }
##
# usage : get_full_version( $epoch, $pkgver, $pkgrel )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
get_full_version() {
if [[ $1 -eq 0 ]]; then
# zero epoch case, don't include it in version
echo $2-$3
else
echo $1:$2-$3
fi
}
# Source makepkg.conf; fail if it is not found # Source makepkg.conf; fail if it is not found
if [ -r '/etc/makepkg.conf' ]; then if [ -r '/etc/makepkg.conf' ]; then
source '/etc/makepkg.conf' source '/etc/makepkg.conf'
else else
abort '/etc/makepkg.conf not found!' die '/etc/makepkg.conf not found!'
fi fi
# Source user-specific makepkg.conf overrides # Source user-specific makepkg.conf overrides
@ -45,7 +27,7 @@ fi
cmd=${0##*/} cmd=${0##*/}
if [ ! -f PKGBUILD ]; then if [ ! -f PKGBUILD ]; then
abort 'No PKGBUILD file' die 'No PKGBUILD file'
fi fi
. PKGBUILD . PKGBUILD
@ -54,7 +36,7 @@ pkgbase=${pkgbase:-$pkgname}
case "$cmd" in case "$cmd" in
commitpkg) commitpkg)
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
abort 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]' die 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]'
fi fi
repo="$1" repo="$1"
shift shift
@ -63,7 +45,7 @@ case "$cmd" in
repo="${cmd%pkg}" repo="${cmd%pkg}"
;; ;;
*) *)
abort 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]' die 'usage: commitpkg <reponame> [-l limit] [-a arch] [commit message]'
;; ;;
esac esac
@ -74,13 +56,13 @@ case "$repo" in
server='aur.archlinux.org' ;; server='aur.archlinux.org' ;;
*) *)
server='gerolde.archlinux.org' server='gerolde.archlinux.org'
echo "Non-standard repository $repo in use, defaulting to server $server" ;; msg "Non-standard repository $repo in use, defaulting to server $server" ;;
esac esac
# check if all local source files are under version control # check if all local source files are under version control
for s in "${source[@]}"; do for s in "${source[@]}"; do
if [[ $s != *://* ]] && ! svn status -v "$s" | grep -q '^[ AMRX~]'; then if [[ $s != *://* ]] && ! svn status -v "$s" | grep -q '^[ AMRX~]'; then
abort "$s is not under version control" die "$s is not under version control"
fi fi
done done
@ -90,7 +72,7 @@ for i in 'changelog' 'install'; do
# evaluate any bash variables used # evaluate any bash variables used
eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\" eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\"
if ! svn status -v "${file}" | grep -q '^[ AMRX~]'; then if ! svn status -v "${file}" | grep -q '^[ AMRX~]'; then
abort "${file} is not under version control" die "${file} is not under version control"
fi fi
done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD) done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD)
done done
@ -101,20 +83,19 @@ while getopts ':l:a:' flag; do
case $flag in case $flag in
l) rsyncopts+=("--bwlimit=$2") ;; l) rsyncopts+=("--bwlimit=$2") ;;
a) commit_arch=$2 ;; a) commit_arch=$2 ;;
:) echo "option requires an argument -- '$OPTARG'" >&2 :) die "option requires an argument -- '$OPTARG'" ;;
exit 1 ;; \?) die "invalid option -- '$OPTARG'" ;;
\?) echo "invalid option -- '$OPTARG'" >&2
exit 1 ;;
esac esac
done done
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
if [ -n "$(svn status -q)" ]; then if [ -n "$(svn status -q)" ]; then
echo -n 'committing changes to trunk...'
msgtemplate="upgpkg: $pkgbase $(get_full_version ${epoch:-0} $pkgver $pkgrel)"$'\n\n'
if [ -n "$1" ]; then if [ -n "$1" ]; then
svn commit -q -m "${msgtemplate}${1}" || abort stat_busy 'committing changes to trunk'
svn commit -q -m "${msgtemplate}${1}" || die
stat_done
else else
msgtemplate="upgpkg: $pkgbase $(get_full_version)"$'\n\n'
msgfile="$(mktemp)" msgfile="$(mktemp)"
echo "$msgtemplate" > "$msgfile" echo "$msgtemplate" > "$msgfile"
if [ -n "$SVN_EDITOR" ]; then if [ -n "$SVN_EDITOR" ]; then
@ -126,23 +107,24 @@ if [ -n "$(svn status -q)" ]; then
else else
vi "$msgfile" vi "$msgfile"
fi fi
[ -s "$msgfile" ] || abort [ -s "$msgfile" ] || die
svn commit -q -F "$msgfile" || abort stat_busy 'committing changes to trunk'
svn commit -q -F "$msgfile" || die
unlink "$msgfile" unlink "$msgfile"
stat_done
fi fi
echo 'done'
fi fi
declare -a uploads declare -a uploads
for _arch in ${arch[@]}; do for _arch in ${arch[@]}; do
if [ -n "$commit_arch" ] && [ "${_arch}" != "$commit_arch" ]; then if [ -n "$commit_arch" ] && [ "${_arch}" != "$commit_arch" ]; then
echo "skipping ${_arch}" warning "skipping ${_arch}"
continue continue
fi fi
for _pkgname in ${pkgname[@]}; do for _pkgname in ${pkgname[@]}; do
fullver=$(get_full_version ${epoch:-0} $pkgver $pkgrel) fullver=$(get_full_version $_pkgname)
pkgfile=$(getpkgfile "$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null) pkgfile=$(getpkgfile "$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null)
pkgdestfile=$(getpkgfile "$PKGDEST/$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null) pkgdestfile=$(getpkgfile "$PKGDEST/$_pkgname-$fullver-${_arch}".pkg.tar.?z 2>/dev/null)
@ -151,58 +133,58 @@ for _arch in ${arch[@]}; do
elif [ -f "$pkgdestfile" ]; then elif [ -f "$pkgdestfile" ]; then
pkgfile="$pkgdestfile" pkgfile="$pkgdestfile"
else else
echo "skipping ${_arch}" warning "skipping ${_arch}"
continue 2 continue 2
fi fi
uploads+=("$pkgfile") uploads+=("$pkgfile")
sigfile="${pkgfile}.sig" sigfile="${pkgfile}.sig"
if [[ $SIGNPKG == 'y' ]] && [ ! -f "${sigfile}" ]; then if [[ $SIGNPKG == 'y' ]] && [ ! -f "${sigfile}" ]; then
echo "Signing package ${pkgfile}..." msg "Signing package ${pkgfile}..."
if [[ -n $GPGKEY ]]; then if [[ -n $GPGKEY ]]; then
SIGNWITHKEY="-u ${GPGKEY}" SIGNWITHKEY="-u ${GPGKEY}"
fi fi
gpg --detach-sign --use-agent ${SIGNWITHKEY} "${pkgfile}" || abort gpg --detach-sign --use-agent ${SIGNWITHKEY} "${pkgfile}" || die
fi fi
if [ -f "${sigfile}" ]; then if [ -f "${sigfile}" ]; then
if ! gpg --verify "$sigfile" >/dev/null 2>&1; then if ! gpg --verify "$sigfile" >/dev/null 2>&1; then
abort "Signature ${pkgfile}.sig is incorrect!" die "Signature ${pkgfile}.sig is incorrect!"
fi fi
uploads+=("$sigfile") uploads+=("$sigfile")
else else
abort "Signature ${pkgfile}.sig was not found" die "Signature ${pkgfile}.sig was not found"
fi fi
done done
done done
if [[ -n $commit_arch ]]; then if [[ -n $commit_arch ]]; then
archrelease "$repo-$commit_arch" || abort archrelease "$repo-$commit_arch" || die
else else
archrelease "${arch[@]/#/$repo-}" || abort archrelease "${arch[@]/#/$repo-}" || die
fi fi
if [[ ${#uploads[*]} -gt 0 ]]; then if [[ ${#uploads[*]} -gt 0 ]]; then
echo 'uploading all package and signature files' msg 'uploading all package and signature files'
rsync "${rsyncopts[@]}" "${uploads[@]}" "$server:staging/$repo/" || abort rsync "${rsyncopts[@]}" "${uploads[@]}" "$server:staging/$repo/" || die
fi fi
if [ "${arch[*]}" == 'any' ]; then if [ "${arch[*]}" == 'any' ]; then
if [ -d ../repos/$repo-i686 -a -d ../repos/$repo-x86_64 ]; then if [ -d ../repos/$repo-i686 -a -d ../repos/$repo-x86_64 ]; then
pushd ../repos/ >/dev/null pushd ../repos/ >/dev/null
echo "removing $repo-i686 and $repo-x86_64..." stat_busy "removing $repo-i686 and $repo-x86_64"
svn rm $repo-i686 svn rm $repo-i686
svn rm $repo-x86_64 svn rm $repo-x86_64
svn commit -q -m "removed $repo-i686 and $repo-x86_64 for $pkgname" svn commit -q -m "removed $repo-i686 and $repo-x86_64 for $pkgname"
echo 'done' stat_done
popd >/dev/null popd >/dev/null
fi fi
else else
if [ -d ../repos/$repo-any ]; then if [ -d ../repos/$repo-any ]; then
pushd ../repos/ >/dev/null pushd ../repos/ >/dev/null
echo "removing $repo-any..." stat_busy "removing $repo-any"
svn rm $repo-any svn rm $repo-any
svn commit -q -m "removed $repo-any for $pkgname" svn commit -q -m "removed $repo-any for $pkgname"
echo 'done' stat_done
popd >/dev/null popd >/dev/null
fi fi
fi fi

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
m4_include(lib/common.sh)
set -e set -e
IGNORE_INTERNAL=0 IGNORE_INTERNAL=0
@ -13,7 +15,7 @@ script_mode=${0##*/find-lib}
case $script_mode in case $script_mode in
deps|provides) true;; deps|provides) true;;
*) echo "error: unknown mode $script_mode"; exit 1;; *) die "unknown mode $script_mode" ;;
esac esac
if [[ -z $1 ]]; then if [[ -z $1 ]]; then
@ -23,36 +25,19 @@ if [[ -z $1 ]]; then
exit 1 exit 1
fi fi
cleanup() {
if [[ $tmpdir ]]; then
rm -rf $tmpdir;
fi
}
if [[ -d $1 ]]; then if [[ -d $1 ]]; then
cd $1 pushd $1 >/dev/null
else else
tmpdir=$(mktemp -d /tmp/find-sodeps.XXXXXXX) setup_workdir
trap "cleanup" EXIT INT TERM
case ${script_mode} in case ${script_mode} in
deps) bsdtar -C $tmpdir -xf "$1";; deps) bsdtar -C $WORKDIR -xf "$1";;
provides)bsdtar -C $tmpdir -xf "$1" --include="*.so*";; provides) bsdtar -C $WORKDIR -xf "$1" --include="*.so*";;
esac esac
cd $tmpdir pushd $WORKDIR >/dev/null
fi fi
in_array() {
local needle=$1; shift
[[ -z $1 ]] && return 1 # Not Found
local item
for item in "$@"; do
[[ $item = $needle ]] && return 0 # Found
done
return 1 # Not Found
}
process_sofile() { process_sofile() {
# extract the library name: libfoo.so # extract the library name: libfoo.so
soname="${sofile%%\.so\.*}.so" soname="${sofile%%\.so\.*}.so"
@ -68,7 +53,7 @@ process_sofile() {
fi fi
} }
case $script_mode in case $script_mode in
deps) find_args="-perm -u+x";; deps) find_args="-perm -u+x";;
provides) find_args="-name *.so*";; provides) find_args="-name *.so*";;
esac esac
@ -98,3 +83,4 @@ find . -type f $find_args | while read filename; do
fi fi
done done
popd >/dev/null

View File

@ -3,6 +3,8 @@
# finddeps - find packages that depend on a given depname # finddeps - find packages that depend on a given depname
# #
m4_include(lib/common.sh)
match=$1 match=$1
if [[ -z $match ]]; then if [[ -z $match ]]; then
@ -11,7 +13,7 @@ if [[ -z $match ]]; then
echo 'Find packages that depend on a given depname.' echo 'Find packages that depend on a given depname.'
echo 'Run this script from the top-level directory of your ABS tree.' echo 'Run this script from the top-level directory of your ABS tree.'
echo '' echo ''
exit 0 exit 1
fi fi
find . -type d | while read d; do find . -type d | while read d; do

View File

@ -3,6 +3,8 @@
# lddd - find broken library links on your machine # lddd - find broken library links on your machine
# #
m4_include(lib/common.sh)
ifs=$IFS ifs=$IFS
IFS="${IFS}:" IFS="${IFS}:"
@ -11,10 +13,10 @@ extras=
TEMPDIR=$(mktemp -d --tmpdir lddd-script.XXXX) TEMPDIR=$(mktemp -d --tmpdir lddd-script.XXXX)
echo 'Go out and drink some tea, this will take a while :) ...' msg 'Go out and drink some tea, this will take a while :) ...'
# Check ELF binaries in the PATH and specified dir trees. # Check ELF binaries in the PATH and specified dir trees.
for tree in $PATH $libdirs $extras; do for tree in $PATH $libdirs $extras; do
echo DIR $tree msg2 "DIR $tree"
# Get list of files in tree. # Get list of files in tree.
files=$(find $tree -type f ! -name '*.a' ! -name '*.la' ! -name '*.py*' ! -name '*.txt' ! -name '*.h' ! -name '*.ttf' ! \ files=$(find $tree -type f ! -name '*.a' ! -name '*.la' ! -name '*.py*' ! -name '*.txt' ! -name '*.h' ! -name '*.ttf' ! \
@ -43,4 +45,4 @@ done
# clean list # clean list
sort -u $TEMPDIR/pacman.txt >> $TEMPDIR/possible-rebuilds.txt sort -u $TEMPDIR/pacman.txt >> $TEMPDIR/possible-rebuilds.txt
echo "Files saved to $TEMPDIR" msg "Files saved to $TEMPDIR"

124
lib/common.sh Normal file
View File

@ -0,0 +1,124 @@
# Avoid any encoding problems
export LANG=C
# check if messages are to be printed using color
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
if [[ -t 2 ]]; then
# prefer terminal safe colored and bold text when tput is supported
if tput setaf 0 &>/dev/null; then
ALL_OFF="$(tput sgr0)"
BOLD="$(tput bold)"
BLUE="${BOLD}$(tput setaf 4)"
GREEN="${BOLD}$(tput setaf 2)"
RED="${BOLD}$(tput setaf 1)"
YELLOW="${BOLD}$(tput setaf 3)"
else
ALL_OFF="\e[1;0m"
BOLD="\e[1;1m"
BLUE="${BOLD}\e[1;34m"
GREEN="${BOLD}\e[1;32m"
RED="${BOLD}\e[1;31m"
YELLOW="${BOLD}\e[1;33m"
fi
fi
readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
plain() {
local mesg=$1; shift
printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
msg() {
local mesg=$1; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
msg2() {
local mesg=$1; shift
printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
warning() {
local mesg=$1; shift
printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
error() {
local mesg=$1; shift
printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
stat_busy() {
local mesg=$1; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" >&2
}
stat_done() {
printf "${BOLD}done${ALL_OFF}\n" >&2
}
setup_workdir() {
[ -z "$WORKDIR" ] && WORKDIR=$(mktemp -d /tmp/$(basename $0).XXXXXXXXXX)
}
cleanup() {
trap - EXIT INT QUIT TERM
[ -n "$WORKDIR" ] && rm -rf "$WORKDIR"
[ "$1" ] && exit $1
}
abort() {
msg 'Aborting...'
cleanup 0
}
die() {
error "$*"
cleanup 1
}
trap abort INT QUIT TERM HUP
trap 'cleanup 0' EXIT
##
# usage : in_array( $needle, $haystack )
# return : 0 - found
# 1 - not found
##
in_array() {
local needle=$1; shift
local item
for item in "$@"; do
[[ $item = $needle ]] && return 0 # Found
done
return 1 # Not Found
}
##
# usage : get_full_version( [$pkgname] )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
get_full_version() {
# set defaults if they weren't specified in buildfile
pkgbase=${pkgbase:-${pkgname[0]}}
epoch=${epoch:-0}
if [[ -z $1 ]]; then
if [[ $epoch ]] && (( ! $epoch )); then
echo $pkgver-$pkgrel
else
echo $epoch:$pkgver-$pkgrel
fi
else
for i in pkgver pkgrel epoch; do
local indirect="${i}_override"
eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")
[[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
done
if (( ! $epoch_override )); then
echo $pkgver_override-$pkgrel_override
else
echo $epoch_override:$pkgver_override-$pkgrel_override
fi
fi
}

View File

@ -8,6 +8,8 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
m4_include(lib/common.sh)
shopt -s nullglob shopt -s nullglob
makepkg_args='-s --noconfirm -L' makepkg_args='-s --noconfirm -L'
@ -91,24 +93,19 @@ for arg in ${*:$OPTIND}; do
done done
if (( EUID )); then if (( EUID )); then
echo 'This script must be run as root.' die 'This script must be run as root.'
exit 1
fi fi
if [[ ! -f PKGBUILD && -z $install_pkg ]]; then if [[ ! -f PKGBUILD && -z $install_pkg ]]; then
echo 'This must be run in a directory containing a PKGBUILD.' die 'This must be run in a directory containing a PKGBUILD.'
exit 1
fi fi
if [[ ! -d $chrootdir ]]; then if [[ ! -d $chrootdir ]]; then
echo "No chroot dir defined, or invalid path '$chrootdir'" die "No chroot dir defined, or invalid path '$chrootdir'"
exit 1
fi fi
if [[ ! -d $chrootdir/root ]]; then if [[ ! -d $chrootdir/root ]]; then
echo 'Missing chroot dir root directory.' die "Missing chroot dir root directory. Try using: mkarchroot $chrootdir/root base base-devel sudo"
echo "Try using: mkarchroot $chrootdir/root base base-devel sudo"
exit 1
fi fi
umask 0022 umask 0022
@ -117,9 +114,9 @@ umask 0022
# Note this is the same FD number as in mkarchroot # Note this is the same FD number as in mkarchroot
exec 9>"$copydir.lock" exec 9>"$copydir.lock"
if ! flock -n 9; then if ! flock -n 9; then
echo -n "locking chroot copy '$copy'..." stat_busy "locking chroot copy '$copy'"
flock 9 flock 9
echo "done" stat_done
fi fi
if [[ ! -d $copydir ]] || $clean_first; then if [[ ! -d $copydir ]] || $clean_first; then
@ -128,12 +125,12 @@ if [[ ! -d $copydir ]] || $clean_first; then
exec 8>"$chrootdir/root.lock" exec 8>"$chrootdir/root.lock"
if ! flock -sn 8; then if ! flock -sn 8; then
echo -n "locking clean chroot..." stat_busy "locking clean chroot"
flock -s 8 flock -s 8
echo "done" stat_done
fi fi
echo -n 'creating clean working copy...' stat_busy 'creating clean working copy'
use_rsync=false use_rsync=false
if type -P btrfs >/dev/null; then if type -P btrfs >/dev/null; then
[[ -d $copydir ]] && btrfs subvolume delete "$copydir" &>/dev/null [[ -d $copydir ]] && btrfs subvolume delete "$copydir" &>/dev/null
@ -147,7 +144,7 @@ if [[ ! -d $copydir ]] || $clean_first; then
mkdir -p "$copydir" mkdir -p "$copydir"
rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir"
fi fi
echo 'done' stat_done
# Drop the read lock again # Drop the read lock again
exec 8>&- exec 8>&-
@ -310,7 +307,6 @@ for f in "$copydir"/srcdest/*; do
done done
if [[ -e $copydir/build/BUILD_FAILED ]]; then if [[ -e $copydir/build/BUILD_FAILED ]]; then
echo "Build failed, check $copydir/build"
rm "$copydir/build/BUILD_FAILED" rm "$copydir/build/BUILD_FAILED"
exit 1 die "Build failed, check $copydir/build"
fi fi

View File

@ -8,6 +8,8 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
m4_include(lib/common.sh)
FORCE='n' FORCE='n'
RUN='' RUN=''
NOCOPY='n' NOCOPY='n'
@ -28,7 +30,7 @@ usage() {
echo ' -n Do not copy config files into the chroot' echo ' -n Do not copy config files into the chroot'
echo ' -c <dir> Set pacman cache. Default: /var/cache/pacman/pkg' echo ' -c <dir> Set pacman cache. Default: /var/cache/pacman/pkg'
echo ' -h This message' echo ' -h This message'
exit $1 exit 1
} }
while getopts 'r:ufnhC:M:c:' arg; do while getopts 'r:ufnhC:M:c:' arg; do
@ -41,29 +43,26 @@ while getopts 'r:ufnhC:M:c:' arg; do
n) NOCOPY='y' ;; n) NOCOPY='y' ;;
c) cache_dir="$OPTARG" ;; c) cache_dir="$OPTARG" ;;
h|?) usage 0 ;; h|?) usage 0 ;;
*) echo "invalid argument '${arg}'"; usage 1 ;; *) error "invalid argument '${arg}'"; usage ;;
esac esac
done done
if [ "$EUID" != '0' ]; then if [ "$EUID" != '0' ]; then
echo 'error: this script must be run as root.' die 'this script must be run as root.'
exit 1
fi fi
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ "$RUN" = '' -a $# -lt 2 ]; then if [ "$RUN" = '' -a $# -lt 2 ]; then
echo 'you must specify a directory and one or more packages' die 'you must specify a directory and one or more packages'
usage 1
elif [ $# -lt 1 ]; then elif [ $# -lt 1 ]; then
echo 'you must specify a directory' die 'you must specify a directory'
usage 1
fi fi
working_dir="$(readlink -f ${1})" working_dir="$(readlink -f ${1})"
shift 1 shift 1
[ "${working_dir}" = '' ] && echo 'error: please specify a working directory' && usage 1 [ "${working_dir}" = '' ] && die 'please specify a working directory'
if [ -z "$cache_dir" ]; then if [ -z "$cache_dir" ]; then
cache_conf=${working_dir}/etc/pacman.conf cache_conf=${working_dir}/etc/pacman.conf
@ -150,9 +149,9 @@ chroot_lock () {
# Lock the chroot. Take note of the FD number. # Lock the chroot. Take note of the FD number.
if ! flock -n 9; then if ! flock -n 9; then
echo -n "locking chroot..." stat_busy "locking chroot"
flock 9 flock 9
echo "done" stat_done
fi fi
} }
# }}} # }}}
@ -162,9 +161,7 @@ if [ "$RUN" != "" ]; then
# run chroot {{{ # run chroot {{{
#Sanity check #Sanity check
if [ ! -f "${working_dir}/.arch-chroot" ]; then if [ ! -f "${working_dir}/.arch-chroot" ]; then
echo "error: '${working_dir}' does not appear to be a Arch chroot" die "'${working_dir}' does not appear to be a Arch chroot"
echo ' please build the image using mkarchroot'
exit 1
fi fi
chroot_lock chroot_lock
@ -177,8 +174,7 @@ if [ "$RUN" != "" ]; then
else else
# {{{ build chroot # {{{ build chroot
if [ -e "${working_dir}" -a "${FORCE}" = "n" ]; then if [ -e "${working_dir}" -a "${FORCE}" = "n" ]; then
echo "error: working dir '${working_dir}' already exists - try using -f" die "working dir '${working_dir}' already exists - try using -f"
exit 1
fi fi
if { type -P btrfs && btrfs subvolume create "${working_dir}"; } &>/dev/null; then if { type -P btrfs && btrfs subvolume create "${working_dir}"; } &>/dev/null; then
@ -202,8 +198,7 @@ else
op="${op}f" op="${op}f"
fi fi
if ! pacman ${op} ${pacargs} $@; then if ! pacman ${op} ${pacargs} $@; then
echo 'error: failed to install all packages' die 'failed to install all packages'
exit 1
fi fi
fi fi

View File

@ -9,6 +9,8 @@
# Currently uses $(pwd)/rebuilds as the directory for rebuilding... # Currently uses $(pwd)/rebuilds as the directory for rebuilding...
# TODO make this work for community too # TODO make this work for community too
m4_include(lib/common.sh)
if [ $# -le 1 ]; then if [ $# -le 1 ]; then
echo "usage: $(basename $0) <chrootdir> <packages to rebuild>" echo "usage: $(basename $0) <chrootdir> <packages to rebuild>"
echo " example: $(basename $0) ~/chroot readline bash foo bar baz" echo " example: $(basename $0) ~/chroot readline bash foo bar baz"
@ -19,15 +21,9 @@ fi
if [ -r '/etc/makepkg.conf' ]; then if [ -r '/etc/makepkg.conf' ]; then
source '/etc/makepkg.conf' source '/etc/makepkg.conf'
else else
echo '/etc/makepkg.conf not found!' die '/etc/makepkg.conf not found!'
exit 1
fi fi
die () {
echo $@ >&2
exit 1
}
bump_pkgrel() { bump_pkgrel() {
# Get the current pkgrel from SVN and update the working copy with it # Get the current pkgrel from SVN and update the working copy with it
# This prevents us from incrementing out of control :) # This prevents us from incrementing out of control :)
@ -53,7 +49,7 @@ pkgs="$@"
SVNPATH='svn+ssh://gerolde.archlinux.org/srv/svn-packages' SVNPATH='svn+ssh://gerolde.archlinux.org/srv/svn-packages'
echo ":: Work will be done in $(pwd)/rebuilds" msg "Work will be done in $(pwd)/rebuilds"
REBUILD_ROOT="$(pwd)/rebuilds" REBUILD_ROOT="$(pwd)/rebuilds"
mkdir -p "$REBUILD_ROOT" mkdir -p "$REBUILD_ROOT"
@ -65,11 +61,11 @@ FAILED=""
for pkg in $pkgs; do for pkg in $pkgs; do
cd "$REBUILD_ROOT/svn-packages" cd "$REBUILD_ROOT/svn-packages"
echo ":: Building '$pkg'" msg2 "Building '$pkg'"
/usr/bin/svn update "$pkg" /usr/bin/svn update "$pkg"
if [ ! -d "$pkg/trunk" ]; then if [ ! -d "$pkg/trunk" ]; then
FAILED="$FAILED $pkg" FAILED="$FAILED $pkg"
echo ":: $pkg does not exist in SVN" warning "$pkg does not exist in SVN"
continue continue
fi fi
cd "$pkg/trunk/" cd "$pkg/trunk/"
@ -78,24 +74,24 @@ for pkg in $pkgs; do
if ! sudo makechrootpkg -u -d -r "$chrootdir" -- --noconfirm; then if ! sudo makechrootpkg -u -d -r "$chrootdir" -- --noconfirm; then
FAILED="$FAILED $pkg" FAILED="$FAILED $pkg"
echo ":: $pkg Failed!" error "$pkg Failed!"
else else
pkgfile=$(pkg_from_pkgbuild) pkgfile=$(pkg_from_pkgbuild)
if [ -e "$pkgfile" ]; then if [ -e "$pkgfile" ]; then
echo ":: $pkg Complete" msg2 "$pkg Complete"
else else
FAILED="$FAILED $pkg" FAILED="$FAILED $pkg"
echo ":: $pkg Failed, no package built!" error "$pkg Failed, no package built!"
fi fi
fi fi
done done
cd "$REBUILD_ROOT" cd "$REBUILD_ROOT"
if [ "$FAILED" != "" ]; then if [ "$FAILED" != "" ]; then
echo 'Packages failed:' msg 'Packages failed:'
for pkg in $FAILED; do for pkg in $FAILED; do
echo -e "\t$pkg" msg2 "$pkg"
done done
fi fi
echo 'SVN pkgbumps in svn-packages/ - commit when ready' msg 'SVN pkgbumps in svn-packages/ - commit when ready'