I'm not [user=54069]Shkhln[/user], but I'll take a crack at it anyway
Code:
system('mkfifo /tmp/pkg.events')
Create a
named pipe at
/tmp/pkg.events
Create an empty list of threads
Code:
threads << Thread.new do
File.open('/tmp/pkg.events').each_line do |line|
Create a thread that reads from the named pipe one line at a time. We'll wait here if no lines are available.
Code:
case line
when /INFO_EXTRACT_BEGIN/
If the line contains the text "INFO_EXTRACT_BEGIN"
Code:
system('pkill -SIGSTOP pkg')
Send the STOP signal to any process called "pkg" using
pkill(1)
Code:
pid = `pgrep pkg`.lines.first.chomp.to_i # might not be the correct pid, YMMV
Grab the pid of any process called "pkg" using
pgrep(1) and store it in a variable called "pid"
Code:
threads << Thread.new do
system("dtrace -n 'pid$target:pkg::entry { trace(timestamp / 1000000); }' -p #{pid}")
end
Start a new thread that creates a
dtrace(1) probe for a provider called "pid$target" with module "pkg" and called "entry". This probe executes a single action. It takes the time in nanoseconds since boot and divides it by 1000000. The "-p" option means this trace will exit when the process with the associated pid exits, among other things. Consult the man page for more details.
Code:
sleep 1
system('pkill -SIGCONT pkg')
Sleep for one second and then send the CONT signal to the pkg process
Code:
when /INFO_EXTRACT_FINISHED/
system('pkill dtrace')
break
Kill the dtrace probe if the next line read out of the pipe contains the text "INFO_EXTRACT_FINISHED". Exit the thread that reads the FIFO one line at a time. Both threads should exit at this point.
Skip to the next line if the current line contains neither "INFO_EXTRACT_BEGIN" nor "INFO_EXTRACT_FINISHED". Wait for the next line if there are no lines to read in the pipe right now.
Code:
system('env EVENT_PIPE=/tmp/pkg.events pkg install -fy papirus-icon-theme')
Invoke
pkg-install(8) and
send JSON output to the named pipe /tmp/pkg.install. Force the (re)installation of
x11-themes/papirus-icon-theme. Answer any prompts with "y".
Code:
threads.each do |t|
t.join
end
Wait for all the threads to exit.
Yes, this requires root for at least the pkg-install step. The dtrace probe probably requires root, too. I don't know. I've never used dtrace.