由於 debconf,postinst 總是失敗

由於 debconf,postinst 總是失敗

我在對我的套件使用 debconf 時遇到一些問題。我在 package.config 檔案中詢問 mysql 密碼:

. /usr/share/debconf/confmodule
db_input high mypkg/mysql_root_pw
db_go

然後,在 postinst 中,我向 debconf 詢問密碼並將其寫入設定檔:

. /usr/share/debconf/confmodule
db_get mypkg/mysql_root_pw
# write pw to config file

當我這樣做時,這有效dpkg-reconfigure --force mypkg。但是,在使用時apt-get -f install(我必須這樣做,因為它說我的 pkg 已損壞)它總是失敗:

Setting up mypkg (1.5.4-3) ...
debconf (developer): frontend started
debconf (developer): frontend running, package name is mypkg
debconf (developer): starting /var/lib/dpkg/info/mypkg.config configure 
debconf (developer): <-- INPUT low mypkg/mysql_root_pw
debconf (developer): --> 30 question skipped
dpkg: error processing mypkg (--configure):
 subprocess installed post-installation script returned error exit status 30
Errors were encountered while processing:
 mypkg

我編輯了腳本/var/lib/dpkg/info/mypkg.postinst,錯誤發生在我獲取 debconf 庫的行上:

. /usr/share/debconf/confmodule

這可能是因為 debconf 已經具有原始安裝的值並且不再顯示該問題。但是我怎麼能跳過詢問它是否已經擁有它以及為什麼它會在那一行失敗而不是當我這樣做時失敗db_get

我搜尋了谷歌,似乎找不到太多有用的信息。

答案1

所以我終於成功了。如果 debconf 已經具有該值,那麼在我的帖子中遇到第一個問題時,debconf 總是會失敗。我終於有了(明顯的)想法來檢查系統上其他軟體包的 postinst 和配置文件,這就是技巧:

在你的配置中

. /usr/share/debconf/confmodule
db_input high mypkg/mysql_root_pw || true
db_go || true

就是這樣。當我請求 postinst debconf 中的值時,我很高興。顯然,當您沒有獲得任何值時,您需要進行處理。

我還在db_stop我的帖子中添加了一個,我不知道是否有必要,但為了完成我會添加它。

mypkg.postinst

. /usr/share/debconf/confmodule
db_get mypkg/mysql_root_pw
mysql_root_pw=$RET
db_get mypkg/some_other_value
some_other_value=$RET
db_stop
# do something with the $mysql_root_pw and $some_other_value vars

希望有一天這能對其他人有幫助。

乾杯

相關內容