/
pkg-builder
executable file
·148 lines (118 loc) · 5.09 KB
/
pkg-builder
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2008 Francesco Piccinno
#
# Author: Francesco Piccinno <stack.box@gmail.com>
#
# This program 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
# (at your option) any later version.
#
# This program 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
import os
import os.path
import sys
import shutil
import glob
from optparse import OptionParser
from pylibs.utils import ConsoleP
from pylibs.pkgbuild import PkgBuild
SKEL = """# This file is autogenerated by pkg-builder
DLAGENTS=('ftp::/usr/bin/wget -c --passive-ftp -t 3 --waitretry=3 -O %o %u'
'http::/usr/bin/wget -c -t 3 --waitretry=3 -O %o %u'
'https::/usr/bin/wget -c -t 3 --waitretry=3 --no-check-certificate -O %o %u'
'rsync::/usr/bin/rsync -z %u %o'
'scp::/usr/bin/scp -C %u %o')
CARCH="i686"
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=i686 -mtune=generic -O2 -pipe"
CXXFLAGS="-march=i686 -mtune=generic -O2 -pipe"
MAKEFLAGS="-j%NCPU%"
BUILDENV=(fakeroot !distcc color !ccache !xdelta)
OPTIONS=(strip docs libtool emptydirs zipman)
INTEGRITY_CHECK=(md5)
DOC_DIRS=(usr/{,share/}{info,doc,gtk-doc} opt/*/{info,doc,gtk-doc})
STRIP_DIRS=(bin lib sbin usr/{bin,lib,sbin,local/{bin,lib,sbin}} opt/*/{bin,lib,sbin})
PKGDEST="%PKGDEST%"
SRCDEST="%SRCDEST%"
PACKAGER="Francesco Piccinno <stack.box@gmail.com>"
BUILDSCRIPT='PKGBUILD'
PKGEXT='.pkg.tar.gz'
SRCEXT='.src.tar.gz'
DB_COMPRESSION='gz'
DB_CHECKSUMS=(md5)
# vim: set ft=sh ts=2 sw=2 et:
"""
OUTFILE = os.path.join(os.getenv("HOME", "/root"), ".makepkg.conf")
class Builder(ConsoleP):
def __init__(self, src, tmp, dst):
self.src, self.tmp, self.dst = os.path.abspath(src), \
os.path.abspath(tmp), \
os.path.abspath(dst)
# We have to create a makepkg.conf file that contains
# proper CFLAGS and PKGDEST, SRCDEST variable (dst, tmp)
# and place under ~/.makepkg.conf
mkp = SKEL.replace("%NCPU%", "3") \
.replace("%PKGDEST%", self.dst) \
.replace("%SRCDEST%", self.tmp)
f = open(OUTFILE, "w+")
f.write(mkp)
f.close()
def build_all(self, verbose):
category = None
for root, dirs, files in os.walk(self.src):
# We could also generate a PKGBUILD on the fly by
# creating a group-overlay file that adds common line
# to the various PKGBUILD.template (like groups, headers)
if os.path.isfile(os.path.join(self.src, root, "group-overlay")):
# Assume a category
category = os.path.basename(root)
self.info("Building category %s" % category)
for dir in (dir for dir in dirs if os.path.isfile(
os.path.join(self.src, root, dir, "PKGBUILD"))):
self.build_pkg(os.path.join(self.src, root, dir), category, verbose)
category = None
def create_repo(self):
os.chdir(self.dst)
os.system("repo-add archpwn.db.tar.gz %s" % " ".join(glob.glob("*.pkg.tar.gz")))
def build_pkg(self, dir_path, category, verbose=True):
dir = os.path.basename(dir_path)
try:
outfile = PkgBuild(os.path.join(dir_path, "PKGBUILD")).get_output()
except:
self.error("Problem while building %s (PKGBUILD malformed)" % dir)
return
if os.path.isfile(os.path.join(self.dst, outfile)):
self.info("Package %s already built" % dir)
return
self.info("Building package %s" % dir)
os.chdir(dir_path)
ret = os.system("makepkg -s --asroot%s" % ((not verbose) and (" > /dev/null") or ""))
if ret != 0:
self.info("Error building %s (Error status: %d)" % (dir, ret))
# Cleaning up the dir by removing 'pkg' and 'src' directories
shutil.rmtree("src", True)
shutil.rmtree("pkg", True)
if __name__ == "__main__":
parser = OptionParser(usage="%s [options] <repodir> <srcdest> <pkgdest>" % sys.argv[0])
parser.add_option("-f", "--file", dest="filename",
help="write report to FILE", metavar="FILE")
parser.add_option("-q", "--quiet",
action="store_true", dest="quiet", default=False,
help="don't print status messages to stdout")
(options, args) = parser.parse_args()
if len(args) != 3:
parser.print_help()
sys.exit(-1)
builder = Builder(args[0], args[1], args[2])
builder.build_all(not options.quiet)
builder.create_repo()
os.remove(OUTFILE)