有时候你可能会发现,想安装一个包,但是这个包只提供 RPM 安装文件,而 ArchLinux 并不支持安装 RPM 文件,这该怎么办呢?
下面这个方法也许可以帮到你。
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...
由于 RPM 文件中打包的目录结构是以根目录为基准的,因此推荐直接在根目录下进行解压:
cd /
sudo rpmextract.sh ~lujun9972/android-x86-7.1-r2.x86_64.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
运气好的话,你就能把 RPM 安装好了。