summaryrefslogtreecommitdiff
path: root/convert-to-any
blob: 862c60b9c3281e602b0143792e79300b4615111d (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
#!/bin/bash
#
# Converts an existing architecture-independent package
# for i686 or x86_64 into a package with "arch = any"
#

# -- Abhishek Dasgupta <abhidg@gmail.com>

[ "$UID" = "" ] && UID=$(uid)
OUTDIR="$(pwd)"
WORKDIR="/tmp/convert-to-any.$UID"

if [ $# -ne 1 ]; then
    echo "Syntax: $(basename $0) <package-file>"
    exit 1
fi

if [ -f /etc/makepkg.conf ]; then
    . /etc/makepkg.conf
else
    echo "E: /etc/makepkg.conf does not exist."
    exit 1
fi

cleanup() {
    trap '' 0 2
    rm -rf "$WORKDIR"
    [ "$1" ] && exit $1
}

ctrl_c() {
    echo "Interrupted" >&2
    cleanup 0
}

die() {
    echo "$*" >&2
    cleanup 1
}

mkdir -p "$WORKDIR/build"

oldpkgname="$1"

if [ -z "$oldpkgname" ]; then
    die "convert-to-any: which package to convert?"
fi

pkg="$(basename $oldpkgname)"
newpkgname=$(echo $pkg | sed "s/-\(i686\|x86_64\)$PKGEXT/-any$PKGEXT/")

if ! cp "$oldpkgname" "$WORKDIR/build/$pkg"; then
    die "convert-to-any: failed to copy package to $WORKDIR"
fi
pushd "$WORKDIR/build" >/dev/null

# Conversion of i686 package into "any" package.
mkdir -p package
if ! fakeroot bsdtar xf "$pkg" -C package; then
	die "convert-to-any: error in extracting $oldpkgname"
fi

sed -i "s/arch = \(i686\|x86_64\)/arch = any/g" package/.PKGINFO
pushd package >/dev/null
fakeroot bsdtar cf "$OUTDIR/$newpkgname" .PKGINFO *
popd >/dev/null

popd >/dev/null
cleanup