Skip to content
Snippets Groups Projects
Commit ceae105e authored by Ramon Buldó's avatar Ramon Buldó
Browse files

Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	Makefile
#	arch-nspawn.in
#	archrelease.in
#	archrm.in
#	bash_completion.in
#	commitpkg.in
#	crossrepomove.in
#	lib/valid-tags.sh
#	rebuildpkgs.in
parents 4804dd5b 086ff8b9
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ edit = sed -e "s|@pkgdatadir[@]|$(DESTDIR)$(PREFIX)/share/devtools|g" ...@@ -42,7 +42,7 @@ edit = sed -e "s|@pkgdatadir[@]|$(DESTDIR)$(PREFIX)/share/devtools|g"
%: %.in Makefile lib/common.sh %: %.in Makefile lib/common.sh
@echo "GEN $@" @echo "GEN $@"
@$(RM) "$@" @$(RM) "$@"
@m4 -P $@.in | $(edit) >$@ @{ echo -n 'm4_changequote([[[,]]])'; cat $@.in; } | m4 -P | $(edit) >$@
@chmod a-w "$@" @chmod a-w "$@"
@chmod +x "$@" @chmod +x "$@"
@bash -O extglob -n "$@" @bash -O extglob -n "$@"
...@@ -78,4 +78,8 @@ dist: ...@@ -78,4 +78,8 @@ dist:
git archive --format=tar --prefix=devtools-$(V)/ $(V) | gzip -9 > devtools-$(V).tar.gz git archive --format=tar --prefix=devtools-$(V)/ $(V) | gzip -9 > devtools-$(V).tar.gz
gpg --detach-sign --use-agent devtools-$(V).tar.gz gpg --detach-sign --use-agent devtools-$(V).tar.gz
check: $(BINPROGS) bash_completion makepkg-x86_64.conf PKGBUILD.proto
shellcheck $^
.PHONY: all clean install uninstall dist .PHONY: all clean install uninstall dist
.DELETE_ON_ERROR:
#!/hint/bash
# shellcheck disable=2034
# This is an example PKGBUILD file, so that shellcheck can know what
# variables to expect be set after including a PKGBUILD.
# Maintainer: Your Name <youremail@domain.com>
pkgname=NAME
pkgver=VERSION
pkgrel=1
epoch=
pkgdesc=""
arch=()
url=""
license=('GPL')
groups=()
depends=()
makedepends=()
checkdepends=()
optdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=()
install=
changelog=
source=("$pkgname-$pkgver.tar.gz"
"$pkgname-$pkgver.patch")
noextract=()
md5sums=()
validpgpkeys=()
prepare() {
:
}
build() {
:
}
check() {
:
}
package() {
:
}
...@@ -44,7 +44,7 @@ while getopts 'hC:M:S:c:f:s' arg; do ...@@ -44,7 +44,7 @@ while getopts 'hC:M:S:c:f:s' arg; do
*) error "invalid argument '%s'" "$arg"; usage ;; *) error "invalid argument '%s'" "$arg"; usage ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
(( $# < 1 )) && die 'You must specify a directory.' (( $# < 1 )) && die 'You must specify a directory.'
check_root check_root
...@@ -60,7 +60,9 @@ else ...@@ -60,7 +60,9 @@ else
cache_dirs=("$cache_dir") cache_dirs=("$cache_dir")
fi fi
# shellcheck disable=2016
host_mirror=$(pacman --cachedir /doesnt/exist -Sddp extra/devtools 2>/dev/null | sed -E "s#(.*/)(.*/)extra/.*#\1branch/\$repo/\$arch#") host_mirror=$(pacman --cachedir /doesnt/exist -Sddp extra/devtools 2>/dev/null | sed -E "s#(.*/)(.*/)extra/.*#\1branch/\$repo/\$arch#")
# shellcheck disable=2016
[[ $host_mirror == *file://* ]] && host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') [[ $host_mirror == *file://* ]] && host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g')
# {{{ functions # {{{ functions
...@@ -68,22 +70,22 @@ build_mount_args() { ...@@ -68,22 +70,22 @@ build_mount_args() {
declare -g mount_args=() declare -g mount_args=()
if [[ -n $host_mirror_path ]]; then if [[ -n $host_mirror_path ]]; then
mount_args+=(--bind-ro="$host_mirror_path") mount_args+=("--bind-ro=$host_mirror_path")
fi fi
mount_args+=(--bind="${cache_dirs[0]}") mount_args+=("--bind=${cache_dirs[0]}")
for cache_dir in ${cache_dirs[@]:1}; do for cache_dir in "${cache_dirs[@]:1}"; do
mount_args+=(--bind-ro="$cache_dir") mount_args+=("--bind-ro=$cache_dir")
done done
} }
copy_hostconf () { copy_hostconf () {
cp -a /etc/pacman.d/gnupg "$working_dir/etc/pacman.d" cp -a /etc/pacman.d/gnupg "$working_dir/etc/pacman.d"
[[ -n $pac_conf ]] && cp $pac_conf "$working_dir/etc/pacman.conf" [[ -n $pac_conf ]] && cp "$pac_conf" "$working_dir/etc/pacman.conf"
[[ -n $makepkg_conf ]] && cp $makepkg_conf "$working_dir/etc/makepkg.conf" [[ -n $makepkg_conf ]] && cp "$makepkg_conf" "$working_dir/etc/makepkg.conf"
[[ -n $mirrors_conf ]] && cp ${mirrors_conf} "${working_dir}/etc/pacman-mirrors.conf" [[ -n $mirrors_conf ]] && cp "$mirrors_conf" "$working_dir/etc/pacman-mirrors.conf"
branch=$(cat "${working_dir}/etc/pacman-mirrors.conf" | grep '^Branch = ' | sed 's/Branch = \s*//g') branch=$(cat "${working_dir}/etc/pacman-mirrors.conf" | grep '^Branch = ' | sed 's/Branch = \s*//g')
host_mirror=$(echo "$host_mirror" | sed -E "s#/branch/#/${branch}/#") host_mirror=$(echo "$host_mirror" | sed -E "s#/branch/#/${branch}/#")
...@@ -95,7 +97,7 @@ copy_hostconf () { ...@@ -95,7 +97,7 @@ copy_hostconf () {
cp -T "$file" "$working_dir$file" cp -T "$file" "$working_dir$file"
done done
sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$working_dir/etc/pacman.conf" sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n "${cache_dirs[@]}")|g" -i "$working_dir/etc/pacman.conf"
} }
# }}} # }}}
...@@ -104,14 +106,14 @@ umask 0022 ...@@ -104,14 +106,14 @@ umask 0022
# Sanity check # Sanity check
if [[ ! -f "$working_dir/.manjaro-chroot" ]]; then if [[ ! -f "$working_dir/.manjaro-chroot" ]]; then
die "'%s' does not appear to be a Manjaro chroot." "$working_dir" die "'%s' does not appear to be a Manjaro chroot." "$working_dir"
elif [[ $(cat "$working_dir/.manjaro-chroot") != $CHROOT_VERSION ]]; then elif [[ $(cat "$working_dir/.manjaro-chroot") != "$CHROOT_VERSION" ]]; then
die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION" die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION"
fi fi
build_mount_args build_mount_args
copy_hostconf copy_hostconf
eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") eval "$(grep '^CARCH=' "$working_dir/etc/makepkg.conf")"
[[ -z $nosetarch ]] || unset CARCH [[ -z $nosetarch ]] || unset CARCH
......
...@@ -5,8 +5,8 @@ _devtools_compgen() { ...@@ -5,8 +5,8 @@ _devtools_compgen() {
local i r local i r
COMPREPLY=($(compgen -W '$*' -- "$cur")) COMPREPLY=($(compgen -W '$*' -- "$cur"))
for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do
for r in ${!COMPREPLY[@]}; do for r in "${!COMPREPLY[@]}"; do
if [[ ${COMP_WORDS[i]} = ${COMPREPLY[r]} ]]; then if [[ ${COMP_WORDS[i]} = "${COMPREPLY[r]}" ]]; then
unset 'COMPREPLY[r]'; break unset 'COMPREPLY[r]'; break
fi fi
done done
......
...@@ -7,6 +7,7 @@ m4_include(lib/common.sh) ...@@ -7,6 +7,7 @@ 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
# shellcheck source=makepkg-x86_64.conf
source '/etc/makepkg.conf' source '/etc/makepkg.conf'
else else
die '/etc/makepkg.conf not found!' die '/etc/makepkg.conf not found!'
...@@ -14,8 +15,10 @@ fi ...@@ -14,8 +15,10 @@ fi
# Source user-specific makepkg.conf overrides # Source user-specific makepkg.conf overrides
if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" ]]; then if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" ]]; then
# shellcheck source=/dev/null
source "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" source "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf"
elif [[ -r "$HOME/.makepkg.conf" ]]; then elif [[ -r "$HOME/.makepkg.conf" ]]; then
# shellcheck source=/dev/null
source "$HOME/.makepkg.conf" source "$HOME/.makepkg.conf"
fi fi
...@@ -23,8 +26,9 @@ if [[ ! -f PKGBUILD ]]; then ...@@ -23,8 +26,9 @@ if [[ ! -f PKGBUILD ]]; then
die 'This must be run in the directory of a built package.' die 'This must be run in the directory of a built package.'
fi fi
# shellcheck source=PKGBUILD.proto
. ./PKGBUILD . ./PKGBUILD
if [[ $arch == 'any' ]]; then if [[ ${arch[0]} == 'any' ]]; then
CARCH='any' CARCH='any'
fi fi
...@@ -39,15 +43,12 @@ for _pkgname in "${pkgname[@]}"; do ...@@ -39,15 +43,12 @@ for _pkgname in "${pkgname[@]}"; do
ln -s "$pkgfile" "$TEMPDIR" ln -s "$pkgfile" "$TEMPDIR"
pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname") pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname") ||
if [[ $? -ne 0 ]]; then
die "Couldn't download previous package for %s." "$_pkgname" die "Couldn't download previous package for %s." "$_pkgname"
fi
oldpkg=${pkgurl##*://*/} oldpkg=${pkgurl##*://*/}
if [[ ${oldpkg##*/} = ${pkgfile##*/} ]]; then if [[ ${oldpkg##*/} = "${pkgfile##*/}" ]]; then
die "The built package (%s) is the one in the repo right now!" "$_pkgname" die "The built package (%s) is the one in the repo right now!" "$_pkgname"
fi fi
......
...@@ -28,7 +28,7 @@ if [[ -z $1 ]]; then ...@@ -28,7 +28,7 @@ if [[ -z $1 ]]; then
fi fi
if [[ -d $1 ]]; then if [[ -d $1 ]]; then
pushd $1 >/dev/null pushd "$1" >/dev/null
else else
setup_workdir setup_workdir
...@@ -45,10 +45,10 @@ process_sofile() { ...@@ -45,10 +45,10 @@ process_sofile() {
soname="${sofile%.so?(+(.+([0-9])))}".so soname="${sofile%.so?(+(.+([0-9])))}".so
# extract the major version: 1 # extract the major version: 1
soversion="${sofile##*\.so\.}" soversion="${sofile##*\.so\.}"
if [[ "$soversion" = "$sofile" ]] && (($IGNORE_INTERNAL)); then if [[ "$soversion" = "$sofile" ]] && ((IGNORE_INTERNAL)); then
continue continue
fi fi
if ! in_array "${soname}=${soversion}-${soarch}" ${soobjects[@]}; then if ! in_array "${soname}=${soversion}-${soarch}" "${soobjects[@]}"; then
# libfoo.so=1-64 # libfoo.so=1-64
echo "${soname}=${soversion}-${soarch}" echo "${soname}=${soversion}-${soarch}"
soobjects+=("${soname}=${soversion}-${soarch}") soobjects+=("${soname}=${soversion}-${soarch}")
...@@ -60,7 +60,7 @@ case $script_mode in ...@@ -60,7 +60,7 @@ case $script_mode in
provides) find_args=(-name '*.so*');; provides) find_args=(-name '*.so*');;
esac esac
find . -type f "${find_args[@]}" | while read filename; do find . -type f "${find_args[@]}" | while read -r filename; do
if [[ $script_mode = "provides" ]]; then if [[ $script_mode = "provides" ]]; then
# ignore if we don't have a shared object # ignore if we don't have a shared object
if ! LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then if ! LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
......
...@@ -17,24 +17,25 @@ if [[ -z $match ]]; then ...@@ -17,24 +17,25 @@ if [[ -z $match ]]; then
exit 1 exit 1
fi fi
find . -type d | while read d; do find . -type d | while read -r d; do
if [[ -f "$d/PKGBUILD" ]]; then if [[ -f "$d/PKGBUILD" ]]; then
unset pkgname depends makedepends optdepends pkgname=() depends=() makedepends=() optdepends=()
# shellcheck source=PKGBUILD.proto
. "$d/PKGBUILD" . "$d/PKGBUILD"
for dep in "${depends[@]}"; do for dep in "${depends[@]}"; do
# lose the version comparator, if any # lose the version comparator, if any
depname=${dep%%[<>=]*} depname=${dep%%[<>=]*}
[[ $depname = $match ]] && echo "$d (depends)" [[ $depname = "$match" ]] && echo "$d (depends)"
done done
for dep in "${makedepends[@]}"; do for dep in "${makedepends[@]}"; do
# lose the version comparator, if any # lose the version comparator, if any
depname=${dep%%[<>=]*} depname=${dep%%[<>=]*}
[[ $depname = $match ]] && echo "$d (makedepends)" [[ $depname = "$match" ]] && echo "$d (makedepends)"
done done
for dep in "${optdepends[@]/:*}"; do for dep in "${optdepends[@]/:*}"; do
# lose the version comaparator, if any # lose the version comaparator, if any
depname=${dep%%[<>=]*} depname=${dep%%[<>=]*}
[[ $depname = $match ]] && echo "$d (optdepends)" [[ $depname = "$match" ]] && echo "$d (optdepends)"
done done
fi fi
done done
...@@ -20,7 +20,7 @@ for tree in $PATH $libdirs $extras; do ...@@ -20,7 +20,7 @@ for tree in $PATH $libdirs $extras; do
msg2 "DIR %s" "$tree" msg2 "DIR %s" "$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' ! \
-name '*.rb' ! -name '*.ko' ! -name '*.pc' ! -name '*.enc' ! -name '*.cf' ! -name '*.def' ! -name '*.rules' ! -name \ -name '*.rb' ! -name '*.ko' ! -name '*.pc' ! -name '*.enc' ! -name '*.cf' ! -name '*.def' ! -name '*.rules' ! -name \
'*.cmi' ! -name '*.mli' ! -name '*.ml' ! -name '*.cma' ! -name '*.cmx' ! -name '*.cmxa' ! -name '*.pod' ! -name '*.pm' \ '*.cmi' ! -name '*.mli' ! -name '*.ml' ! -name '*.cma' ! -name '*.cmx' ! -name '*.cmxa' ! -name '*.pod' ! -name '*.pm' \
! -name '*.pl' ! -name '*.al' ! -name '*.tcl' ! -name '*.bs' ! -name '*.o' ! -name '*.png' ! -name '*.gif' ! -name '*.cmo' \ ! -name '*.pl' ! -name '*.al' ! -name '*.tcl' ! -name '*.bs' ! -name '*.o' ! -name '*.png' ! -name '*.gif' ! -name '*.cmo' \
...@@ -28,22 +28,22 @@ for tree in $PATH $libdirs $extras; do ...@@ -28,22 +28,22 @@ for tree in $PATH $libdirs $extras; do
-name '*.mcopclass' ! -name '*.mcoptype') -name '*.mcopclass' ! -name '*.mcoptype')
IFS=$ifs IFS=$ifs
for i in $files; do for i in $files; do
if (( $(file $i | grep -c 'ELF') != 0 )); then if (( $(file "$i" | grep -c 'ELF') != 0 )); then
# Is an ELF binary. # Is an ELF binary.
if (( $(ldd $i 2>/dev/null | grep -c 'not found') != 0 )); then if (( $(ldd "$i" 2>/dev/null | grep -c 'not found') != 0 )); then
# Missing lib. # Missing lib.
echo "$i:" >> $TEMPDIR/raw.txt echo "$i:" >> "$TEMPDIR/raw.txt"
ldd $i 2>/dev/null | grep 'not found' >> $TEMPDIR/raw.txt ldd "$i" 2>/dev/null | grep 'not found' >> "$TEMPDIR/raw.txt"
fi fi
fi fi
done done
done done
grep '^/' $TEMPDIR/raw.txt | sed -e 's/://g' >> $TEMPDIR/affected-files.txt grep '^/' "$TEMPDIR/raw.txt" | sed -e 's/://g' >> "$TEMPDIR/affected-files.txt"
# invoke pacman # invoke pacman
for i in $(cat $TEMPDIR/affected-files.txt); do while read -r i; do
pacman -Qo $i | awk '{print $4,$5}' >> $TEMPDIR/pacman.txt pacman -Qo "$i" | awk '{print $4,$5}' >> "$TEMPDIR/pacman.txt"
done done < "$TEMPDIR/affected-files.txt"
# clean list # clean list
sort -u $TEMPDIR/pacman.txt >> $TEMPDIR/possible-rebuilds.txt sort -u "$TEMPDIR/pacman.txt" >> "$TEMPDIR/possible-rebuilds.txt"
msg "Files saved to %s" "$TEMPDIR" msg "Files saved to %s" "$TEMPDIR"
#!/hint/bash #!/hint/bash
# License: Unspecified # License: Unspecified
:
# shellcheck disable=2034
CHROOT_VERSION='v4' CHROOT_VERSION='v4'
## ##
...@@ -24,6 +26,23 @@ is_btrfs() { ...@@ -24,6 +26,23 @@ is_btrfs() {
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]] [[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]]
} }
##
# usage : is_subvolume( $path )
# return : whether $path is a the root of a btrfs subvolume (including
# the top-level subvolume).
##
is_subvolume() {
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs && "$(stat -c %i "$1")" == 256 ]]
}
##
# usage : is_same_fs( $path_a, $path_b )
# return : whether $path_a and $path_b are on the same filesystem
##
is_same_fs() {
[[ "$(stat -c %d "$1")" == "$(stat -c %d "$1")" ]]
}
## ##
# usage : subvolume_delete_recursive( $path ) # usage : subvolume_delete_recursive( $path )
# #
...@@ -32,14 +51,17 @@ is_btrfs() { ...@@ -32,14 +51,17 @@ is_btrfs() {
subvolume_delete_recursive() { subvolume_delete_recursive() {
local subvol local subvol
is_btrfs "$1" || return 0 is_subvolume "$1" || return 0
while IFS= read -d $'\0' -r subvol; do while IFS= read -d $'\0' -r subvol; do
if ! btrfs subvolume delete "$subvol" &>/dev/null; then if ! subvolume_delete_recursive "$subvol"; then
error "Unable to delete subvolume %s" "$subvol"
return 1 return 1
fi fi
done < <(find "$1" -xdev -depth -inum 256 -print0) done < <(find "$1" -mindepth 1 -xdev -depth -inum 256 -print0)
if ! btrfs subvolume delete "$1" &>/dev/null; then
error "Unable to delete subvolume %s" "$subvol"
return 1
fi
return 0 return 0
} }
...@@ -35,35 +35,42 @@ readonly ALL_OFF BOLD BLUE GREEN RED YELLOW ...@@ -35,35 +35,42 @@ readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
plain() { plain() {
local mesg=$1; shift local mesg=$1; shift
# shellcheck disable=2059
printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
} }
msg() { msg() {
local mesg=$1; shift local mesg=$1; shift
# shellcheck disable=2059
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
} }
msg2() { msg2() {
local mesg=$1; shift local mesg=$1; shift
# shellcheck disable=2059
printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
} }
warning() { warning() {
local mesg=$1; shift local mesg=$1; shift
# shellcheck disable=2059
printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
} }
error() { error() {
local mesg=$1; shift local mesg=$1; shift
# shellcheck disable=2059
printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
} }
stat_busy() { stat_busy() {
local mesg=$1; shift local mesg=$1; shift
# shellcheck disable=2059
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2
} }
stat_done() { stat_done() {
# shellcheck disable=2059
printf "${BOLD}done${ALL_OFF}\n" >&2 printf "${BOLD}done${ALL_OFF}\n" >&2
} }
...@@ -79,7 +86,7 @@ cleanup() { ...@@ -79,7 +86,7 @@ cleanup() {
if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then
rm -rf "$WORKDIR" rm -rf "$WORKDIR"
fi fi
exit ${1:-0} exit "${1:-0}"
} }
abort() { abort() {
...@@ -112,7 +119,7 @@ in_array() { ...@@ -112,7 +119,7 @@ in_array() {
local needle=$1; shift local needle=$1; shift
local item local item
for item in "$@"; do for item in "$@"; do
[[ $item = $needle ]] && return 0 # Found [[ $item = "$needle" ]] && return 0 # Found
done done
return 1 # Not Found return 1 # Not Found
} }
...@@ -123,24 +130,27 @@ in_array() { ...@@ -123,24 +130,27 @@ in_array() {
## ##
get_full_version() { get_full_version() {
# set defaults if they weren't specified in buildfile # set defaults if they weren't specified in buildfile
pkgbase=${pkgbase:-${pkgname[0]}} local pkgbase=${pkgbase:-${pkgname[0]}}
epoch=${epoch:-0} local epoch=${epoch:-0}
local pkgver=${pkgver}
local pkgrel=${pkgrel}
if [[ -z $1 ]]; then if [[ -z $1 ]]; then
if (( ! epoch )); then if (( ! epoch )); then
echo $pkgver-$pkgrel printf '%s\n' "$pkgver-$pkgrel"
else else
echo $epoch:$pkgver-$pkgrel printf '%s\n' "$epoch:$pkgver-$pkgrel"
fi fi
else else
local pkgver_override='' pkgrel_override='' epoch_override=''
for i in pkgver pkgrel epoch; do for i in pkgver pkgrel epoch; do
local indirect="${i}_override" local indirect="${i}_override"
eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p") eval "$(declare -f "package_$1" | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")"
[[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\" [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
done done
if (( ! $epoch_override )); then if (( ! epoch_override )); then
echo $pkgver_override-$pkgrel_override printf '%s\n' "$pkgver_override-$pkgrel_override"
else else
echo $epoch_override:$pkgver_override-$pkgrel_override printf '%s\n' "$epoch_override:$pkgver_override-$pkgrel_override"
fi fi
fi fi
} }
...@@ -155,9 +165,9 @@ lock() { ...@@ -155,9 +165,9 @@ lock() {
eval "exec $1>"'"$2"' eval "exec $1>"'"$2"'
fi fi
if ! flock -n $1; then if ! flock -n "$1"; then
stat_busy "${@:3}" stat_busy "${@:3}"
flock $1 flock "$1"
stat_done stat_done
fi fi
} }
...@@ -172,9 +182,9 @@ slock() { ...@@ -172,9 +182,9 @@ slock() {
eval "exec $1>"'"$2"' eval "exec $1>"'"$2"'
fi fi
if ! flock -sn $1; then if ! flock -sn "$1"; then
stat_busy "${@:3}" stat_busy "${@:3}"
flock -s $1 flock -s "$1"
stat_done stat_done
fi fi
} }
...@@ -184,6 +194,8 @@ slock() { ...@@ -184,6 +194,8 @@ slock() {
## ##
lock_close() { lock_close() {
local fd=$1 local fd=$1
# https://github.com/koalaman/shellcheck/issues/862
# shellcheck disable=2034
exec {fd}>&- exec {fd}>&-
} }
...@@ -247,7 +259,7 @@ find_cached_package() { ...@@ -247,7 +259,7 @@ find_cached_package() {
return 1 return 1
;; ;;
1) 1)
printf '%s\n' "$results" printf '%s\n' "${results[0]}"
return 0 return 0
;; ;;
*) *)
......
#!/hint/bash #!/hint/bash
# License: Unspecified # License: Unspecified
:
# shellcheck disable=2034
_arch=( _arch=(
i686 i686
x86_64 x86_64
......
...@@ -92,42 +92,43 @@ load_vars() { ...@@ -92,42 +92,43 @@ load_vars() {
[[ -f $makepkg_conf ]] || return 1 [[ -f $makepkg_conf ]] || return 1
for var in {SRC,SRCPKG,PKG,LOG}DEST MAKEFLAGS PACKAGER; do for var in {SRC,SRCPKG,PKG,LOG}DEST MAKEFLAGS PACKAGER; do
[[ -z ${!var:-} ]] && eval $(grep "^${var}=" "$makepkg_conf") [[ -z ${!var:-} ]] && eval "$(grep "^${var}=" "$makepkg_conf")"
done done
return 0 return 0
} }
# Usage: sync_chroot $CHROOTDIR/$CHROOT <$CHROOTCOPY|$copydir> # Usage: sync_chroot $rootdir $copydir [$copy]
sync_chroot() { sync_chroot() {
local chrootdir=$1 local rootdir=$1
local copy=$2 local copydir=$2
local copydir='' local copy=${3:-$2}
if [[ ${copy:0:1} = / ]]; then
copydir=$copy
else
copydir="$chrootdir/$copy"
fi
if [[ "$chrootdir/root" -ef "$copydir" ]]; then if [[ "$rootdir" -ef "$copydir" ]]; then
error 'Cannot sync copy with itself: %s' "$copydir" error 'Cannot sync copy with itself: %s' "$copydir"
return 1 return 1
fi fi
# Get a read lock on the root chroot to make # Get a read lock on the root chroot to make
# sure we don't clone a half-updated chroot # sure we don't clone a half-updated chroot
slock 8 "$chrootdir/root.lock" \ slock 8 "$rootdir.lock" \
"Locking clean chroot [%s]" "$chrootdir/root" "Locking clean chroot [%s]" "$rootdir"
stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$rootdir" "$copy"
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then if is_subvolume "$rootdir" && is_same_fs "$rootdir" "$(dirname -- "$copydir")" && ! mountpoint -q "$copydir"; then
subvolume_delete_recursive "$copydir" || if is_subvolume "$copydir"; then
die "Unable to delete subvolume %s" "$copydir" subvolume_delete_recursive "$copydir" ||
btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir"
else
# avoid change of filesystem in case of an umount failure
rm --recursive --force --one-file-system "$copydir" ||
die "Unable to delete %s" "$copydir"
fi
btrfs subvolume snapshot "$rootdir" "$copydir" >/dev/null ||
die "Unable to create subvolume %s" "$copydir" die "Unable to create subvolume %s" "$copydir"
else else
mkdir -p "$copydir" mkdir -p "$copydir"
rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" rsync -a --delete -q -W -x "$rootdir/" "$copydir"
fi fi
stat_done stat_done
...@@ -144,7 +145,7 @@ delete_chroot() { ...@@ -144,7 +145,7 @@ delete_chroot() {
local copy=${1:-$2} local copy=${1:-$2}
stat_busy "Removing chroot copy [%s]" "$copy" stat_busy "Removing chroot copy [%s]" "$copy"
if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then if is_subvolume "$copydir" && ! mountpoint -q "$copydir"; then
subvolume_delete_recursive "$copydir" || subvolume_delete_recursive "$copydir" ||
die "Unable to delete subvolume %s" "$copydir" die "Unable to delete subvolume %s" "$copydir"
else else
...@@ -189,8 +190,9 @@ prepare_chroot() { ...@@ -189,8 +190,9 @@ prepare_chroot() {
$repack || rm -rf "$copydir/build" $repack || rm -rf "$copydir/build"
local builduser_uid="${SUDO_UID:-$UID}" local builduser_uid builduser_gid
local builduser_gid="$(id -g "$builduser_uid")" builduser_uid="${SUDO_UID:-$UID}"
builduser_gid="$(id -g "$builduser_uid")"
local install="install -o $builduser_uid -g $builduser_gid" local install="install -o $builduser_uid -g $builduser_gid"
local x local x
...@@ -198,8 +200,8 @@ prepare_chroot() { ...@@ -198,8 +200,8 @@ prepare_chroot() {
# which we might not be able to load (i.e. when building i686 packages on # which we might not be able to load (i.e. when building i686 packages on
# an x86_64 host). # an x86_64 host).
sed -e '/^builduser:/d' -i "$copydir"/etc/{passwd,group} sed -e '/^builduser:/d' -i "$copydir"/etc/{passwd,group}
printf >>"$copydir/etc/group" 'builduser:x:%d:\n' $builduser_gid printf >>"$copydir/etc/group" 'builduser:x:%d:\n' "$builduser_gid"
printf >>"$copydir/etc/passwd" 'builduser:x:%d:%d:builduser:/build:/bin/bash\n' $builduser_uid $builduser_gid printf >>"$copydir/etc/passwd" 'builduser:x:%d:%d:builduser:/build:/bin/bash\n' "$builduser_uid" "$builduser_gid"
$install -d "$copydir"/{build,build/.gnupg,startdir,{pkg,srcpkg,src,log}dest} $install -d "$copydir"/{build,build/.gnupg,startdir,{pkg,srcpkg,src,log}dest}
...@@ -239,7 +241,12 @@ EOF ...@@ -239,7 +241,12 @@ EOF
# These functions aren't run in makechrootpkg, # These functions aren't run in makechrootpkg,
# so no global variables # so no global variables
_chrootbuild() { _chrootbuild() {
# shellcheck source=/dev/null
. /etc/profile . /etc/profile
# Beware, there are some stupid arbitrary rules on how you can
# use "$" in arguments to commands with "sudo -i". ${foo} or
# ${1} is OK, but $foo or $1 isn't.
# https://bugzilla.sudo.ws/show_bug.cgi?id=765
sudo -iu builduser bash -c 'cd /startdir; makepkg "$@"' -bash "$@" sudo -iu builduser bash -c 'cd /startdir; makepkg "$@"' -bash "$@"
} }
...@@ -251,27 +258,27 @@ _chrootnamcap() { ...@@ -251,27 +258,27 @@ _chrootnamcap() {
done done
} }
# Usage: download_sources $copydir $src_owner # Usage: download_sources $copydir $makepkg_user
# Globals: # Globals:
# - SRCDEST # - SRCDEST
# - USER # - USER
download_sources() { download_sources() {
local copydir=$1 local copydir=$1
local src_owner=$2 local makepkg_user=$2
local builddir="$(mktemp -d)" local builddir
builddir="$(mktemp -d)"
chmod 1777 "$builddir" chmod 1777 "$builddir"
# Ensure sources are downloaded # Ensure sources are downloaded
makepkg_user=${makepkg_user:-$SUDO_USER} if [[ "$(id -u "$makepkg_user")" != 0 ]]; then
if [[ -n $makepkg_user ]]; then
sudo -u "$makepkg_user" env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ sudo -u "$makepkg_user" env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \
makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o ||
die "Could not download sources."
else else
error "Running makepkg as root is not allowed." error "Running makepkg as root is not allowed."
exit 1 exit 1
fi fi
(( $? != 0 )) && die "Could not download sources."
# Clean up garbage from verifysource # Clean up garbage from verifysource
rm -rf "$builddir" rm -rf "$builddir"
...@@ -306,6 +313,11 @@ move_products() { ...@@ -306,6 +313,11 @@ move_products() {
for s in "$copydir"/srcpkgdest/*; do for s in "$copydir"/srcpkgdest/*; do
chown "$src_owner" "$s" chown "$src_owner" "$s"
mv "$s" "$SRCPKGDEST" mv "$s" "$SRCPKGDEST"
# Fix broken symlink because of temporary chroot SRCPKGDEST /srcpkgdest
if [[ "$PWD" != "$SRCPKGDEST" && -L "$PWD/${s##*/}" ]]; then
ln -sf "$SRCPKGDEST/${s##*/}"
fi
done done
} }
# }}} # }}}
...@@ -316,8 +328,8 @@ main() { ...@@ -316,8 +328,8 @@ main() {
while getopts 'hcur:I:l:nTD:d:U:' arg; do while getopts 'hcur:I:l:nTD:d:U:' arg; do
case "$arg" in case "$arg" in
c) clean_first=true ;; c) clean_first=true ;;
D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; D) bindmounts_ro+=("--bind-ro=$OPTARG") ;;
d) bindmounts_rw+=(--bind="$OPTARG") ;; d) bindmounts_rw+=("--bind=$OPTARG") ;;
u) update_first=true ;; u) update_first=true ;;
r) passeddir="$OPTARG" ;; r) passeddir="$OPTARG" ;;
I) install_pkgs+=("$OPTARG") ;; I) install_pkgs+=("$OPTARG") ;;
...@@ -331,6 +343,7 @@ main() { ...@@ -331,6 +343,7 @@ main() {
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' [[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
[[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.' [[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.'
makepkg_user=${makepkg_user:-${SUDO_USER:-$USER}}
check_root check_root
...@@ -379,7 +392,7 @@ main() { ...@@ -379,7 +392,7 @@ main() {
lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy"
if [[ ! -d $copydir ]] || $clean_first; then if [[ ! -d $copydir ]] || $clean_first; then
sync_chroot "$chrootdir" "$copy" sync_chroot "$chrootdir/root" "$copydir" "$copy"
fi fi
$update_first && arch-nspawn "$copydir" \ $update_first && arch-nspawn "$copydir" \
...@@ -393,7 +406,7 @@ main() { ...@@ -393,7 +406,7 @@ main() {
[[ -f PKGBUILD ]] || return $ret [[ -f PKGBUILD ]] || return $ret
fi fi
download_sources "$copydir" "$src_owner" download_sources "$copydir" "$makepkg_user"
prepare_chroot "$copydir" "$USER_HOME" "$repack" prepare_chroot "$copydir" "$USER_HOME" "$repack"
......
#!/hint/bash
# shellcheck disable=2034
# #
# /etc/makepkg.conf # /etc/makepkg.conf
# #
...@@ -37,9 +40,9 @@ CHOST="i686-pc-linux-gnu" ...@@ -37,9 +40,9 @@ CHOST="i686-pc-linux-gnu"
# -march (or -mcpu) builds exclusively for an architecture # -march (or -mcpu) builds exclusively for an architecture
# -mtune optimizes for an architecture, but builds for whole processor family # -mtune optimizes for an architecture, but builds for whole processor family
CPPFLAGS="-D_FORTIFY_SOURCE=2" CPPFLAGS="-D_FORTIFY_SOURCE=2"
CFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong" CFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt"
CXXFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong" CXXFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt"
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro" LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
#-- Make Flags: change this for DistCC/SMP systems #-- Make Flags: change this for DistCC/SMP systems
#MAKEFLAGS="-j2" #MAKEFLAGS="-j2"
#-- Debugging flags #-- Debugging flags
......
#!/hint/bash
# shellcheck disable=2034
# #
# /etc/makepkg.conf # /etc/makepkg.conf
# #
...@@ -37,9 +40,9 @@ CHOST="x86_64-pc-linux-gnu" ...@@ -37,9 +40,9 @@ CHOST="x86_64-pc-linux-gnu"
# -march (or -mcpu) builds exclusively for an architecture # -march (or -mcpu) builds exclusively for an architecture
# -mtune optimizes for an architecture, but builds for whole processor family # -mtune optimizes for an architecture, but builds for whole processor family
CPPFLAGS="-D_FORTIFY_SOURCE=2" CPPFLAGS="-D_FORTIFY_SOURCE=2"
CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong" CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt"
CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong" CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt"
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro" LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
#-- Make Flags: change this for DistCC/SMP systems #-- Make Flags: change this for DistCC/SMP systems
#MAKEFLAGS="-j2" #MAKEFLAGS="-j2"
#-- Debugging flags #-- Debugging flags
......
...@@ -42,19 +42,19 @@ while getopts 'hC:M:S:c:f:s' arg; do ...@@ -42,19 +42,19 @@ while getopts 'hC:M:S:c:f:s' arg; do
*) error "invalid argument '%s'" "$arg"; usage ;; *) error "invalid argument '%s'" "$arg"; usage ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $((OPTIND - 1))
(( $# < 2 )) && die 'You must specify a directory and one or more packages.' (( $# < 2 )) && die 'You must specify a directory and one or more packages.'
check_root check_root
working_dir="$(readlink -f $1)" working_dir="$(readlink -f "$1")"
shift 1 shift 1
[[ -z $working_dir ]] && die 'Please specify a working directory.' [[ -z $working_dir ]] && die 'Please specify a working directory.'
if [[ -z $cache_dir ]]; then if [[ -z $cache_dir ]]; then
cache_dirs=($(pacman -v $cache_conf 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g')) cache_dirs=($(pacman -v "$cache_conf" 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
else else
cache_dirs=(${cache_dir}) cache_dirs=(${cache_dir})
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment