You are not logged in.

#1 2016-12-17 19:45:45

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Echo a character and line return to a running makepkg when it pauses

Applying a patch to a linux kernel PKGBUILD (from abs) leaves makepkg waiting for user input on the `make prepare` step.  I'd like to automate an answer for the sole question that will be asked ideally in the same invocation of `makepkg -s` but I can deal with doing it in a separate shell too.  In searching, I found this wherein the proposed solution is to echo a value to /proc/$PID/fd/0 which seems to work for me but I am unable to have makepkg continue when doing so; the echoed value is printed in the makepkg shell, and I can even echo a newline character but makepkg does not continue.

1) How can I change the echo solution to echo the value and a "Enter" key press and allow makepkg to continue?
or
2) What is an alternative method to achieve the effect?

Example:

makepkg -s
...
<<make prepare runs>>
choice[1-21?]:
4

I got the "4 new line" via this command in another shell:

echo "4\n" > /proc/$(pidof -x makepkg)/fd/0

Thanks all!

...I see this also without makepkg.  Consider this simple script:

% cat ./simple
#!/bin/bash

while [ "$input1" != quit ]; do
  echo "type q to quit"
  read input1
  if [ $input1 == Q ] || [ $input1 == q ]; then
    echo "later!"
    exit 0
  fi
done

# vim:set ts=2 sw=2 et:

Run that and attempt to have the echo or printf to /proc as the reference I found suggests... the same thing happens for me: the text is printed to the script, but it doens't seem to treat it as if the user typed it.  What am I missing?

Thanks!

example:

% ./simple 
type q to quit
q
q
q
q

The 4 "q" values above were not entered in the running shell, but with the following in a separate shell:

printf "q\n" > /proc/$(pidof -x simple)/fd/0

EDIT: A more careful read of the reference I provided describes this limitation (they use the example of gphoto2).  So I'm back to my original question of how to send a value to the running script hmm

Last edited by graysky (2016-12-18 10:11:48)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2016-12-17 20:03:47

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: Echo a character and line return to a running makepkg when it pauses

Either issuing `yes 4 | makepkg -s` or directly modifying  the PKGBUILD at the `make prepare` stop does not work either:

Original line: make prepare
Modified line: yes 4 | make prepare

This leads to:

% makepkg -s
...
choice[1-21?]: aborted!

Console input/output is redirected. Run 'make oldconfig' to update configuration.

make[2]: *** [scripts/kconfig/Makefile:38: silentoldconfig] Error 1
make[1]: *** [Makefile:546: silentoldconfig] Error 2
  SYSTBL  arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_x32.h
make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'.  Stop.
make: *** Waiting for unfinished jobs....
==> ERROR: A failure occurred in prepare().

Last edited by graysky (2016-12-17 20:29:10)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#3 2016-12-17 21:30:25

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Echo a character and line return to a running makepkg when it pauses

I've come across expect a few times, but I'd never really tried/studied it.

Following command file seems to work with your simple script:

spawn ./simple
expect "type q to quit"
send "q\r"
expect eof

Offline

#4 2016-12-18 00:01:12

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,788
Website

Re: Echo a character and line return to a running makepkg when it pauses

This all sounds very hacky. Can you not just set the value in a config file and bypass the interaction completely? This is what I would try to do. Building a package with makepkg shouldn't be interactive imo, and people should be able to take the same PKGBUILD and source you used to create the same package, without having to guess the magic number (I believe this used to be a policy, but dammed if I can find where I read it).


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2016-12-18 10:30:40

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: Echo a character and line return to a running makepkg when it pauses

@Raynman - Interesting, I will look into that, thank you!

@WorMzy - Agreed.  It is more of a curiosity to me now.  Particularly how using /usr/bin/yes does not work with the following edit to line 88 of the PKGBUILD
From: "make prepare"
Change to: "yes 4 | make prepare"

In contrast, the simple script in my first post runs fine with "yes q | ./simple"

Seems like there some check in the Makefile or directives therein working against this.  Need to dig more.

EDIT: Interestingly, I can in fact modify the PKGBUILD to accomplish my goal simply by inserting the following above line 88:

yes 4 | make oldconfig

Last edited by graysky (2016-12-18 10:33:44)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB