aboutsummaryrefslogtreecommitdiff
path: root/trunk/src/rebuildpkg
blob: 6d3d10ce36d82a906d2172d432889f68e4e7d98a (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
#!/bin/bash
#
# rebuildpkg: build a package from a /var/log/packages entry
#
# feedback: rhatto at riseup.net | gpl
#
#  Rebuildpkg is free software; you can redistribute it and/or modify it under the
#  terms of the GNU General Public License as published by the Free Software
#  Foundation; either version 2 of the License, or any later version.
#
#  Rebuildpkg is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
#  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
#  Place - Suite 330, Boston, MA 02111-1307, USA
#

COMMON="/usr/libexec/simplepkg/common.sh"
TMP="/tmp"

function usage {
  echo "usage: ROOT=/otherroot `basename $0` <package-name>"
}

if [ -f "$COMMON" ]; then
  source $COMMON
else
  echo "error: file $COMMON found, check your `basename $0` installation"
  exit 1
fi

if [ -z "$1" ]; then
  usage
  exit 1
fi

pack="$1"

for file in `ls $ROOT/var/log/packages/$pack*`; do
  if [[ "`package_name $file.tgz`" == "$pack" ]]; then
    package_file="$file"
    break
  fi
done

if [ -z "$package_file" ]; then
  echo error: package $pack does not exist
  exit 1
fi 

if [ -d "$TMP/package-$pack" ]; then
  rm -rf $TMP/package-$pack
fi

mkdir $TMP/package-$pack
cd $TMP/package-$pack

for file in `grep -v -e "^PACKAGE NAME:" -e "^UNCOMPRESSED PACKAGE SIZE:"    \
                     -e "^COMPRESSED PACKAGE SIZE:" -e "^PACKAGE LOCATION:"  \
                     -e "^PACKAGE DESCRIPTION:" -e "^$pack:" -e "^FILE LIST:" $package_file`; do

  if [ "$file" != "install" ] && [ "$file" != "install/slack-desc" ] && [ "$file" != "install/doinst,sh" ]; then
    if [ -d /$file ]; then
      mkdir -p $TMP/package-$pack/$file
    elif [ -f /$file ]; then
      cp /$file $TMP/package-$pack/$file
    else
      echo file /$file was not found, please add it manually, exploding and making the package again
    fi
  fi

done

mkdir $TMP/package-$pack/install
grep "^$pack:" $package_file > $TMP/package-$pack/install/slack-desc

package_name="`grep "PACKAGE NAME:" $package_file | awk '{ print $3 }'`"

if [ -f "$ROOT/var/log/scripts/$package_name" ]; then
  cp $ROOT/var/log/scripts/$package_name $TMP/package-$pack/install/doinst.sh
fi

makepkg $package_name.tgz
mv $package_name.tgz $TMP/
echo "done: package rebuilt and stored at $TMP/$package_name.tgz"