~ubuntu-branches/debian/sid/deborphan/sid

« back to all changes in this revision

Viewing changes to util/orphaner

  • Committer: Bazaar Package Importer
  • Author(s): Peter Palfrader
  • Date: 2001-10-28 01:28:24 UTC
  • Revision ID: james.westby@ubuntu.com-20011028012824-0jvhpixo5ldm3h85
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# Options are passed on to deborphan
 
4
 
5
# Orphaner is a neat frontend for deborphan displaying a list
 
6
# of orphaned packages with dialog or whiptail. Packages may be
 
7
# selected for removal with apt-get which is then called to do the
 
8
# work. After removal a new list of orphaned packages is gathered
 
9
# from deborphan. The program ends when either `Cancel' is pressed
 
10
# or no package is marked for removal.
 
11
#
 
12
# (c) 2000 Goswin Brederlow <goswin.brederlow@student.uni-tuebingen.de>
 
13
# (c) 2000 Peter Palfrader <peter@palfrader.org>
 
14
#
 
15
# This program is dual licensed either unter the GNU GPL as published
 
16
# by the Free Software Foundation; either version 2, or (at your option)
 
17
# any later version,
 
18
# _OR_ (at your opinion)
 
19
# the Artistic license (under which deborphan itself is distributed).
 
20
#
 
21
# The full text of both can be found in /usr/share/common-licenses on
 
22
# Debian systems. If you have problems obtaining the files please
 
23
# write to the authors.
 
24
 
 
25
set -e
 
26
 
 
27
OPTIONS=$@
 
28
VALIDOPTIONS='^-([aDHns]|-fake-dev|-nice-mode|-all-packages|-priority(.+)|p(.+)|-show-section|-force-hold)[[:space:]]$'
 
29
VALIDKEEPOPTIONS='^-([aDHns]|-guess-(dev|perl|section|debug|all)|-nice-mode|-all-packages|-priority(.+)|p(.+)|-show-section|-force-hold)[[:space:]]$'
 
30
 
 
31
if [ -x /usr/bin/dialog ]; then
 
32
  DIALOG=/usr/bin/dialog
 
33
elif [ -x /usr/local/bin/dialog ]; then
 
34
  DIALOG=/usr/local/bin/dialog
 
35
elif [ -x /usr/bin/whiptail ]; then
 
36
  DIALOG=/usr/bin/whiptail
 
37
elif [ -x /usr/local/bin/whiptail ]; then
 
38
  DIALOG=/usr/local/bin/whiptail
 
39
else
 
40
  echo "$0: You need dialog or whiptail to run this frontend." >&2
 
41
  exit 1
 
42
fi
 
43
 
 
44
if echo `deborphan -h` | grep 'Do not read debfoster' >/dev/null 2>&1; then
 
45
  nodf="--df-keep"
 
46
else
 
47
  nodf=""
 
48
fi
 
49
 
 
50
printhelp(){
 
51
  echo "Usage: $0 [OPTIONS]"
 
52
  echo
 
53
  echo "See orphaner(8) and deborphan(1) for a list of valid options."
 
54
  exit 0
 
55
}
 
56
 
 
57
editkeepers() {
 
58
  for each in $OPTIONS; do
 
59
    if [ "$SKIPONE" = "1" ]; then
 
60
      SKIPONE=0;
 
61
    elif [ " $each" = " --keep-file" -o " $each" = " -k" ]; then
 
62
      SKIPONE=1;
 
63
    elif [ " $each" = " --status-file" -o " $each" = " -f" ]; then
 
64
      SKIPONE=1;
 
65
    elif ! echo "$each " | egrep $VALIDKEEPOPTIONS >/dev/null; then
 
66
      case "$each" in
 
67
        --status-file* | -f* | --keep-file* | -k*)
 
68
          ;;
 
69
        *)
 
70
          echo "$0: Invalid option: $each." >&2
 
71
          exit 1
 
72
          ;;
 
73
      esac;
 
74
    fi
 
75
  done
 
76
 
 
77
    ORPHANED=`keeping_list $OPTIONS | sort`;
 
78
    # insert clever error handling
 
79
 
 
80
    if [ "$ORPHANED" != "" ]; then
 
