#!/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