forked from archhaskell/habs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeahpkg
executable file
·166 lines (139 loc) · 4.28 KB
/
makeahpkg
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#! /bin/bash
set -eu
##################################################
# some useful stuff
ALL_OFF="$(tput sgr0)"
BOLD="$(tput bold)"
BLUE="${BOLD}$(tput setaf 4)"
GREEN="${BOLD}$(tput setaf 2)"
RED="${BOLD}$(tput setaf 1)"
YELLOW="${BOLD}$(tput setaf 3)"
msg() {
local msg=$1; shift
printf "${GREEN}***${ALL_OFF}${BOLD} ${msg}${ALL_OFF}\n" $@ >&2
}
error() {
local msg=$1; shift
printf "${RED}*** ERROR:${ALL_OFF}${BOLD} ${msg}${ALL_OFF}\n" $@ >&2
}
die() {
[ -n "${1}" ] && error ${1}
exit 1
}
##################################################
# default values
arch=$(uname -m)
chrootdir=.
pristine_chrootdir=root
build_chrootdir=build
habs_dir=.
clean_build_first=0
update_pristine_first=0
usage() {
cat << EOF
Usage: makeahpkg [options] -- [packages]
Run this script in your HABS dir to build the named packages inside a
chroot.
The chroot dir consists of two dirs, a pristine chroot (root), and a build
chroot (build). This script handles both of them.
Options:
-h This help
-c Clean the build chroot before building
-x Update the pristine chroot first (implies -c)
-l <dir> Location of chroot (default .)
-a <arch> Architecture to build for i686 or x86_64 (default is local arch)
-b <dir> Location of your HABS dir (default .)
EOF
}
buildpkg() {
eval "$(grep '^pkg\(rel\|ver\)=' PKGBUILD)"
if [[ -f ${pkg}-${pkgver}-${pkgrel}-${arch}.pkg.tar.xz ]]; then
sudo mkdir -p ${CHROOT_BUILDDIR}/repo
sudo cp ${pkg}-${pkgver}-${pkgrel}-${arch}.pkg.tar.xz \
${CHROOT_BUILDDIR}/repo
(cd ${CHROOT_BUILDDIR}/repo; sudo repo-add repo.db.tar.gz \
${pkg}-${pkgver}-${pkgrel}-${arch}.pkg.tar.xz)
msg "Skipping build in $PWD"
else
msg "Building in $PWD"
sudo setarch ${arch} makechrootpkg -u -d -l ${build_chrootdir} -r ${CHROOT_DIR} -- -i
fi
}
while getopts hcxa:l:b: opt; do
case "${opt}" in
h) usage; exit 0;;
c) clean_build_first=1;;
x) update_pristine_first=1;;
a) arch=${OPTARG};;
l) chrootdir="${OPTARG}";;
b) habs_dir="${OPTARG}";;
esac
done
shift $((OPTIND - 1))
CHROOT_DIR=$(readlink -f ${chrootdir}/${arch}-chroot)
CHROOT_ROOTDIR=${CHROOT_DIR}/${pristine_chrootdir}
CHROOT_BUILDDIR=${CHROOT_DIR}/${build_chrootdir}
if [ ! -d ${CHROOT_ROOTDIR} ]; then
msg "Creating the pristine chroot ${CHROOT_DIR} ..."
mkdir -p "${CHROOT_DIR}" || die "Couldn't create ${CHROOT_DIR}"
pacman_conf=$(mktemp "/tmp/pacman-habs.XXXXXXXX.conf")
trap 'rm -f "${pacman_conf}"' 0
cat > "${pacman_conf}" << EOF
[options]
HoldPkg = pacman libc
SyncFirst = pacman
Architecture = auto
SigLevel = Never
#[repo]
#Server = file:///repo
[haskell]
Server = http://xsounds.org/~haskell/\$arch
[core]
Include = /etc/pacman.d/mirrorlist
Server = http://mirrors.kernel.org/archlinux/\$repo/os/\$arch
[extra]
Include = /etc/pacman.d/mirrorlist
Server = http://mirrors.kernel.org/archlinux/\$repo/os/\$arch
[community]
Include = /etc/pacman.d/mirrorlist
Server = http://mirrors.kernel.org/archlinux/\$repo/os/\$arch
EOF
sudo setarch ${arch} mkarchroot -f -C ${pacman_conf} \
-M /usr/share/devtools/makepkg-${arch}.conf ${CHROOT_ROOTDIR} \
base base-devel curl \
sudo \
ghc-haddock ghc
# fix up the local repo
sudo mkdir ${CHROOT_ROOTDIR}/repo
sudo touch ${CHROOT_ROOTDIR}/repo/repo.db
sudo sed -i.org -e 's/^#\(.*\)/\1/' ${CHROOT_ROOTDIR}/etc/pacman.conf
# no point in updating the newly built pristine
update_pristine_first=0
msg "Done"
fi
if [[ "${update_pristine_first}" == "1" ]]; then
msg "Updating the the pristine chroot (in 5 sec)..."
sleep 5
msg "starting..."
sudo setarch ${arch} mkarchroot -u ${CHROOT_ROOTDIR}
clean_build_first=1
msg " Done"
fi
if [[ "${clean_build_first}" == "1" ]]; then
msg "Cleaning up the build chroot (in 5 sec)..."
sleep 5
msg "starting..."
sudo rsync -a --delete -q -W -x "${CHROOT_ROOTDIR}/" "${CHROOT_BUILDDIR}"
msg " Done"
fi
for pkg0 in $@; do
pkg1=${pkg0,,}
[ -d ${habs_dir}/${pkg1} ] && pkg=${pkg1}
[ -d ${habs_dir}/haskell-${pkg1} ] && pkg=haskell-${pkg1}
if [[ "x${pkg}" != "x" ]]; then
(cd ${habs_dir}/$pkg; buildpkg )
else
die "No such package: $pkg0"
fi
pkg=
done