File: repack.sh

package info (click to toggle)
diet 2.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 38,140 kB
  • sloc: ansic: 65,575; cpp: 58,570; xml: 365; sh: 83; makefile: 29
file content (65 lines) | stat: -rwxr-xr-x 1,653 bytes parent folder | download
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
#! /bin/sh
# repackage upstream source to exclude unreleased embedded library boost/process
# should be called "repack.sh <original_sources> [<output_directory>]

## usage message
usage() {
    echo "Usage: $1 <original_sources> [<ouput_directory>]"
    echo "  repack upstream sources into debian compliant tarball"
}

## check that we are in working directory 
check_path() {
    if [ -d debian ]; then
        return
    else
        echo "please move to working directory (uncompressed sources)"
        echo "current path: $(pwd)"
        exit 1
    fi
}

main() {        
    check_path
    NAME=$(dpkg-parsechangelog | awk '/Source:/ { print $2 }')
    ORIG=$1
    if [ $2 ]; then
        OUTPUT=$(readlink -f $2) # canonicalize output path
    fi
    # extract version from upstream tarball
    VERSION=$(echo $ORIG | sed 's/.*diet-\([0-9.]\+\).tgz/\1/')

    # .0 upstream release sometimes don't get patch version in tarball name
    if [ ${#VERSION} -le 3 ]; then
        VERSION="$VERSION.0"
    fi

    # make sure that unpacked file will be cleansed
    DIR=$(mktemp -d tmpRepackXXXXXX)
    trap "rm -rf $DIR" QUIT INT EXIT
    DIR_DEL="$DIR/diet-$VERSION/src/Testing/third-party"
    
    # unpack upstream tarball
    tar xzf $ORIG -C $DIR

    CURRENT_DIR=$(pwd)
    TARGET="$CURRENT_DIR/diet_$VERSION.orig.tar.gz"
    
    cd $DIR
    # files to remove
    rm -rf $DIR_DEL
    # recompress tarball
    tar czvf $TARGET "diet-$VERSION"
    if [ -e $OUTPUT ]; then
        mv $TARGET $OUTPUT
    fi
    cd $CURRENT_DIR
}

# we should have at least one argument (upstream tarball)
if [ $# -ge 1 ]; then
    main $@
else
    usage $0
fi;