不小心移除 emerge 的安裝方法

假如您哪一天要知道甚麼叫做手殘,可以執行下面這個指令

emerge unmerge portage

這樣 Gentoo 的 emerge 就不能用了...
搜尋 Google 並沒有人像偶這麼白目,
所以當然不會有人回答怎麼裝回去..
經過請教高人,裝回去的方法如下:

1. 找一台沒經過手殘的 Gentoo ,用下面指令包一個 emerge 的 Package
emerge -B portage
會產生 binary Package 在 /usr/portage/packages/

2. 把產生的 Package 丟到被手殘的那台 Gentoo
解開後複製到相對的目錄下

3. emerge 就裝回來了(留下了感動的眼淚)

附註:沒事別亂玩...


經過查詢與驗證正解如下(2008/02/12):
/usr/portage/sys-apps/portage/files/README.RESCUE 中說明恢復 portage 的網址為
http://www.gentoo.org/proj/en/portage/doc/manually-fixing-portage.xml
為了以防萬一連結不見,就把整篇文章複製過來,以後查詢也方便,需要的人請自行參考

Manually fixing broken portage installations

1. Manually fixing portage

Purpose

This section will tell you how to manually update/fix your portage installation in case you can't run emerge sys-apps/portage. While not hard it is still to be done with great care, so please follow the listed steps exactly (but apply common sense when necessary).

Getting a portage tarball

The first step to do is to get the tarball of a current portage version. In the following text we will use portage-2.1.1 as an example (as this is the current stable version at the time of this writing), please replace that with a version present in the tree if possible.

Warning: If your currently installed version of python reported by python -V is less than 2.4 then you must choose a version of portage that is compatible with it. If you have at least python 2.3 then use portage-2.1.1.tar.bz2. If you have python 2.2 then use portage-2.0.51.22.tar.bz2.

Depending on the exact reason portage doesn't work for you anymore it may still be possible to use it to fetch the tarball for you, so as a first step please try to run emerge --fetchonly sys-apps/portage, only if that doesn't work you have to manually fetch the tarball with:

Code Listing 1.1: Fetching portage tarball with wget

# wget -P /usr/portage/distfiles http://distfiles.gentoo.org/distfiles/portage-2.1.1.tar.bz2 

After that you should have the tarball available as /usr/portage/distfiles/portage-2.1.1.tar.bz2.

Replacing the installed version

The next step is to unpack the tarball to a temporary location, using /root/portage-recover as example the commands to do that are:

Code Listing 1.2: Unpacking portage tarball

# cd /root
# mkdir portage-recover
# cd portage-recover
# tar xfj /usr/portage/distfiles/portage-2.1.1.tar.bz2

After you have done this it's just a matter of replacing the python and bash files of your existing installation with the ones from the tarball (in most cases anyway). To do so please run:

Code Listing 1.3: Replacing installed files

# cd /root/portage-recover/portage-2.1.1
# cp -R pym bin /usr/lib/portage/

If you are not using Gentoo on FreeBSD then you should remove the sed wrapper script since it's not needed and it is known to cause problems with old versions of bash:

Code Listing 1.4: Removing the sed wrapper script

# rm -f /usr/lib/portage/bin/sed 

Note: If you accidently unmerged portage before or lost /etc/make.globals for other reasons you should also copy cnf/make.globals back into /etc, otherwise portage might behave in strange ways.

Note: If the previous version of portage was less than 2.1 then you should now run emerge --metadata before continuing to the next step. This is necessary in order to convert the ebuild metadata to the new format that is used by portage 2.1 and above. It is okay to run this command even if you are not sure what the previous version of portage was.

Now you should have a working portage install again. To ensure a consistent system state however you should now run emerge sys-apps/portage again immediately.

If you get a command not found error message when you try to run emerge you have to recreate the symlink:

Code Listing 1.5: Recreating the emerge symlink

# ln -s ../lib/portage/bin/emerge /usr/bin/emerge 

If these steps didn't work for you your problem is likely not a broken portage installation but something else beyond the scope of this document. Please recheck the list of common problems and also look in bugzilla if the problem is reported there.

0 意見