Dash:
[t2.git] / misc / archive / catedit.sh
blob0145d1b6c3ba7a582314b6f93095a036c62fc529
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 #
5 # T2 SDE: misc/archive/catedit.sh
6 # Copyright (C) 2004 - 2005 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 # WARNING: Create backup copies of your files before you use this tool
17 # for editing the categories of your packages !!!
19 # Usage: sh misc/archive/catedit.sh package/base/*/*.desc
20 # or: sh misc/archive/catedit.sh -a
23 set -e
25 item=''
26 tmp=$( mktemp )
28 if [ $(dialog --version 2>&1| grep -c "0.9") -eq 0 ]; then
29 echo "dialog's version at least 0.9 needed"
30 exit 1
33 if [ "$1" = "-a" -o "$1" = "--all" ]
34 then files="$(find package/ -name *.desc | sort -t '/' -k 4)"
35 else files="$@"
38 until
39 pkglst=$(grep '^\[C\]' $files | sed -e 's,^[^:]*/,,;' \
40 -e 's,\.[^ ]* , ",;' -e 's,$,",;' | sed -e 's, "$,",' \
41 | tr '\n' ' ' )
43 eval dialog --backtitle \"ROCK Linux package category editor\" \
44 ${item:+--default-item} $item --cancel-label \
45 Quit --menu \"Choose the package you want to edit\" \
46 42 120 35 $pkglst 2> $tmp
48 item="$( cat $tmp )"
49 cat $tmp
50 [ -z "$item" ]
52 for file in $files; do
53 [[ $file = */$item.desc ]] && break
54 done
56 (for category in $(awk '/^[^# ]/ {print $1}' < Documentation/Developers/PKG-CATEGORIES); do
57 echo -n $category $category
58 if [ -n "$(grep "^\[C\].*$category" $file )" ]
59 then echo -e " on "
60 else echo -e " off "
62 done ) > $tmp
64 dialog --cancel-label Back --backtitle " categories for $item " \
65 --checklist "$(grep '^\[I\]' $file | sed 's/\[I\] //' )" \
66 42 80 35 $(cat $tmp) 2> $tmp
67 value=$( cat $tmp | sed -e 's/"//g' -e 's/ $//' )
69 if [ "$value" ] ; then
70 cat $file | sed "s,^\[C\] .*,\[C\] $value,g" > $tmp
71 cat $tmp > $file
72 #grep -v '^\[C\]' "$file" > $tmp
73 #echo -e '\n'"[C] $value" >> $tmp
74 #./scripts/Create-DescPatch $item | patch -p1
76 done
78 rm -f $tmp