summaryrefslogtreecommitdiff
path: root/convert-to-any
blob: b8d298c1fa2f4356077f44d5ecb224b64a7b1385 (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
#!/bin/bash
# Converts an existing package into an
# architecture-independent package and updates
# the repositories accordingly.

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

. "$(dirname $0)/db-functions"
[ "$UID" = "" ] && UID=$(uid)

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

repo=$(echo $1 | sed "s#\(.*\)/.*#\1#g")
pkg=$(echo $1 | sed "s#.*/\(.*\)#\1#g")

if [ -f "$(dirname $0)/config" ]; then
    . "$(dirname $0)/config"
else
    TMPDIR=/srv/tmp
    FTP_BASE=/srv/ftp
fi

if [ -f /etc/makepkg.conf ]; then
    . /etc/makepkg.conf
else
    echo "W: /etc/makepkg.conf does not exist."
    DB_COMPRESSION=gz
    PKGEXT=".pkg.tar.gz"
fi

repo_lock $repo any
WORKDIR="$TMPDIR/convert-to-any.$pkg.$UID"
ftppath="$FTP_BASE/$repo/os"

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

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

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

# Enter the temporary build directory
# and convert the i686 package into an
# architecture-independent package.
mkdir -p "$WORKDIR/build"
pushd "$WORKDIR/build" >/dev/null

oldpkgname=$ftppath/i686/$pkg*
if [ -f "$oldpkgname" ]; then
    cp "$oldpkgname" .
else
    die "E: Package $oldpkgname not found in $ftppath/i686"
fi

for architecture in i686 x86_64; do
    if [ -f "$ftppath/$architecture/$repo.db.tar.$DB_COMPRESSION" ]; then
        cp $ftppath/$architecture/$repo.db.tar.$DB_COMPRESSION \
        $repo-$architecture.db.tar.$DB_COMPRESSION
    else
        touch $repo-$architecture.db.tar.$DB_COMPRESSION
    fi
done

if [ ! -d "$ftppath/any" ]; then mkdir -p "$ftppath/any"; fi

# Conversion of i686 package into "any" package.
echo -n "Extracting $pkg..."
mkdir -p package
tar zxf $pkg*i686$PKGEXT -C package
echo " done."

sed -i "s/arch = i686/arch = any/g" package/.PKGINFO
newpkgname=$(ls $pkg*i686$PKGEXT | sed "s/i686/any/g")
pushd package >/dev/null
tar czf "$newpkgname" * .PKGINFO
popd >/dev/null
mv "package/$newpkgname" .
echo "Created $newpkgname."

# New package is ready, move it into place and update db.
mv "$newpkgname" "$ftppath/any/"
for architecture in i686 x86_64; do
    #       rm -f $ftppath/$architecture/$pkg*$PKGEXT
    ln -s "$ftppath/any/$newpkgname" "$ftppath/$architecture/$newpkgname"
    repo-remove -q $repo-$architecture.db.tar.$DB_COMPRESSION $pkg
    repo-add -q $repo-$architecture.db.tar.$DB_COMPRESSION $newpkgname
    mv $repo-$architecture.db.tar.$DB_COMPRESSION "$ftppath/os/$architecture"
    echo "Updated $repo-$architecture for $pkg."
done

echo -n "Cleaning up..."
popd >/dev/null
cleanup
echo " done."