hook a script to apt-get

I have /tmp on a separate partition, and mounted with noexec. I am using Debian.

The installation of some packages fails, because the post-installation scripts of some packages need to run from /tmp.

I was wondering if it would be possible to “hook” a simple script to apt-get, which would be run every time before apt-get, and remount /tmp to exec. And similarly, remount it to noexec after apt-get has finished.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can use dpkg‘s hook system to remount it — put this in /etc/apt/apt.conf.d/00exectmp:

DPkg::Pre-Invoke {"mount -o remount,exec /tmp";};
DPkg::Post-Invoke {"mount -o remount /tmp";};

Method 2

Mumble, you can simply replace apt-get with a script of yours.

Move apt-get to real-apt-get and, then, create a script called apt-get like this one:

#!/bin/sh

mount -o remount -o ... /tmp
real-apt-get "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="795d39">[email protected]</a>"
mount -o remount -o ... -o noexec /tmp

In any case, I do not like this solution. It is easier change the temporary directory environment variable when you need it. Something like (sh style):

mkdir /root/mytmp
TMPDIR=/root/mytmp
export TMPDIR
apt-get ...
rm -rf /root/mytmp

This way apt-get will use /root/mytmp as temporary dir. No need to change the system.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x