81
      PACKAGES=`$DIALOG \
 
82
        --backtitle "Orphaner V1.1" \
 
83
        --separate-output \
 
84
        --title "Orphaner V1.1" \
 
85
        --checklist "Select Packages that should never be recommended for removal in deborphan:" \
 
86
        18 70 11 \
 
87
        $ORPHANED \
 
88
        2>&1 >/dev/tty` || true
 
89
  
 
90
      if [ ! -z "`deborphan ${nodf} -L $@`" ]; then
 
91
        deborphan ${nodf} -L $@ | xargs deborphan -R $@
 
92
      fi
 
93
      if [ ! -z "$PACKAGES" ]; then
 
94
        deborphan -A $@ $PACKAGES
 
95
      fi
 
96
    fi
 
97
  exit 0;
 
98
}
 
99
 
 
100
keeping_list() {
 
101
 (
 
102
  (deborphan -a $@ || echo "ERROR" ) \
 
103
   | while read SECTION PACKAGE; do 
 
104
       echo $PACKAGE $SECTION off
 
105
     done;
 
106
  (deborphan -L $@ 2>/dev/null|| echo "ERROR" ) \
 
107
   | while read PACKAGE; do 
 
108
       echo $PACKAGE "." on
 
109
     done;
 
110
 ) | sort;
 
111
};
 
112
 
 
113
deborphan_list() {
 
114
  (deborphan -s $@ || echo "ERROR") \
 
115
   | while read SECTION PACKAGE; do 
 
116
       echo $PACKAGE $SECTION off
 
117
     done
 
118
}
 
119
 
 
120
doorphans() {
 
121
  # Check options
 
122
  for each in $OPTIONS; do
 
123
    if [ "$SKIPONE" = "1" ]; then
 
124
      SKIPONE=0;
 
125
    elif [ " $each" = " --status-file" -o " $each" = " -f" ]; then
 
126
      SKIPONE=1;
 
127
    elif ! echo "$each " | egrep $VALIDOPTIONS >/dev/null; then
 
128
      case "$each" in
 
129
        --status-file* | -f*)
 
130
          ;;
 
131
        *)
 
132
          echo "$0: Invalid option: $each." >&2
 
133
          exit 1
 
134
          ;;
 
135
      esac;
 
136
    fi
 
137
  done
 
138
 
 
139
  while [ 1 ]; do
 
140
    ORPHANED=`deborphan_list $OPTIONS | sort`;
 
141
    if [ "$ORPHANED" = "ERROR off" ] ; then
 
142
      exit 1
 
143
    fi
 
144
 
 
145
    if [ "$ORPHANED" != "" ]; then
 
146
      PACKAGES=`$DIALOG \
 
147
        --backtitle "Orphaner V1.1" \
 
148
        --separate-output \
 
149
        --title "Orphaner V1.1" \
 
150
        --checklist "Select Packages for removal or cancel to quit:" \
 
151
        18 70 11 \
 
152
        $ORPHANED \
 
153
        2>&1 >/dev/tty` || true
 
154
  
 
155
      ERROR=$?
 
156
 
 
157
      if [ $ERROR = 0 -a "$PACKAGES" != "" ]; then
 
158
        clear;
 
159
        echo "Removing $PACKAGES..."
 
160
        apt-get -u remove $PACKAGES
 
161
      else
 
162
        exit 0;
 
163
      fi
 
164
    else
 
165
      $DIALOG \
 
166
        --backtitle "Orphaner V1.1" \
 
167
        --title "Orphaner V1.1" \
 
168
        --msgbox "No orphaned packages found." \
 
169
        18 70
 
170
      exit 0;
 
171
    fi
 
172
  done
 
173
  exit 0;
 
174
}
 
175
 
 
176
 
 
177
 
 
178
# Plea for help?
 
179
for each in $OPTIONS; do
 
180
  if [ " $each" = " --help" -o " $each" = " -h" ]; then
 
181
    printhelp;
 
182
  fi
 
183
done
 
184
 
 
185
case $0 in
 
186
  *orphaner)
 
187
    doorphans;
 
188
    ;;
 
189
  *editkeep)
 
190
    editkeepers;
 
191
    ;;
 
192
  *)
 
193
    printhelp;
 
194
    ;;
 
195
esac