summaryrefslogtreecommitdiffstats
path: root/scripts/re-pacman
blob: 4c93524fc9d644eef7ab40abca37cadcfbf468b7 (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
#!/bin/sh
# This script is useful to rebuild a package from existing installed files
# Good for users on slow connections that want to share, say, kdelibs but have
# already cleaned their cache.  Many other useful things as well
#
# TODO check the BACKUP section and change pkgrel if anything has changed

pacinfo ()
{
    [ $# -ne 2 ] && return 1
    #use echo to strip spaces
    echo $(pacman -Qi ${1} | grep "${2}" | cut -d: -f2-)
}

make_pkginfo ()
{
    echo "# Generated by re-pacman 1.0.0"
    echo "# On $(date)"
    echo "pkgname =$(pacinfo ${1} Name)"
    echo "pkgver =$(pacinfo ${1} Version)"
    echo "pkgdesc =$(pacinfo ${1} Description)"
    echo "url =$(pacinfo ${1} URL)"
    echo "builddate =$(pacinfo ${1} 'Build Date')"
    echo "packager =$(pacinfo ${1} Packager)"
    echo "size =$(pacinfo ${1} Size)"
    echo "arch =$(pacinfo ${1} Architecture)"
    deps=$(pacinfo ${1} 'Depends On')
    for d in ${deps}; do
        echo "depend = ${d}"
    done
}

if [ $# -ne 1 ]; then
    echo "usage: re-pacman <installed package name>"
    exit 1
fi

ver=$(pacinfo ${1} Version)
if [ "x${ver}" = "x" ]; then
    echo "Package '${1}' not found, aborting."
    exit 1
fi

echo ":: Cleaning up old files"
rm -f .PKGINFO .FILELIST "${1}-${ver}.pkg.tar.gz"

echo ":: Building PKGINFO"
make_pkginfo ${1} > .PKGINFO
echo ":: Building FILELIST"
pacman -Ql ${1} | cut -d' ' -f2- > .FILELIST

flist=".PKGINFO .FILELIST"
flist="${flist} $(pacman -Ql ${1} | sed 's|\w* \(.*\)|/\1|g' | grep -v '/$')"

echo ":: Building final package tarball"
echo ${flist} | tr ' ' '\n' | tar czf "${1}-${ver}.pkg.tar.gz" -T - 2>/dev/null

rm -f .PKGINFO .FILELIST
echo ":: Package '${1}-${ver}.pkg.tar.gz' is now ready for installation"