xref: /freebsd/release/scripts/pkg-stage.sh (revision 94e44a074e5212cc3459e360a9de55500f7c41d0)
1#!/bin/sh
2#
3#
4
5set -e
6
7unset NO_ROOT
8
9export ASSUME_ALWAYS_YES="YES"
10export PKG_DBDIR="/tmp/pkg"
11export PERMISSIVE="YES"
12export REPO_AUTOUPDATE="NO"
13export ROOTDIR="$PWD/dvd"
14export PORTSDIR="${PORTSDIR:-/usr/ports}"
15
16_DVD_PACKAGES="
17devel/git@lite
18misc/freebsd-doc-all
19net/mpd5
20net/rsync
21net/wifi-firmware-kmod@release
22ports-mgmt/pkg
23shells/bash
24shells/zsh
25security/sudo@default
26sysutils/screen
27sysutils/seatd
28sysutils/tmux
29www/firefox
30www/links
31x11/gnome
32x11/kde
33x11/sddm
34x11/xorg
35x11-wm/sway
36"
37
38# If NOPORTS is set for the release, do not attempt to build pkg(8).
39if [ ! -f ${PORTSDIR}/Makefile ]; then
40	echo "*** ${PORTSDIR} is missing!    ***"
41	echo "*** Skipping pkg-stage.sh     ***"
42	echo "*** Unset NOPORTS to fix this ***"
43	exit 0
44fi
45
46usage()
47{
48	echo "usage: $0 [-N]"
49	exit 0
50}
51
52while getopts N opt; do
53	case "$opt" in
54	N)	NO_ROOT=1 ;;
55	*)	usage ;;
56	esac
57done
58
59PKG_ARGS="-d --rootdir ${ROOTDIR}"
60if [ $NO_ROOT ]; then
61	PKG_ARGS="$PKG_ARGS -o INSTALL_AS_USER=1"
62fi
63PKGCMD="/usr/sbin/pkg ${PKG_ARGS}"
64
65if [ ! -x /usr/local/sbin/pkg ]; then
66	/etc/rc.d/ldconfig restart
67	/usr/bin/make -C ${PORTSDIR}/ports-mgmt/pkg install clean
68fi
69
70export PKG_ABI=$(pkg --rootdir ${ROOTDIR} config ABI)
71export PKG_ALTABI=$(pkg --rootdir ${ROOTDIR} config ALTABI 2>/dev/null)
72export PKG_REPODIR="packages/${PKG_ABI}"
73
74/bin/mkdir -p ${ROOTDIR}/${PKG_REPODIR}
75if [ -n "${PKG_ALTABI}" ]; then
76	ln -s ${PKG_ABI} ${ROOTDIR}/packages/${PKG_ALTABI}
77fi
78
79# Ensure the ports listed in _DVD_PACKAGES exist to sanitize the
80# final list.
81for _P in ${_DVD_PACKAGES}; do
82	if [ -d "${PORTSDIR}/${_P%%@*}" ]; then
83		DVD_PACKAGES="${DVD_PACKAGES} ${_P}"
84	else
85		echo "*** Skipping nonexistent port: ${_P%%@*}"
86	fi
87done
88
89# Make sure the package list is not empty.
90if [ -z "${DVD_PACKAGES}" ]; then
91	echo "*** The package list is empty."
92	echo "*** Something is very wrong."
93	# Exit '0' so the rest of the build process continues
94	# so other issues (if any) can be addressed as well.
95	exit 0
96fi
97
98# Print pkg(8) information to make debugging easier.
99${PKGCMD} -vv
100${PKGCMD} update -f
101${PKGCMD} fetch -o ${PKG_REPODIR} -d ${DVD_PACKAGES}
102
103# Create the 'Latest/pkg.pkg' symlink so 'pkg bootstrap' works
104# using the on-disc packages.
105export LATEST_DIR="${ROOTDIR}/${PKG_REPODIR}/Latest"
106mkdir -p ${LATEST_DIR}
107ln -s ../All/$(${PKGCMD} rquery %n-%v pkg).pkg ${LATEST_DIR}/pkg.pkg
108
109${PKGCMD} repo ${PKG_REPODIR}
110
111if [ $NO_ROOT ]; then
112	mtree -c -p $ROOTDIR | mtree -C -k type,mode,link,size | \
113	    grep '^./packages/' >> $ROOTDIR/METALOG
114fi
115
116# Always exit '0', even if pkg(8) complains about conflicts.
117exit 0
118