2015-12-16 154 views
1

我已經做了一個debian軟件包來自動安裝oozie。 postinst腳本基本上是一個shell腳本,在安裝該軟件包後運行。我想訪問這個腳本中的環境變量。我應該在哪裏設置環境變量?訪問Debian軟件包的postinst腳本中的環境變量

+0

環境變量從父到子繼承(複製)。所以,在父母,即無論運行腳本。 – cdarke

+0

@cdarke,當我部署debian時,仍然無法訪問env變量。我將它們設置在bashrc文件中。 –

+0

你確定.bashrc文件正在執行嗎?它通常不會被腳本執行,並且如果bash被調用爲'sh',則不會被執行。 – cdarke

回答

0

取決於你是什麼實際上試圖完成,將信息傳遞給包腳本的正確方法是使用Debconf變量。

簡單地說,你添加一個debian/templates文件是這樣的:

Template: oozie/secret 
Type: string 
Default: xyzzy 
Description: Secret word for teleportation? 
Configure the secret word which allows the player to teleport. 

,改變你的postinst腳本像

#!/bin/sh -e 

# Source debconf library. 
. /usr/share/debconf/confmodule 

db_input medium oozie/secret || true 
db_go 

# Check their answer. 
db_get oozie/secret 
instead_of_env=$RET 
: do something with the variable 

可以preseed與價值debconf數據庫爲oozie/secret運行前包裝腳本;那麼它不會提示該值。只需執行如下操作:

​​

預配置值爲plugh

又見http://www.fifi.org/doc/debconf-doc/tutorial.html

0

添加到您的postinst腳本:

#!/bin/sh -e 
# ... 
pid=$$ 
while [ -z "$YOUR_EVAR" -a $pid != 1 ]; do 
    ppid=`ps -oppid -p$pid|tail -1|awk '{print $1}'` 
    env=`strings /proc/$ppid/environ` 
    YOUR_EVAR=`echo "$env"|awk -F= '$1 == "YOUR_EVAR" { print $2; }'` 
    pid=$ppid 
done 
# ... Do something with YOUR_EVAR if it was set. 

只有export YOUR_EVAR=... dpkg -i來運行之前。

不是推薦的方式,但它緊湊,簡單,正是PO所要求的。