sidux.com
Menu

News

Give back
Last 3 Contributions
30-11-2008 20.00
25-11-2008 100.00
25-11-2008 20.00

Donate


Sponsor
hetzner.de

Languages
Preferred language:



Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
ModestUser
Post subject: hold/unhold management  PostPosted: Jun 11, 2008 - 01:35 AM



Joined: Jan 07, 2008
Posts: 298

Status: Offline
This script lists all packages that are on hold, sets packages on hold, can unhold them and can do an install/hold.

Example:
hold # lists all packages on hold
hold iceweasel # sets iceweasel on hold
hold -i iceweasel koffice # updates iceweasel and koffice and sets them on hold afterwards
hold -u iceweasel # sets iceweasel on install, will be updated with next d-u
hold -h # help

It supports a handy numerical notation like "hold -ni 1 3 4" (those numbers are in the list that hold displays).

Install: own as root, make executable, copy to /usr/local/bin

Feedback welcome!

EDIT: I realized that tar is not such a good choice, so i will go for the code-way. Unfortunately, the forum upload function does only support gz, tar and this stuff.

Scriptname: hold

Code:

#!/bin/bash
#
# Author:   ModestUser
# Version:   0.1
# License:   GPLv2
#
# Simple management tool for setting packages on hold, unhold them or install/hold them
# Install: own as root, make executable, copy to /usr/local/bin
#
# For usage: hold -h

function usage () {
   cat <<EOF
USAGE:   ${my_name} [ -i | -u | -h ] [ -n ] package1 package2 ...

   Without any arguments all packages that are set to HOLD are displayed.
   Without any option the packages are set to HOLD.

OPTIONS:
   -i   installs packages and sets them to HOLD
   -u   unhold packages, i.e. set to install (no dist-upgrade)
   -n   use numbers instead of package names to reference packages
   -h   display this help
EOF
}

function print_error () {
   echo >&2 "${*}"
   exit 1
}
   
function numbers_to_packages () {
   [[ -f ${hold_list} ]] || print_error "Error: hold list has not been generated! Run 'hold' without arguments first!"
   numbers="${packages}"
   packages=
   for num in ${numbers}; do
      packages="${packages} $(sed -n "${num}p" ${hold_list})"   
   done
}

function write_hold_list () {
   dpkg --get-selections | awk '/hold$/ { print $1 }' > "${hold_list}"
}

function display_hold_list () {
   echo "Packages on hold:"
   cat -n "${hold_list}"
}

function set_hold () {
   for package in ${packages}; do
      echo "Setting package ${package} to hold..."
      echo "${package} hold" | dpkg --set-selections
   done
}

function hold_install () {
   apt-get update && apt-get -V install ${packages}
   set_hold
}

function unhold () {
   for package in ${packages}; do
      echo "Setting package ${package} to install..."
      echo "${package} install" | dpkg --set-selections
   done
}

(($UID)) && print_error "You must be root to run this script!"

my_name="$(basename $0)"
hold_list="${TMPDIR:=/tmp}/${my_name}.list"
action="set_hold"
use_numbers=0


if ((${#} == 0)); then
   write_hold_list && display_hold_list
   exit 0
fi

while getopts "hinu" opt; do
   case $opt in
      i)   [[ "${action}" == "unhold" ]] && print_error "Error: Options -i and -u are not compatible!"
         action="hold_install" ;;
      u)    [[ "${action}" == "hold_install" ]] && print_error "Error: Options -i and -u are not compatible!"
         action="unhold" ;;
      n)   use_numbers=1 ;;
      h)   usage; exit 0 ;;
   esac
done

shift $((${OPTIND} - 1))
packages="${@}"
((${use_numbers})) && numbers_to_packages
${action}
write_hold_list && display_hold_list
exit 0


Last edited by ModestUser on Jun 11, 2008 - 04:14 PM; edited 2 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
LessWire
Post subject: RE: hold/unhold management  PostPosted: Jun 11, 2008 - 02:24 AM



Joined: Dec 04, 2006
Posts: 264
Location: Bavaria
Status: Offline
cat compliments | ModestUser Smile

Thanks for the script, will try it soon, looked at the style of code and it seems it's your profession!!? Wink

greets, L.W.

_________________
Everybody knows, that's how it goes ... (L. Cohen)
 
 View user's profile Send private message  
Reply with quote Back to top
ModestUser
Post subject: RE: hold/unhold management  PostPosted: Jun 11, 2008 - 04:22 PM



Joined: Jan 07, 2008
Posts: 298

Status: Offline
No, gladly I am not a professional bash hacker. It is nice for quick & dirty maintenance tasks but not suited for real problem solving. h2 does the research on how far you can go with bash. Wink
 
 View user's profile Send private message  
Reply with quote Back to top
drb
Post subject:   PostPosted: Jun 12, 2008 - 06:51 AM



Joined: Dec 01, 2006
Posts: 722

Status: Offline
hold -l would be a nice addition to list all held packages?

drb

IGNORE - It's already there; I should have read the script!

_________________
sidux Chaos fully dist-upgraded!
kernel 2.6.27-7.slh.2-sidux-686
 
 View user's profile Send private message  
Reply with quote Back to top
j-pj
Post subject:   PostPosted: Jun 16, 2008 - 10:27 AM



Joined: Nov 21, 2007
Posts: 42

Status: Offline
Much better than mine Wink. Thanks
 
 View user's profile Send private message  
Reply with quote Back to top
sde
Post subject:   PostPosted: Jun 30, 2008 - 08:15 PM



Joined: Apr 30, 2008
Posts: 31

Status: Offline
Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
HeSaid
Post subject:   PostPosted: Jun 30, 2008 - 09:25 PM



Joined: Aug 08, 2007
Posts: 34
Location: Southwest Florida, USA
Status: Offline
Thanks for the script, ModestUser. Nice work!
--
Neal

_________________
Registered Linux User 159445.
sidux 2008-1 on HP Pavilion dv6451us laptop.
 
 View user's profile Send private message  
Reply with quote Back to top
MeanDean
Post subject:   PostPosted: Jul 02, 2008 - 05:56 AM



Joined: Mar 16, 2008
Posts: 94

Status: Offline
interesting...

_________________
-debian sid live cd with installer-
aptitude install live-helper
lh_config -d sid -a i386 --debian-installer=enabled && lh_build

DEBIAN INFO!
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
 
Logos and trademarks are the property of their respective owners, comments are property of their posters, the rest is © 2006-2008 by sidux e.V., 10407 Berlin, Kniprodestr. 104. sidux e.V. is a Berlin, Germany based non-profit foundation. Consult Impressum and Legal Terms for details. sidux™ is Free Software released under the GNU/GPL license and other compatible licenses.
powered by Zikula & Zafenio