https://github.com/lujun9972/lujun9972.github.com/blob/source/linux%E5%92%8C%E5%AE%83%E7%9A%84%E5%B0%8F%E4%BC%99%E4%BC%B4/%E5%A6%82%E4%BD%95%E5%9C%A8archlinux%E4%B8%8A%E5%AE%89%E8%A3%85RPM%E5%8C%85.org
作者 | Lujun9972
有時候你可能會發現,想安裝一個包,但是這個包只提供 RPM 安裝檔案,而 ArchLinux 並不支援安裝 RPM 檔案,這該怎麼辦呢?
下麵這個方法也許可以幫到你。
1、 安裝 rpmextract
rpmextract 是一個用來解壓 RPM 的工具,它會將 RPM 包中的內容解壓到當前目錄下。
sudo pacman -S rpmextract --noconfirm
resolving dependencies...
looking for conflicting packages...
Packages (1) rpmextract-1.0-8
Total Download Size: 0.00 MiB
Total Installed Size: 0.00 MiB
:: Proceed with installation? [Y/n]
:: Retrieving packages...
rpmextract-1.0-8-any 0.0 B 0.00B/s 00:00 [----------------------] 0%
rpmextract-1.0-8-any 2.5 KiB 0.00B/s 00:00 [######################] 100%
(0/1) checking keys in keyring [----------------------] 0%
(1/1) checking keys in keyring [######################] 100%
(0/1) checking package integrity [----------------------] 0%
(1/1) checking package integrity [######################] 100%
(0/1) loading package files [----------------------] 0%
(1/1) loading package files [######################] 100%
(0/1) checking for file conflicts [----------------------] 0%
(1/1) checking for file conflicts [######################] 100%
(0/1) checking available disk space [----------------------] 0%
(1/1) checking available disk space [######################] 100%
:: Processing package changes...
(1/1) installing rpmextract [----------------------] 0%
(1/1) installing rpmextract [######################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
2、 使用 rpmextract 解壓 RPM 檔案
由於 RPM 檔案中打包的目錄結構是以根目錄為基準的,因此推薦直接在根目錄下進行解壓:
cd /
sudo rpmextract.sh ~lujun9972/android-x86-7.1-r2.x86_64.rpm
3、 抽取出安裝 RPM 時呼叫的指令碼
光把RPM包中的檔案解壓出來還是不夠的,RPM 檔案在安裝(或者解除安裝)前/後還會執行一個指令碼。
這個指令碼可以透過命令 rpm -qp --script file.rpm
來檢視。
然而, ArchLinux 並沒有 rpm
命令怎麼辦呢?我們可以可以在虛擬機器上執行一個 CentOS 或者直接使用 docker 來模擬一個 CentOS 環境也可以:
docker run --rm -v ~lujun9972/android-x86-7.1-r2.x86_64.rpm:/tmp/android.rpm centos rpm -qp --scripts /tmp/android.rpm
postinstall scriptlet (using /bin/sh):
. /etc/os-release
mkdir -p /android-7.1-r2/data
if [ "$ID" = "debian" -o "$ID_LIKE" = "debian" ]; then
grubcfg=/boot/grub/custom.cfg
elif mountpoint -q /boot/efi; then
grubcfg=/boot/efi/EFI/$ID/custom.cfg && efi=efi
else
grubcfg=/boot/grub2/custom.cfg
fi
echo -e "menuentry \"Android-x86 7.1-r2\" {\n\tsearch --set=root --file /android-7.1-r2/kernel\n\tlinux$efi /android-7.1-r2/kernel quiet root=/dev/ram0 androidboot.selinux=permissive buildvariant=userdebug \n\tinitrd$efi /android-7.1-r2/initrd.img\n}" > $grubcfg
echo -e "menuentry \"Android-x86 7.1-r2 (DEBUG mode)\" {\n\tsearch --set=root --file /android-7.1-r2/kernel\n\tlinux$efi /android-7.1-r2/kernel root=/dev/ram0 androidboot.selinux=permissive buildvariant=userdebug DEBUG=2\n\tinitrd$efi /android-7.1-r2/initrd.img\n}" >> $grubcfg
if [ "$ID" = "debian" -o "$ID_LIKE" = "debian" ]; then
sed -i 's/^GRUB_HIDDEN_/#GRUB_HIDDEN_/' /etc/default/grub
update-grub
fi
postuninstall scriptlet (using /bin/sh):
. /etc/os-release
if [ "$ID" = "debian" -o "$ID_LIKE" = "debian" ]; then
grubcfg=/boot/grub/custom.cfg
elif mountpoint -q /boot/efi; then
grubcfg=/boot/efi/EFI/$ID/custom.cfg
else
grubcfg=/boot/grub2/custom.cfg
fi
if [ "$1" = "1" ]; then
new_prefix=`dirname $(grep initrd $grubcfg | head -1 | awk '{print $2}')`
if [ "$new_prefix" != "/android-7.1-r2" ]; then
rmdir $new_prefix/data
mv /android-7.1-r2/data $new_prefix
rmdir /android-7.1-r2
fi
else
rmdir /android-7.1-r2/data /android-7.1-r2
rm -f $grubcfg
fi
4、 呼叫安裝指令碼
運氣好的話,你就能把 RPM 安裝好了。