Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Run a script before and after the emerge process?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Cyberstudio
Apprentice
Apprentice


Joined: 17 Oct 2005
Posts: 237
Location: /usr/src/linux

PostPosted: Fri Jul 12, 2013 7:36 pm    Post subject: [SOLVED] Run a script before and after the emerge process? Reply with quote

Hi guys!

I have a thinkpad w500. Its a workstation class laptop but it gets very very hot when im compiling a big package (kde, firefox, etc). My idea is to make portage run a script before it begins the compilation process, and run another script after it finishes.

The first script will increase the fan speed to maximun. This will run before the compilation process begins. The second one will make the fans run quiet again, and will run after the compilation process has finished.

If im compiling 10 packages, the first script should run when the first package starts compiling. The second script should run after the lastest package finishes.

I have these scripts already. How can i plug those scripts to portage?
_________________
En los CDs de Microsoft, al reves escuchas un mensaje satanico. Eso no es lo peor, al derecho, te instala windows. 8O


Last edited by Cyberstudio on Sat Jul 13, 2013 3:54 pm; edited 1 time in total
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7415
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri Jul 12, 2013 8:24 pm    Post subject: Reply with quote

No need. Portage's emerge is in /usr/bin. Put this script in /usr/local/bin (which is ahead of /usr/bin on the PATH) and name it emerge:
Code:
#!/bin/bash

echo "I would put my pre-emerge script invocation here."

/usr/bin/emerge "$@"

echo "I would put my post-emerge script invocation here."
After putting the script there, force bash to recalculate it's hash table for the emerge command with
Code:
hash emerge
And done. One of the cardinal rules of the Unix way is, "Never add a feature to a program if a half dozen lines of shell script will accomplish the goal." :wink:

- John
_________________
This space intentionally left blank.


Last edited by John R. Graham on Fri Jul 12, 2013 9:21 pm; edited 2 times in total
Back to top
View user's profile Send private message
DONAHUE
Watchman
Watchman


Joined: 09 Dec 2006
Posts: 6256
Location: Goose Creek SC

PostPosted: Fri Jul 12, 2013 8:28 pm    Post subject: Reply with quote

a script in similar vein to do something, run emerge, undo that something. I'm not the author, just a user.

Quote:
#!/bin/bash
MEMSIZE=8000M
mounted=false

. /etc/make.conf
. /etc/init.d/functions.sh

if [ -z "$PORTAGE_TMPDIR" ]; then
PORTAGE_TMPDIR="/var/tmp/portage"
fi


mounttmpfs() {
mount -t tmpfs -o size=$MEMSIZE,nr_inodes=1M tmpfs ${PORTAGE_TMPDIR}
mounted="true"
}

compile() {
einfo "running emerge ${*}"
emerge ${*}
}

unmount() {
ebegin "unmounting tmpfs"
umount -f ${PORTAGE_TMPDIR}
eend $?
}

ebegin "Mounting $MEMSIZE of memory to ${PORTAGE_TMPDIR}"
if [ -z "$(pgrep -f /usr/bin/emerge)" ];then
if [ -z "$(mount | grep ${PORTAGE_TMPDIR})" ];then
mounttmpfs
else
eerror "tmpfs already mounted!"
exit 0
fi
else
eerror "emerge already running!"
exit 0
fi
eend $?

# the next line would change the cpu-governour, if available, to the highest frequency
#[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ] && echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

# run emerge
compile $@

# unmount tmpfs
$mounted && umount ${PORTAGE_TMPDIR}

# and set the scheduler back to "ondemand"
#[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ] && echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor



anyone seen my mind?
_________________
Defund the FCC.


Last edited by DONAHUE on Fri Jul 12, 2013 9:49 pm; edited 2 times in total
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7415
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri Jul 12, 2013 9:06 pm    Post subject: Reply with quote

Attach the script (or a link)?

- John
_________________
This space intentionally left blank.
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1225
Location: 42.68n 85.41w

PostPosted: Fri Jul 12, 2013 9:13 pm    Post subject: Reply with quote

script encapsulation of emerge?

/home/user/script location && ./script

script
script stuff
emerge
more script stuff
done

ok so you want emerge passed some stuff.... that can be done too i _think_ its emerge $@ instead of the emerge alone that would do nothing.... then it would be ./script package though i could be wrong.

my fix, put a cookie rack under the laptop!

