]> CyberLeo.Net >> Repos - CDN/Mosi.git/blob - script/makepkg
script/lib/ansi: add additional ANSI style codes
[CDN/Mosi.git] / script / makepkg
1 #!/bin/sh
2
3 # == Objective ==
4 # Create a virgin chroot
5 # Copy in build (make.conf) and port (/var/db/ports) configuration
6 # Compute build/runtime dependencies for leaf port
7 # Install build/runtime dependency packages, if they exist from a previous leaf port build
8 # Build a single leaf port
9 # Create packages for leaf port and its runtime dependencies
10 # Create a separate set of packages for its build-time dependencies, to use for later leaf port builds
11
12 ROOT="$(realpath "$(dirname "${0}")")"
13 TARGET=amd64
14 CONFIG=SS4200
15
16 meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; }
17 omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; }
18 wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; }
19
20 tgtdir="${TARGET}/${CONFIG}"
21 build="${ROOT}/port/root" # Location of build environment
22 date="$(date +%Y%m%d)"
23 srctree="${ROOT}/${tgtdir}" # Virgin build env will be copied from here
24
25 # Prepare a build chroot
26 prepare() {
27   mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue"
28   
29   # Put cleanup trap here so that an abort during prepare properly cleans up
30   trap "cleanup" exit hup int term kill
31
32   meh "Preparing build environment"
33   mkdir -p "${build}" || wtf
34   cd "${srctree}"; find . | cpio -p "${build}" || wtf
35   # Hold packages for build deps
36   mkdir -p "${build}/pkg/build" || wtf
37   # Hold packages for runtime deps
38   mkdir -p "${build}/pkg/run" || wtf
39
40   meh "Mounting chroot directories" || wtf
41   mkdir -p "${build}/usr/ports" || wtf
42   mkdir -p "${build}/usr/obj" || wtf
43   mount -t devfs devfs "${build}/dev" || wtf
44   mount -t nullfs -r /usr/src "${build}/usr/src" || wtf # Just in case a port needs kernel sources
45   mount -t nullfs -r /usr/ports "${build}/usr/ports" || wtf
46
47   if [ -d "${world}/config" ]
48   then
49     meh "Installing build-time configuration"
50     # Install make.conf
51     [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/" || wtf
52     # Install port options files
53     [ -d "${world}/config/ports" ] && ( cd "${world}/config/ports"; find . -type d -o -type f -name 'options' | cpio -p "${build}/var/db/ports/" ) || wtf
54   fi
55 }
56
57 # Evaluate a bit of code within the ${build} chroot
58 # If ${chroot_env} is set, replace environment with it before chrooting
59 chroot_eval() {
60   [ "${chroot_env}" ] && env="env -i ${chroot_env}"
61   ${env} chroot "${build}" /bin/sh
62 }
63
64 # Clean up and remove the build chroot
65 cleanup() {
66   meh "Cleaning up"
67   umount -f "${build}/usr/ports"
68   umount -f "${build}/usr/src"
69   umount -f "${build}/dev"
70   mount |grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
71   chflags -R noschg "${build}"
72   rm -Rf "${build}"
73 }
74
75 prepare
76 chroot_eval
77 cleanup