summaryrefslogtreecommitdiff
path: root/scripts/tothreaded
blob: bf6750eddcf481c8b451c2a7a85e520845f8aac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh

# PURPOSE : 
#
# this script converts a non-threaded control file to a threaded one
# by extending appropriate names with -mt as extension
#
# eg abc.control becoms abc-mt.control
#

#
# make sure that the depends expression has enough spaces
# expression can contian : , ( ) || && 
#
tokenize() {
    sed "s/,/ & /g" | sed "s/)/ & /g" | sed "s/(/ & /g" |  sed "s/|/ & /g" | sed "s/&/ & /g"
}

#
# function converts package name to threaded equivalend IF the
# package file HAS a threaded version
#
findthreadedequiv() {
      local isin i
      for i in $*
      do
        isin=`grep "^$i\$" "$ALLTHREADEDPKGSFILE"`
        if [ -z "$isin" ]
        then
          # no threaded package
          echo -n "$i"
        else
          # threaded package
          echo -n "${isin}-mt" 
        fi
      done
      echo 
}

#
# signature of binary files
# currently obsolete
#
# ISBINARY="*ELF*LSB*"

usage() {
      echo "Usage : tothreaded <controlfile> <ALLPackages file>"
      exit 2
}

. scripts/SpecialMTFiles

#
# get the name of the controlfile to check for threading
#
if [ -z "$1" ]
then
    usage
fi
controlfile=$1
shift

case $controlfile in
  *-mt.control)
    #already threaded
    echo $controlfile
    exit 0;
    ;;
esac

#
# file containing list of all known threaded packages
#
if [ -z "$1" ]
then
    usage
fi
ALLTHREADEDPKGSFILE=$1
shift

#
# strip out the name of the package
#
packagename=${controlfile##*/}  # path
packagename=${packagename%.control} # extension

#
# generate new control file
#
newcontrolfile=${controlfile/\.control/-mt\.control}

#
# read all lines in original control file
#
while read line
do
  case $line in
    # convert some files to threaded equivalent
    "Files:"*)
       files=${line#Files:}
       # thread-converted files
       T_files=`ConvertSpecialFiles "$files"`
       echo "Files: $T_files"
       ;;
     "Package: "*)
       T_package=`findthreadedequiv ${line#Package: }`
       echo "Package: ${T_package}"
       ;;
     "Depends: "*)
       depends=`echo "${line#Depends: }" | tokenize`
       T_depends=`findthreadedequiv ${depends}`
       echo "Depends: $T_depends"
       ;;
     "Provides: "*)
       T_provides=`findthreadedequiv ${line#Provides: }`
       echo "Provides: $T_provides"
       ;;
     "Recommends: "*)
       T_recommends=`findthreadedequiv ${line#Recommends: }`
       echo "Recommends: $T_recommends"
       ;;
     "Conflicts: "*)
       conflicts=`echo "${line#Conflicts: }" | tokenize`
       T_conflicts=`findthreadedequiv ${conflicts}`
       echo "Conflicts: $T_conflicts"
       ;;
     *":"*) 
       echo "$line"
       ;;
     *) # al other lines
       echo " $line"
       ;;
  esac
done < $controlfile > $newcontrolfile

echo $newcontrolfile