(John r grams answer beat me to the punch.)
_________________
cat /etc/*-release
Funtoo Linux - baselayout 2.2.0
consider this warning no. 1
http://ecx.images-amazon.com/images/I/81Ku-vxIb3L._SL1500_.jpg
http://wiki.gentoo.org/wiki/Special:Contributions/666threesixes666
Back to top
View user's profile Send private message
Cyberstudio
Apprentice
Apprentice


Joined: 17 Oct 2005
Posts: 237
Location: /usr/src/linux

PostPosted: Fri Jul 12, 2013 11:27 pm    Post subject: Reply with quote

John R. Graham wrote:
No need. Portage's emerge is in /usr/bin. Put this script in /usr/local/bin (which is ahead of /usr/bin on the PATH) and name it emerge:
Code:
#!/bin/bash

echo "I would put my pre-emerge script invocation here."

/usr/bin/emerge "$@"

echo "I would put my post-emerge script invocation here."
After putting the script there, force bash to recalculate it's hash table for the emerge command with
Code:
hash emerge
And done. One of the cardinal rules of the Unix way is, "Never add a feature to a program if a half dozen lines of shell script will accomplish the goal." :wink:

- John


Hi! Thanks to all of you for your answers.

I did what you said. I created the file /usr/local/bin/emerge with this content:

Code:

#!/bin/bash

echo level 7 > /proc/acpi/ibm/fan

/usr/bin/emerge "$@"

echo level auto > /proc/acpi/ibm/fan


After that i ran hash emerge, and tested it with firefox: Firefox compiles ok, but the fan stays normal, without changes in its speed.

These 2 commands,

Code:
echo level auto > /proc/acpi/ibm/fan


and

Code:
echo level 7 > /proc/acpi/ibm/fan


do work, i have tested them. So, what i may be doing wrong?
_________________
En los CDs de Microsoft, al reves escuchas un mensaje satanico. Eso no es lo peor, al derecho, te instala windows. 8O
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1225
Location: 42.68n 85.41w

PostPosted: Fri Jul 12, 2013 11:44 pm    Post subject: Reply with quote

"/usr/local/bin (which is ahead of /usr/bin on the PATH)"

my new users do not have this in their path.

post the contents of

Code:

echo $PATH


to see if its in yours.
_________________
cat /etc/*-release
Funtoo Linux - baselayout 2.2.0
consider this warning no. 1
http://ecx.images-amazon.com/images/I/81Ku-vxIb3L._SL1500_.jpg
http://wiki.gentoo.org/wiki/Special:Contributions/666threesixes666
Back to top
View user's profile Send private message
Cyberstudio
Apprentice
Apprentice


Joined: 17 Oct 2005
Posts: 237
Location: /usr/src/linux

PostPosted: Fri Jul 12, 2013 11:47 pm    Post subject: Reply with quote

Gentrino axyom # echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin
_________________
En los CDs de Microsoft, al reves escuchas un mensaje satanico. Eso no es lo peor, al derecho, te instala windows. 8O
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1225
Location: 42.68n 85.41w

PostPosted: Sat Jul 13, 2013 12:02 am    Post subject: Reply with quote

beware.... updating path can cause PROBLEMS if it is not done correctly.

Code:

echo 'export PATH=/usr/local/bin:$PATH' >> $HOME/.bashrc


then open a new terminal.....

testing of answer given to you.....

test@mksrv ~ $ echo 'export PATH=/usr/local/bin:$PATH' >> $HOME/.bashrc
test@mksrv ~ $ echo $PATH
/bin:/usr/bin
test@mksrv ~ $ exit
exit
mksrv mkultra # su test
test@mksrv /home/mkultra $ echo $PATH
/usr/local/bin:/bin:/usr/bin

then resume where you left off testing the other post up there. and as a hint, the file contents are /usr/local/bin/emerge, not /usr/local/bin/hash\ emerge
_________________
cat /etc/*-release
Funtoo Linux - baselayout 2.2.0
consider this warning no. 1
http://ecx.images-amazon.com/images/I/81Ku-vxIb3L._SL1500_.jpg
http://wiki.gentoo.org/wiki/Special:Contributions/666threesixes666
Back to top
View user's profile Send private message
Cyberstudio
Apprentice
Apprentice


Joined: 17 Oct 2005
Posts: 237
Location: /usr/src/linux

PostPosted: Sat Jul 13, 2013 12:39 am    Post subject: Reply with quote

Thanks to all of you!

Its working now :)
_________________
En los CDs de Microsoft, al reves escuchas un mensaje satanico. Eso no es lo peor, al derecho, te instala windows. 8O
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1225
Location: 42.68n 85.41w

PostPosted: Sat Jul 13, 2013 1:29 am    Post subject: Reply with quote

you're welcome. please edit post number 1 and change the title to include [solved] somewhere :D
_________________
cat /etc/*-release
Funtoo Linux - baselayout 2.2.0
consider this warning no. 1
http://ecx.images-amazon.com/images/I/81Ku-vxIb3L._SL1500_.jpg
http://wiki.gentoo.org/wiki/Special:Contributions/666threesixes666
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 7415
Location: Somewhere over Atlanta, Georgia

PostPosted: Sun Jul 14, 2013 7:43 pm    Post subject: Reply with quote

666threesixes666 wrote:
"/usr/local/bin (which is ahead of /usr/bin on the PATH)"

my new users do not have this in their path.
I think you'll find that, if you log in as root at a console, you'll have the whole normal path, just as I described.
su man page wrote:
Invoked without a username, su defaults to becoming the superuser. The optional argument - may be used to provide an environment similar to what the user would expect had the user logged in directly
So, just like the man page says, for consistency, you should be changing to superuser with
Code:
su -
There's no need to muck with the standard path definition: you just need to take the proper steps to get the standard path definition. :wink:

- John
_________________
This space intentionally left blank.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum