summaryrefslogtreecommitdiff
path: root/emulators/suse_base/scripts/rpm2pkg.sh
blob: 1ce74db2a50053e6b3a548be6d062d2223a9e50a (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
#!/bin/sh
export PATH=/bin:/usr/bin:@@PREFIX@@/bin

TMPDIR=/tmp/.rpm.$$.`date +%s`
LIST=$TMPDIR/LIST
DIRS=$TMPDIR/DIRS
FILES=$TMPDIR/FILES
LINKS=$TMPDIR/LINKS

if ! rm -rf $TMPDIR
then 
 exit 1
fi
if ! mkdir -p $TMPDIR/@@EMULSUBDIR@@
then 
 exit 1
fi

touch $LIST
for RPM
do
 rpm2cpio $RPM | (cd @@EMULDIR@@; @@PAX@@ -r -v 2>>$LIST)
done

touch $DIRS $LINKS
cd @@PREFIX@@
grep -v ^pax:\  $LIST | @@AWK@@ '{print("@@EMULSUBDIR@@/"$1)}' |
(while read ENTRY
 do
  if [ -L "$ENTRY" ]
  then
   set - `file $ENTRY`
   shift `expr $# - 1`;
   case $1 in
   /* )
    TARGET=`echo $1 | cut -c 2-`
    DIR=`dirname $ENTRY`
    while [ $DIR != @@EMULSUBDIR@@ ]
    do
     TARGET=../$TARGET
     DIR=`dirname $DIR`
    done
    unset DIR
    rm $ENTRY
    ln -s $TARGET $ENTRY
    ;;
   * )
    TARGET=$1
   esac
   if cd `dirname $ENTRY` && test -f $TARGET
   then
    echo $ENTRY
   else
    echo "@exec ln -s $TARGET %D/$ENTRY" >>$LINKS
    echo "@unexec rm -f %D/$ENTRY" >>$LINKS
   fi
   cd @@PREFIX@@
  else
   if [ -f "$ENTRY" ]
   then
    echo "$ENTRY"
   else
    if [ -d "$ENTRY" ]
    then
     echo "$ENTRY" >>$DIRS
    fi
   fi
  fi
 done) >$FILES

cat $FILES
sort $DIRS | awk '{print("@exec mkdir -p %D/"$1)}'
cat $LINKS
sort -r $DIRS | awk '{print("@unexec rmdir %D/"$1" >/dev/null 2>&1 || true")}'

rm -rf $TMPDIR
exit 0