| 站 內 搜 尋 |
|
日 曆 |
|||||||||||||||||||||||||||||||||||||||||||||||||
| 近 期 文 章 |
| 文 章 分 類 |
apt-hold 自力救濟版
敝人在之前的
DPKG/APT 常用指令 (上)中提到,我們可以把某個套件給 "hold"(保留)起來,以避免它被 apt-get update 給升級了。但問題是 APT 並沒有提供什麼類似 apt-hold 的便利指令可供使用,要 hold 一個套件可真是不容易:
DPKG/APT 常用指令 (下)
以上指令將會 hold 住 tree 這個套件,但說實在敝人真的怎麼樣也記不住這麼長的一個指令,並且在沒有檢查套件狀態之前(它可能是 purge 或 deinstall 等其它狀態呀!)就直接把它 hold 起來也有點危險,所以就寫一個比較聰明的 apt-hold 自力救濟了:
echo "tree hold" | dpkg --set-selections
其使用方法如下:
#!/bin/bash
list()
{
dpkg --get-selections | grep -P "\t+hold$"
}
hold()
{
check_exist $1
if [ $? -eq 1 ]; then
echo -e "ERROR:\tThe package '$1' not found!"
return
fi
check_hold $1
if [ $? -eq 0 ]; then
echo -e "INFO:\tThe package '$1' is already hold."
return
fi
check_install $1
if [ $? -eq 1 ]; then
echo -e "WARN:\tThe status of package '$1' is NOT 'install'."
return
fi
echo -e "$1 hold" | dpkg --set-selections
check_hold $1
if [ $? = 1 ]; then
echo -e "ERROR:\tHold package '$1' fault!"
else
echo -e "INFO:\t`dpkg --get-selections | grep -P "^$1\t+"`"
fi
}
unhold()
{
check_exist $1
if [ $? -eq 1 ]; then
echo -e "ERROR:\tThe package '$1' not found!"
return
fi
check_install $1
if [ $? -eq 0 ]; then
echo -e "INFO:\tThe package '$1' is already unhold."
return
fi
check_hold $1
if [ $? -eq 1 ]; then
echo -e "WARN:\tThe status of package '$1' is NOT 'hold'."
return
fi
echo -e "$1 install" | dpkg --set-selections
check_install $1
if [ $? = 1 ]; then
echo -e "ERROR:\tUnHold package '$1' fault!"
else
echo -e "INFO:\t`dpkg --get-selections | grep -P "^$1\t+"`"
fi
}
check_exist()
{
PKG=`dpkg --get-selections | grep -P "^$1\t+"`
if [ -z "$PKG" ]; then
return 1
else
return 0
fi
}
check_install()
{
PKG=`dpkg --get-selections | grep -P "^$1\t+install$"`
if [ -z "$PKG" ]; then
return 1
else
return 0
fi
}
check_hold()
{
PKG=`dpkg --get-selections | grep -P "^$1\t+hold$"`
if [ -z "$PKG" ]; then
return 1
else
return 0
fi
}
list_not_install()
{
dpkg --get-selections | grep -v -P "\t+install$"
}
get_help()
{
echo -e "Usage: $0\t\t\tList holded packages."
echo -e " $0 pkg1 [pkg2 ...]\thold packages."
echo -e " $0 -u pkg1 [pkg2 ...]\tunhold packages."
echo -e " $0 -v\t\t\tList packages not 'install'."
echo -e " $0 -h/-?\t\t\tThis help text."
}
case $1 in
'')
list
;;
-v)
shift
if [ -z "$1" ]; then
list_not_install
else
get_help
fi
;;
-u)
shift
if [ -z "$1" ]; then
echo -e "WARN:\tMissing package name after -u option."
else
while [ -n "$1" ]; do
unhold "$1"
shift
done
fi
;;
-*)
get_help
;;
-)
get_help
;;
*)
while [ -n "$1" ]; do
hold "$1"
shift
done
;;
esac
如果您心臟夠大顆想試用看看的話,可以把它的屬性改成 755 執行看看,若真覺得沒問題的話可以再把它放在 /usr/bin 裡。而若有任何意見或建議的話也請不妨提出。謝謝!
apt-hold 列出狀態為 hold 的套件。
apt-hold pkg1 [pkg2 ...] hold 套件。
apt-hold -u pkg1 [pkg2 ...] 取消套件的 hold 狀態。
apt-hold -v 列出狀態並非 install 的套件。
apt-hold -h/-? 說明訊息。
Re: apt-hold 自力救濟版
想要問一下這個跟 aptitude 裡面的 Hold 有什麼分別嗎?
[回應] $4 @ 15/06/2010, 10:04
Re: apt-hold 自力救濟版
http://tetralet.luna.com.tw/index.php?op=ViewArticle&articleId=219&blogId=1 這邊有提到『不 過 dpkg 及 aptitude 的 hold 資料庫並不是共通的,也就是說,使用 apt-get 並不會理會被 aptitude 所 hold 的套件;但 aptitude 則不會升級被 dpkg 所 hold 的套件。這是在 hold 套件時所必須注意到的事項。』感謝
[回應] $4 @ 15/06/2010, 10:24