FS#65411 - makechrootpkg doesn't work if called from bash scripts

Attached to Project: Arch Linux
Opened by Holly (kalinda) - Friday, 07 February 2020, 16:46 GMT
Last edited by Eli Schwartz (eschwartz) - Monday, 10 February 2020, 02:12 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To No-one
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
I have a bash program I'm using to automate building packages in my repo and part of it is that it uses makechrootpkg, which used to work fine until a couple days ago. Now when makechrootpkg -r $CHROOT -- --clean is called from the script, it gives me an error: /usr/bin/makechrootpkg: illegal option -- -

If I remove the -- --clean argument, then I get this error instead: /usr/bin/makechrootpkg: option requires an argument -- r

Running the command or calling the function I have makechrootpkg directly from the terminal works fine, however. I have tried removing and completely redoing my chroot, but it still gives these errors. My chroot is ext4, not btrfs.

The error doesn't happen if I use regular makepkg instead. I will try to see if I can find other workarounds for, too, and report back.

Additional info:
* devtools 20191227-2, util-linux 2.35.1-1, arch-install-scripts 23-1, let me know if you need to know anymore.
* Running kernel 5.5.2-arch1-1

Steps to reproduce:
* Write a simple bash script with the command makechrootpkg -r $CHROOT (optionally add the clean flag if you like)
* Go to a folder with a PKGBUILD in it, run the script, get the error.

Any help is appreciated, thanks a lot!
This task depends upon

Closed by  Eli Schwartz (eschwartz)
Monday, 10 February 2020, 02:12 GMT
Reason for closing:  Not a bug
Additional comments about closing:  User error.
Comment by Eli Schwartz (eschwartz) - Friday, 07 February 2020, 17:30 GMT
> now when makechrootpkg -r $CHROOT -- --clean is called from the script

> If I remove the -- --clean argument, then I get this error instead: /usr/bin/makechrootpkg: option requires an argument -- r

The problem seems evident. The "$CHROOT" variable is not defined in your script. Try running the script with "set -x" to see what command you are actually executing, I suspect the argument list which is being invoked by the kernel is:

{"makechrootpkg", "-r", "--", "--clean"}

then later:

{"makechrootpkg", "-r"}

This will obviously not work.
Comment by Holly (kalinda) - Monday, 10 February 2020, 01:41 GMT
OH! lol.. well now I feel silly. That worked, of course. I thought it would be ok because I had $CHROOT defined in my bashrc but I guess it doesn't work that way, I'll have to do some more reading.

Anyway sorry for wasting your guys' time!
Comment by Eli Schwartz (eschwartz) - Monday, 10 February 2020, 02:12 GMT
In order for a bash variable to be "export"ed to another command, such as a bash script.sh, you need to use the shell "export" builtin. Use that to guide your reading. Also I recommend reading https://mywiki.wooledge.org/BashGuide

Loading...