cos*_*mos 4 package-management command-line dpkg debian software-installation
我使用的是 Ubuntu 22.04.3 LTS。我制作了一个名为 的文件helloworld.deb
,其源文件结构如下:
helloworld\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 DEBIAN\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 control\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 usr\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 games\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mygame.sh\n
Run Code Online (Sandbox Code Playgroud)\n我曾经dpkg-deb --build helloworld
制作过helloworld.deb
文件。然后我把sudo dpkg --instdir=phonyRoot -i helloworld.deb
它安装在一个名为 的文件夹中phonyRoot
。
我执行tree phonyRoot
并得到以下结果:
phonyRoot\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 usr\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 games\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mygame.sh\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 var\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lib\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 dpkg\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 info\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 format\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 helloworld.list\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 helloworld.md5sums\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 lock\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 lock-frontend\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 status\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 status-old\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 triggers\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Lock\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Unincorp\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 updates\n\n8 directories, 10 files\n
Run Code Online (Sandbox Code Playgroud)\n然后我执行了dpkg -l | grep helloworld
,但无法获取有关我刚刚安装的软件包的任何信息。
如上所示,--instdir=phonyRoot
还将管理目录更改为phonyRoot
文件夹。看来这个选项--admindir=dir
也被添加到了引擎盖下。根据手册,这与该选项的行为相同--root=dir
。
为什么行为与--instdir=dir
手册中的描述不符?
1.22.0
DPKG 之前的版本(Ubuntu 23.10 附带)似乎存在问题,可以通过DPKG_ADMINDIR
在命令行上显式设置环境变量来修复,如下所示:
sudo DPKG_ADMINDIR="/var/lib/dpkg" dpkg --instdir=...\n
Run Code Online (Sandbox Code Playgroud)\n--instdir
实际上,它本身似乎并没有做到这一点......请看下面的演示:
sudo DPKG_ADMINDIR="/var/lib/dpkg" dpkg --instdir=...\n
Run Code Online (Sandbox Code Playgroud)\n请注意, (Reading database ... 217181 files and directories currently installed.)
因为它是从原始系统范围的默认值读取admindir
的/var/lib/dpkg
,因此读取的数字很大217181
......事实上,它不应该按照以下明确说明的那样这样做dpkg -b --help
:
--instdir=<directory> Change installation dir without changing admin dir.\n
Run Code Online (Sandbox Code Playgroud)\n同时,--root
确实:
$tree myapp/\nmyapp/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 DEBIAN\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 control\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 install\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 usr\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 bin\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 myap\n\n4 directories, 3 files\n$\n$\n$tree dir\ndir\n\n0 directories, 0 files\n$\n$\n$head myapp/{DEBIAN,usr/bin}/*\n==> myapp/DEBIAN/control <==\nPackage: myapp\nVersion: 0.01\nArchitecture: all\nMaintainer: my contact\nSection: extras\nPriority: optional\nHomepage: my homepage\nDescription: myapp description\n\n==> myapp/DEBIAN/install <==\nmyapp usr/bin/\n\n==> myapp/usr/bin/myap <==\n#!/bin/bash\n\nprintf \'%s\\n\' {1..9}\n$\n$\n$dpkg --version\nDebian \'dpkg\' package management program version 1.22.0 (amd64).\nThis is free software; see the GNU General Public License version 2 or\nlater for copying conditions. There is NO warranty.\n$\n$\n$dpkg -b myapp/\ndpkg-deb: building package \'myapp\' in \'myapp.deb\'.\n$\n$\n$sudo dpkg --instdir=dir -i myapp.deb \nSelecting previously unselected package myapp.\n(Reading database ... 217181 files and directories currently installed.)\nPreparing to unpack myapp.deb ...\nUnpacking myapp (0.01) ...\nSetting up myapp (0.01) ...\n$\n$\n$tree dir\ndir\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 usr\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 bin\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 myap\n\n3 directories, 1 file\n$\n$\n$./dir/usr/bin/myap \n1\n2\n3\n4\n5\n6\n7\n8\n9\n$\n$\n$dpkg -s myapp\nPackage: myapp\nStatus: install ok installed\nPriority: optional\nSection: extras\nMaintainer: my contact\nArchitecture: all\nVersion: 0.01\nDescription: myapp description\nHomepage: my homepage\n$\n$\n$dpkg --root=dir -l\n$\n
Run Code Online (Sandbox Code Playgroud)\n请注意 (Reading database ... 0 files and directories currently installed.)
,它是从备用admindir
位置读取的dir2/var/lib/dpkg
,因此是数字0
。
如中所述man dpkg
:
--root=dir\n Changing root changes instdir to dir and admindir to dir/var/lib/dpkg.\n
Run Code Online (Sandbox Code Playgroud)\n...确实如此,但是:
\n--instdir=dir\n Change default installation directory which refers to the directory where packages\n are to be installed. instdir is also the directory passed to chroot(2) before\n running package\'s installation scripts, which means that the scripts see instdir as\n a root directory. (Defaults to /)\n
Run Code Online (Sandbox Code Playgroud)\n...似乎没有改变admindir
,而是更改了包安装脚本的根目录,因此可能会查看包中的脚本(如果有)或相关内容或其他内容。
也就是说,--instdir
\ 的行为虽然不一定直接记录在手册中的描述下,但可能取决于是否DPKG_ADMINDIR
设置了环境变量......引用自diff from 1.21.1ubuntu2 to 1.21.7ubuntu1
:
+ man: Clarify --admindir and --instdir default values\n+ \n+ These depend on the DPKG_ADMINDIR and DPKG_ROOT environment variables\n+ being set or not. Although this is mentioned in the ENVIRONMENT section\n+ it is not obvious directly from the command-line options descriptions.\n
Run Code Online (Sandbox Code Playgroud)\n1.22.0
...如果您通过在命令行本身上显式设置环境变量来确保正确设置环境变量,则可以在操作中看到这一点(在之前的 DPKG 版本中),例如:
sudo DPKG_ADMINDIR="/var/lib/dpkg" dpkg --instdir=dir -i myapp.deb\n
Run Code Online (Sandbox Code Playgroud)\n然而,根据上面使用 DPKG 版本的演示,这个问题似乎已得到修复,1.22.0
该版本是 Ubuntu 23.10 下的默认版本。
归档时间: |
|
查看次数: |
9248 次 |
最近记录: |