From c9b1fc08b5f63c9f6bb1a992431c661129ab2db1 Mon Sep 17 00:00:00 2001 From: Bartłomiej Piotrowski Date: Tue, 4 Jul 2017 12:04:51 +0200 Subject: Sync makepkg.conf files with pacman 5.0.2-2 --- makepkg-i686.conf | 6 +++--- makepkg-x86_64.conf | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/makepkg-i686.conf b/makepkg-i686.conf index c565795..e57988f 100644 --- a/makepkg-i686.conf +++ b/makepkg-i686.conf @@ -37,9 +37,9 @@ CHOST="i686-pc-linux-gnu" # -march (or -mcpu) builds exclusively for an architecture # -mtune optimizes for an architecture, but builds for whole processor family CPPFLAGS="-D_FORTIFY_SOURCE=2" -CFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong" -CXXFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong" -LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro" +CFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" +CXXFLAGS="-march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" +LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now" #-- Make Flags: change this for DistCC/SMP systems #MAKEFLAGS="-j2" #-- Debugging flags diff --git a/makepkg-x86_64.conf b/makepkg-x86_64.conf index 058da9b..7aa192e 100644 --- a/makepkg-x86_64.conf +++ b/makepkg-x86_64.conf @@ -37,9 +37,9 @@ CHOST="x86_64-pc-linux-gnu" # -march (or -mcpu) builds exclusively for an architecture # -mtune optimizes for an architecture, but builds for whole processor family CPPFLAGS="-D_FORTIFY_SOURCE=2" -CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong" -CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong" -LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro" +CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" +CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt" +LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now" #-- Make Flags: change this for DistCC/SMP systems #MAKEFLAGS="-j2" #-- Debugging flags -- cgit v1.2.3-70-g09d2 From 2a9b30ed3594c2dc8c5012fc845572b8d452a9b0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:40:58 -0400 Subject: makechrootpkg: delete_chroot: Fix the is-btrfs-subvolume check. First of all, it ran `is_btrfs "$chrootdir"` to decide if it was on btrfs, but $chrootdir wasn't defined locally; it just happens to work because $chrootdir was defined in main(). (I noticed this because in Parabola, it is called differently, so $chrootdir was empty). So I was tempted to just change it to `is_btrfs "$copydir"`, but if $copydir is just a regular directory on a btrfs filesystem, then it It would leave much of $copydir intact. What we really care about is if $copydir is a btrfs subvolume; which we can check by combining the is_btrfs check with inspecting the inum of the directory. I put this combined check in lib/archroot.sh:is_subvolume. https://lists.archlinux.org/pipermail/arch-projects/2013-September/003901.html --- lib/archroot.sh | 11 ++++++++++- makechrootpkg.in | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/archroot.sh b/lib/archroot.sh index 46d4963..87c28a2 100644 --- a/lib/archroot.sh +++ b/lib/archroot.sh @@ -24,6 +24,15 @@ is_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 : subvolume_delete_recursive( $path ) # @@ -32,7 +41,7 @@ is_btrfs() { subvolume_delete_recursive() { local subvol - is_btrfs "$1" || return 0 + is_subvolume "$1" || return 0 while IFS= read -d $'\0' -r subvol; do if ! btrfs subvolume delete "$subvol" &>/dev/null; then diff --git a/makechrootpkg.in b/makechrootpkg.in index 72b7eb7..88c2cdc 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -144,7 +144,7 @@ delete_chroot() { local copy=${1:-$2} 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" || die "Unable to delete subvolume %s" "$copydir" else -- cgit v1.2.3-70-g09d2 From 928744cbc457b9b7e89e4b80c136ccbfd1164fb2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:40:59 -0400 Subject: makechrootpkg: sync_chroot: make usage easier to understand. Also, shorten the "Synchronizing" message to only include the full path to the copy if it was specified. The capslocked variable names in the Usage comment were references to things in Parabola's tools, that didn't make much sense here out of context. --- makechrootpkg.in | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 88c2cdc..d92d6ab 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -98,16 +98,11 @@ load_vars() { return 0 } -# Usage: sync_chroot $CHROOTDIR/$CHROOT <$CHROOTCOPY|$copydir> +# Usage: sync_chroot $chrootdir $copydir [$copy] sync_chroot() { local chrootdir=$1 - local copy=$2 - local copydir='' - if [[ ${copy:0:1} = / ]]; then - copydir=$copy - else - copydir="$chrootdir/$copy" - fi + local copydir=$2 + local copy=${3:-$2} if [[ "$chrootdir/root" -ef "$copydir" ]]; then error 'Cannot sync copy with itself: %s' "$copydir" @@ -119,7 +114,7 @@ sync_chroot() { slock 8 "$chrootdir/root.lock" \ "Locking clean chroot [%s]" "$chrootdir/root" - stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" + stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copy" if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then subvolume_delete_recursive "$copydir" || die "Unable to delete subvolume %s" "$copydir" @@ -379,7 +374,7 @@ main() { lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" if [[ ! -d $copydir ]] || $clean_first; then - sync_chroot "$chrootdir" "$copy" + sync_chroot "$chrootdir" "$copydir" "$copy" fi $update_first && arch-nspawn "$copydir" \ -- cgit v1.2.3-70-g09d2 From 6d1992909cc46e293027ff488ae2632047603e66 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:00 -0400 Subject: makechrootpkg: sync_chroot: Make more general. This is inspired by the thought that went in to the delete_chroot is_subvolume commit. sync_chroot($chrootdir, $copydir) copies `$chrootdir/root` to `$copydir`. That seems a little silly; why do we care about "$chrootdir"? Have it just be sync_chroot(source, destination) like every other sync/copy command. Where this becomes tricky is check to decide if we are going to use btrfs subvolumes or not. We don't care if "$source/.." is on btrfs; the root could be a directly-mounted subvolume, but and the destination could be another subvolume of the same btrfs mounted somewhere else. The things we do care about are: - The source is a btrfs subvolume (so that we can snapshot it) - The source is on the same filesystem as the directory that the copy will be created in. - If the destination exists: * that it is not a mountpoint (so that we can delete and recreate it) * that it is a btrfs subvolume (so that we can quickly delete it) On the last point, it isn't necessary for creating the new snapshot, just for quick deletion. That can be a separate check, where we use regular `rm` for deleting the existing copy, but use subvolume snapshots for creating the new one. --- lib/archroot.sh | 8 ++++++++ makechrootpkg.in | 32 +++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/lib/archroot.sh b/lib/archroot.sh index 87c28a2..6b1b52e 100644 --- a/lib/archroot.sh +++ b/lib/archroot.sh @@ -33,6 +33,14 @@ 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 ) # diff --git a/makechrootpkg.in b/makechrootpkg.in index d92d6ab..cc3c738 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -98,31 +98,37 @@ load_vars() { return 0 } -# Usage: sync_chroot $chrootdir $copydir [$copy] +# Usage: sync_chroot $rootdir $copydir [$copy] sync_chroot() { - local chrootdir=$1 + local rootdir=$1 local copydir=$2 local copy=${3:-$2} - if [[ "$chrootdir/root" -ef "$copydir" ]]; then + if [[ "$rootdir" -ef "$copydir" ]]; then error 'Cannot sync copy with itself: %s' "$copydir" return 1 fi # Get a read lock on the root chroot to make # sure we don't clone a half-updated chroot - slock 8 "$chrootdir/root.lock" \ - "Locking clean chroot [%s]" "$chrootdir/root" - - stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copy" - if is_btrfs "$chrootdir" && ! mountpoint -q "$copydir"; then - subvolume_delete_recursive "$copydir" || - die "Unable to delete subvolume %s" "$copydir" - btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || + slock 8 "$rootdir.lock" \ + "Locking clean chroot [%s]" "$rootdir" + + stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$rootdir" "$copy" + if is_subvolume "$rootdir" && is_same_fs "$rootdir" "$(dirname -- "$copydir")" && ! mountpoint -q "$copydir"; then + if is_subvolume "$copydir"; then + subvolume_delete_recursive "$copydir" || + 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" else mkdir -p "$copydir" - rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" + rsync -a --delete -q -W -x "$rootdir/" "$copydir" fi stat_done @@ -374,7 +380,7 @@ main() { lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" if [[ ! -d $copydir ]] || $clean_first; then - sync_chroot "$chrootdir" "$copydir" "$copy" + sync_chroot "$chrootdir/root" "$copydir" "$copy" fi $update_first && arch-nspawn "$copydir" \ -- cgit v1.2.3-70-g09d2 From 31a800fd8821396f6a17a2e38e04c792c7f61b3e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:01 -0400 Subject: lib/archroot.sh: subvolume_delete_recursive: support arbitrary recursion The `-xdev` flag to `find` makes it not recurse over subvolumes; so it only supports recursion with depth=1. Fix this by having the function recursively call itself. --- lib/archroot.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/archroot.sh b/lib/archroot.sh index 6b1b52e..3a1023e 100644 --- a/lib/archroot.sh +++ b/lib/archroot.sh @@ -52,11 +52,14 @@ subvolume_delete_recursive() { is_subvolume "$1" || return 0 while IFS= read -d $'\0' -r subvol; do - if ! btrfs subvolume delete "$subvol" &>/dev/null; then - error "Unable to delete subvolume %s" "$subvol" + if ! subvolume_delete_recursive "$subvol"; then return 1 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 } -- cgit v1.2.3-70-g09d2 From 4f23609d4e4a9a8be837b6d426442de1cd68c653 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:02 -0400 Subject: makechroot: download_sources: Accept makepkg_owner as an argument What this is really doing is fixing a conflict that I had incorrectly resolved when rebasing what became 2fd5931 onto cda9cf4. Of course, because of dynamic scoping, everything worked out, and everything worked as intended. Before cda9cf4, it was appropriate for download_sources to take src_owner as an argument, but after cda9cf4, it is now appropriate to take makepkg_user as an argument. However, it still takes src_owner as an argument, but pays 0 attention to it; instead looking at makepkg_user which it happily inherited because of dynamic scoping. So change it to take makepkg_user as the argument. --- makechrootpkg.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index cc3c738..d922fa0 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -252,20 +252,19 @@ _chrootnamcap() { done } -# Usage: download_sources $copydir $src_owner +# Usage: download_sources $copydir $makepkg_user # Globals: # - SRCDEST # - USER download_sources() { local copydir=$1 - local src_owner=$2 + local makepkg_user=$2 local builddir="$(mktemp -d)" chmod 1777 "$builddir" # Ensure sources are downloaded - makepkg_user=${makepkg_user:-$SUDO_USER} - if [[ -n $makepkg_user ]]; then + if [[ "$(id -u "$makepkg_user")" != 0 ]]; then sudo -u "$makepkg_user" env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o else @@ -332,6 +331,7 @@ main() { [[ ! -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.' + makepkg_user=${makepkg_user:-${SUDO_USER:-$USER}} check_root @@ -394,7 +394,7 @@ main() { [[ -f PKGBUILD ]] || return $ret fi - download_sources "$copydir" "$src_owner" + download_sources "$copydir" "$makepkg_user" prepare_chroot "$copydir" "$USER_HOME" "$repack" -- cgit v1.2.3-70-g09d2 From 007d6fc15feb9e4ba8b0e7eedf83d14eb4d54441 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:03 -0400 Subject: Makefile: add .DELETE_ON_ERROR: The absence of it was allowing an (m4-produced) syntax error in in a change I had made to be masked. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3b30097..f4a00ba 100644 --- a/Makefile +++ b/Makefile @@ -115,4 +115,4 @@ upload: scp devtools-$(V).tar.gz devtools-$(V).tar.gz.sig repos.archlinux.org:/srv/ftp/other/devtools/ .PHONY: all clean install uninstall dist upload - +.DELETE_ON_ERROR: -- cgit v1.2.3-70-g09d2 From 2fdd1654b5dbfa508b15e258b51af1a000402459 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:04 -0400 Subject: Makefile: m4_changequote([[[, ]]]) to avoid accidental quoting. The default m4 quote characters: `QUOTE' are troublesome, because ` is fairly likely to pop up in a shell script (if not for a subshell, because it is a useful character in comments and user-facing messages). So, this changes it to [[[QUOTE]]], as it is unlikely to see three braces together like that, let alone in unbalanced sets. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f4a00ba..d5f6ad7 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ edit = sed -e "s|@pkgdatadir[@]|$(DESTDIR)$(PREFIX)/share/devtools|g" %: %.in Makefile lib/common.sh @echo "GEN $@" @$(RM) "$@" - @m4 -P $@.in | $(edit) >$@ + @{ echo -n 'm4_changequote([[[,]]])'; cat $@.in; } | m4 -P | $(edit) >$@ @chmod a-w "$@" @chmod +x "$@" @bash -O extglob -n "$@" -- cgit v1.2.3-70-g09d2 From 56cace32b29e427e2f33754cf7f50bf691b619ce Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:05 -0400 Subject: makechrootpkg: Add a comment warning about a bug in "sudo -i" The bug isn't currently triggered, but I accidentally did trigger when I was trying to modify the command a bit. I figure a "caution" sign would be helpful to any future developers. --- makechrootpkg.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/makechrootpkg.in b/makechrootpkg.in index d922fa0..2a19dbb 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -241,6 +241,10 @@ EOF # so no global variables _chrootbuild() { . /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 "$@" } -- cgit v1.2.3-70-g09d2 From 430e1265fbe5c752217195aebdb5949416f0bb7a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:06 -0400 Subject: Makefile: Add a simple 'check' target that runs shellcheck --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d5f6ad7..39614a4 100644 --- a/Makefile +++ b/Makefile @@ -114,5 +114,8 @@ dist: upload: scp devtools-$(V).tar.gz devtools-$(V).tar.gz.sig repos.archlinux.org:/srv/ftp/other/devtools/ -.PHONY: all clean install uninstall dist upload +check: $(BINPROGS) bash_completion makepkg-x86_64.conf + shellcheck $^ + +.PHONY: all clean install uninstall dist upload check .DELETE_ON_ERROR: -- cgit v1.2.3-70-g09d2 From 3f72579b2813bd93c586aec80c48472f41c60d78 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:07 -0400 Subject: Make purely stylistic changes to make shellcheck happier. These are purely stylistic changes that make shellcheck complain less. This does NOT include things like quoting currently unquoted variables. --- arch-nspawn.in | 8 ++++---- bash_completion.in | 2 +- checkpkg.in | 7 ++----- commitpkg.in | 2 +- find-libdeps.in | 2 +- finddeps.in | 2 +- lib/common.sh | 4 ++-- makechrootpkg.in | 16 +++++++++------- mkarchroot.in | 2 +- rebuildpkgs.in | 2 +- 10 files changed, 23 insertions(+), 24 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 08ed2fa..548ebec 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -42,7 +42,7 @@ while getopts 'hC:M:c:f:s' arg; do *) error "invalid argument '%s'" "$arg"; usage ;; esac done -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) (( $# < 1 )) && die 'You must specify a directory.' check_root @@ -66,13 +66,13 @@ build_mount_args() { declare -g mount_args=() if [[ -n $host_mirror_path ]]; then - mount_args+=(--bind-ro="$host_mirror_path") + mount_args+=("--bind-ro=$host_mirror_path") fi - mount_args+=(--bind="${cache_dirs[0]}") + mount_args+=("--bind=${cache_dirs[0]}") for cache_dir in ${cache_dirs[@]:1}; do - mount_args+=(--bind-ro="$cache_dir") + mount_args+=("--bind-ro=$cache_dir") done } diff --git a/bash_completion.in b/bash_completion.in index f5a3077..f0a6bd0 100644 --- a/bash_completion.in +++ b/bash_completion.in @@ -15,7 +15,7 @@ _devtools_compgen() { _archco_pkg() { _devtools_compgen "$( - \pacman -$1 + command pacman "-$1" )" } diff --git a/checkpkg.in b/checkpkg.in index ec58ff6..03e29f7 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -24,7 +24,7 @@ if [[ ! -f PKGBUILD ]]; then fi . ./PKGBUILD -if [[ $arch == 'any' ]]; then +if [[ ${arch[0]} == 'any' ]]; then CARCH='any' fi @@ -39,11 +39,8 @@ for _pkgname in "${pkgname[@]}"; do ln -s "$pkgfile" "$TEMPDIR" - pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname") - - if [[ $? -ne 0 ]]; then + pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname") || die "Couldn't download previous package for %s." "$_pkgname" - fi oldpkg=${pkgurl##*://*/} diff --git a/commitpkg.in b/commitpkg.in index 1f9492c..87f5b8b 100644 --- a/commitpkg.in +++ b/commitpkg.in @@ -64,7 +64,7 @@ if (( ${#needsversioning[*]} )); then (( ${#unversioned[*]} )) && die "%s is not under version control" "${unversioned[@]}" fi -rsyncopts=(-e ssh -p --chmod=ug=rw,o=r -c -h -L --progress --partial -y) +rsyncopts=(-e ssh -p '--chmod=ug=rw,o=r' -c -h -L --progress --partial -y) archreleaseopts=() while getopts ':l:a:s:f' flag; do case $flag in diff --git a/find-libdeps.in b/find-libdeps.in index 5c350a9..c596f48 100644 --- a/find-libdeps.in +++ b/find-libdeps.in @@ -45,7 +45,7 @@ process_sofile() { soname="${sofile%.so?(+(.+([0-9])))}".so # extract the major version: 1 soversion="${sofile##*\.so\.}" - if [[ "$soversion" = "$sofile" ]] && (($IGNORE_INTERNAL)); then + if [[ "$soversion" = "$sofile" ]] && ((IGNORE_INTERNAL)); then continue fi if ! in_array "${soname}=${soversion}-${soarch}" ${soobjects[@]}; then diff --git a/finddeps.in b/finddeps.in index 89ccc41..03e5501 100644 --- a/finddeps.in +++ b/finddeps.in @@ -19,7 +19,7 @@ fi find . -type d | while read d; do if [[ -f "$d/PKGBUILD" ]]; then - unset pkgname depends makedepends optdepends + pkgname=() depends=() makedepends=() optdepends=() . "$d/PKGBUILD" for dep in "${depends[@]}"; do # lose the version comparator, if any diff --git a/lib/common.sh b/lib/common.sh index c9afc36..8f043e8 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -137,7 +137,7 @@ get_full_version() { eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p") [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\" done - if (( ! $epoch_override )); then + if (( ! epoch_override )); then echo $pkgver_override-$pkgrel_override else echo $epoch_override:$pkgver_override-$pkgrel_override @@ -247,7 +247,7 @@ find_cached_package() { return 1 ;; 1) - printf '%s\n' "$results" + printf '%s\n' "${results[0]}" return 0 ;; *) diff --git a/makechrootpkg.in b/makechrootpkg.in index 2a19dbb..f8e8505 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -190,8 +190,9 @@ prepare_chroot() { $repack || rm -rf "$copydir/build" - local builduser_uid="${SUDO_UID:-$UID}" - local builduser_gid="$(id -g "$builduser_uid")" + local builduser_uid builduser_gid + builduser_uid="${SUDO_UID:-$UID}" + builduser_gid="$(id -g "$builduser_uid")" local install="install -o $builduser_uid -g $builduser_gid" local x @@ -264,18 +265,19 @@ download_sources() { local copydir=$1 local makepkg_user=$2 - local builddir="$(mktemp -d)" + local builddir + builddir="$(mktemp -d)" chmod 1777 "$builddir" # Ensure sources are downloaded if [[ "$(id -u "$makepkg_user")" != 0 ]]; then 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 error "Running makepkg as root is not allowed." exit 1 fi - (( $? != 0 )) && die "Could not download sources." # Clean up garbage from verifysource rm -rf "$builddir" @@ -320,8 +322,8 @@ main() { while getopts 'hcur:I:l:nTD:d:U:' arg; do case "$arg" in c) clean_first=true ;; - D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; - d) bindmounts_rw+=(--bind="$OPTARG") ;; + D) bindmounts_ro+=("--bind-ro=$OPTARG") ;; + d) bindmounts_rw+=("--bind=$OPTARG") ;; u) update_first=true ;; r) passeddir="$OPTARG" ;; I) install_pkgs+=("$OPTARG") ;; diff --git a/mkarchroot.in b/mkarchroot.in index 3aff357..152d323 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -40,7 +40,7 @@ while getopts 'hC:M:c:f:s' arg; do *) error "invalid argument '%s'" "$arg"; usage ;; esac done -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) (( $# < 2 )) && die 'You must specify a directory and one or more packages.' diff --git a/rebuildpkgs.in b/rebuildpkgs.in index 9197231..be3fd33 100644 --- a/rebuildpkgs.in +++ b/rebuildpkgs.in @@ -42,7 +42,7 @@ bump_pkgrel() { #remove decimals rel=$(echo $oldrel | cut -d. -f1) - newrel=$(($rel + 1)) + newrel=$((rel + 1)) sed -i "s/pkgrel=$oldrel/pkgrel=$newrel/" PKGBUILD } -- cgit v1.2.3-70-g09d2 From 78fabcfa0694ae8c81e1d5ec0e5dacaed533545e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:08 -0400 Subject: Quote strings that shellcheck warns about. These changes are all strictly "slap some double-quotes in there". Anything more than that is not included in this commit. --- arch-nspawn.in | 12 ++++++------ archrelease.in | 2 +- archrm.in | 2 +- bash_completion.in | 4 ++-- checkpkg.in | 2 +- commitpkg.in | 30 +++++++++++++++--------------- crossrepomove.in | 10 +++++----- find-libdeps.in | 4 ++-- finddeps.in | 6 +++--- lddd.in | 16 ++++++++-------- lib/common.sh | 16 +++++++++------- makechrootpkg.in | 6 +++--- mkarchroot.in | 4 ++-- 13 files changed, 58 insertions(+), 56 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 548ebec..2d42e3a 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -71,7 +71,7 @@ build_mount_args() { 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") done } @@ -80,8 +80,8 @@ copy_hostconf () { cp -a /etc/pacman.d/gnupg "$working_dir/etc/pacman.d" echo "Server = $host_mirror" >"$working_dir/etc/pacman.d/mirrorlist" - [[ -n $pac_conf ]] && cp $pac_conf "$working_dir/etc/pacman.conf" - [[ -n $makepkg_conf ]] && cp $makepkg_conf "$working_dir/etc/makepkg.conf" + [[ -n $pac_conf ]] && cp "$pac_conf" "$working_dir/etc/pacman.conf" + [[ -n $makepkg_conf ]] && cp "$makepkg_conf" "$working_dir/etc/makepkg.conf" local file for file in "${files[@]}"; do @@ -89,7 +89,7 @@ copy_hostconf () { cp -T "$file" "$working_dir$file" 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" } # }}} @@ -98,14 +98,14 @@ umask 0022 # Sanity check if [[ ! -f "$working_dir/.arch-chroot" ]]; then die "'%s' does not appear to be an Arch chroot." "$working_dir" -elif [[ $(cat "$working_dir/.arch-chroot") != $CHROOT_VERSION ]]; then +elif [[ $(cat "$working_dir/.arch-chroot") != "$CHROOT_VERSION" ]]; then die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION" fi build_mount_args copy_hostconf -eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") +eval "$(grep '^CARCH=' "$working_dir/etc/makepkg.conf")" [[ -z $nosetarch ]] || unset CARCH diff --git a/archrelease.in b/archrelease.in index 3b11652..2ba9d48 100644 --- a/archrelease.in +++ b/archrelease.in @@ -74,7 +74,7 @@ for tag in "$@"; do fi # 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/" stat_done done diff --git a/archrm.in b/archrm.in index 3173131..6f4dfc3 100644 --- a/archrm.in +++ b/archrm.in @@ -13,4 +13,4 @@ fi # #popd -rm -rf $1 +rm -rf "$1" diff --git a/bash_completion.in b/bash_completion.in index f0a6bd0..9feef74 100644 --- a/bash_completion.in +++ b/bash_completion.in @@ -5,8 +5,8 @@ _devtools_compgen() { local i r COMPREPLY=($(compgen -W '$*' -- "$cur")) for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do - for r in ${!COMPREPLY[@]}; do - if [[ ${COMP_WORDS[i]} = ${COMPREPLY[r]} ]]; then + for r in "${!COMPREPLY[@]}"; do + if [[ ${COMP_WORDS[i]} = "${COMPREPLY[r]}" ]]; then unset 'COMPREPLY[r]'; break fi done diff --git a/checkpkg.in b/checkpkg.in index 03e29f7..20920be 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -44,7 +44,7 @@ for _pkgname in "${pkgname[@]}"; do oldpkg=${pkgurl##*://*/} - if [[ ${oldpkg##*/} = ${pkgfile##*/} ]]; then + if [[ ${oldpkg##*/} = "${pkgfile##*/}" ]]; then die "The built package (%s) is the one in the repo right now!" "$_pkgname" fi diff --git a/commitpkg.in b/commitpkg.in index 87f5b8b..0482170 100644 --- a/commitpkg.in +++ b/commitpkg.in @@ -50,7 +50,7 @@ done for i in 'changelog' 'install'; do while read -r file; do # evaluate any bash variables used - eval file=\"$(sed "s/^\(['\"]\)\(.*\)\1\$/\2/" <<< "$file")\" + eval "file=\"$(sed "s/^\(['\"]\)\(.*\)\1\$/\2/" <<< "$file")\"" needsversioning+=("$file") done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD) done @@ -79,12 +79,12 @@ done shift $(( OPTIND - 1 )) # check packages have the packager field set -for _arch in ${arch[@]}; do +for _arch in "${arch[@]}"; do if [[ -n $commit_arch && ${_arch} != "$commit_arch" ]]; then continue fi - for _pkgname in ${pkgname[@]}; do - fullver=$(get_full_version $_pkgname) + for _pkgname in "${pkgname[@]}"; do + fullver=$(get_full_version "$_pkgname") if pkgfile=$(find_cached_package "$_pkgname" "$_arch" "$fullver"); then if grep -q "packager = Unknown Packager" <(bsdtar -xOqf "$pkgfile" .PKGINFO); then @@ -128,18 +128,18 @@ declare -a uploads declare -a commit_arches declare -a skip_arches -for _arch in ${arch[@]}; do +for _arch in "${arch[@]}"; do if [[ -n $commit_arch && ${_arch} != "$commit_arch" ]]; then - skip_arches+=($_arch) + skip_arches+=("$_arch") continue fi - for _pkgname in ${pkgname[@]}; do - fullver=$(get_full_version $_pkgname) + for _pkgname in "${pkgname[@]}"; do + fullver=$(get_full_version "$_pkgname") if ! pkgfile=$(find_cached_package "$_pkgname" "$fullver" "${_arch}"); then warning "Skipping %s: failed to locate package file" "$_pkgname-$fullver-$_arch" - skip_arches+=($_arch) + skip_arches+=("$_arch") continue 2 fi uploads+=("$pkgfile") @@ -159,9 +159,9 @@ for _arch in ${arch[@]}; do done done -for _arch in ${arch[@]}; do - if ! in_array $_arch ${skip_arches[@]}; then - commit_arches+=($_arch) +for _arch in "${arch[@]}"; do + if ! in_array "$_arch" "${skip_arches[@]}"; then + commit_arches+=("$_arch") fi done @@ -187,8 +187,8 @@ if [[ "${arch[*]}" == 'any' ]]; then if [[ -d ../repos/$repo-i686 && -d ../repos/$repo-x86_64 ]]; then pushd ../repos/ >/dev/null stat_busy "Removing %s and %s" "$repo-i686" "$repo-x86_64" - svn rm -q $repo-i686 - svn rm -q $repo-x86_64 + svn rm -q "$repo-i686" + svn rm -q "$repo-x86_64" svn commit -q -m "Removed $repo-i686 and $repo-x86_64 for $pkgname" stat_done popd >/dev/null @@ -197,7 +197,7 @@ else if [[ -d ../repos/$repo-any ]]; then pushd ../repos/ >/dev/null stat_busy "Removing %s" "$repo-any" - svn rm -q $repo-any + svn rm -q "$repo-any" svn commit -q -m "Removed $repo-any for $pkgname" stat_done popd >/dev/null diff --git a/crossrepomove.in b/crossrepomove.in index 14c264e..ffc4507 100644 --- a/crossrepomove.in +++ b/crossrepomove.in @@ -38,7 +38,7 @@ target_dbscripts="/srv/repos/svn-${target_name}/dbscripts" setup_workdir -pushd $WORKDIR >/dev/null +pushd "$WORKDIR" >/dev/null msg "Downloading sources for %s" "${pkgbase}" svn -q checkout -N "${target_svn}" target_checkout @@ -47,14 +47,14 @@ svn -q export "${source_svn}/${pkgbase}/trunk" "target_checkout/${pkgbase}/trunk . "target_checkout/${pkgbase}/trunk/PKGBUILD" msg "Downloading packages for %s" "${pkgbase}" -for _arch in ${arch[@]}; do +for _arch in "${arch[@]}"; do if [[ "${_arch[*]}" == 'any' ]]; then repo_arch='x86_64' else repo_arch=${_arch} fi - for _pkgname in ${pkgname[@]}; do - fullver=$(get_full_version $_pkgname) + for _pkgname in "${pkgname[@]}"; do + fullver=$(get_full_version "$_pkgname") pkgpath="/srv/ftp/$source_repo/os/$repo_arch/$_pkgname-$fullver-${_arch}.pkg.tar.*" ssh "$server" "cp $pkgpath staging/$target_repo" || die done @@ -71,7 +71,7 @@ popd >/dev/null ssh "${server}" "${target_dbscripts}/db-update" || die msg "Removing %s from %s" "${pkgbase}" "${source_repo}" -for _arch in ${arch[@]}; do +for _arch in "${arch[@]}"; do ssh "${server}" "${source_dbscripts}/db-remove ${source_repo} ${_arch} ${pkgbase}" done svn -q checkout -N "${source_svn}" source_checkout diff --git a/find-libdeps.in b/find-libdeps.in index c596f48..04adebf 100644 --- a/find-libdeps.in +++ b/find-libdeps.in @@ -28,7 +28,7 @@ if [[ -z $1 ]]; then fi if [[ -d $1 ]]; then - pushd $1 >/dev/null + pushd "$1" >/dev/null else setup_workdir @@ -48,7 +48,7 @@ process_sofile() { if [[ "$soversion" = "$sofile" ]] && ((IGNORE_INTERNAL)); then continue fi - if ! in_array "${soname}=${soversion}-${soarch}" ${soobjects[@]}; then + if ! in_array "${soname}=${soversion}-${soarch}" "${soobjects[@]}"; then # libfoo.so=1-64 echo "${soname}=${soversion}-${soarch}" soobjects+=("${soname}=${soversion}-${soarch}") diff --git a/finddeps.in b/finddeps.in index 03e5501..c71f151 100644 --- a/finddeps.in +++ b/finddeps.in @@ -24,17 +24,17 @@ find . -type d | while read d; do for dep in "${depends[@]}"; do # lose the version comparator, if any depname=${dep%%[<>=]*} - [[ $depname = $match ]] && echo "$d (depends)" + [[ $depname = "$match" ]] && echo "$d (depends)" done for dep in "${makedepends[@]}"; do # lose the version comparator, if any depname=${dep%%[<>=]*} - [[ $depname = $match ]] && echo "$d (makedepends)" + [[ $depname = "$match" ]] && echo "$d (makedepends)" done for dep in "${optdepends[@]/:*}"; do # lose the version comaparator, if any depname=${dep%%[<>=]*} - [[ $depname = $match ]] && echo "$d (optdepends)" + [[ $depname = "$match" ]] && echo "$d (optdepends)" done fi done diff --git a/lddd.in b/lddd.in index f01ebf9..d83c3e6 100644 --- a/lddd.in +++ b/lddd.in @@ -20,7 +20,7 @@ for tree in $PATH $libdirs $extras; do msg2 "DIR %s" "$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 \ '*.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' \ @@ -28,22 +28,22 @@ for tree in $PATH $libdirs $extras; do -name '*.mcopclass' ! -name '*.mcoptype') IFS=$ifs 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. - 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. - echo "$i:" >> $TEMPDIR/raw.txt - ldd $i 2>/dev/null | grep 'not found' >> $TEMPDIR/raw.txt + echo "$i:" >> "$TEMPDIR/raw.txt" + ldd "$i" 2>/dev/null | grep 'not found' >> "$TEMPDIR/raw.txt" fi fi 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 for i in $(cat $TEMPDIR/affected-files.txt); do - pacman -Qo $i | awk '{print $4,$5}' >> $TEMPDIR/pacman.txt + pacman -Qo "$i" | awk '{print $4,$5}' >> "$TEMPDIR/pacman.txt" done # 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" diff --git a/lib/common.sh b/lib/common.sh index 8f043e8..4a15d9a 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -79,7 +79,7 @@ cleanup() { if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then rm -rf "$WORKDIR" fi - exit ${1:-0} + exit "${1:-0}" } abort() { @@ -112,7 +112,7 @@ in_array() { local needle=$1; shift local item for item in "$@"; do - [[ $item = $needle ]] && return 0 # Found + [[ $item = "$needle" ]] && return 0 # Found done return 1 # Not Found } @@ -134,7 +134,7 @@ get_full_version() { 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") + eval "$(declare -f "package_$1" | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")" [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\" done if (( ! epoch_override )); then @@ -155,9 +155,9 @@ lock() { eval "exec $1>"'"$2"' fi - if ! flock -n $1; then + if ! flock -n "$1"; then stat_busy "${@:3}" - flock $1 + flock "$1" stat_done fi } @@ -172,9 +172,9 @@ slock() { eval "exec $1>"'"$2"' fi - if ! flock -sn $1; then + if ! flock -sn "$1"; then stat_busy "${@:3}" - flock -s $1 + flock -s "$1" stat_done fi } @@ -184,6 +184,8 @@ slock() { ## lock_close() { local fd=$1 + # https://github.com/koalaman/shellcheck/issues/862 + # shellcheck disable=2034 exec {fd}>&- } diff --git a/makechrootpkg.in b/makechrootpkg.in index f8e8505..2dd160a 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -92,7 +92,7 @@ load_vars() { [[ -f $makepkg_conf ]] || return 1 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 return 0 @@ -200,8 +200,8 @@ prepare_chroot() { # which we might not be able to load (i.e. when building i686 packages on # an x86_64 host). sed -e '/^builduser:/d' -i "$copydir"/etc/{passwd,group} - 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/group" 'builduser:x:%d:\n' "$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} diff --git a/mkarchroot.in b/mkarchroot.in index 152d323..52e363f 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -46,13 +46,13 @@ shift $((OPTIND - 1)) check_root -working_dir="$(readlink -f $1)" +working_dir="$(readlink -f "$1")" shift 1 [[ -z $working_dir ]] && die 'Please specify a working directory.' 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 cache_dirs=(${cache_dir}) fi -- cgit v1.2.3-70-g09d2 From a396a6908110a860a89a1e640153bac1e0da2a57 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:09 -0400 Subject: Make slightly more involved changes to make shellcheck happy. - Use `read -r` instead of other forms of read or looping - Use arrays instead of strings with whitespaces. - In one instance, use ${var%%.*} instead of $(echo $var|cut -f. -d1) --- archrelease.in | 4 ++-- commitpkg.in | 4 ++-- find-libdeps.in | 2 +- finddeps.in | 2 +- lddd.in | 4 ++-- lib/common.sh | 15 +++++++++------ rebuildpkgs.in | 6 +++--- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/archrelease.in b/archrelease.in index 2ba9d48..6b4f1be 100644 --- a/archrelease.in +++ b/archrelease.in @@ -38,7 +38,7 @@ trunk=${PWD##*/} # Normally this should be trunk, but it may be something # such as 'gnome-unstable' IFS='/' read -r -d '' -a parts <<< "$PWD" -if [[ "${parts[@]:(-2):1}" == "repos" ]]; then +if [[ "${parts[*]:(-2):1}" == "repos" ]]; then die 'archrelease: Should not be in repos dir (try from trunk/)' fi unset parts @@ -67,7 +67,7 @@ for tag in "$@"; do while read -r file; do trash+=("repos/$tag/$file") done < <(svn ls "repos/$tag") - [[ $trash ]] && svn rm -q "${trash[@]/%/@}" + [[ ${#trash[@]} == 0 ]] || svn rm -q "${trash[@]/%/@}" else mkdir -p "repos/$tag" svn add --parents -q "repos/$tag" diff --git a/commitpkg.in b/commitpkg.in index 0482170..90210e5 100644 --- a/commitpkg.in +++ b/commitpkg.in @@ -148,9 +148,9 @@ for _arch in "${arch[@]}"; do if [[ ! -f $sigfile ]]; then msg "Signing package %s..." "${pkgfile}" if [[ -n $GPGKEY ]]; then - SIGNWITHKEY="-u ${GPGKEY}" + SIGNWITHKEY=(-u "${GPGKEY}") fi - gpg --detach-sign --use-agent --no-armor ${SIGNWITHKEY} "${pkgfile}" || die + gpg --detach-sign --use-agent --no-armor "${SIGNWITHKEY[@]}" "${pkgfile}" || die fi if ! gpg --verify "$sigfile" >/dev/null 2>&1; then die "Signature %s.sig is incorrect!" "$pkgfile" diff --git a/find-libdeps.in b/find-libdeps.in index 04adebf..1fb1fdf 100644 --- a/find-libdeps.in +++ b/find-libdeps.in @@ -60,7 +60,7 @@ case $script_mode in provides) find_args=(-name '*.so*');; 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 # 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 diff --git a/finddeps.in b/finddeps.in index c71f151..80774bb 100644 --- a/finddeps.in +++ b/finddeps.in @@ -17,7 +17,7 @@ if [[ -z $match ]]; then exit 1 fi -find . -type d | while read d; do +find . -type d | while read -r d; do if [[ -f "$d/PKGBUILD" ]]; then pkgname=() depends=() makedepends=() optdepends=() . "$d/PKGBUILD" diff --git a/lddd.in b/lddd.in index d83c3e6..908923b 100644 --- a/lddd.in +++ b/lddd.in @@ -40,9 +40,9 @@ for tree in $PATH $libdirs $extras; do done grep '^/' "$TEMPDIR/raw.txt" | sed -e 's/://g' >> "$TEMPDIR/affected-files.txt" # 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" -done +done < "$TEMPDIR/affected-files.txt" # clean list sort -u "$TEMPDIR/pacman.txt" >> "$TEMPDIR/possible-rebuilds.txt" diff --git a/lib/common.sh b/lib/common.sh index 4a15d9a..ad6194d 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -123,24 +123,27 @@ in_array() { ## get_full_version() { # set defaults if they weren't specified in buildfile - pkgbase=${pkgbase:-${pkgname[0]}} - epoch=${epoch:-0} + local pkgbase=${pkgbase:-${pkgname[0]}} + local epoch=${epoch:-0} + local pkgver=${pkgver} + local pkgrel=${pkgrel} if [[ -z $1 ]]; then if (( ! epoch )); then - echo $pkgver-$pkgrel + printf '%s\n' "$pkgver-$pkgrel" else - echo $epoch:$pkgver-$pkgrel + printf '%s\n' "$epoch:$pkgver-$pkgrel" fi else + local pkgver_override='' pkgrel_override='' epoch_override='' 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 + printf '%s\n' "$pkgver_override-$pkgrel_override" else - echo $epoch_override:$pkgver_override-$pkgrel_override + printf '%s\n' "$epoch_override:$pkgver_override-$pkgrel_override" fi fi } diff --git a/rebuildpkgs.in b/rebuildpkgs.in index be3fd33..a0e8250 100644 --- a/rebuildpkgs.in +++ b/rebuildpkgs.in @@ -40,7 +40,7 @@ bump_pkgrel() { oldrel=$(grep 'pkgrel=' $pbuild | cut -d= -f2) #remove decimals - rel=$(echo $oldrel | cut -d. -f1) + rel=${oldrel%%.*} newrel=$((rel + 1)) @@ -54,7 +54,7 @@ pkg_from_pkgbuild() { } chrootdir="$1"; shift -pkgs="$@" +pkgs=("$@") SVNPATH='svn+ssh://repos.archlinux.org/srv/repos/svn-packages/svn' @@ -67,7 +67,7 @@ cd "$REBUILD_ROOT" /usr/bin/svn co -N $SVNPATH FAILED="" -for pkg in $pkgs; do +for pkg in "${pkgs[@]}"; do cd "$REBUILD_ROOT/svn-packages" msg2 "Building '%s'" "$pkg" -- cgit v1.2.3-70-g09d2 From a9dab9533498577cd0196939bd9346310a7552e0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 18:41:10 -0400 Subject: Add `# shellcheck` directives to quiet shellcheck, add PKGBUILD.proto The added PKGBUILD.proto file is so that shellcheck can know know what to expect that a PKGBUILD sets. --- Makefile | 2 +- PKGBUILD.proto | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ arch-nspawn.in | 2 ++ checkpkg.in | 4 ++++ commitpkg.in | 5 +++++ crossrepomove.in | 4 ++++ finddeps.in | 1 + lib/archroot.sh | 2 ++ lib/common.sh | 7 +++++++ lib/valid-tags.sh | 3 +++ makechrootpkg.in | 1 + makepkg-i686.conf | 3 +++ makepkg-x86_64.conf | 3 +++ rebuildpkgs.in | 4 ++++ 14 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 PKGBUILD.proto diff --git a/Makefile b/Makefile index 39614a4..9549569 100644 --- a/Makefile +++ b/Makefile @@ -114,7 +114,7 @@ dist: upload: scp devtools-$(V).tar.gz devtools-$(V).tar.gz.sig repos.archlinux.org:/srv/ftp/other/devtools/ -check: $(BINPROGS) bash_completion makepkg-x86_64.conf +check: $(BINPROGS) bash_completion makepkg-x86_64.conf PKGBUILD.proto shellcheck $^ .PHONY: all clean install uninstall dist upload check diff --git a/PKGBUILD.proto b/PKGBUILD.proto new file mode 100644 index 0000000..e8690e4 --- /dev/null +++ b/PKGBUILD.proto @@ -0,0 +1,48 @@ +#!/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 +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() { + : +} diff --git a/arch-nspawn.in b/arch-nspawn.in index 2d42e3a..c21b2ce 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -58,7 +58,9 @@ else cache_dirs=("$cache_dir") fi +# shellcheck disable=2016 host_mirror=$(pacman --cachedir /doesnt/exist -Sddp extra/devtools 2>/dev/null | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#') +# shellcheck disable=2016 [[ $host_mirror == *file://* ]] && host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') # {{{ functions diff --git a/checkpkg.in b/checkpkg.in index 20920be..e0e1f83 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -7,6 +7,7 @@ m4_include(lib/common.sh) # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then + # shellcheck source=makepkg-x86_64.conf source '/etc/makepkg.conf' else die '/etc/makepkg.conf not found!' @@ -14,8 +15,10 @@ fi # Source user-specific makepkg.conf overrides if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" ]]; then + # shellcheck source=/dev/null source "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" elif [[ -r "$HOME/.makepkg.conf" ]]; then + # shellcheck source=/dev/null source "$HOME/.makepkg.conf" fi @@ -23,6 +26,7 @@ if [[ ! -f PKGBUILD ]]; then die 'This must be run in the directory of a built package.' fi +# shellcheck source=PKGBUILD.proto . ./PKGBUILD if [[ ${arch[0]} == 'any' ]]; then CARCH='any' diff --git a/commitpkg.in b/commitpkg.in index 90210e5..53b6612 100644 --- a/commitpkg.in +++ b/commitpkg.in @@ -5,6 +5,7 @@ m4_include(lib/common.sh) # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then + # shellcheck source=makepkg-x86_64.conf source '/etc/makepkg.conf' else die '/etc/makepkg.conf not found!' @@ -12,8 +13,10 @@ fi # Source user-specific makepkg.conf overrides if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" ]]; then + # shellcheck source=/dev/null source "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" elif [[ -r "$HOME/.makepkg.conf" ]]; then + # shellcheck source=/dev/null source "$HOME/.makepkg.conf" fi @@ -23,6 +26,8 @@ if [[ ! -f PKGBUILD ]]; then die 'No PKGBUILD file' fi +source=() +# shellcheck source=PKGBUILD.proto . ./PKGBUILD pkgbase=${pkgbase:-$pkgname} diff --git a/crossrepomove.in b/crossrepomove.in index ffc4507..b45b8ae 100644 --- a/crossrepomove.in +++ b/crossrepomove.in @@ -44,6 +44,7 @@ msg "Downloading sources for %s" "${pkgbase}" svn -q checkout -N "${target_svn}" target_checkout mkdir -p "target_checkout/${pkgbase}/repos" svn -q export "${source_svn}/${pkgbase}/trunk" "target_checkout/${pkgbase}/trunk" || die +# shellcheck source=PKGBUILD.proto . "target_checkout/${pkgbase}/trunk/PKGBUILD" msg "Downloading packages for %s" "${pkgbase}" @@ -56,6 +57,7 @@ for _arch in "${arch[@]}"; do for _pkgname in "${pkgname[@]}"; do fullver=$(get_full_version "$_pkgname") pkgpath="/srv/ftp/$source_repo/os/$repo_arch/$_pkgname-$fullver-${_arch}.pkg.tar.*" + # shellcheck disable=2029 ssh "$server" "cp $pkgpath staging/$target_repo" || die done done @@ -68,10 +70,12 @@ pushd "target_checkout/${pkgbase}/trunk" >/dev/null archrelease "${arch[@]/#/$target_repo-}" || die popd >/dev/null +# shellcheck disable=2029 ssh "${server}" "${target_dbscripts}/db-update" || die msg "Removing %s from %s" "${pkgbase}" "${source_repo}" for _arch in "${arch[@]}"; do + # shellcheck disable=2029 ssh "${server}" "${source_dbscripts}/db-remove ${source_repo} ${_arch} ${pkgbase}" done svn -q checkout -N "${source_svn}" source_checkout diff --git a/finddeps.in b/finddeps.in index 80774bb..2a085e5 100644 --- a/finddeps.in +++ b/finddeps.in @@ -20,6 +20,7 @@ fi find . -type d | while read -r d; do if [[ -f "$d/PKGBUILD" ]]; then pkgname=() depends=() makedepends=() optdepends=() + # shellcheck source=PKGBUILD.proto . "$d/PKGBUILD" for dep in "${depends[@]}"; do # lose the version comparator, if any diff --git a/lib/archroot.sh b/lib/archroot.sh index 3a1023e..98fd2cf 100644 --- a/lib/archroot.sh +++ b/lib/archroot.sh @@ -1,6 +1,8 @@ #!/hint/bash # License: Unspecified +: +# shellcheck disable=2034 CHROOT_VERSION='v4' ## diff --git a/lib/common.sh b/lib/common.sh index ad6194d..0fb93d9 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -35,35 +35,42 @@ readonly ALL_OFF BOLD BLUE GREEN RED YELLOW plain() { local mesg=$1; shift + # shellcheck disable=2059 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg() { local mesg=$1; shift + # shellcheck disable=2059 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg2() { local mesg=$1; shift + # shellcheck disable=2059 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } warning() { local mesg=$1; shift + # shellcheck disable=2059 printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } error() { local mesg=$1; shift + # shellcheck disable=2059 printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } stat_busy() { local mesg=$1; shift + # shellcheck disable=2059 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2 } stat_done() { + # shellcheck disable=2059 printf "${BOLD}done${ALL_OFF}\n" >&2 } diff --git a/lib/valid-tags.sh b/lib/valid-tags.sh index e0a3b7c..2916dc7 100644 --- a/lib/valid-tags.sh +++ b/lib/valid-tags.sh @@ -1,12 +1,15 @@ #!/hint/bash # License: Unspecified +: +# shellcheck disable=2034 _arch=( i686 x86_64 any ) +# shellcheck disable=2034 _tags=( core-i686 core-x86_64 core-any extra-i686 extra-x86_64 extra-any diff --git a/makechrootpkg.in b/makechrootpkg.in index 2dd160a..ffe6e42 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -241,6 +241,7 @@ EOF # These functions aren't run in makechrootpkg, # so no global variables _chrootbuild() { + # shellcheck source=/dev/null . /etc/profile # Beware, there are some stupid arbitrary rules on how you can # use "$" in arguments to commands with "sudo -i". ${foo} or diff --git a/makepkg-i686.conf b/makepkg-i686.conf index e57988f..f7ea2c2 100644 --- a/makepkg-i686.conf +++ b/makepkg-i686.conf @@ -1,3 +1,6 @@ +#!/hint/bash +# shellcheck disable=2034 + # # /etc/makepkg.conf # diff --git a/makepkg-x86_64.conf b/makepkg-x86_64.conf index 7aa192e..67cb200 100644 --- a/makepkg-x86_64.conf +++ b/makepkg-x86_64.conf @@ -1,3 +1,6 @@ +#!/hint/bash +# shellcheck disable=2034 + # # /etc/makepkg.conf # diff --git a/rebuildpkgs.in b/rebuildpkgs.in index a0e8250..4f4f98b 100644 --- a/rebuildpkgs.in +++ b/rebuildpkgs.in @@ -21,6 +21,7 @@ fi # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then + # shellcheck source=makepkg-x86_64.conf source '/etc/makepkg.conf' else die '/etc/makepkg.conf not found!' @@ -28,8 +29,10 @@ fi # Source user-specific makepkg.conf overrides if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" ]]; then + # shellcheck source=/dev/null source "${XDG_CONFIG_HOME:-$HOME/.config}/pacman/makepkg.conf" elif [[ -r "$HOME/.makepkg.conf" ]]; then + # shellcheck source=/dev/null source "$HOME/.makepkg.conf" fi @@ -50,6 +53,7 @@ bump_pkgrel() { pkg_from_pkgbuild() { # we want the sourcing to be done in a subshell so we don't pollute our current namespace export CARCH PKGEXT + # shellcheck source=PKGBUILD.proto (source PKGBUILD; echo "$pkgname-$pkgver-$pkgrel-$CARCH$PKGEXT") } -- cgit v1.2.3-70-g09d2 From 3efa4b7bf550e87ade5f484e2f086e164292a51f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 12 May 2017 19:57:05 -0400 Subject: makechrootpkg: Fix broken symlinks because of chroot SRCPKGDEST /srcpkgdest Commit 58968cf fixed symlinks for package products in $startdir in light of the simplified chroot setup. However, a similar change needs to be made for source-package products. This was an easy omission to make because makechrootpkg does not produce source-pakcages by default. --- makechrootpkg.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/makechrootpkg.in b/makechrootpkg.in index ffe6e42..246774a 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -313,6 +313,11 @@ move_products() { for s in "$copydir"/srcpkgdest/*; do chown "$src_owner" "$s" 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 } # }}} -- cgit v1.2.3-70-g09d2 From 041afb5f0740ca5ecc96daa48681b2272f8e8e90 Mon Sep 17 00:00:00 2001 From: Laurent Carlier via arch-projects Date: Mon, 19 Jun 2017 17:55:10 +0200 Subject: archrelease: sync the repos directory before commiting changes --- archrelease.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archrelease.in b/archrelease.in index 6b4f1be..2ebabc9 100644 --- a/archrelease.in +++ b/archrelease.in @@ -57,6 +57,8 @@ done # gracefully handle files containing an "@" character known_files=("${known_files[@]/%/@}") +# update repo directory first to avoid a commit failure +svn up repos for tag in "$@"; do stat_busy "Copying %s to %s" "${trunk}" "${tag}" -- cgit v1.2.3-70-g09d2 From 086ff8b9e7cc5a5cb57d230039a28354fe3f62f8 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Wed, 5 Jul 2017 18:35:16 +0200 Subject: archrelease: Whitespace adjustment --- archrelease.in | 1 + 1 file changed, 1 insertion(+) diff --git a/archrelease.in b/archrelease.in index 2ebabc9..25379a7 100644 --- a/archrelease.in +++ b/archrelease.in @@ -57,6 +57,7 @@ done # gracefully handle files containing an "@" character known_files=("${known_files[@]/%/@}") + # update repo directory first to avoid a commit failure svn up repos -- cgit v1.2.3-70-g09d2 From eb3e9087aa0723dde54c3b1bd813f617e71ddeab Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 9 May 2016 18:37:02 -0400 Subject: arch-nspawn: Message style: two spaces after a period This affects both the usage() text, and the error message if the `/.arch-chroot` version doesn't match. The latter is the one that I really care about, and motivates this change. On Parabola, the `arch-nspawn` program isn't in PATH, it's somewhere under `/usr/lib/`, and gets called as a helper to user-facing programs; and the error message is displayed directly to the user. These programs consistently put two spaces after a period when printing a message to the terminal. --- arch-nspawn.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index c21b2ce..669bcfa 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -19,7 +19,7 @@ files=() usage() { echo "Usage: ${0##*/} [options] working-dir [systemd-nspawn arguments]" - echo "A wrapper around systemd-nspawn. Provides support for pacman." + echo "A wrapper around systemd-nspawn. Provides support for pacman." echo echo ' options:' echo ' -C Location of a pacman config file' @@ -101,7 +101,7 @@ umask 0022 if [[ ! -f "$working_dir/.arch-chroot" ]]; then die "'%s' does not appear to be an Arch chroot." "$working_dir" elif [[ $(cat "$working_dir/.arch-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 build_mount_args -- cgit v1.2.3-70-g09d2 From 295246e86f7abcd5fc31e2c4e74de19bfbb2f344 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 15:56:42 -0500 Subject: makechrootpkg: _chrootbuild: Split into _chroot{prepare,build}. --- makechrootpkg.in | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 246774a..ccfe77f 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -225,6 +225,12 @@ EOF # This is a little gross, but this way the script is recreated every time in the # working copy + { + printf '#!/bin/bash\n' + declare -f _chrootprepare + printf '_chrootprepare "$@"\n' + } > "$copydir/chrootprepare" + chmod +x "$copydir/chrootprepare" { printf '#!/bin/bash\n' declare -f _chrootbuild @@ -240,6 +246,16 @@ EOF # These functions aren't run in makechrootpkg, # so no global variables +_chrootprepare() { + # shellcheck source=/dev/null + . /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 "$@" --nobuild' -bash "$@" +} + _chrootbuild() { # shellcheck source=/dev/null . /etc/profile @@ -247,7 +263,7 @@ _chrootbuild() { # 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 "$@" --noextract --noprepare' -bash "$@" } _chrootnamcap() { @@ -411,6 +427,11 @@ main() { prepare_chroot "$copydir" "$USER_HOME" "$repack" if arch-nspawn "$copydir" \ + --bind="$PWD:/startdir" \ + --bind="$SRCDEST:/srcdest" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + /chrootprepare "${makepkg_args[@]}" && + arch-nspawn "$copydir" \ --bind="$PWD:/startdir" \ --bind="$SRCDEST:/srcdest" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ -- cgit v1.2.3-70-g09d2 From c242c6bf2f21d212d935f9ef6f7dd78910d6c601 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 10 May 2016 13:44:46 -0400 Subject: arch-nspawn: add a table of CARCH/setarch overrides The table is just armv7h->armv7l for now. --- arch-nspawn.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch-nspawn.in b/arch-nspawn.in index 669bcfa..e695a29 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -108,6 +108,9 @@ build_mount_args copy_hostconf eval "$(grep '^CARCH=' "$working_dir/etc/makepkg.conf")" +case "$CARCH" in + armv7h) CARCH=armv7l;; +esac [[ -z $nosetarch ]] || unset CARCH -- cgit v1.2.3-70-g09d2 From 7c20294dd96519953537d2d6b5d1735dceafb05e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:40:06 -0500 Subject: makechrootpkg, arch-nspawn: Force-enable local '/repo/' repository. The change in arch-nspawn is subtle: This was the source of "infamous" "it fails every other time" bug that took me over a year to solve. By having a repository of local packages (rather than simply running `pacman -U`), we are inviting pacman to cache them in `/var/cache/pacman/pkg`. Besides being needless disk writes, this actually causes a real issue. If the package gets rebuilt, pacman will balk, as the file no longer matches the cached signature. So, how do we prevent pacman from caching these local packages? Simple: include the directory they are already in in the pacman.conf:CacheDir list. This will prevent pacman from copying the files to one of the other cache directories. --- arch-nspawn.in | 1 + makechrootpkg.in | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/arch-nspawn.in b/arch-nspawn.in index e695a29..0b0dc68 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -105,6 +105,7 @@ elif [[ $(cat "$working_dir/.arch-chroot") != "$CHROOT_VERSION" ]]; then fi build_mount_args +cache_dirs+=('/repo/') copy_hostconf eval "$(grep '^CARCH=' "$working_dir/etc/makepkg.conf")" diff --git a/makechrootpkg.in b/makechrootpkg.in index ccfe77f..4985172 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -223,6 +223,19 @@ builduser ALL = NOPASSWD: /usr/bin/pacman EOF chmod 440 "$copydir/etc/sudoers.d/builduser-pacman" + if ! grep -q '^\[repo\]' "$copydir/etc/pacman.conf"; then + local line + line=$(grep -n '^\[' "$copydir/etc/pacman.conf" |grep -Fv ':[options]'|sed 's/:.*//;1q') + local ins='[repo] +SigLevel = Optional TrustAll +Server = file:///repo +' + sed -i "${line}i${ins//$'\n'/\\n}" "$copydir/etc/pacman.conf" + fi + # Avoid having to use `pacman -Sy` to update [repo], as + # networking might be disabled inside of the chroot. + cp "$copydir/repo/repo.db" "$copydir/var/lib/pacman/sync/repo.db" + # This is a little gross, but this way the script is recreated every time in the # working copy { -- cgit v1.2.3-70-g09d2 From 852833fd610ec277cbea2ff865c1d6dbc0a095a3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 2 May 2013 15:12:42 -0400 Subject: lib/common.sh: Internationalize. --- lib/common.sh | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 0fb93d9..c3c3454 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -6,8 +6,18 @@ [[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 _INCLUDE_COMMON_SH=true -# Avoid any encoding problems -export LANG=C +[[ -n ${TEXTDOMAIN:-} ]] || export TEXTDOMAIN='libretools' +[[ -n ${TEXTDOMAINDIR:-} ]] || export TEXTDOMAINDIR='/usr/share/locale' + +if type gettext &>/dev/null; then + _() { gettext "$@"; } +else + _() { echo "$@"; } +fi + +_l() { + TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@" +} shopt -s extglob @@ -34,44 +44,44 @@ fi readonly ALL_OFF BOLD BLUE GREEN RED YELLOW plain() { - local mesg=$1; shift + local mesg; mesg="$(_ "$1")"; shift # shellcheck disable=2059 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg() { - local mesg=$1; shift + local mesg; mesg="$(_ "$1")"; shift # shellcheck disable=2059 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg2() { - local mesg=$1; shift + local mesg; mesg="$(_ "$1")"; shift # shellcheck disable=2059 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } warning() { - local mesg=$1; shift + local mesg; mesg="$(_ "$1")"; shift # shellcheck disable=2059 printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } error() { - local mesg=$1; shift + local mesg; mesg="$(_ "$1")"; shift # shellcheck disable=2059 printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } stat_busy() { - local mesg=$1; shift + local mesg; mesg="$(_ "$1")"; shift # shellcheck disable=2059 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2 } stat_done() { # shellcheck disable=2059 - printf "${BOLD}done${ALL_OFF}\n" >&2 + printf "${BOLD}$(_l _ "done")${ALL_OFF}\n" >&2 } _setup_workdir=false @@ -90,7 +100,7 @@ cleanup() { } abort() { - error 'Aborting...' + _l error 'Aborting...' cleanup 255 } @@ -263,7 +273,7 @@ find_cached_package() { return 0 ;; *) - error 'Multiple packages found:' + _l error 'Multiple packages found:' printf '\t%s\n' "${results[@]}" >&2 return 1 esac -- cgit v1.2.3-70-g09d2 From a35a199f62a46e372491bf396a9699b64ab2dadd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:42:06 -0500 Subject: checkpkg, find-libdeps, finddeps, lddd: Use libremessages to add help text. --- checkpkg.in | 27 +++++++++++++++++++++++++-- find-libdeps.in | 28 ++++++++++++++++++++++++---- finddeps.in | 18 ++++++++++++------ lddd.in | 18 +++++++++++++++++- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/checkpkg.in b/checkpkg.in index e0e1f83..cfec71e 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -3,7 +3,28 @@ shopt -s extglob -m4_include(lib/common.sh) +. "$(librelib messages)" + +usage() { + print 'Usage: %s [-h]' "${0##*/}" + print 'Compare a locally built a package with the one in the repositories.' + echo + prose 'This should be run from a directory containing a + PKGBUILD. It searches for a locally built package + corresponding to the PKGBUILD, and downloads the last + version of that package from the pacman repositories. + It then compares the list of .so files provided by each + version of the package. It does this for each part of + a split package.' +} + +if [[ $1 = '-h' ]]; then + usage + exit 0 +elif [[ $# -gt 0 ]]; then + usage >&2 + exit 1 +fi # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then @@ -23,7 +44,9 @@ elif [[ -r "$HOME/.makepkg.conf" ]]; then fi if [[ ! -f PKGBUILD ]]; then - die 'This must be run in the directory of a built package.' + error 'This must be run in the directory of a built package.' + usage >&2 + exit 1 fi # shellcheck source=PKGBUILD.proto diff --git a/find-libdeps.in b/find-libdeps.in index 1fb1fdf..cb68237 100644 --- a/find-libdeps.in +++ b/find-libdeps.in @@ -1,7 +1,7 @@ #!/bin/bash # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" set -e shopt -s extglob @@ -20,12 +20,32 @@ case $script_mode in *) die "Unknown mode %s" "$script_mode" ;; esac +usage() { + print "Usage: find-lib(deps|provides) [options] " + print "Find library dependencies or provides of a package." + echo + prose 'Prints a list of library dependencies in the format:' + echo + print ' =-' + echo + prose "Where is the shared library version, or + repeated if there is no version attached; and + is the architecture of the library (either \`32\` + or \`64\`, based on the ELF Class)." + echo + print "Options:" + flag "--ignore-internal" "Ignore internal libraries; libraries + without a version attached" + flag "-h" "Show this message" +} if [[ -z $1 ]]; then - echo "${0##*/} [options] " - echo "Options:" - echo " --ignore-internal ignore internal libraries" + usage >&2 exit 1 fi +if [[ $1 = '-h' ]]; then + usage + exit 0 +fi if [[ -d $1 ]]; then pushd "$1" >/dev/null diff --git a/finddeps.in b/finddeps.in index 2a085e5..5f89b55 100644 --- a/finddeps.in +++ b/finddeps.in @@ -4,18 +4,24 @@ # # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" match=$1 +usage() { + print 'Usage: %s ' "${0##*/}" + print 'Find packages that depend on a given depname.' + echo + prose 'Run this script from the top-level directory of your ABS tree.' +} if [[ -z $match ]]; then - echo 'Usage: finddeps ' - echo '' - echo 'Find packages that depend on a given depname.' - echo 'Run this script from the top-level directory of your ABS tree.' - echo '' + usage >&2 exit 1 fi +if [[ $match = '-h' ]]; then + usage + exit 0 +fi find . -type d | while read -r d; do if [[ -f "$d/PKGBUILD" ]]; then diff --git a/lddd.in b/lddd.in index 908923b..4c6871c 100644 --- a/lddd.in +++ b/lddd.in @@ -4,7 +4,23 @@ # # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" + +usage() { + print "Usage: %s [-h]" "${0##*/}" + print "Find broken library links on your machine." + echo + prose "Scans \$PATH and library directories for ELF files with + references to missing shared libraries." +} + +if [[ $1 = '-h' ]]; then + usage + exit 0 +elif [[ $# -gt 0 ]]; then + usage >&2 + exit 1 +fi ifs=$IFS IFS="${IFS}:" -- cgit v1.2.3-70-g09d2 From b56e515bead46f854be12947c3e2341679e1c067 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 18:50:04 -0500 Subject: lib/common.sh: Discourage use in favor of libremessages. --- lib/common.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index c3c3454..ed98449 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,6 +1,9 @@ #!/hint/bash # This may be included with or without `set -euE` +# This file is included by libremessages. +# You should probably use libremessages instead of this. + # License: Unspecified [[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 -- cgit v1.2.3-70-g09d2 From 439574a0ff87f9b5e9b070a1028fa3d8461e6f55 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 18:50:27 -0500 Subject: mkarchroot: Use librelib rather than PATH to find arch-nspawn. --- mkarchroot.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkarchroot.in b/mkarchroot.in index 52e363f..5165960 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -92,7 +92,7 @@ echo "$CHROOT_VERSION" > "$working_dir/.arch-chroot" systemd-machine-id-setup --root="$working_dir" -exec arch-nspawn \ +exec "$(librelib chroot/arch-nspawn)" \ ${nosetarch:+-s} \ ${pac_conf:+-C "$pac_conf"} \ ${makepkg_conf:+-M "$makepkg_conf"} \ -- cgit v1.2.3-70-g09d2 From d9a68fb0e2248636ab6f5f25630693a220ee8a25 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 20 Apr 2017 13:49:19 -0400 Subject: makechrootpkg: Also build --allsource packages. It also sets SRCEXT="-$pkgarch$SRCEXT", so that two runs of makechrootpkg on different architectures don't overwrite eachothers source packages. --- makechrootpkg.in | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/makechrootpkg.in b/makechrootpkg.in index 4985172..83eb787 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -272,10 +272,24 @@ _chrootprepare() { _chrootbuild() { # shellcheck source=/dev/null . /etc/profile + local srcext + srcext="$( + # shellcheck source=makepkg-x86_64.conf + . /etc/makepkg.conf || exit + # shellcheck source=PKGBUILD.proto + . /startdir/PKGBUILD || exit + if [ "$arch" = any ]; then + pkgarch=any + else + pkgarch=$CARCH + fi + printf '%s\n' "-$pkgarch$SRCEXT" + )" || return # 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; SRCEXT="${1}" makepkg "${@:2}" --allsource' -bash "$srcext" "$@" || return sudo -iu builduser bash -c 'cd /startdir; makepkg "$@" --noextract --noprepare' -bash "$@" } -- cgit v1.2.3-70-g09d2 From 90815fec833f8efd73b95bc291d538396e13784e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 5 May 2017 13:12:32 -0400 Subject: common.sh: Add a find_cached_srcpackage counterpart to find_cached_package --- lib/common.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index ed98449..118a06c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -281,3 +281,60 @@ find_cached_package() { return 1 esac } + +## +# usage: find_cached_srcpackage( $pkgname, $pkgver, $arch ) +# +# $pkgver can be supplied with or without a pkgrel appended. +# If not supplied, any pkgrel will be matched. +## +find_cached_srcpackage() { + local searchdirs=("$PWD" "$SRCPKGDEST") results=() + local targetname=$1 targetver=$2 targetarch=$3 + local dir pkg pkgbasename name ver rel arch r results + + for dir in "${searchdirs[@]}"; do + [[ -d $dir ]] || continue + + for pkg in "$dir"/*.src.tar?(.?z); do + [[ -f $pkg ]] || continue + + # avoid adding duplicates of the same inode + for r in "${results[@]}"; do + [[ $r -ef $pkg ]] && continue 2 + done + + # split apart package filename into parts + pkgbasename=${pkg##*/} + pkgbasename=${pkgbasename%.src.tar?(.?z)} + + arch=${pkgbasename##*-} + pkgbasename=${pkgbasename%-"$arch"} + + rel=${pkgbasename##*-} + pkgbasename=${pkgbasename%-"$rel"} + + ver=${pkgbasename##*-} + name=${pkgbasename%-"$ver"} + + if [[ $targetname = "$name" && $targetarch = "$arch" ]] && + pkgver_equal "$targetver" "$ver-$rel"; then + results+=("$pkg") + fi + done + done + + case ${#results[*]} in + 0) + return 1 + ;; + 1) + printf '%s\n' "${results[0]}" + return 0 + ;; + *) + _l error 'Multiple packages found:' + printf '\t%s\n' "${results[@]}" >&2 + return 1 + esac +} -- cgit v1.2.3-70-g09d2 From b57ae07ee862fe022a637661cc39f41484abeec4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 5 Jul 2017 11:43:26 -0400 Subject: arch-nspawn: make sure that makepkg.conf is always parsed as text https://lists.parabola.nu/pipermail/dev/2017-June/005576.html --- arch-nspawn.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 0b0dc68..0d93b5d 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -108,7 +108,7 @@ build_mount_args cache_dirs+=('/repo/') copy_hostconf -eval "$(grep '^CARCH=' "$working_dir/etc/makepkg.conf")" +eval "$(grep -a '^CARCH=' "$working_dir/etc/makepkg.conf")" case "$CARCH" in armv7h) CARCH=armv7l;; esac -- cgit v1.2.3-70-g09d2